<template>
  <div>

    <el-transfer v-model="value" :data="data"
                 class="edit_dev"
                 @change="transferChange"
                 filterable
                 :titles="['未选入单据类型', '已选入单据类型']"

    >

      <template slot-scope="scope">
        <span>
          <span>{{ scope.option.label }}</span>
        </span>
      </template>

    </el-transfer>
    <div style="text-align: center;margin-top: 20px">
      <el-button type="primary" size="small" icon="search" @click="onAddSubmit"
      >提交
      </el-button
      >
      <el-button type="primary" size="small" icon="search" @click="cancelDialog"
      >取消
      </el-button
      >
    </div>
  </div>
</template>

<script>
import {invRelBusTypeList, updateInvRelBusType} from "@/api/system/invWarehouse";

export default {
  name: "invRelBusType",
  props: {
    configParms: {
      type: Object,
      required: true,
    },
    inputQuery: {
      type: Object,
      required: true,
    },
    closeDialog: {
      type: Function,
      required: true,
    },
  },

  data() {
    return {
      bussinessTypeTotal: 0,
      bussinessTypeQuery: {
        enabled: true,
        page: 1,
        limit: 10,
        ids: ""
      },
      keyArr:[],
      busQuery: {
        code: null,
        page: 1,
        limit: 10
      },
      selectBussinessTypeList: [],
      busTypes: [],
      bussinessTypeFormVisible: false,
      data: [],
      value: [],
      loading: false,
    }
  },
  methods: {
    selsectBussinessType() {    //获取单据类型
      this.busQuery = {
        code: this.inputQuery.code
      }
      invRelBusTypeList(this.busQuery).then((res) => {
        if (res.code == 20000) {
          this.busTypes = res.data;
          this.$nextTick(() => {
            for (let i = 0; i < this.busTypes.length; i++) {
              this.data.push({
                key: this.busTypes[i].action,
                label: this.busTypes[i].name,
              });
              if (this.busTypes[i].select) {
                this.value.push(
                  this.busTypes[i].action
                );
              }
            }
          });
        } else {
          this.$message.error(res.message);
        }
      }).catch((error) => {
        this.$message.error("单据类型数据加载失败")
      });
    },

    checkSelectable(row) {
      return !row.select;
    },

    onAddSubmit() {
      var postRequesty = {
        invCode: this.inputQuery.code,
        selectActions: this.keyArr,
      };
      updateInvRelBusType(postRequesty).then((res) => {
        if (res.code == 20000) {
          this.closeDialog();
        } else {
          this.$message.error(res.message);
        }

      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },


    transferChange(value, direction, keyArr) {
      this.keyArr=value;
      console.log(value);
      console.log(direction);
      console.log(keyArr);
    },

    cancelDialog() {
      this.closeDialog();
    },

  },
  created() {
    this.selsectBussinessType();
  },
}
</script>

<style scoped>

</style>
