<template>
	<div style="width: 100%">
		<Modal v-model="modals" scrollable footer-hide closable title="商品列表" :mask-closable="false" width="700">
			<Form ref="formValidate" :label-width="labelWidth" :label-position="labelPosition" class="tabform"
				@submit.native.prevent>
				<Row :gutter="24" type="flex">
					<Col span="12">
					<FormItem label="关键字：">
						<Input enter-button placeholder="请输入商品名称/编码" element-id="name" v-model="formValidate.key" clearable />
					</FormItem>
					</Col>
					<Col span="4">
					<Button type="primary" icon="ios-search" @click="userSearchs">搜索</Button>
					</Col>
				</Row>
			</Form>
			<!-- <Divider dashed/> -->
			<Table :columns="columns" :data="tabList" ref="table" :loading="loading" no-userFrom-text="暂无数据"
				no-filtered-userFrom-text="暂无筛选结果" class="table" @on-selection-change="change">
				<template slot-scope="{ row, index }" slot="price">
					<span> {{ row.my.price }}</span>
				</template>
				<!-- product_num -->
				<!-- <template slot-scope="{ row, index }" slot="product_num">
					<span> {{ row.product_num }}{{row.unit_name || row.info['unit_name' + (row.unit_type == 0 ? '':(row.unit_type == 1?"_1":"_2"))]}}</span>
				</template> -->
				
				</Table>
			<div class="acea-row row-right page">
				<Page :total="total" :current="formValidate.page" show-elevator show-total @on-change="pageChange"
					:page-size="formValidate.limit" />
			</div>
			<Button type="primary"  @click="ok" style="width: 100%;margin-top:20px;">确认</Button>
		</Modal>
	</div>
</template>

<script>
	import {
		commissionDetailApi,
		extractlistApi
	} from '@/api/finance';
	import {
		getGodownList,
		createGodown,
		getGodownInfo,
		getUserList,
		getOutGoods,
		getOutGoodList
	} from "@/api/erp";
	import {
		mapState
	} from 'vuex';
	export default {
		name: 'commissionDetails',
		data() {
			return {
				chooseGoods:[],
				key: '',
				wid: '',
				my_store_id: '',
				store_id: '',
				type: 0,
				modals: false,
				spinShow: false,
				detailsData: {},
				Ids: 0,
				loading: false,
				formValidate: {
					page: 1, // 当前页
					limit: 10 ,// 每页显示条数
					key: '',
					wid: '',
					my_store_id: '',
					store_id: '',
					type: 0,
				},
				total: 0,
				columns: [{
						type: 'selection',
						width: 60,
						align: 'center'
					},
					{
						title: 'ID',
						key: 'product_id',
						minWidth: 50
					},
					{
						title: '商品名称',
						key: 'product_name',
						minWidth: 200
					},
					{
						title: '单位',
						key: 'unit_name',
						minWidth: 150
					},
					{
						title: '价格',
						slot: 'price',
						minWidth: 330
					}
				],
				tabList: []

			}
		},
		computed: {
			...mapState('admin/layout', [
				'isMobile'
			]),
			labelWidth() {
				return this.isMobile ? undefined : 80;
			},
			labelPosition() {
				return this.isMobile ? 'top' : 'left';
			}
		},
		mounted() {
			// if (this.Ids) {
			//     this.getList();
			// }
			this.chooseGoods = []
		},
		methods: {
			clearChoose() {
				this.chooseGoods = []
				this.tabList = []
				this.$refs.table.selectAll(false);
			},
			change(e) {
				this.chooseGoods = e
			},
			ok() {
				this.modals = false;
				 this.$emit('setGoods',this.chooseGoods);
			},
			// 时间
			onchangeTime(e) {
				this.formValidate.start_time = e[0];
				this.formValidate.end_time = e[1];
			},
			// 详情
			getDetails(id) {
				this.Ids = id;
				this.spinShow = true;
				commissionDetailApi(id).then(async res => {
					if (res.status === 200) {
						let data = res.data
						this.detailsData = data.user_info;
						this.spinShow = false;
					} else {
						this.spinShow = false;
						this.$Message.error(res.msg);
					}
				}).catch(res => {
					this.spinShow = false;
					this.$Message.error(res.msg);
				})
			},
			// 列表
			getList() {
				this.loading = true;
				let qdata = {
					key: this.formValidate.key,
					my_store_id: this.formValidate.store_id,
					store_id: this.formValidate.store_id,
					page: this.formValidate.page,
					limit: this.formValidate.limit
				}
				// if (this.formValidate.type == 1) {
				// 	this.formValidate.wid = ''
				// 	qdata.store_id = this.formValidate.store_id
					
				// } else {
				// 	this.formValidate.store_id = ''
				// 	qdata.wid =  this.formValidate.wid
				// }
				
				getOutGoodList(qdata).then(async res => {
					let data = res.data;
					this.tabList = data.data;
					this.total = data.count;
					this.loading = false;
				}).catch(res => {
					this.loading = false;
					this.$Message.error(res.msg);
				})
			},
			pageChange(index) {
				this.formValidate.page = index
				this.getList();
			},
			// 搜索
			userSearchs() {
				this.formValidate.page = 1;
				this.getList();
			}
		}
	}
</script>

<style lang="less" scoped>
	.table {
		.ivu-table-default {
			overflow-y: auto;
			max-height: 350px;
		}
	}

	.dashboard-workplace {
		&-header {
			&-avatar {
				width: 64px;
				height: 64px;
				border-radius: 50%;
				margin-right: 16px;
				font-weight: 600;
			}

			&-tip {
				width: 82%;
				display: inline-block;
				vertical-align: middle;

				&-title {
					font-size: 13px;
					color: #000000;
					margin-bottom: 12px;
				}

				&-desc {
					&-sp {
						width: 33.33%;
						color: #17233D;
						font-size: 12px;
						display: inline-block;
					}
				}
			}

			&-extra {
				.ivu-col {
					p {
						text-align: right;
					}

					p:first-child {
						span:first-child {
							margin-right: 4px;
						}

						span:last-child {
							color: #808695;
						}
					}

					p:last-child {
						font-size: 22px;
					}
				}
			}
		}
	}
</style>