<template>
<el-container>
	<el-header>
		<div class="left-panel">
			<el-input v-model="search.keyword" placeholder="关键词" style="width:150px; margin-right: 10px;" clearable></el-input>
			<el-button-group style="margin-left: 10px;">
				<el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
			</el-button-group>
		</div>
		<div class="right-panel">
			<el-button-group>
				<el-button type="danger" icon="el-icon-plus" @click="add">添加</el-button>
			</el-button-group>
		</div>
	</el-header>
	<el-main class="nopadding">
		<scTable tableName="member" ref="table" :apiObj="list.apiObj" :column="list.column" row-key="id" :params="search" @selection-change="selectionChange" border stripe size="small">
			<el-table-column type="selection" width="50"></el-table-column>
			<template #level="scope">
				{{scope.row.level.classname}}
			</template>
			<el-table-column label="操作" fixed="right" align="center" width="160">
				<template #default="scope">
					<el-button-group>
						<el-button type="primary" @click="store_show(scope.row, scope.$index)" v-if="scope.row.status == 1">商家收款码</el-button>
						<el-button type="warning" @click="table_edit(scope.row, scope.$index)" v-if="scope.row.status == 1">编辑</el-button>
						<el-button type="success" @click="store_audit(scope.row)" v-if="scope.row.status != 1">审核</el-button>
					</el-button-group>
				</template>
			</el-table-column>
		</scTable>
	</el-main>
	<save-box v-if="dialog.save" ref="saveBox" @success="upsearch" @closed="dialog.save=false"></save-box>
	<push v-if="dialog.push" ref="pushBox" @success="upsearch" @closed="dialog.push=false" />
	<show v-if="dialog.show" ref="showBox" @closed="dialog.show=false" />
	<goods v-if="dialog.goods" ref="goodsBox" @success="upsearch" @closed="dialog.goods=false" />
	<copy v-if="dialog.copy" ref="copyBox" @success="upsearch" @closed="dialog.copy=false" />
</el-container>
</template>

<script>
import saveBox from './save.vue'
import push from './push.vue'
import show from './show.vue'
import goods from './goods.vue'
import copy from './copy.vue'

export default{
	name: 'store.lists',
	components:{
		saveBox,
		push,
		show,
		goods,
		copy
	},
	data(){
		return {
			dialog: {search: false, push: false, save: false,show: false, goods: false},

			list: {
				apiObj: this.$API.store.lists.list,
				column: [
					{prop: 'id', label: 'ID', width: 80},
					{prop: 'title', label: '店名', width: 120},
					{prop: 'member_id', label: '申请人UID', width: 100},
					{prop: 'mobile', label: '手机号码', width: 120},
					{prop: 'province', label: '省份', width: 120},
					{prop: 'city', label: '市级', width: 120},
					{prop: 'area', label: '区县', width: 120},
					{prop: 'address', label: '详细地址', width: 120, showOverflowTooltip: true},
					{prop: 'created_at', label: '添加时间', width: 140},
					{prop: 'updated_at', label: '更新时间', width: 140},
				],
			},
			selection: [],
			search: {},
		}
	},
	methods:{
		upsearch(){
			this.$refs.table.reload(this.search);
		},
		moreUpsearch(search){
			this.search = search;
			this.upsearch();
		},
		moreSearch(){
			this.dialog.search = true
			this.$nextTick(() => {
				this.$refs.searchBox.open().setData(this.search)
			})
		},
		//表格选择后回调事件
		selectionChange(selection){
			this.selection = selection;
		},
		store_show(row){
			this.dialog.show = true
			this.$nextTick(() => {
				this.$refs.showBox.open(row.id)
			})
		},
		table_show(row){
			this.dialog.detail = true
			this.$nextTick(() => {
				this.$refs.detailBox.open().setData(row)
			})
		},
		add(){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveBox.open()
			})
		},
		table_edit(row){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveBox.open('edit').setData(row)
			})
		},
		store_audit(row){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveBox.open('audit').setData(row)
			})
		},
		store_push(row){
			this.dialog.push = true
			this.$nextTick(() => {
				this.$refs.pushBox.open().setData(row)
			})
		},
		goods_list(row){
			this.dialog.goods = true
			this.$nextTick(() => {
				this.$refs.goodsBox.open().setData(row)
			})
		},
		copy_store(row){
			this.dialog.copy = true
			this.$nextTick(() => {
				this.$refs.copyBox.open().setData(row)
			})
		},
		store_diy(row){
			this.$message.warning("功能开发中……")
		},
		async table_del(row){
			var reqData = {id: row.id}
			var res = await this.$API.waybill.lists.delete.post(reqData);
			if(res.code == 1){
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.upsearch()
				this.$message.success("删除成功")
			}else{
				this.$alert(res.message, "提示", {type: 'error'})
			}
		}
	}
}
</script>
