let mixin = {};
mixin = {
  props: ['visiable', 'multi', 'rows', 'param', 'current_prefix', 'wfInfo'],
  components: {},
  created() {
    this.initSetting({
      pageEnabled: false,
      url: this.current_prefix + '/wf/getAllNodes',
      param: () => {
        return {
          stringOne: this.wfInfo.uuid
        }
      }
    });
  },
  mounted() {
    this.searchEvent();
  },
  data() {
    var that = this;
    return {
      showDialog: true,
      falseValue: false,
      selectMulti: true,
      vxeOption: {},
      showUserDialog: false,
      userRows: [],
      operateIndex: -1
    };
  },
  methods: {
    getUsernames(row) {
      return row.wfTaskCandidateDTOs.map(item => item.name).join(",")
    },
    openUserDialig(row, rowIndex) {
      this.userRows = row.wfTaskCandidateDTOs.map(item => {
        return {
          id: item.id,
          nickName: item.name
        }
      });
      this.operateIndex = rowIndex;
      this.showUserDialog = true;
    },
    userConfirm(rows) {
      let item = this.$baseLodash.cloneDeep(this.page.records[this.operateIndex]);
      let wfTaskCandidateDTOs = item.wfTaskCandidateDTOs;
      let item1s = [];
      let item2s = []
      rows.forEach(row => {
        let wfTaskCandidateDTO = wfTaskCandidateDTOs.find(item => item.id == row.id)
        if (wfTaskCandidateDTO) {
          if (!wfTaskCandidateDTO.userFlag) wfTaskCandidateDTO.userFlag = 6
          item1s.push({...wfTaskCandidateDTO});
        } else {
          item2s.push({
            id: row.id,
            name: row.nickName,
            userFlag: 6
          })
        }
      })
      item.wfTaskCandidateDTOs = item1s.concat(item2s)

      this.saveItem(item);
    },
    saveItem(row) {
      this.$http({
        url: this.current_prefix + '/wf/setTaskUser',
        method: `post`,
        data: row,
        isLoading: true,
        success: res => {
          this.$message({
            message: res.content,
            type: 'success',
            duration: 500,
            onClose: t => {
              this.searchEvent();
            }
          });
        }
      });
    },
    closeWin() {
      this.dialogClose();
      this.$emit('close')
    }
  }
};
export default mixin;
