<template>
	<cl-crud :ref="setRefs('crud')" @load="onLoad">
		<el-row type="flex">
			<cl-refresh-btn />
			<cl-add-btn plain>新建目标</cl-add-btn>
			<cl-multi-delete-btn plain />
			<demo-query-isfinish />
			<cl-flex1 />
			<!-- <p>tips:效率数值分别为：新增/留存/付费</p> -->
			<!-- <p>目标是否完成默认按照最低目标计算</p> -->
			<!-- <cl-search-key
				field="id"
				:field-list="[
					{
						label: '任务id',
						value: 'id'
					}
				]"
			></cl-search-key> -->
			<cl-export-btn :columns="table.columns"></cl-export-btn>
			<!-- <el-button type="primary" size="mini" @click="exportExcel()" plain>导出EXCEL</el-button> -->
			<demo-adv-search-target />
			<!-- <cl-adv-search :items="items" :op-list="opList"></cl-adv-search> -->
		</el-row>

		<el-row>
			<cl-table v-bind="table">
				<!-- <template #slot-resetPay="{ scope }">
					<el-button v-if="showResetPay(scope.row)" type="primary" plain size="mini"
						@click="switchResetPay(scope.row)">
						重置付费
					</el-button>
				</template> -->
				<template #slot-resetPay="{ scope }">
					<el-button
						v-if="showResetPay(scope.row)"
						type="text"
						size="mini"
						@click="switchResetPay(scope.row)"
						>重置付费</el-button
					>
				</template>
				<!-- <template #slot-payFailed="{ scope }">
					<el-button v-if="showResetPay(scope.row)" type="text" size="mini"
						@click="switchResetPay(scope.row)">付费失败</el-button>
				</template>
				<template #slot-unpaid="{ scope }">
					<el-button v-if="showResetPay(scope.row)" type="text" size="mini"
						@click="switchResetPay(scope.row)">未付费</el-button>
				</template> -->
				<template #slot-incomplete="{ scope }">
					<el-button
						v-if="showPage(scope.row)"
						type="warning"
						size="mini"
						@click="switchPage(scope.row)"
						>原因填写
					</el-button>
				</template>
			</cl-table>
		</el-row>

		<el-row type="flex">
			<cl-flex1 />
			<cl-pagination />
		</el-row>

		<cl-upsert
			v-model="form"
			v-bind="upsert"
			:on-info="onInfoSubmit"
			:on-submit="onUpsertSubmit"
		>
			<!-- 动态增减表单验证 -->
			<template #slot-validate="{}">
				<el-button @click="addCardMsg()">添加卡号</el-button>
				<div class="container-scrollbar">
					<el-scrollbar max-height="200px">
						<el-row :gutter="24" v-for="(item, index) in cardList" :key="index">
							<el-col :span="10">
								<el-form-item label="QQ卡号">
									<el-input v-model="item.card_account"></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="8">
								<el-form-item label="消耗金额">
									<el-input v-model="item.card_balance"></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="2" v-if="cardList.length !== 1">
								<el-button
									@click="deleteCardMsg(index)"
									class="el-icon-delete"
									size="mini"
									circle
								>
								</el-button>
							</el-col>
						</el-row>
					</el-scrollbar>
				</div>
			</template>
		</cl-upsert>
		<cl-dialog title="未完成原因" v-model="visible">
			<el-form ref="elForm" :model="reasonForm" size="medium" label-width="100px">
				<el-row>
					<el-form-item label="警告:" prop="task_id">
						<el-col :span="24">
							<p style="color: red; font-size: larger">
								当日目标未完成,请于次日9点以后填写原因说明,否则无效
							</p>
						</el-col>
					</el-form-item>
				</el-row>
				<el-row>
					<el-form-item label="任务ID" prop="task_id">
						<el-col :span="24">
							<el-input
								v-model="reasonForm.task_id"
								placeholder="任务ID"
								disabled="true"
							></el-input>
						</el-col>
					</el-form-item>
					<el-form-item label="任务名称" prop="task_name">
						<el-col :span="24">
							<el-input
								v-model="reasonForm.task_name"
								placeholder="任务名称"
								disabled="true"
							></el-input>
						</el-col>
					</el-form-item>
				</el-row>
				<el-row>
					<el-form-item label="负责人" prop="directorName">
						<el-col :span="24">
							<el-input
								v-model="reasonForm.directorName"
								placeholder="任务名称"
								disabled="true"
							></el-input>
						</el-col>
					</el-form-item>
					<el-form-item label="任务日期" prop="new_date">
						<el-col :span="24">
							<el-input
								v-model="reasonForm.new_date"
								placeholder="任务日期"
								disabled="true"
							></el-input>
						</el-col>
					</el-form-item>
				</el-row>
				<el-form-item label="问题类型" prop="type_id">
					<el-col :span="6">
						<demo-problem-type-select
							v-model="reasonForm.type_id"
						></demo-problem-type-select>
					</el-col>
				</el-form-item>
				<el-form-item label="未完原因" prop="reason">
					<el-col :span="20">
						<el-input
							v-model="reasonForm.reason"
							type="textarea"
							placeholder="未完原因"
							:autosize="{ minRows: 4, maxRows: 4 }"
							:style="{ width: '100%' }"
						></el-input>
					</el-col>
				</el-form-item>
				<el-form-item label="解决方案" prop="solution">
					<el-col :span="20">
						<el-input
							v-model="reasonForm.solution"
							type="textarea"
							placeholder="解决方案"
							:autosize="{ minRows: 4, maxRows: 4 }"
							:style="{ width: '100%' }"
						></el-input>
					</el-col>
				</el-form-item>
				<el-form-item>
					<el-button size="small" @click="visible = false">取消</el-button>
					<el-button type="primary" size="small" @click="updateReason(reasonForm)"
						>提交</el-button
					>
				</el-form-item>
			</el-form>
		</cl-dialog>
		<cl-dialog title="账号获取" v-model="visible_pay">
			<el-form ref="elForm" :model="payAccount" size="medium" label-width="100px">
				<el-form-item label="类型" prop="type">
					<el-col :span="20">
						<p style="color: red; font-size: larger">{{ payAccount.type }}</p>
					</el-col>
				</el-form-item>
				<el-form-item label="账号" prop="account">
					<el-col :span="20">
						<el-input
							v-model="payAccount.account"
							type="textarea"
							placeholder=""
							:autosize="{ minRows: 20, maxRows: 20 }"
							:style="{ width: '100%' }"
						></el-input>
					</el-col>
				</el-form-item>
				<el-form-item>
					<el-button size="small" @click="visible_pay = false">取消</el-button>
				</el-form-item>
			</el-form>
		</cl-dialog>
		<el-dialog
			title="今日可付费账号获取"
			v-model="visible_can_pay"
			:center="true"
			:close-on-click-modal="false"
			:close-on-press-escape="false"
			width="50%"
		>
			<p style="color: red; font-size: larger; margin-bottom: 10px">{{ payAccount.type }}</p>
			<!--付费金额填写-->
			<div v-if="rowTask.login_modeId == 2">
				<span>加币金额</span>
				<el-input-number
					v-model="pay_price"
					:precision="0"
					:step="1"
					:max="10"
					:min="1"
					size="small"
					style="margin-left: 20px; margin-bottom: 10px"
					controls-position="right"
					step-strictly
				/>
			</div>
			<el-table :data="accountList" border style="width: 100%" max-height="500">
				<el-table-column
					prop="account"
					label="账号"
					align="left"
					min-width="50"
					header-align="left"
				/>
				<!-- <el-table-column prop="account" label="账号" align="left" min-width="200" header-align="left">
					<template #default="scope">
						<el-button size="small">
							{{ scope.row.account }}
						</el-button>
					</template>
				</el-table-column> -->
				<el-table-column
					prop="password"
					label="密码"
					align="left"
					min-width="50"
					header-align="left"
				/>
				<el-table-column
					fixed="right"
					label="操作"
					width="110"
					align="center"
					header-align="center"
				>
					<template #default="scope">
						<el-button
							v-permission="service.shuyouGameTarget.permission.handAddPayMz"
							v-if="rowTask.login_modeId == 2"
							size="small"
							type="warning"
							plain
							@click="handAddPayMz(scope.row)"
						>
							魅族加币
						</el-button>
					</template>
				</el-table-column>
				<el-table-column
					fixed="right"
					label="信息展示"
					align="center"
					header-align="center"
				>
					<template #default="scope">
						<span>{{ scope.row.msg }}</span>
					</template>
				</el-table-column>
			</el-table>
			<div v-if="rowTask.login_modeId == 2">
				<el-divider>
					<span style="color: #ff0080">↓任意账号强制加币,谨慎使用↓</span>
				</el-divider>
				<el-row :gutter="24" style="margin-top: 20px">
					<el-col :span="10">
						<span style="color: red"
							>如果加不上币,提示额度不足等需要强制加币请联系王梳霖</span
						>
					</el-col>
				</el-row>
				<el-row
					:gutter="24"
					style="margin-top: 20px"
					v-permission="service.shuyouGameTarget.permission.forceAddPayMz"
				>
					<el-col :span="6">
						<el-input v-model="force_add.force_account" size="small" />
					</el-col>
					<el-col :span="5">
						<el-button
							class="el-icon-plus"
							type="danger"
							plain
							size="small"
							@click="forceAddPayMz()"
						>
							强制加币
						</el-button>
					</el-col>
					<el-col :span="10">
						<span style="color: red">{{ force_add.msg }}</span>
					</el-col>
				</el-row>
			</div>
		</el-dialog>
	</cl-crud>
</template>

<script lang="ts">
import { CrudLoad, Table, Upsert } from "cl-admin-crud-vue3/types";
import { defineComponent, inject, reactive, ref, computed } from "vue";
import AdvSearch from "../components/adv-search-target.vue";
import dayjs from "dayjs";
import Query from "../components/query-isfinish.vue";
import ProblemType from "../components/shuyouProblemType-select.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { useRefs } from "/@/core";

export default defineComponent({
	name: "game-target",

	components: {
		"demo-adv-search-target": AdvSearch,
		"demo-query-isfinish": Query,
		"demo-problem-type-select": ProblemType
	},

	setup() {
		const service = inject<any>("service");
		const { refs, setRefs }: any = useRefs();
		// 表单值
		const form = reactive<any>({
			relevance: 1
		});
		// 是否可见
		const visible = ref<boolean>(false);
		const visible_pay = ref<boolean>(false);
		const visible_can_pay = ref<boolean>(false);
		let accountList = ref<any[]>([]);
		const pay_price = ref<number>(6);
		const force_add = reactive<any>({
			force_account: "",
			force_msg: ""
		});
		const rowTask = reactive<any>({
			xjf_id: "",
			login_modeId: 0
		});
		let cardList = ref<any[]>([]);
		// 新增、编辑配置
		const upsert = reactive<Upsert>({
			width: "800px",

			items: [
				{
					prop: "task_id",
					label: "任务ID",
					span: 8,
					component: {
						name: "el-input",
						props: {
							placeholder: "请填写任务ID",
							disabled: true
						}
					},
					rules: {
						required: true,
						message: "任务ID不能为空"
					}
				},
				{
					prop: "task_name",
					label: "任务名称",
					span: 12,
					component: {
						name: "el-input",
						props: {
							placeholder: "任务名称",
							disabled: true
						}
					},
					rules: {
						required: true,
						message: "任务名称不能为空"
					}
				},
				{
					prop: "new_date",
					label: "目标日期",
					span: 8,
					value: dayjs(new Date()).format("YYYY-MM-DD"),
					component: {
						name: "el-date-picker",
						props: {
							type: "date",
							placeholder: "选择日期",
							format: "YYYY-MM-DD",
							valueFormat: "YYYY-MM-DD",
							disabled: true
						}
					},
					rules: {
						required: true,
						message: "日期不能为空"
					}
				},
				{
					prop: "directorId",
					label: "负责人",
					span: 8,
					component: {
						name: "shuyouGameDirectorselect",
						props: {
							placeholder: "负责人"
						}
					},
					rules: {
						required: true,
						message: "负责人不能为空"
					}
				},
				{
					type: "tabs",
					props: {
						labels: [
							{
								label: "目标信息",
								value: "target"
							},
							{
								label: "手动完成上传",
								value: "complete"
							},
							{
								label: "财务专用",
								value: "remark"
							}
						]
					}
				},
				{
					prop: "target_new",
					label: "目标新增",
					span: 8,
					value: 0,
					group: "target",
					component: {
						name: "el-input",
						props: {
							placeholder: "目标新增"
						}
					},
					rules: {
						required: true,
						message: "不能为空"
					}
				},
				{
					prop: "target_pay",
					label: "目标付费",
					span: 8,
					value: 0,
					group: "target",
					component: {
						name: "el-input",
						props: {
							placeholder: "目标付费"
						}
					},
					rules: {
						required: true,
						message: "不能为空"
					}
				},
				{
					prop: "target_active",
					label: "目标活跃",
					span: 8,
					value: 0,
					group: "target",
					component: {
						name: "el-input",
						props: {
							placeholder: "目标活跃"
							// disabled: "true"
						}
					}
				},
				//====================================
				{
					label: "新增个数",
					prop: "complete_new_hand",
					value: 0,
					span: 8,
					group: "complete",
					component: {
						name: "el-input"
					}
				},
				{
					label: "留存个数",
					prop: "complete_lc_hand",
					value: 0,
					span: 8,
					group: "complete",
					component: {
						name: "el-input"
					}
				},
				{
					label: "有无付费",
					prop: "is_pay_hand",
					value: 1,
					span: 8,
					group: "complete",
					component: {
						name: "el-radio-group",
						options: [
							{
								label: "有付费",
								value: 0
							},
							{
								label: "无付费",
								value: 1
							}
						]
					}
				},
				{
					label: "",
					prop: "demo1",
					group: "complete",
					hidden: ({ scope }: any) => {
						return scope.is_pay_hand != 0;
					},
					component: ({ h }: any) => {
						return h("p", "以下信息为付费相关↓↓↓");
					}
				},
				{
					label: "支付方式",
					prop: "pay_mode_hand",
					value: 4,
					span: 16,
					group: "complete",
					hidden: ({ scope }: any) => {
						return scope.is_pay_hand != 0;
					},
					component: {
						name: "el-radio-group",
						options: [
							{
								label: "QQ卡",
								value: 0
							},
							{
								label: "微信",
								value: 1
							},
							{
								label: "支付宝",
								value: 2
							},
							{
								label: "银行卡",
								value: 3
							},
							{
								label: "其他方式",
								value: 4
							}
						]
					}
				},
				{
					label: "其他支付方式",
					prop: "other_pay_hand",
					value: "",
					span: 6,
					group: "complete",
					hidden: ({ scope }: any) => {
						return scope.pay_mode_hand != 4 || scope.is_pay_hand != 0;
					},
					component: {
						name: "el-input"
					}
				},
				{
					label: "单价一致",
					prop: "is_same_hand",
					value: 0,
					group: "complete",
					span: 10,
					hidden: ({ scope }: any) => {
						return scope.is_pay_hand != 0;
					},
					component: {
						name: "el-radio-group",
						options: [
							{
								label: "一致",
								value: 0
							},
							{
								label: "不一致",
								value: 1
							}
						]
					}
				},
				{
					label: "付费个数",
					prop: "complete_pay_hand",
					value: 0,
					span: 6,
					group: "complete",
					hidden: ({ scope }: any) => {
						return scope.is_pay_hand != 0 || scope.is_pay_hand != 0;
					},
					component: {
						name: "el-input"
					}
				},
				{
					label: "付费单价",
					prop: "price_hand",
					value: 0,
					span: 6,
					group: "complete",
					hidden: ({ scope }: any) => {
						return scope.is_same_hand != 0 || scope.is_pay_hand != 0;
					},
					component: {
						name: "el-input"
					}
				},
				{
					label: "付费总金额",
					prop: "amount_hand",
					value: 0,
					span: 6,
					group: "complete",
					hidden: ({ scope }: any) => {
						return scope.is_same_hand != 1;
					},
					component: {
						name: "el-input"
					}
				},
				{
					prop: "card_list",
					label: "卡消耗记录",
					group: "complete",
					value: cardList.value,
					span: 20,
					hidden: ({ scope }: any) => {
						return scope.pay_mode_hand != 0;
					},
					component: {
						name: "slot-validate"
					}
				},
				{
					prop: "account_hand",
					label: "账号记录",
					group: "complete",
					value: "",
					span: 20,
					component: {
						name: "cl-editor-quill",
						props: {
							height: "200"
						}
					}
				},
				{
					prop: "is_wt_hand",
					label: "上传WT",
					value: 1,
					span: 8,
					group: "complete",
					component: {
						name: "el-radio-group",
						options: [
							{
								label: "是",
								value: 1
							},
							{
								label: "否",
								value: 0
							}
						]
					}
				},
				{
					prop: "is_xjf_hand",
					label: "上传机房",
					value: 1,
					span: 8,
					group: "complete",
					component: {
						name: "el-radio-group",
						options: [
							{
								label: "是",
								value: 1
							},
							{
								label: "否",
								value: 0
							}
						]
					}
				},
				{
					prop: "remark",
					label: "异常记录",
					span: 24,
					group: "remark",
					component: {
						name: "el-input",
						props: {
							placeholder: "请控制在200个字以内",
							type: "textarea",
							rows: 10
						}
					}
				}
			]
		});

		// 表格配置
		const table = reactive<Table>({
			props: {
				border: true,
				"show-summary": true,
				stripe: true,
				"default-sort": {
					prop: "new_date,directorName,task_id",
					order: "descending"
				}
			},
			"context-menu": [
				(scope: any) => {
					return {
						label: scope.task_name,
						disabled: true
					};
				},
				"refresh",
				"update",
				"order-desc",
				"order-asc",
				(scope: any) => {
					return {
						label: "账号获取",
						"suffix-icon": "el-icon-right",
						children: [
							{
								label: "今日付费失败账号",
								callback: (_: any, done: Function) => {
									payFailed(scope);
									done();
								}
							},
							{
								label: "今日可以付费账号",
								callback: (_: any, done: Function) => {
									unpaid(scope);
									done();
								}
							}
						]
					};
				}
			],
			columns: [
				{
					type: "selection",
					width: 60
				},
				{
					label: "序",
					type: "index",
					width: 40
				},
				{
					prop: "new_date",
					label: "目标日期",
					align: "left",
					sortable: "custom",
					minWidth: 100
				},
				{
					prop: "task_id",
					label: "任务ID",
					align: "left",
					sortable: "custom",
					minWidth: 100
				},
				{
					prop: "task_name",
					label: "任务名",
					minWidth: 200,
					showOverflowTooltip: true,
					headerAlign: "left",
					align: "left"
				},
				{
					prop: "login_mode",
					label: "登录方式",
					minWidth: 80
				},
				{
					prop: "target_new",
					label: "目标新增",
					minWidth: 80
				},
				{
					prop: "target_pay",
					label: "目标付费",
					minWidth: 80
				},
				{
					prop: "target_active",
					label: "目标活跃",
					minWidth: 80
				},
				{
					prop: "complete_new",
					label: "完成新增",
					minWidth: 80
				},
				{
					prop: "complete_pay",
					label: "完成付费",
					minWidth: 80
				},
				{
					prop: "complete_active",
					label: "完成活跃",
					minWidth: 80
				},
				{
					prop: "incomplete_new",
					label: "未完新增",
					minWidth: 80
				},
				{
					prop: "incomplete_pay",
					label: "未完付费",
					minWidth: 80
				},
				{
					prop: "incomplete_active",
					label: "未完活跃",
					minWidth: 80
				},
				// {
				// 	prop: "game_rate",
				// 	label: "手动(新增/留存/付费)",
				// 	align: "center",
				// 	minWidth: 100
				// },
				{
					prop: "directorName",
					label: "负责人",
					align: "center",
					sortable: "custom",
					fixed: "right",
					minWidth: 100
				},
				{
					prop: "is_complete",
					label: "完成",
					minWidth: 60,
					fixed: "right",
					dict: [
						{
							label: "是",
							value: 1,
							type: "success"
						},
						{
							label: "否",
							value: 0,
							type: "danger"
						}
					]
				},
				{
					prop: "complete_pay_hand",
					label: "手动付费数量",
					align: "center",
					minWidth: 100
				},
				{
					prop: "amount_hand",
					label: "手动付费金额",
					align: "center",
					minWidth: 100
				},
				{
					prop: "game_rate",
					label: "群控效率",
					align: "center",
					minWidth: 100
				},
				{
					prop: "remark",
					label: "异常记录",
					align: "left",
					minWidth: 150
				},
				{
					prop: "amount",
					label: "付费流水",
					align: "center",
					minWidth: 100
				},
				{
					prop: "updateTime",
					label: "更新时间",
					minWidth: 150
				},
				{
					type: "op",
					buttons: ["edit", "slot-resetPay", "slot-incomplete"],
					width: 110
				}
			]
		});

		// 编辑提交钩子
		function onUpsertSubmit(_: boolean, data: any, { next }: any) {
			const card_list = cardList.value;
			next({
				...data,
				card_list
			});
		}
		//编辑打开时的钩子
		function onInfoSubmit(data: any, { next, done, close }: any) {
			service.info;
			done(data);
			cardList.value = data.card_list;
			// console.log(data)
		}

		//查询当前付费失败的账号
		async function payFailed(scope: any) {
			const task_id = scope.task_id;
			service.shuyouUtils
				.payFailed({ task_id: task_id })
				.then((data) => {
					// console.log(data.code)
					visible_pay.value = true;
					payAccount.type = "付费失败的账号";
					if (data.code == 1) {
						if (data.message == "null") {
							payAccount.account = "暂无账号";
						} else {
							let arr = "";
							data.message.forEach((e) => {
								arr += e.account + "----" + e.password + "\n";
							});
							payAccount.account = arr;
						}
					}
				})
				.catch((err: string) => {
					ElMessage.error(err);
				});
		}

		function addCardMsg() {
			let hasFlag = false;
			for (let i = 0; i < cardList.value.length; i++) {
				if (cardList.value[i].card_account == "" || cardList.value[i].card_balance == "") {
					hasFlag = true;
					break;
				}
			}
			if (hasFlag == true) {
				ElMessage.error("有未填写项");
			} else {
				cardList.value.push({
					card_account: "",
					card_balance: ""
				});
			}
		}
		function deleteCardMsg(index: number) {
			cardList.value.splice(index, 1);
		}

		// 权限service.shuyouGameTarget.permission.forceAddPayMz
		// const perm: any = computed(() => service.shuyouGameTarget.permission);
		// console.log(perm.value)

		//查询今日可付费账号
		async function unpaid(scope: any) {
			const task_id = scope.task_id;
			rowTask.xjf_id = scope.xjf_id;
			rowTask.login_modeId = scope.login_modeId;
			accountList.value = [];
			service.shuyouUtils
				.unpaid({ task_id: task_id })
				.then((data) => {
					visible_can_pay.value = true;
					payAccount.type =
						"( " +
						scope.task_name +
						" ) - " +
						"当日可付费账号,仅展示100个,如需更多,请联系国亮哥获取";
					if (data.code == 1) {
						if (data.message == "null") {
							payAccount.type = "暂无账号";
						} else {
							data.message.forEach((e) => {
								let obj = {
									account: e.account,
									password: e.password,
									msg: ""
								};
								accountList.value.push(obj);
							});
						}
					}
				})
				.catch((err: string) => {
					ElMessage.error(err);
				});
		}
		async function handAddPayMz(row: any) {
			ElMessageBox.confirm("确定要手动加币吗，请谨慎操作！！！", "账号: " + row.account, {
				dangerouslyUseHTMLString: true,
				type: "warning"
			})
				.then(() => {
					service.shuyouGameTarget
						.handAddPayMz({
							xjf_id: rowTask.xjf_id,
							account: row.account,
							pay_price: pay_price.value
						})
						.then((data) => {
							// console.log(data)
							if (data.code == 1) {
								ElMessage.success(data.message);
							} else {
								ElMessage.error(data.message);
							}
							row.msg = data.message;
						})
						.catch((err: string) => {
							ElMessage.error(err);
						});
				})
				.catch(() => null);
		}
		async function forceAddPayMz() {
			force_add.msg = "";
			ElMessageBox.confirm(
				"确定要强制给账号加币吗，请谨慎操作！！！",
				"账号: " + force_add.force_account,
				{
					dangerouslyUseHTMLString: true,
					type: "error"
				}
			)
				.then(() => {
					service.shuyouGameTarget
						.handAddPayMz({
							xjf_id: rowTask.xjf_id,
							account: force_add.force_account,
							pay_price: pay_price.value
						})
						.then((data) => {
							// console.log(data)
							if (data.code == 1) {
								ElMessage.success(data.message);
							} else {
								ElMessage.error(data.message);
							}
							force_add.msg = data.message;
						})
						.catch((err: string) => {
							ElMessage.error(err);
						});
				})
				.catch(() => null);
		}

		// crud 加载
		async function onLoad({ ctx, app }: CrudLoad) {
			// console.log(service);
			// const aa = await service.shuyouTargetFlag.getTodayFlag();
			const aa = await service.shuyouTargetFlag.getTodayFlag();
			// console.log(aa);
			if (aa.code == 1000) {
				ctx.service(service.shuyouGameTarget).done();
				app.refresh();
			} else {
				ElMessageBox.confirm(aa.message, "数据查询失败", {
					type: "error"
				})
					.then(() => {})
					.catch(() => null);

				// ctx.service(service.shuyouGameTarget).done();
				// app.refresh();
			}
		}

		function showPage(row: any) {
			var ret = false;
			if (row.is_complete == 0 && dayjs(new Date()).format("YYYY-MM-DD") != row.new_date) {
				ret = true;
			}
			return ret;
		}
		function showResetPay(row: any) {
			var ret = false;
			if (dayjs(new Date()).format("YYYY-MM-DD") == row.new_date) {
				ret = true;
			}
			return ret;
		}

		// 表单值
		const reasonForm = reactive<any>({
			task_id: "",
			task_name: "",
			new_date: dayjs(new Date()).format("YYYY-MM-DD"),
			directorName: "",
			type_id: 0,
			reason: "",
			solution: ""
		});
		const payAccount = reactive<any>({
			type: "",
			account: ""
		});

		// 调起弹窗
		async function switchPage(xxx) {
			reasonForm.task_id = xxx.task_id;
			reasonForm.task_name = xxx.task_name;
			reasonForm.new_date = xxx.new_date;
			reasonForm.directorName = xxx.directorName;
			reasonForm.type_id = xxx.type_id;
			reasonForm.reason = xxx.reason;
			reasonForm.solution = xxx.solution;
			if (xxx.is_complete == 0) {
				visible.value = true;
			}
		}
		// 填写原因
		async function updateReason(aaa) {
			// console.log(aaa)
			aaa.is_write = 1;
			service.shuyouReasonIncomplete
				.add(aaa)
				.then((data) => {
					visible.value = false;
					// console.log(data.code)
					if (data.code == -1) {
						ElMessage.error(data.message);
					} else {
						ElMessage.success(data.message);
					}
					// console.log('刷新页面')
					refs.value.crud.refresh();
				})
				.catch((err: string) => {
					ElMessage.error(err);
				});
		}
		async function switchResetPay(xxx) {
			ElMessageBox.confirm(
				"确定要重新下发今日付费未成功的账号以及重置留存账号吗?!!",
				xxx.task_id + xxx.task_name,
				{
					dangerouslyUseHTMLString: true,
					type: "info"
				}
			)
				.then(() => {
					service.shuyouGameTarget
						.resetPay({ id: xxx.task_id })
						.then((data) => {
							// console.log(data)
							if (data.code == 1) {
								ElMessage.success(data.message);
							} else {
								ElMessage.error(data.message);
							}
							refs.value.crud.refresh();
						})
						.catch((err: string) => {
							ElMessage.error(err);
						});
				})
				.catch(() => null);
		}

		return {
			service,
			form,
			upsert,
			refs,
			setRefs,
			visible,
			table,
			onLoad,
			reasonForm,
			updateReason,
			switchPage,
			showPage,
			showResetPay,
			switchResetPay,
			visible_pay,
			payAccount,
			visible_can_pay,
			accountList,
			pay_price,
			handAddPayMz,
			rowTask,
			addCardMsg,
			deleteCardMsg,
			cardList,
			forceAddPayMz,
			force_add,
			onUpsertSubmit,
			onInfoSubmit
		};
	}
});
</script>
<style lang="scss" scoped>
.container-scrollbar {
	border: 1px solid #dcdde0;
	padding-top: 20px;
	border-radius: 3px;
}
</style>
