<template>
  <div>
    <el-form :model="inputQuery" :rules="formRules" ref="dataForm" label-width="120px" border>
      <el-row type="flex" style="margin-bottom: 20px">
        <el-col :span="11">
          <el-form-item label="出入库单" prop="originAction">
            <el-select v-model="inputQuery.originAction" placeholder="原单据类型" clearable size="small"
                       style="width: 90%">
              <el-option
                v-for="item in originBusTypes"
                :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">
          <el-form-item label="补单方式" prop="supplementAll">
            <el-select v-model="inputQuery.supplementAll" placeholder="补单方式" clearable size="small"
                       style="width: 90%">
              <el-option label="全量补单" :value="true"></el-option>
              <el-option label="缺量补单" :value="false"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <!--      <el-row type="flex"  style="margin-bottom: 20px">-->
      <!--        <el-col :span="11">-->
      <!--          <el-form-item label="目标所在仓库" prop="invCode">-->
      <!--            <el-select v-model="inputQuery.invCode" placeholder="目标所在仓库" clearable size="small"-->
      <!--                       @change="invChange"-->
      <!--                       style="width: 90%">-->
      <!--              <el-option-->
      <!--                v-for="item in locInvs"-->
      <!--                :key="item.name"-->
      <!--                :label="item.name"-->
      <!--                :value="item.code">-->
      <!--                <span style="float: left"> {{ item.name }}</span>-->
      <!--              </el-option>-->
      <!--            </el-select>-->
      <!--          </el-form-item>-->
      <!--        </el-col>-->
      <!--      </el-row>-->

      <!--        <el-col :span="11">-->
      <!--          <el-form-item label="目标往来仓库" prop="defaultInvCode">-->
      <!--            <el-select v-model="inputQuery.defaultInvCode" placeholder="目标往来仓库" clearable size="small"-->
      <!--                       @change="invChange"-->
      <!--                       style="width: 90%">-->
      <!--              <el-option-->
      <!--                v-for="item in fromInvs"-->
      <!--                :key="item.name"-->
      <!--                :label="item.name"-->
      <!--                :value="item.code">-->
      <!--                <span style="float: left"> {{ item.name }}</span>-->
      <!--              </el-option>-->
      <!--            </el-select>-->
      <!--          </el-form-item>-->
      <!--        </el-col>-->
      <!--      </el-row>-->
      <el-divider content-position="left">生成出入库单</el-divider>
      <el-row style="margin-top: 20px">
        <el-col :span="11">
          <el-form-item label="目标出入库单" prop="action">
            <el-select v-model="inputQuery.action" placeholder="目标出入库单" clearable size="small" style="width: 90%">
              <el-option
                v-for="item in targetTypes"
                :key="item.action"
                :label="item.name"
                :value="item.action">
                <span> {{ item.name }}</span>
              </el-option>

            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="时间间隔（h）" prop="beforeTime">
            <el-input style="width: 90%"
                      size="small"
                      type="number"
                      placeholder="请输入内容"
                      v-model="inputQuery.beforeTime"
                      onkeyup="this.value=this.value.replace(/\D/g,'')"
                      onafterpaste="this.value=this.value.replace(/\D/g,'')"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>

        <el-col :span="11">
          <el-form-item label="创建单据模式" prop="createType">
            <el-select v-model="inputQuery.createType" placeholder="创建单据模式" size="small"
                       style="width: 90%">
              <el-option label="送货至入库补单" :value="1"></el-option>
              <el-option label="向上级仓库补单" :value="2"></el-option>
              <el-option label="预验收转入库补单" :value="3"></el-option>
              <el-option label="寄售转入库补单" :value="4"></el-option>
              <el-option label="退货补单" :value="5"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="审核状态" prop="auditStatus" class="query-form-item">
            <el-radio-group v-model="inputQuery.auditStatus">
              <el-radio :label="1">草稿</el-radio>
              <el-radio :label="2">待核对</el-radio>
            </el-radio-group>
            <!--            <el-select v-model="inputQuery.auditStatus" placeholder="请选择出入库类型" style="width: 90%">-->
            <!--              <el-radio :label="1">草稿</el-radio>-->
            <!--              <el-radio :label="2">待核对</el-radio>-->
            <!--              <el-radio :label="3">待审核</el-radio>-->
            <!--            </el-select>-->

          </el-form-item>
        </el-col>
      </el-row>
      <el-row style="margin-bottom: 20px">
        <el-col :span="11">
          <el-form-item label="单据拆单类型" prop="createType">
            <el-select v-model="inputQuery.splitOrder" placeholder="单据拆单类型" size="small"
                       style="width: 90%">
              <el-option label="无需拆单" :value="0"></el-option>
              <el-option label="按入账库拆单" :value="1"></el-option>
              <el-option label="按预验收库拆单" :value="2"></el-option>
              <el-option label="按寄售仓库拆单" :value="3"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="默认补单仓库" prop="defaultInvCode">
            <el-select v-model="inputQuery.defaultInvCode" placeholder="默认补单仓库" clearable size="small"
                       @change="invChange"
                       style="width: 90%">
              <el-option
                v-for="item in fromInvs"
                :key="item.name"
                :label="item.name"
                :value="item.code">
                <span style="float: left"> {{ item.name }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-divider content-position="left">生成业务单</el-divider>
      <el-row>
        <el-col :span="11">
          <el-form-item label="目标业务单">
            <el-select v-model="inputQuery.targetBusAction" placeholder="目标业务单" clearable size="small"
                       style="width: 90%">
              <el-option
                v-for="item in targetBusTypes"
                :key="item.originAction"
                :label="item.originName"
                :value="item.originAction">
                <span> {{ item.originName }}</span>
              </el-option>

            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="时间间隔（h）" prop="beforeTime">
            <el-input style="width: 90%"
                      size="small"
                      type="number"
                      placeholder="请输入内容"
                      v-model="inputQuery.busBeforeTime"
                      onkeyup="this.value=this.value.replace(/\D/g,'')"
                      onafterpaste="this.value=this.value.replace(/\D/g,'')"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="审核状态" prop="busAuditStatus" class="query-form-item">
            <el-radio-group v-model="inputQuery.busAuditStatus">
              <el-radio :label="1">草稿</el-radio>
              <el-radio :label="2">待审核</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex">
        <el-col :span="23" type="flex">
          <el-form-item prop="intro">
            <label slot="label">说&emsp;&emsp;明</label>
            <el-input v-model="inputQuery.intro" size="small" style="width: 90%" type="textarea"
                      row="3"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
  </div>
</template>

<script>

import {findChangeOrigin, findChangeTarget, getBusTypeList, getBusTypeListByUser} from "@/api/basic/busType";
import {filterSubAll, findByFrom, getInvWarehouseList} from "@/api/system/invSubWarehouse";
import {isBlank} from "@/utils/strUtil";
import {getBusTypeChangeList} from "@/api/basic/busTypeChange";

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

  data() {
    return {
      filterQuery: {
        enabled: true,
        isBuType: true,
      },
      originBusTypes: [],
      targetTypes: [],
      targetBusTypes: [],
      locInvs: [],
      fromInvs: [],
      isAdd: false,
      formRules: {
        originAction: [
          {
            required: true,
            message: "原单据类型不能为空",
            trigger: "blur"
          }
        ],
        action: [
          {
            required: true,
            message: "目标单据类型不能为空",
            trigger: "blur"
          }
        ],
        supplementAll: [
          {
            required: true,
            message: "补单方式不能为空",
            trigger: "blur"
          }
        ],
        // invCode: [
        //   {
        //     required: true,
        //     message: "目标所在仓库不能为空",
        //     trigger: "blur"
        //   }
        // ],
        // defaultInvCode: [
        //   {
        //     required: true,
        //     message: "目标往来仓库不能为空",
        //     trigger: "blur"
        //   }
        // ],
      },
    }
  },
  methods: {
    getBusType() {
      let params = {
        enable: true
      };
      getBusTypeList(params).then((res) => {
        if (res.code === 20000) {
          this.busTypes = res.data.list || [];
        }
      })
    },

    getOriginBusType() {
      let query = {
        enable: true
      };
      findChangeOrigin(query).then((res) => {
        if (res.code === 20000) {
          this.originBusTypes = res.data.list || [];
        }
      })
    },

    getTargetBusType() {
      let query = {
        enable: true,
        invCode: this.inputQuery.defaultInvCode,
      };
      findChangeTarget(query).then((res) => {
        if (res.code === 20000) {
          this.targetTypes = res.data.list || [];
        }
      })
    },


    getTargetChangeType() {
      let query = {
        enable: true
      };
      getBusTypeChangeList(query).then((res) => {
        if (res.code === 20000) {
          this.targetBusTypes = res.data.list || [];
        }
      })
    },

    getLocInv() {
      let params = {};
      filterSubAll(params).then((res) => {
        if (res.code === 20000) {
          this.locInvs = res.data || [];
        }
      });
    },

    getFromInv() {
      let params = {
        // locInvCode: this.inputQuery.invCode,
        // filter: 2
      };
      getInvWarehouseList(params).then((res) => {
        if (res.code === 20000) {
          this.fromInvs = res.data;
        }
      })
    },

    invChange() {
      this.targetTypes = [];
      this.getTargetBusType()
    },
  },
  created() {
    if (this.inputQuery.originAction == null) {
      this.isAdd = true;
      this.inputQuery.createType = 1;
      this.inputQuery.auditStatus = 1;
      this.inputQuery.busAuditStatus = 1;
    } else {
      this.getTargetBusType();
    }
    this.getTargetBusType();
    this.getTargetChangeType();

    this.getOriginBusType();
    this.getLocInv();
    this.getFromInv();

  }
}
</script>

<style scoped>

</style>
