<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 hidePagination>
			<el-table-column type="selection" width="50"></el-table-column>
			<template #member="scope">
				<div style="display: flex; gap: 8px; align-items: center;">
					<el-image :src="scope.row.member?.avatar" style="width: 40px; height: 40px" />
					<div style="display: flex; flex-direction: column;">
						<span>{{ scope.row.member?.nickname }}</span>
						<span>{{ scope.row.member?.username }}</span>
					</div>
				</div>
			</template>
			<template #store="scope">
				<div style="display: flex; gap: 8px; align-items: center;">
					<el-image :src="scope.row.store?.logo" style="width: 40px; height: 40px" />
					<div style="display: flex; flex-direction: column;">
						<span>{{ scope.row.store?.title }}</span>
					</div>
				</div>
			</template>
			<template #payment_type="scope">
				<el-tag v-if="scope.row.payment_type == 'miniapp'" type="success">小程序微信支付</el-tag>
				<el-tag v-else-if="scope.row.payment_type == 'alipay'" type="warning">支付宝</el-tag>
			</template>
			<template #payment_status="scope">
				<el-tag :type="status[scope.row.payment_status]?.type">{{status[scope.row.payment_status]?.label}}</el-tag>
			</template>
		</scTable>
	</el-main>
</el-container>
</template>

<script>
export default{
	name: 'store.payment',
	data(){
		return {
			dialog: {search: false, import: false, print: false},
			status: {
				0: {label: '待支付', type: 'info'},
				1: {label: '已支付', type: 'success'}
			},
			list: {
				apiObj: this.$API.store.payment.list,
				column: [
					{prop: 'id', label: 'ID', width: 80},
					{prop: 'order_no', label: '账单号', width: 240},
					{prop: 'store', label: '店铺', width: 240},
					{prop: 'member', label: '购买人', width: 240},
					{prop: 'amount', label: '支付金额', width: 120},
					{prop: 'integral', label: '支付积分', width: 120},
					{prop: 'payment_type', label: '支付方式', width: 120},
					{prop: 'payment_remark', label: '备注', width: 120},
					{prop: 'payment_status', label: '状态', width: 120},
					{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;
		},
		batch_del(){

		},
		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)
			})
		},
		async table_del(row){
			var reqData = {id: row.id}
			var res = await this.$API.store.payment.delete.post(reqData);
			if(res.code == 1){
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.upsearch()
				this.$message.success("删除成功")
			}else{
				this.$alert(res.message, "提示", {type: 'error'})
			}
		}
	}
}
</script>
