<template>
	<view>
		<view class="hm-p-b-100">
			<view  v-if="list.data.length">
				<view class="hm-p-lr-20">
					<u-alert type="error" description="店员登录账号和初始密码为手机号" :closable="true" :center="true"></u-alert>
				</view>
				<view v-for="(item, index) in list.data" :key="index" class="table-box">
					<view class="hm-text-center hm-font-b hm-font-30 hm-p-b-20 hm-border-b hm-col-main">{{item.real_name}}</view>
					<view class="hm-p-t-20"><text class="hm-col-content">身份：</text>{{item.status.text}}</view>
					<view><text class="hm-col-content">电话：</text>{{item.phone}}</view>
					<view class="hm-p-t-20 hm-text-right hm-border-t hm-m-t-20">
						<view class="hm-dis-block-inline hm-m-l-20"
							@click="goTo('user/clerk/edit?id='+item.shop_clerk_id)">
							<view class="hm-dis-block-inline"><u-icon name="edit-pen"></u-icon></view>编辑
						</view>
						<view class="hm-dis-block-inline hm-m-l-20" @click="del(item.shop_clerk_id)">
							<view class="hm-dis-block-inline"><u-icon name="trash"></u-icon></view>删除
						</view>
					</view>
				</view>
			</view>
			<view v-else class="hm">
				<img :src="applet.domain + '/addons/food/img/empty/data.png'" />
				<view class="text">暂无店员数据</view>
			</view>
			<!-- 技术支持 -->
			<view class="hm">
				{{applet.copyright}} <text class="v">V{{applet.version}}</text>
			</view>
		</view>
		<view class="hm-footer-fixed">
			<view class="hm-p-lr-b25 hm-w-b100">
				<u-button @click="goTo('user/clerk/add')" type="success" text="添加店员"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	let App = getApp();

	export default {
		data() {
			return {
				list: {data:[]},
				applet: {}
			};
		},

		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			let _this = this;
			_this.applet = App.getApplet();
		},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			let _this = this;
			_this.getClerk();
		},
		methods: {
			/**
			 * 获取配置数据
			 */
			getClerk: function() {
				let _this = this;
				App._get('user.clerk/lists', {}, function(result) {
					_this.setData(result.data);
				});
			},

			/**
			 * 删除
			 */
			del: function(shop_clerk_id) {
				let _this = this;
				uni.showModal({
					title: "提示",
					content: "确定要删除？",
					success: function(o) {
						if (o.confirm) {
							App._get('user.clerk/delete', {
								id:shop_clerk_id
							}, function(result) {
								App.showSuccess(result.msg, function() {
									_this.getClerk();
								});
							});
						}
					}
				});
			},

			/**
			 * 跳转
			 */
			goTo: function(url) {
				App.goTo(url);
			}
		}
	};
</script>
<style>
	.table-box {
		padding: 20rpx;
		width: 41%;
		margin: 20rpx 0rpx 0rpx 20rpx;
		border-radius: 10rpx;
		background-color: #fff;
		color: #999;
		font-size: 26rpx;
		box-shadow: 6rpx 6rpx 8rpx rgba(26, 26, 26, 0.2);
		display: inline-block;
	}
</style>
