<template>
  <div>
    <el-form :model="inputQuery" :rules="formRules" ref="dataForm" label-width="100px">
      <el-row :gutter="20">
        <el-col :span="11">
          <el-form-item label="当前仓库" prop="curInv">
            <el-select v-model="inputQuery.curInv" placeholder="当前仓库"
                       @change="curInvChange"
                       @clear="clear"
                       filterable
                       style="width: 90%"
                       clearable>
              <el-option
                v-for="item in invList"
                :key="item.code"
                :label="item.name"
                :value="item.code">
                <span style="float: left">{{ item.name }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.warehouseName }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="当前单据类型" prop="action">
            <el-select v-model="inputQuery.action" placeholder="请选择" clearable
                       style="width: 90%"
            >
              <el-option
                v-for="item in busTypes"
                :key="item.action"
                :label="item.name"
                :value="item.action">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>


      <el-row :gutter="20" type="flex">
        <el-col :span="11">
          <el-form-item label="委托仓库" prop="entrustInv">
            <el-select v-model="inputQuery.entrustInv" placeholder="委托仓库"
                       @change="entrustInvChange"
                       @clear="clear1"
                       filterable
                       style="width: 90%"
                       clearable>
              <el-option
                v-for="item in entrustSubInvList"
                :key="item.code"
                :label="item.name"
                :value="item.code">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>


        <el-col :span="11">
          <el-form-item label="委托验收人" prop="entrustUser">
            <el-select v-model="inputQuery.entrustUser" placeholder="委托验收人" clearable style="width: 90%">
              <el-option
                v-for="item in entrustUserArray"
                :key="item.userid"
                :label="item.employeeName"
                :value="item.userid">
                <span style="float: left">{{ item.employeeName }}</span>
              </el-option>

            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20" type="flex">

        <el-col :span="11">
          <el-form-item label="生成单据类型" prop="entrustUser">
            <el-select v-model="inputQuery.entrustAction" placeholder="单据类型"
                       style="width: 90%"
                       clearable>
              <el-option
                v-for="item in entrustBusArray"
                :key="item.action"
                :label="item.name"
                :value="item.action">
                <span style="float: left">{{ item.name }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>


        <el-col :span="11">
          <div class="text item">
            <el-checkbox v-model="inputQuery.finishRece">是否直接验收完成
            </el-checkbox>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>

import {
  getBasicThirdSys,
} from "@/api/basic/basicThirdSys";

import {
  filterUnUse, findByInvUser
} from "@/api/basic/busType";
import {filterAll, filterNext, warehouseBussinessTypeList, warehouseUserList} from "@/api/system/invWarehouse";
import {filterSubByInv, filterSub, findInvByUser, findByFrom} from "@/api/system/invSubWarehouse";


export default {
  name: "inputQuery",
  props: {
    inputQuery: {
      type: Object,
      required: true,
    },
  },

  data() {
    return {
      filterQuery: {
        enabled: true,
        isBuType: true,
        isFilterBind: true,
      },
      storageList: [],
      invList: [],
      entrustSubInvList: [],
      entrustStorageList: [],
      orderTypeList: [],
      fromSpecialOptions: [],
      thirdSys: [],
      busTypes: [],
      entrustBusArray: [],
      entrustUserArray: [],
      formRules: {
        action: [
          {required: true, message: "请输入扫码单据类型", trigger: "blur"}
        ],
        entrustInv: [
          {required: true, message: "请输入委托验收人仓库", trigger: "blur"}
        ],
        entrustUser: [
          {required: true, message: "请输入委托验收人", trigger: "blur"}
        ],
      },
    }
  },
  methods: {


    //获取当前仓库
    findCurInvs() {
      this.invList = [];
      findInvByUser()
        .then((response) => {
          this.invList = response.data || [];
        })
        .catch(() => {
        });
    },

    //切换当前仓库
    curInvChange() {

      this.getOrderType();
      this.findEntrustInv();
    },
    clear(){
      this.inputQuery.action = null;
      this.inputQuery.entrustInv = null;
      this.inputQuery.entrustUser = null;
      this.inputQuery.entrustAction = null;
    },

    //获取当前单据类型
    getOrderType() {
      let query = {
        code: this.inputQuery.curInv
      }
      findByInvUser(query).then((response) => {
        this.busTypes = response.data || [];
      }).catch(() => {
      })
    },

    //获取委托仓库
    findEntrustInv() {
      let query = {
        locInvCode: this.inputQuery.curInv,
      };
      findByFrom(query)
        .then((response) => {
          this.entrustSubInvList = response.data || [];
        })
        .catch(() => {
        });
    },

    //切换委托仓库
    entrustInvChange() {
      this.getUserBus();
    },
    clear1(){
      this.inputQuery.entrustUser = null;
      this.inputQuery.entrustAction = null;
    },


    getUserBus() {
      let query = {
        code: this.inputQuery.entrustInv,
      }

      //加载用户数据
      warehouseUserList(query).then((res) => {

        this.entrustUserArray = [];
        this.entrustUserArray = res.data.list;
      }).catch((error) => {
        this.$message.error("用户数据加载失败")
      });

      //加载单据类型数据
      warehouseBussinessTypeList(query).then((res) => {

        this.entrustBusArray = res.data.list;
      }).catch((error) => {
        this.$message.error("单据类型数据加载失败")
      });
    },


  },
  computed: {
    corpType() {
      return this.inputQuery.corpType;
    }
  },


  created() {

    this.findCurInvs();

    if (this.inputQuery.action != null) {
      //编辑----加载候选数据
      this.getOrderType();
      this.findEntrustInv();
      this.getUserBus();
    }


  },
};
</script>

<style scoped>
.itemTag {
  float: left;
  text-align: left;
  margin-top: 10px;
  width: 100px;
}

.text {
  font-size: 13px;
  font-family: "Microsoft YaHei";
}

</style>
