<template>
  <el-dialog v-model="setCrewShow" :before-close="cancel" :title="title" width="600px">
    <avue-form :option="option" ref="from"></avue-form>

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel()">取消</el-button>
        <el-button type="primary" @click="submit()"> 确认 </el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script>
// setDispatch
import { setDispatch } from '@/api/processManagement/taskDispatch';
import { taskRedeploy } from '@/api/processManagement/taskProcessing';

export default {
  name: 'SetPersonnel',
  props: {
    setCrewOpen: {
      type: Boolean,
      default: false,
    },
    id: {
      type: String,
      default: null,
    },
    type: {
      type: String,
      default: '',
    },
    title: {
      type: String,
      default: '分派',
    },
    updateRow: {
      type: Array,
      default: [],
    },
  },
  data() {
    return {
      url: '',
      setCrewShow: false,
      formData: {},
      option: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: '工艺员',
            prop: 'userId',
            span: 23,
            type: 'select',
            dicUrl: '/blade-system/user/page?current=1&&size=99999',
            props: {
              label: 'name',
              value: 'id',
              res: 'data.records',
            },
            rules: [
              {
                required: true,
                message: '请选择',
                trigger: 'blur',
              },
            ],
          },
        ],
      },
    };
  },
  mounted() {
    this.setCrewShow = this.setCrewOpen;
  },
  methods: {
    submit() {
      this.$refs.from.validate((valid, done, msg) => {
        if (valid) {
          // done();
          let arr = [];
          this.updateRow.forEach((item, index) => {
            arr.push(item.id);
          });
          let query = {
            dtIdList: arr.join(','),
            userId: this.$refs.from.form.userId,
            // remarks:'任务分派'
          };
          if (this.title == '转派') {
            taskRedeploy(query).then(res => {
              this.$message.success('操作成功！');
              this.cancel(true);
            });
          } else {
            setDispatch(query).then(res => {
              this.$message.success('操作成功！');
              this.cancel(true);
            });
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },

    cancel(refresh) {
      this.setCrewShow = false;
      this.$emit('setCrewOpeSancel', typeof refresh === 'boolean' && refresh);
    },
  },
};
</script>
