<template>
  <el-dialog
    v-model="setCrewShow"
    :before-close="cancel"
    title="设置班组"
    width="640px"
    @open="open"
    @opened="opened"
  >
    <el-transfer
      v-model="value"
      filterable
      :filter-method="filterMethod"
      filter-placeholder="输入关键字进行确认"
      :titles="['未选择', '已选择']"
      :data="dataList"
      :props="{
        key: 'id',
        label: 'tsName'
      }"
    />
    <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>
import { getProcessesTeams, setTeams } from "@/api/processManagement/basicProcesses";

export default {
  name: "SetPersonnel",
  props: {
    setCrewOpen: {
      type: Boolean,
      default: false,
    },
    pId: {
      type: String,
      default: null,
    },
    type: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      url: "",
      setCrewShow: false,
      dataList: [],
      value: [],
    };
  },
  mounted() {
    this.setCrewShow = this.setCrewOpen;
    this.getTeams();
  },
  methods: {
    getTeams() {
      getProcessesTeams(this.pId).then((res) => {
        this.dataList = res.data.data.teamSetEntityList
        if(res.data.data.processTeamVOList.length > 0){
          this.value = res.data.data.processTeamVOList.map(item => item.id)
        }
      });
    },
    open() {
    },
    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);
      //   });
      let ids = this.value;
      let query = {
        // BsTeamSetDTO:{
         pid: this.pId,
         tsIdList: ids,
        // }
      };
      setTeams(query).then(() => {
        this.$message.success("设置班组成功");
        this.cancel(true);
      });
    },
    opened() {
      // this.$refs["tree-transfer"].axios();
    },
    cancel(refresh) {
      this.setCrewShow = false;
      this.$emit("setCrewOpeSancel", typeof refresh === "boolean" && refresh);
    },
  },
};
</script>
