import Api from '~/service/Api';
import Utils from "~/utils"
import commonFunctions from '~/mixin/commonFunctions.js';
import moment from 'moment'
export default {
	mixins: [commonFunctions],
	methods: {
    //柜员明细
  async  usrDetail(row){
      let params = {
        usr : row.extkey,
      }
      let res = await Api.post('/public/taskdist/config/changelog/getloglistbyextkey',params);
      if(res.respCode == SUCCESS){
        this.taskData.data = res.data
      }
    },
		//重置
		handleReset() {
			this.model.extkey = ''
      this.model.bizGroup = ''
      this.model.bizPosition = ''
      this.model.status = ''
      this.model.participateFlag = ''
		},

		//查询列表
		async handleSearch() {
			let params = {
        extkey: this.model.extkey,
        bizGroup: this.model.bizGroup ,
        bizPosition: this.model.bizPosition ,
        status: this.model.status,
        participateFlag: this.model.participateFlag,
        pageNo: this.pagination.pageIndex,
				pageSize: this.pagination.pageSize,
			};
			//查询接口
			const loading = this.loading();
			const res = await Api.post('/public/taskdist/user/getTaskUsrs', params);
			if (res.respCode === SUCCESS) {
				this.tskUsrData = res.data.records;
				this.pagination.total = Number(res.data.total);
			}
			loading.close();
    },
    //参与/退出分配
    async inOutDist(row){
      let flg = row.participateFlag
      let params = {
        extkey : row.extkey,
        participationFlag :flg == 'Y' ? 'N' :'Y'
      }
      this.$confirm('您确定将该柜员'+ (flg == 'Y' ? '退出' : '加入') +'分配?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning',
			}).then(async () => {
      const res = await Api.post('/public/taskdist/user/update/participationFlag',params);
      if(res.respCode === SUCCESS){
        this.$notify({
          title: '成功',
          message: (flg == 'Y' ? '退出' : '参与') +'分配成功',
          type: 'success',
        });
        this.handleSearch()
      }
    })
    },
    async queryUsrByBch(){
      const res = await Api.post('/manager/usr/queryUserByPage');
      if(res.respCode === SUCCESS){
        this.usrs = res.data.list
      }
      console.log("usrs:" ,this.model.usrs)
      console.log("list:" ,res.data.list)
    },
		currentChange(num) {
			this.currentPage = num;
			this.getTableData();
		},

	
		beforeClose(done) {
			this.dialogTableVisible = false;
			this.currentPage = 1;
			done();
		},

		
		
		// pageSize改变
		handleSizeChange(val) {
			this.pagination.pageIndex = 1;
			this.pagination.pageSize = val;
			this.handleSearch();
		},
		// 页码改变
		handleCurrentChange(val) {
			this.pagination.pageIndex = val;
			this.handleSearch();
    },
       //格式化列表显示
       flgFormat(flg){
        if(flg == 'Y'){
          return '参与';
        }else{
          return '不参与';
        }
        
      },
       //获取码表
    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;
      },
		
	},
};