<template>
	<ContainerQuery>
		<div v-if="$accessCheck($Access.CommissionRuleAddCommissionRule)" slot="left">
			<el-button size="small" type="primary" @click="$router.push('/Shareholders/RuleCommission')">
				新增股东
			</el-button>
		</div>
		<div slot="more">
			<el-form size="small" :inline="true">
				<el-form-item>
					<el-date-picker v-model="time" clearable type="date" end-placeholder="添加日期" @change="changeTime">
					</el-date-picker>
				</el-form-item>
			</el-form>
		</div>
		<el-table :data="rule_list">
			<el-table-column prop="name" label="股东名称" show-overflow-tooltip min-width="155"></el-table-column>
			<el-table-column prop="number" label="联系方式" show-overflow-tooltip min-width="155"></el-table-column>
			<el-table-column prop="dends" label="分红股份" min-width="140"></el-table-column>
			<el-table-column prop="shares" label="原始股份" min-width="140"></el-table-column>
			<el-table-column prop="createTime" label="添加时间" min-width="140"></el-table-column>
			<el-table-column prop="name" label="操作" min-width="120">
				<template slot-scope="scope">
					<el-button v-if="$accessCheck($Access.CommissionRuleEditCommissionRule)" type="text" @click="
              $router.push(
                '/Shareholders/RuleCommissionEdit?id=' + scope.row.id
              )
            ">
						修改
					</el-button>
					<el-button v-if="$accessCheck($Access.CommissionRuleDelCommissionRule)" type="text"
						@click="delData(scope.row.id)">
						删除
					</el-button>
				</template>
			</el-table-column>
		</el-table>
		<FooterPage :page-size="pageSize" :total-page.sync="total" :current-page.sync="page" @pageChange="pageChange"
			@sizeChange="sizeChange"></FooterPage>
	</ContainerQuery>
</template>

<script>
	import {
		Lst,
	} from "@/api/Holders";
	import {
		enableRewardRule,
		getAllRewardRule,
		deleteRewardRule,
	} from "@/api/Reward";
	export default {
		name: "RewardList",
		data() {
			return {
				rule_list: [],
				time: '',
				search_form: {
					start: "",
				},
				total: 0,
				page: 1,
				pageSize: 10,
			};
		},
		created() {
			this.Lst();
		},
		activated() {
			if (this.$_isInit()) return;
			this.Lst();
		},
		methods: {
			//  订单时间
			changeTime(val) {
				if (val && val.length) {
					this.search_form.start = val[0] / 1000;
				} else {
					this.search_form.start = "";
				}
				this.pageChange(1);
			},
			pageChange(page) {
				this.page = page;
				this.Lst();
			},
			// 每页数据大小改变
			sizeChange(val) {
				this.pageSize = val;
				this.pageChange(1);
			},
			editData(index) {},
			async Lst() {
				const {
					data,
					pageTotal
				} = await Lst({
					page: this.page,
					pageSize: this.pageSize,
					createTime: this.search_form.start,
				});
				this.rule_list = data.map((item) => {
					const staffName = data.map((item) => item.staffName);
					return {
						...item,
						staffName: staffName.length ? staffName.join("，") : "",
					};
				});
				this.total = pageTotal;
			},
			// 删除
			async delData(id) {
				this.$confirm("是否要将该提成规则删除?", "提示", {
					confirmButtonText: "确定",
					cancelButtonText: "取消",
					type: "warning",
				}).then(async () => {
					const data = await deleteRewardRule(id);

					this.$message({
						type: "success",
						message: "操作成功!",
					});
					this.getAllRewardRule();
				});
			},
		},
	};
</script>

<style scoped></style>
