<template>
	<div>
		<!-- 指派任务弹窗 -->
		<el-dialog :title="showTitle" :visible.sync="dialogVisible" :close-on-click-modal="false" :before-close="closeDialog" width="700px" top="3%">
			<div>
				<div class="orange" style="text-align: center;padding-bottom: 10px;" v-if="config.event_review_status&&config.event_task_review">复核开启后，积分需管理员复核后才计入排名和统计</div>
				<el-form :model="formData" ref="formData" label-width="100px" v-loading="taskload">
					<el-form-item
						label="任务内容"
						prop="task_name"
						:rules="[{ required: true, message: '请填写任务内容', trigger: 'blur' }, { min: 3, max:100, message: '长度在 3 到 100 个字符', trigger: 'blur' }]"
					>
						<el-input type="textarea" rows="3" maxlength="100" show-word-limit v-model="formData.task_name" placeholder="请输入任务内容(限100字)"></el-input>
					</el-form-item>

					<el-form-item label="积分类型" prop="pt_id" :rules="[{ required: true, message: '请选择积分类型', trigger: 'blur' }]">
						<el-radio-group v-model="formData.pt_id">
							<el-radio v-for="(item, index) in point_types" :key="index" v-show="item.code !== 'JX'" :label="item.id">{{ item.name }}</el-radio>
						</el-radio-group>
					</el-form-item>
					
					<el-form-item label="指定规则">
						 <el-switch  v-model="isSelectType"></el-switch>
					</el-form-item>
					<!-- 选择分类 -->
					<el-form-item class="test_cascader_id" label="选择分类"	v-if="!isSelectType"
						prop="rule_value"
						:rules="[{ required: true, message: '请选择规则分类', trigger: 'blur' }]"
					>
						<el-cascader
							v-model="formData.rule_value"
							ref="ruleCascader"
							:popper-class="'ruleClass'"
							filterable
							clearable
							:options="trees_ab.rule_tree_all"
							@change="ruleChange"
							:props="{ children: 'child', label: 'name', value: 'id', checkStrictly: true }"
						></el-cascader>
					</el-form-item>
					<!-- 选择规则 -->
					<el-form-item :label="trees_PtId(formData.pt_id) +'规则'" v-else	prop="tree_echo" :rules="[{ required: true, message: '请选择规则', trigger: 'blur' }]"
					>
						<el-cascader
							v-model="formData.tree_echo"
							ref="ruleItem"
							:popper-class="'itemClass'"
							filterable
							clearable
							:options="formData.pt_id == 2 ? trees_ab.A : trees_ab.B"
							@change="ruleItemChange"
							:show-all-levels="false"
							:props="{ children: 'child', label: 'name', value: 'id' }"
						></el-cascader>
					</el-form-item>
					
					
					
					<el-form-item prop="range_type" v-if="formData.range_type != 0">
						<div style="line-height: 24px;" v-show="formData.range_type == 1">
							{{ min }}
							<span class="blue">{{ trees_PtId(formData.pt_id) }}</span>
						</div>
						<div style="line-height: 24px;" v-show="formData.range_type == 2">
							{{ min }} ~ {{ max }}
							<span class="blue">{{ trees_PtId(formData.pt_id) }}</span>
						</div>
						<div style="line-height: 24px;">{{ treeName }}</div>
					</el-form-item>

					<el-form-item label="任务积分" prop="base_point" :rules="[{ required: true, message: '请填写任务积分', trigger: 'change' }]">
						<el-input-number style="width: 220px;" v-if="formData.range_type == 0" v-model.number="formData.base_point"></el-input-number>
						<el-input-number style="width: 220px;" v-else :disabled="formData.range_type == 1" v-model.number="formData.base_point" :min="min" :max="max"></el-input-number>
					</el-form-item>

					<el-form-item label="执行人" prop="targets" :rules="[{ required: true, message: '请选择执行人', trigger: 'change' }]">
						<el-row>
							<el-col :span="18">
								<el-input auto-complete="off" v-model="executorName" placeholder="请选择执行人"></el-input>
								<div @click="show_employee_selector = true" style=" position: absolute; top: 0; right: 0; left: 0; bottom: 0; z-index: 9;"></div>
							</el-col>
						</el-row>

						<el-dialog title="选择执行人员" width="640px" :visible.sync="show_employee_selector" append-to-body :before-close="handleClose">
							<EmployeeSelector
								v-if="show_employee_selector"
								ref="members"
								:isCreatorSelect="true"
								:employee_list="employee_list"
								:user_no_select="false"
								:selected="approval_selected"
								@confirm="approval_confirm"
							/>
							<span slot="footer" class="dialog-footer">
								<el-button @click="show_employee_selector = false">取 消</el-button>
								<el-button type="primary" @click="submitEmployee('members')">确 定</el-button>
							</span>
						</el-dialog>
					</el-form-item>
					<el-form-item label="审批人" prop="reviewer_id" :rules="[{ required: true, message: '请选择审批人', trigger: 'change' }]">
						<el-row>
							<el-col :span="18">
								<el-input auto-complete="off" v-model="reviewerName" placeholder="请选择审批人"></el-input>
								<div @click="show_reviewer_selector = true" style=" position: absolute; top: 0; right: 0; left: 0; bottom: 0; z-index: 9;"></div>
							</el-col>
						</el-row>
						<el-dialog title="选择审批人员" width="640px" :visible.sync="show_reviewer_selector" append-to-body :before-close="handleClose">
							<EmployeeSelector
								v-if="show_reviewer_selector"
								ref="members1"
								:isChecKedAll="false"
								:user_Administrator_list="true"
								:multi="false"
								:selected="reviewer_selected"
								@confirm="reviewer_confirm"
							/>
							<span slot="footer" class="dialog-footer">
								<el-button @click="show_reviewer_selector = false">取 消</el-button>
								<el-button type="primary" @click="submitEmployee('members1')">确 定</el-button>
							</span>
						</el-dialog>
					</el-form-item>
					
					<el-form-item label="重复周期" prop="task_cycle">
						<el-select v-model="formData.task_cycle" placeholder="请选择重复周期">
							<el-option v-for="(item, index) in task_cycle_arr" :key="index" :label="item.name" :value="item.value"></el-option>
						</el-select>
					</el-form-item>

					<el-form-item label="截止日期" prop="expire_time" v-if="formData.task_cycle == 0" :rules="[{ required: true, message: '请选择截止日期', trigger: 'blur' }]">
						<el-date-picker
							v-model="formData.expire_time"
							type="datetime"
							placeholder="选择日期时间"
							format="yyyy-MM-dd HH:mm"
							value-format="yyyy-MM-dd HH:mm"
							default-time="18:00"
							:clearable="false"
						></el-date-picker>
					</el-form-item>

					<el-form-item label="截止日期" prop="task_expire_day" v-if="formData.task_cycle == 1" :rules="[{ required: true, message: '请选择截止日期', trigger: 'blur' }]">
						<el-select v-model="formData.task_expire_day" placeholder="请选择截止日期">
							<el-option v-for="item in columns1" :key="item.value" :label="item.name" :value="item.value"></el-option>
						</el-select>
					</el-form-item>

					<el-form-item label="截止日期" prop="task_expire_day" v-if="formData.task_cycle == 2" :rules="[{ required: true, message: '请选择截止日期', trigger: 'blur' }]">
						<el-select v-model="formData.task_expire_day" placeholder="请选择截止日期">
							<el-option v-for="item in columns2" :key="item.value" :label="item.name" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
					
					<el-form-item label="截止日期" prop="task_expire_day" v-if="formData.task_cycle == 3" :rules="[{ required: true, message: '请选择截止日期', trigger: 'blur' }]">
						<el-select v-model="formData.task_expire_day" placeholder="请选择截止日期">
							<el-option v-for="item in columns3" :key="item.value" :label="item.name" :value="item.value"></el-option>
						</el-select>
					</el-form-item>

					<el-form-item label="任务备注" prop="task_remark" :rules="[{ max: 300, message: '长度不能超过 300 个字', trigger: 'blur' }]">
						<el-input type="textarea" :rows="5" maxlength="300" show-word-limit v-model="formData.task_remark" placeholder="请输入任务备注(限300字)"></el-input>
					</el-form-item>

					<el-form-item label="图片">
						<upload
							:headers="Xtoken"
							class="avatar-uploader"
							:action="'https://' + 'integralsys.oss-cn-shenzhen.aliyuncs.com'"
							:show-file-list="true"
							:file-list="fileList"
							:on-success="handleFilesSuccess"
							:on-preview="onFilePreView"
							:before-upload="beforeUpload"
							:on-remove="onFileRemove"
							:limit="3"
							accept="image/jpeg,image/png"
							:multiple="true"
							ref="clearPicture"
						>
							<el-button size="small" type="primary">点击上传</el-button>
							（最多选择3张）
						</upload>
					</el-form-item>

					<div style="margin-left: 80px; margin-bottom: 8px;">以天为单位，每 提前/逾期 一天 加分/扣分</div>
					<el-form-item label="提前奖分" prop="ahead_award_point">
						<el-input v-model="formData.ahead_award_point" oninput="value=value.replace(/[^\d]/g,'')" placeholder="请输入每日奖分" style="width: 150px;"></el-input>
						B分/每天， 奖分上限 &nbsp;
						<el-input
							v-model="formData.ahead_award_point_limit"
							oninput="value=value.replace(/[^\d]/g,'')"
							placeholder="请输入奖分上限"
							style="width: 150px;"
						></el-input>
						B分
					</el-form-item>
					<el-form-item label="逾期扣分" prop="timeout_deduction_point">
						<el-input
							v-model="formData.timeout_deduction_point"
							oninput="value=value.replace(/[^\d]/g,'')"
							placeholder="请输入每日扣分"
							style="width: 150px;"
						></el-input>
						B分/每天， 扣分上限 &nbsp;
						<el-input
							v-model="formData.timeout_deduction_point_limit"
							oninput="value=value.replace(/[^\d]/g,'')"
							placeholder="请输入扣分上限"
							style="width: 150px;"
						></el-input>
						B分
					</el-form-item>

					<el-form-item>
						<div class="flex-box-end">
							<el-button @click="resetForm('formData')">取消</el-button>
							<el-button type="primary" @click="sub('formData')">提交</el-button>
						</div>
					</el-form-item>
				</el-form>
			</div>
		</el-dialog>
	</div>
</template>

<script>
import moment from 'moment';
import EmployeeSelector from '@/components/EmployeeSelector.vue';
import upload from '@/components/upload';
export default {
	name: 'temporaryTask',
	props: {
		employee_not_select: {
			type: Array,
			default: () => {
				return [];
			}
		},
		dialogVisible: {
			type: Boolean,
			default: false
		},
		showTitle: {
			type: String,
			default: ''
		},
		trees_ab: {
			type: Object,
			default: ()=>{
				return {};
			}
		},
		modifyData: { //重复任务 复用时的数据
			type: Object
		},
		isFy:{ //是否为复用操作
			type: Boolean,
			default: false
		}
		
	},
	data() {
		return {
			isSelectType:false,//是否选择分类
			//图片附件
			Xtoken: { 'X-Token': this.$getToken() },
			fileList: [],
			// treesAb: [],
			max: 0,
			min: 0,
			treeName: '',

			taskload: false,
			formData: {
				task_name: '',

				base_point: '0',
				task_remark: '',
				pt_id: 3,

				tree_echo: [], //用于编辑任务时的规则回显
				range_type: 0,
				rule_id: '',
				rule_value:[],
				file_list: [],
				
				task_expire_day: 1,
				expire_time: moment().format('YYYY-MM-DD 18:00'),
				weight: 0,
				package_id: 0,
				targets: [],
				reviewer_id: '',
				task_cycle: 0,
				timeout_deduction_point: null,
				timeout_deduction_point_limit: null,
				ahead_award_point: null,
				ahead_award_point_limit: null
			},
			point_types: [],
			// 执行者
			executorName: null,
			show_employee_selector: false,
			approval_selected: { dept: [], employee: [] },
			approval_not_select: [],
			employee_list: this.$getUserData().employee_detail.manage_scope,
			// 审批人
			reviewerName: null,
			reviewer_not_select: [],
			reviewer_selected: { dept: [], employee: [] },
			show_reviewer_selector: false,

			// 重复周期
			task_cycle_arr: [{ value: 0, name: '不重复' }, { value: 1, name: '每天重复' }, { value: 2, name: '每周重复' }, { value: 3, name: '每月重复' }],
			// 周期时间
			columns1: [
				{ name: '01:00', value: 1 },
				{ name: '02:00', value: 2 },
				{ name: '03:00', value: 3 },
				{ name: '04:00', value: 4 },
				{ name: '05:00', value: 5 },
				{ name: '06:00', value: 6 },
				{ name: '07:00', value: 7 },
				{ name: '08:00', value: 8 },
				{ name: '09:00', value: 9 },
				{ name: '10:00', value: 10 },
				{ name: '11:00', value: 11 },
				{ name: '12:00', value: 12 },
				{ name: '13:00', value: 13 },
				{ name: '14:00', value: 14 },
				{ name: '15:00', value: 15 },
				{ name: '16:00', value: 16 },
				{ name: '17:00', value: 17 },
				{ name: '18:00', value: 18 },
				{ name: '19:00', value: 19 },
				{ name: '20:00', value: 20 },
				{ name: '21:00', value: 21 },
				{ name: '22:00', value: 22 },
				{ name: '23:00', value: 23 },
				{ name: '24:00', value: 24 }
			],
			columns2: [
				{ name: '周一', value: 1 },
				{ name: '周二', value: 2 },
				{ name: '周三', value: 3 },
				{ name: '周四', value: 4 },
				{ name: '周五', value: 5 },
				{ name: '周六', value: 6 },
				{ name: '周日', value: 7 }
			],
			columns3: [
				{ name: '1号', value: 1 },
				{ name: '2号', value: 2 },
				{ name: '3号', value: 3 },
				{ name: '4号', value: 4 },
				{ name: '5号', value: 5 },
				{ name: '6号', value: 6 },
				{ name: '7号', value: 7 },
				{ name: '8号', value: 8 },
				{ name: '9号', value: 9 },
				{ name: '10号', value: 10 },
				{ name: '11号', value: 11 },
				{ name: '12号', value: 12 },
				{ name: '13号', value: 13 },
				{ name: '14号', value: 14 },
				{ name: '15号', value: 15 },
				{ name: '16号', value: 16 },
				{ name: '17号', value: 17 },
				{ name: '18号', value: 18 },
				{ name: '19号', value: 19 },
				{ name: '20号', value: 20 },
				{ name: '21号', value: 21 },
				{ name: '22号', value: 22 },
				{ name: '23号', value: 23 },
				{ name: '24号', value: 24 },
				{ name: '25号', value: 25 },
				{ name: '26号', value: 26 },
				{ name: '27号', value: 27 },
				{ name: '28号', value: 28 },
				{ name: '29号', value: 29 },
				{ name: '30号', value: 30 },
				{ name: '31号', value: 31 }
			],
			config:{},
			arr:[],
		};
	},
	components: { EmployeeSelector, upload },
	watch: {
		dialogVisible() {
			if (this.dialogVisible&&this.isFy) {
				this.Datas();
			}
		},
		'formData.task_cycle'(val) {
			if (val) {
				this.formData.task_expire_day = 1;
			} else {
				this.formData.expire_time = moment().format('YYYY-MM-DD 18:00');
			}
		},
		isSelectType(val) {
			let item = this.formData;
			this.max = 0;
			this.min = 0;
			this.treeName = '';
			item.task_remark = '';
			item.base_point = '0';
			item.range_type = 0;
			item.rule_id='';
			item.item_id = 0;
			item.rule_value=[];
		},
		'formData.pt_id'(val) {
			let item = this.formData;
			this.max = 0;
			this.min = 0;
			this.treeName = '';
			item.tree_echo = [];
			item.task_remark = '';
			item.base_point = '0';
			item.range_type = 0;
			item.rule_id='';
			item.rule_value=[];
		}
	},
	mounted() {
		this.config=this.$store.state.config;
		this.point_types = this.$getCache('types');
	},
	methods: {
		//复原数据
		Datas() {
			// this.formData.id = this.modifyData.id;
			this.formData.task_name = this.modifyData.name;
			this.formData.range_type = 0;
			this.formData.base_point = this.modifyData.point_config.base_point;
			this.formData.pt_id = this.modifyData.pt_id;
			this.formData.expire_time = this.modifyData.expire_time;
			this.formData.task_cycle = this.modifyData.task_cycle;
			this.reviewerName = this.modifyData.reviewer_name;
			
			this.executorName='';
			this.modifyData.target_info.forEach(element => {//执行人信息
				this.formData.targets.push(element.id);
				this.executorName += element.name + ',';
			});
			this.approval_selected.employee = this.modifyData.target_info;
					
					
					
			this.formData.reviewer_id = this.modifyData.reviewer_id; //审批者
			this.reviewer_selected.employee = [{ id: this.modifyData.reviewer_id, img_url: this.modifyData.img_url, name: this.modifyData.reviewer_name }];
			
			let filtList = []
			this.modifyData.task_file_list.forEach((item, index) =>{
				filtList.push({name: item ,url:item, response: { url:item }})
			})
			this.fileList = filtList
			this.fileFun('', filtList)
			// 指定了规则
			// console.log(this.modifyData.point_config)
			if(this.modifyData.point_config.item_info){
				let itemInfo = this.modifyData.point_config.item_info
				this.arr=[itemInfo.id];
				// 获取规则的上级分类
				this.getruleChange(itemInfo.rule_id)
				this.isSelectType=true;
				this.$nextTick(_=>{
					this.formData.tree_echo = JSON.parse(JSON.stringify(this.arr))
					this.$nextTick(_=>{
						this.ruleItemChange(this.formData.tree_echo);
					})
				})
				
			}else if(this.modifyData.point_config.rule_info){//指定了分类
				this.isSelectType=false;
				this.formData.rule_id = this.modifyData.point_config.rule_info.id;
				this.formData.rule_value = this.returnRuleVal(this.modifyData.point_config.rule_info.id,[]);
			}
			this.$nextTick(_=>{
				this.$nextTick(_=>{
					this.formData.task_remark = this.modifyData.remark;
				})
			})
			
			let add = ['ahead_award_point', 'ahead_award_point_limit', 'timeout_deduction_point', 'timeout_deduction_point_limit']
			add.forEach(item =>{
				this.deductionPoint(item)
			})
		},
		deductionPoint(item){
			if (this.modifyData.point_config[item] != '0') {
				this.formData[item] = this.modifyData.point_config[item];
			} else {
				this.formData[item] = '';
			}
		},
		getruleChange(aid){
			this.arr.unshift(aid);
			let list = this.trees_ab.rule_tree.filter(x => x.id == aid)
			if(list[0]&&list[0].pid == 0){
				return false
			}else{
				if(list[0]){
					this.getruleChange(list[0].pid)
				}
			}
		},
		returnRuleVal(rule_id,arr){
			arr.unshift(rule_id)
			let list = this.trees_ab.rule_tree.filter(x => x.id == rule_id)
			if(list[0]&&list[0].pid != 0){
				this.returnRuleVal(list[0].pid,arr)
			}
			return arr;
		},
		
		trees_PtId(id) {
			return id == 2 ? 'A分' : 'B分';
		},
		ruleItemChange(val) {
			let item = this.formData;
			if (val.length > 0) {
				let id=val[val.length-2]
				let key='rule_'+id
				let list =this.trees_ab.item_list[key]; //当前选中的节点数据
				let data={};
				list.forEach(e=>{
					if(e.id==val[val.length-1]){
						data=e;
					}
				})
				// let data = this.$refs.ruleItem.getCheckedNodes()[0].data;//当前选中的节点数据
				// console.log(data)
				item.task_remark = data.remark;
				this.treeName = data.remark;
				this.max = data.max_point * 1;
				this.min = data.min_point * 1;
				item.base_point = data.min_point;
				item.range_type = data.range_type;
				item.rule_id = data.rule_id;
				item.item_id = data.id;
			} else {
				item.task_remark = '';
				this.treeName = '';
				this.max = 0;
				this.min = 0;
				item.base_point = '0';
				item.range_type = 0;
				item.rule_id = 0;
				item.item_id = 0;
			}
		},
		// 规则分类变化关闭dewn
		ruleChange(value) {
			const item = this.formData;
			if (value.length > 0) {
				item.rule_id = value[value.length - 1];
			} else {
				item.rule_id = '';
				item.rule_value = '';
			}
			this.$refs.ruleCascader.dropDownVisible=false;
		},
		
		handleFilesSuccess(response, file, fileList) {
			let fileListData=fileList.filter(e=>{
			  return e.url
			})
			this.fileFun(file, fileListData);
		},
		onFilePreView(file) {
			if (file.response) {
				window.open(file.response.url, '_blank');
			}
		},
		onFileRemove(file, fileList) {
			this.fileFun(file, fileList);
		},
		fileFun(file, fileList) {
			this.fileList = fileList;
			this.formData.file_list = [];
			fileList.forEach((item, index) => {
				this.formData.file_list.push(item.url);
			});
		},
		// 附件上传
		beforeUpload(file) {
			const isJPG = /^image\/(jpeg|png|jpg)$/.test(file.type);
			const isLt2M = file.size / 1024 / 1024 < 5;
			if (!isJPG) {
				this.$message.error('上传图片只能是 JPEG,PNG,JPG 格式!');
			}
			if (!isLt2M) {
				this.$message.error('上传图片大小不能超过 5MB!');
			}
			return isJPG && isLt2M;
		},
		submitEmployee(name) {
			this.$refs[name].confirm(); //调用组件的confirm（）；
		},
		//关闭
		handleClose(done) {
			done();
		},
		sub(formName) {
			this.$refs[formName].validate(valid => {
				if (valid) {
					this.saveFun(formName);
				}
			});
		},
		resetForm(formName) {
			this.$emit('update:dialogVisible', false);
			this.$refs[formName].resetFields();
			this.formData={
				task_name: '',
				
				base_point: '0',
				task_remark: '',
				pt_id: 3,
				
				tree_echo: [], //用于编辑任务时的规则回显
				range_type: 0,
				rule_id: '',
				rule_value:[],
				file_list: [],
				
				task_expire_day: 1,
				expire_time: moment().format('YYYY-MM-DD 18:00'),
				weight: 0,
				package_id: 0,
				targets: [],
				reviewer_id: '',
				task_cycle: 0,
				timeout_deduction_point: null,
				timeout_deduction_point_limit: null,
				ahead_award_point: null,
				ahead_award_point_limit: null
			}
			this.fileList = [];
			this.max = 0; 
			this.min = 0;
			this.treeName = '';
			this.executorName = '';
			this.reviewerName = '';
			this.approval_selected = { dept: [], employee: [] };
			this.reviewer_selected = { dept: [], employee: [] };
		},
		ahead_timeout(item, arr, codes, code) {
			if (item) {
				if (arr) {
					if (Number(item) > Number(arr)) {
						this.$message.warning(code + '上限不能小于每日' + code);
						return true;
					}
				} else {
					this.$message.warning(codes + '不为0时，' + code + '上限不能为空');
					// this.$message.warning(`设置${codes}时，需同时设置每天${code}及${code}上限`);
					return true;
				}
			}
		},
		deletedata(data, arr) {
			data[arr] && data[arr] != 0 ? '' : delete data[arr];
		},
		// 提交
		saveFun(formName) {
			// 没有选择重复任务的时候
			// /api/integral/work/publish
			// 选择重复任务之后
			// /api/integral/schedule/publish/work
			let self = this;
			let data = JSON.parse(JSON.stringify(self.formData));
			if (data.task_cycle == 0) {
				delete data.task_cycle;
				delete data.task_expire_day;
				data.task_remark ? '' : delete data.task_remark;
			} else {
				delete data.package_id;
				delete data.weight;
				delete data.expire_time;
				data.task_remark ? '' : delete data.task_remark;
			}

			if (!data.ahead_award_point && data.ahead_award_point_limit) {
				// this.$message.warning('奖分上限不为0时每日奖分不能为空');
				this.$message.warning('设置提前奖分时，需同时设置每天奖分及奖分上限');
				return;
			} else if (data.ahead_award_point && !data.ahead_award_point_limit) {
				this.$message.warning('设置提前奖分时，需同时设置每天奖分及奖分上限');
				return;
			}
			if (!data.timeout_deduction_point && data.timeout_deduction_point_limit) {
				this.$message.warning('设置逾期扣分时，需同时设置每天扣分及扣分上限');
				return;
			} else if (data.timeout_deduction_point && !data.timeout_deduction_point_limit) {
				this.$message.warning('设置逾期扣分时，需同时设置每天扣分及扣分上限');
				return;
			}
			if (this.ahead_timeout(data.ahead_award_point, data.ahead_award_point_limit, '提前奖分', '奖分')) return;
			if (this.ahead_timeout(data.timeout_deduction_point, data.timeout_deduction_point_limit, '逾期扣分', '扣分')) return;
			if (!this.$getIsCreator('creator') || this.$getUserData().point_config.point_limit.length != 0) {
				let entry_limit = Number(this.$getUserData().point_config.point_limit[1].point);
				if (entry_limit > 0) {
					if (data.ahead_award_point > entry_limit || data.timeout_deduction_point > entry_limit) {
						this.$message.warning('每日奖扣分 不能超过您的奖扣分权限（您的奖扣分权限：' + entry_limit + '分）');
						return;
					}
					if (data.ahead_award_point_limit > entry_limit * 10 || data.timeout_deduction_point_limit > entry_limit * 10) {
						this.$message.warning('奖扣分上限不能超过' + entry_limit * 10 + '分（您的奖扣分权限' + entry_limit + '分*10）');
						return;
					}
				}
			}
			let add = ['ahead_award_point', 'ahead_award_point_limit', 'timeout_deduction_point', 'timeout_deduction_point_limit'];
			add.forEach(item => {
				this.deletedata(data, item);
			});
			let is=true;
			if(this.formData.task_cycle==1&&this.formData.task_expire_day<=moment().format('HH')){
				is=false  
			}else if(this.formData.task_cycle==2&&this.formData.task_expire_day<=moment().day()){
				is=false  
			}else if(this.formData.task_cycle==3&&this.formData.task_expire_day<=moment().format('D')){
				is=false  
			}
			if(data.base_point<=0){
				this.$message.warning('任务积分必须大于0，请调整后再发布');
				return;
			}
			this.taskload = true;
			this.$axios('post', this.formData.task_cycle == 0 ? '/api/integral/work/publish' : '/api/integral/schedule/publish/work', data).then(res => {
				let msg=res.data.msg;
				if(this.config.event_review_status&&this.config.event_task_review){
					msg+='！复核开启后，积分需管理员复核后才计入排名和统计'
				}
				this.$message.success(msg);
				if(this.formData.task_cycle&&is){//是否重复任务
					let str=this.formData.task_cycle==1? '您发布的每日重复任务将于明天0点执行自动发布，是否需要立即发布一条任务？':this.formData.task_cycle==2? '您发布的每周重复任务将于下周一执行自动发布，是否需要立即发布一条任务？':'您发布的每月重复任务将于下个月1号执行自动发布，是否需要立即发布一条任务？'
					this.$confirm(str, '提示', {
					  confirmButtonText: '发布',
					  cancelButtonText: '不需要',
					  type: 'warning'
					}).then(() => {
						this.executeTask(res.data.data)
					}).catch(() => { 
						this.$parent.get_list();
					});
				}else{
					this.$parent.get_list();
				}
				
				this.resetForm('formData');
			}).finally(() => {
				this.taskload = false;
			});
		},
		//执行周期任务
		executeTask(id){
			this.$axios('POST', '/api/integral/schedule/hand_exec',{schedule_id:id}).then(res => {
				this.$message.success('已发布');
				this.$parent.get_list();
			});
		},
		// 执行者
		approval_confirm(data) {
			this.approval_selected = { dept: [], employee: [] };
			this.formData.targets = [];
			this.executorName = '';
			if (data.employee !== null && data.employee.length != 0) {
				this.approval_selected = data;
				data.employee.forEach(element => {
					this.formData.targets.push(element.id);
					this.executorName += element.name + ',';
				});
			}
			this.show_employee_selector = false;
		},
		// 审核人
		reviewer_confirm(data) {
			this.reviewer_selected = { dept: [], employee: [] };
			this.formData.reviewer_id = '';
			this.reviewerName = '';
			if (data.employee !== null && data.employee.length != 0) {
				this.reviewer_selected = data;
				this.formData.reviewer_id = data.employee[0].id;
				this.reviewerName = data.employee[0].name;
			}
			this.show_reviewer_selector = false;
		},
		closeDialog() {
			this.resetForm('formData');
		}
	}
};
</script>
<style scoped lang="scss">
	::v-deep .el-dialog__body{
		padding: 20px;
	}
</style>
