import Api from '~/service/Api';
import Utils from "~/utils"
import commonFunctions from '~/mixin/commonFunctions.js';
import moment from 'moment'
export default {
	mixins: [commonFunctions],
	methods: {
		//重置
		handleReset() {
			this.model.bchcon = '';
			this.model.trncorco.ownref = '';
			this.model.trncorco.relflg = '';
			this.model.usrcon = '';
			this.model.trncorco.inidatfro = '';
			this.model.trncorco.inidattil = '';
			this.model.atp.cod = '';
			this.model.trncorco.dflg = '1';
			this.model.atptxt = '';
			this.model.searchAllUsers = false;
			this.model.channel = '';
    },
		//查询列表
		async handleSearch() {
			let inidatfro = this.model.trncorco.inidatfro;
			if (!inidatfro) {
				this.$notify.error({
					title: '错误',
					message: '查询开始日期必输!'
				});
				return;
			}
			let inidattil = this.model.trncorco.inidattil;
			if (!inidattil) {
				this.$notify.error({
					title: '错误',
					message: '查询结束日期必输!'
				});
				return;
			}
			let params = {
				ownref: this.model.trncorco.ownref,
				inidatfro: moment(inidatfro).format('YYYY-MM-DD') + ' 00:00:00',
        inidattil: moment(inidattil).format('YYYY-MM-DD') + ' 23:59:59',
        tskcla:this.model.tskcla,
        tsksta:this.model.tsksta,
        // frm:this.model.frm,
        usr:this.model.usr,
				pageNo: this.pagination.pageIndex,
				pageSize: this.pagination.pageSize,
			};
			//查询接口
			const loading = this.loading();
			const res = await Api.post('/public/quesel/manAssignTaskList', params);
			if (res.respCode === SUCCESS) {
				this.stmData.data = res.data.list;
        this.pagination.total = Number(res.data.total);
			}
			loading.close();
		},
		// 领取任务
		async getUnAssignData () {
        const loading = this.loading();
        const res = await Api.post('/public/sptsel/getTask', {});
        if (res.respCode === SUCCESS) {
          this.$notify({
						title: '成功',
						message: '领取任务成功!',
						type: 'success',
          });
        }
        loading.close();
        this.handleSearch();
    },
    async rebackTask(row){
      const loading = this.loading();
      const res = await Api.post('/public/sptsel/rebackTask', {queinr:row.inr});
      if (res.respCode === SUCCESS) {
        this.$notify({
          title: '成功',
          message: '退回分配成功!',
          type: 'success',
        });
      }
      loading.close();
      this.handleSearch();
    },
    unAssignMethod(){
			this.isShowManualAssign = true
    },
    currentChange(num) {
			this.currentPage = num;
			this.getTableData();
		},
		// 手工分配关闭弹框
		closeDialog () {
			this.isShowManualAssign = false
		},
		// 手工分配成功回调,刷新页面
		refresh () {
			this.isShowManualAssign = false
			this.handleSearch();
    },
    
    closeCorDialog () {
			this.isShowCorToQue = false
    },
    refreshC () {
			this.isShowCorToQue = false
			this.handleSearch();
    },
		// pageSize改变
		handleSizeChange(val) {
			this.pagination.pageIndex = 1;
			this.pagination.pageSize = val;
			this.handleSearch();
		},
		// 页码改变
		handleCurrentChange(val) {
			this.pagination.pageIndex = val;
			this.handleSearch();
		},
		selectableFn (row) {
			return 'new|assigned|correct|incoming|waiting'.indexOf(row.status) != -1
		},
		// 表格多选
		handleSelectionChange (val) {
			this.multipleSelection = val.map((item) => {
				return item
			})
			console.log(this.multipleSelection)
    },
    async  getallusers(){
      let res = await Api.post("/public/taskdist/user/getallusers");
      if (res.respCode == SUCCESS) {
        this.userList= res.data 
      }
   },
     //初始化码表
async getdbCode(codeType, uil, codeNam) {
  let params = {
    codeType: codeType,
    uil: uil ? uil : 'EN'
  }
  let rtnmsg = await Api.post("/manager/dic/listDicInfo", params)
  if (rtnmsg.respCode === SUCCESS) {
    let curList = rtnmsg.data.map(item => ({
      value: item.codeValue,
      label: item.codeName
    }));
    this.dbCodes[codeNam] = curList
  }
}, //表格码表格式化
getCodelabel(value,codenam) {
      const codeobj = this.dbCodes[codenam].find(obj => obj.value === value)
      return codeobj ? codeobj.label : value;
},

    // 机构列表
    async getBranchList() {
      const res = await Api.post("/public/quesel/getBranchList");
      if (res.respCode == SUCCESS) {
        this.bchtypList = res.data.list;
      }
    },

    //格式化机构
    bchFormat(value){
      const codeobj = this.bchtypList.find(obj => obj.inr === value)
      return codeobj ? codeobj.bchname : value;
    }
	},
};