<template>
	<!-- 营销-积分商品 -->
	<div>
		<Card :bordered="false" dis-hover class="ivu-mt" :padding="0">
			<div class="new_card_pd">
				<!-- 查询条件 -->
				<Form ref="tableFrom" inline :model="tableFrom" :label-width="labelWidth"
					:label-position="labelPosition" @submit.native.prevent>
					<!-- <FormItem label="创建时间：" label-for="user_time">
            <DatePicker
                :editable="false"
                @on-change="onchangeTime"
                :value="timeVal"
                format="yyyy/MM/dd"
                type="datetimerange"
                placement="bottom-start"
                placeholder="自定义时间"
                class="mr20 input-add"
                :options="options"
            ></DatePicker>
          </FormItem> -->
					<!-- <FormItem label="上架状态：">
            <Select
                placeholder="请选择"
                clearable
                class="input-add"
                v-model="tableFrom.is_show"
            >
              <Option value="1">上架</Option>
              <Option value="0">下架</Option>
            </Select>
          </FormItem> -->
		  <FormItem label="门店：">
		  	<Select v-model="tableFrom.store_id" clearable filterable @on-change="userSearchs"
		  		class="input-add">
		  		<Option v-for="item in staffData" :value="item.id" :key="item.id">{{ item.name }}
		  		</Option>
		  	</Select>
		  </FormItem>
		  <FormItem label="创建人：">
		  	<Select v-model="tableFrom.create_uid" clearable filterable @on-change="userSearchs"
		  		class="input-add">
		  		<Option v-for="item in authList" :value="item.id" :key="item.id">{{ item.staff_name }}
		  		</Option>
		  	</Select>
		  </FormItem>
					<!-- <FormItem label="仓位搜索：" label-for="store_name">
						<Input class="input-add mr14" placeholder="请输入仓位名称" v-model="tableFrom.key" />
						<Button type="primary" @click="tableSearchs()">查询</Button>
					</FormItem> -->
					<!-- <Button
            v-auth="['marketing-store_seckill-create']"
            type="primary"
            icon="md-add"
            @click="addMore"
            class="mr10"
            >批量添加积分商品</Button
          > -->
					<!--<Button v-auth="['export-storeSeckill']" class="export" icon="ios-share-outline" @click="exports">导出</Button>-->
				</Form>
			</div>
		</Card>
		<Card :bordered="false" dis-hover class="ivu-mt">
			<!-- 操作 -->
			<Button v-auth="['admin-erp-add_position']" type="primary" @click="add" class="mr10">添加调价单</Button>
			<!-- 积分商品-表格 -->
			<Table :columns="columns1" :data="tableList" :loading="loading" highlight-row no-userFrom-text="暂无数据"
				no-filtered-userFrom-text="暂无筛选结果" class="ivu-mt">
				<template slot-scope="{ row, index }" slot="cuser">
					<div>{{row.cuser.staff_name}}</div>
					<!-- <div>名称：{{row.cuser.title}}</div>
					<div>ID:{{row.cuser.id}}</div>
					<div>手机：{{row.cuser.phone}}</div> -->
				</template>
				<template slot-scope="{ row, index }" slot="store">
					<div>{{row.store.name}}</div>
					<!-- <div>名称：{{row.store.name}}</div>
					<div>ID:{{row.store.id}}</div>
					<div>手机：{{row.store.phone}}</div> -->
				</template>
				<template slot-scope="{ row, index }" slot="type">
					<div>{{row.type == 1?"比例调整": "价格调整"}}</div>
				</template>
				<template slot-scope="{ row, index }" slot="add_time">
					<div>{{row.add_time|formatDate}}</div>
				</template>
				<template slot-scope="{ row, index }" slot="body">
					<div v-for="(item,index) in row.body" class="info">
						<div>名称:{{item.product_name}}</div>
						<!-- <div>ID:{{item.product_id}}</div> -->
						<div v-if="item.ot_price">调价前价格:{{item.ot_price*1}}</div>
						<div v-if="item.price">调价后价格:{{item.price*1}}</div>
						<div v-if="item.scale">比例:{{item.scale}}%</div>
					</div>
				</template>
				<template slot-scope="{ row, index }" slot="status">
					<Tag color="default" v-if="row.status == 0">待审核</Tag>
					<Tag color="primary" v-if="row.status == 1">通过</Tag>
					<Tag color="error" v-if="row.status == -1">拒绝</Tag>
				</template>
				<template slot-scope="{ row, index }" slot="action">
					<a v-if="row.status == 0" @click="edit(row)">审核</a>
				</template>
			</Table>
			<div class="acea-row row-right page">
				<Page :total="total" :current="tableFrom.page" show-elevator show-total @on-change="pageChange"
					:page-size="tableFrom.limit" />
			</div>
		</Card>
	</div>
</template>

<script>
	import {
		mapState
	} from "vuex";
	import {
		integralProductListApi,
		integralIsShowApi,
		storeSeckillApi,
	} from "@/api/marketing";
	import {
		getBatchList,
		getUserInfo,
		getUserList,
		getAdjustList
	} from "@/api/erp";
	import {staffListInfo} from '@/api/store'
	import {
		formatDate
	} from "@/utils/validate";
	import timeOptions from "@/utils/timeOptions";
	import Setting from "@/setting";
	export default {
		name: "godownList",
		filters: {
			formatDate(time) {
				if (time !== 0) {
					let date = new Date(time * 1000);
					return formatDate(date, "yyyy-MM-dd hh:mm");
				}
			},
		},
		data() {
			return {
				roterPre: Setting.roterPre,
				loading: false,
				options: timeOptions,
				columns1: [{
						title: "ID",
						key: "id",
						width: 80,
					},
					{
						title: '调价单编号',
						key: 'order_id',
						width: 150,
					},
					{
						title: '类型',
						slot: 'type',
						width: 80,
					},
					{
						title: "门店",
						slot: "store",
						minWidth: 200,
					},
					{
						title: "创建人",
						slot: "cuser",
						minWidth: 200,
					},
					{
						title: "详情",
						slot: "body",
						minWidth: 200,
					},
					// {
					// 	title: "备注",
					// 	slot: "auth_remark",
					// 	minWidth: 200,
					// },
					{
						title: "创建时间",
						slot: "add_time",
						minWidth: 200,
					},
					{
						title: "状态",
						slot: "status",
						minWidth: 200,
					},
					{
						title: "操作",
						slot: "action",
						fixed: "right",
						width: 200,
					},
				],
				tableList: [],
				timeVal: [],
				grid: {
					xl: 7,
					lg: 10,
					md: 12,
					sm: 24,
					xs: 24,
				},
				tableFrom: {
					// integral_time: "",
					// is_show: "",
					// store_name: "",
					store_id: 0,
					create_uid: 0,
					key: '',
					page: 1,
					limit: 10,
				},
				total: 0,
				staffData:[],
				authList:[],
			};
		},
		computed: {
			...mapState("admin/layout", ["isMobile"]),
			labelWidth() {
				return this.isMobile ? undefined : 96;
			},
			labelPosition() {
				return this.isMobile ? "top" : "right";
			},
		},
		created() {
			this.getList();
			this.getUserList();
			this.staffList()
		},
		methods: {
			getUserList() {
				getUserList().then(res => {
					// console.log(res);
					this.authList = res.data.data
				})
			},
			userSearchs(e) {
				this.tableFrom.page = 1;
				this.getList();
			},
			staffList() {
				staffListInfo()
					.then((res) => {
						this.staffData = res.data;
					})
					.catch((err) => {
						this.$Message.error(err.msg);
					});
			},
			// 添加
			add() {
				this.$router.push({
					path: this.roterPre + "/erp/adjust_add?id=0"
				});
			},
			addMore() {
				this.$router.push({
					path: this.roterPre + "/marketing/store_integral/add_store_integral",
				});
			},
			orderList(row) {
				this.$router.push({
					path: this.roterPre + "/marketing/store_integral/order_list",
					query: {
						product_id: row.id,
					},
				});
			},
			// 导出
			exports() {
				let formValidate = this.tableFrom;
				let data = {
					start_status: formValidate.start_status,
					status: formValidate.status,
					store_name: formValidate.store_name,
				};
				storeSeckillApi(data)
					.then((res) => {
						location.href = res.data[0];
					})
					.catch((res) => {
						this.$Message.error(res.msg);
					});
			},
			// 编辑
			edit(row) {
				this.$router.push({
					path: this.roterPre + "/erp/add_position?id=" + row.id
				});
			},
			// 一键复制
			copy(row) {
				this.$router.push({
					path: this.roterPre + "/marketing/store_integral/create/" + row.id + "/1",
				});
			},
			// 删除
			del(row, tit, num) {
				let delfromData = {
					title: tit,
					num: num,
					url: `/erp/Warehouse/position_del/${row.id}`,
					method: "DELETE",
					ids: "",
				};
				this.$modalSure(delfromData)
					.then((res) => {
						this.$Message.success(res.msg);
						this.tableList.splice(num, 1);
						if (!this.tableList.length) {
							this.tableFrom.page =
								this.tableFrom.page == 1 ? 1 : this.tableFrom.page - 1;
						}
						this.getList();
					})
					.catch((res) => {
						this.$Message.error(res.msg);
					});
			},
			// 列表
			getList() {
				this.loading = true;
				// this.tableFrom.start_status = this.tableFrom.start_status || "";
				// this.tableFrom.is_show = this.tableFrom.is_show || "";
				getAdjustList(this.tableFrom)
					.then(async (res) => {
						let data = res.data;
						this.tableList = data.data;
						this.total = data.count;
						this.loading = false;
					})
					.catch((res) => {
						this.loading = false;
						this.$Message.error(res.msg);
					});
			},
			pageChange(index) {
				this.tableFrom.page = index;
				this.getList();
			},
			// 表格搜索
			tableSearchs() {
				this.tableFrom.page = 1;
				this.getList();
			},
			// 具体日期
			onchangeTime(e) {
				this.timeVal = e;
				this.tableFrom.integral_time = this.timeVal[0] ? this.timeVal.join("-") : "";
			},
			// 修改是否显示
			onchangeIsShow(row) {
				let data = {
					id: row.id,
					is_show: row.is_show,
				};
				integralIsShowApi(data)
					.then(async (res) => {
						this.$Message.success(res.msg);
					})
					.catch((res) => {
						this.$Message.error(res.msg);
					});
			},
		},
	};
</script>

<style scoped lang="stylus">
	.tabBox_img {
		width: 36px;
		height: 36px;
		border-radius: 4px;
		cursor: pointer;

		img {
			width: 100%;
			height: 100%;
		}
	}
	.info {
		padding-top: 10px;
		border-bottom: 1px dashed #515a6e;
	
		&:last-of-type {
			border: none;
		}
	}
</style>