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

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel()">取消</el-button>
        <el-button type="primary" @click="cancel()">
          确认
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script>
export default {
  name: 'SetPersonnel',
  props: {
    setCrewOpen: {
      type: Boolean,
      default: false
    },
    id: {
      type: Number,
      default: null
    },
    type: {
      type: String,
      default: ''
    },
    title: {
      type: String,
      default: '分派'
    }
  },
  data() {
    return {
      url: '',
      setCrewShow: false,
      formData: {},
      option: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: '工艺员',
            prop: 'userId',
            span: 23,
            type: 'select',
            dicData: [
              {
                label: '工艺员一',
                value: '1'
              },
              {
                label: '工艺员二',
                value: '2'
              },
            ],
            rules: [
              {
                required: true,
                message: '请备注',
                trigger: 'blur'
              }
            ]
          },

        ]
      }
    };
  },
  mounted() {
    this.setCrewShow = this.setCrewOpen
    console.log(9999, this.setCrewOpen)
  },
  methods: {
    open() {
      // if (this.type === 'teamSet') {
      //   this.url = 'teamSet/findUserByTeam/' + this.id;
      // } else if (this.type === 'platingAssort') {
      //   this.url = 'bsPlatingAssort/findUserByPlatingAssort/' + this.id;
      // } else if (this.type === 'abnormalConfig') {
      //   this.url = 'bsBasicClass/findUserByAbnormalConfig/' + this.id;
      // }
    },
    submit() {
      const keyIds = this.$refs['tree-transfer'].getChecked();
      if (keyIds == null) {
        this.$message.warning(this.$t('publics.message.noDataToSave'));
        return;
      }
      let url = '';
      if (this.type === 'teamSet') {
        url = '/teamSet/addOrDeleteUserRight';
      } else if (this.type === 'platingAssort') {
        url = '/bsPlatingAssort/addOrDeleteUserRight';
      } else if (this.type === 'abnormalConfig') {
        url = '/bsBasicClass/addOrDeleteUserRight';
      }
      this.loading = true;
      this.$ajax
        .post(url, {
          id: this.id,
          keyIdArr: keyIds
        })
        .then(() => {
          this.loading = false;
          this.$message.success(this.$t('videaVueLib.publics.message.success'));
          this.cancel(true);
        });
    },
    opened() {
      this.$refs['tree-transfer'].axios();
    },
    cancel(refresh) {
      this.setCrewShow = false
      this.$emit('setCrewOpeSancel', typeof refresh === 'boolean' && refresh);
    }
  }
};
</script>
