<template>
  <div>
    <el-form :model="inputQuery" :rules="formRules" ref="dataForm" label-width="120px" border>
      <el-row type="flex">
        <el-col :span="11">
          <el-form-item label="单据类型名称" prop="originName">
            <el-input v-model="inputQuery.originName" :disabled="!isAdd" size="small" placeholder="请输入内容"
                      style="width: 90%"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="11">
          <el-form-item label="单据类型代码" prop="originAction">
            <el-input v-model="inputQuery.originAction" :disabled="!isAdd" size="small" placeholder="请输入内容"
                      style="width: 90%"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex"  style="margin-bottom: 20px">
        <el-col :span="11">
          <el-form-item label="启用状态" prop="enable">
            <el-select v-model="inputQuery.enable"
                       size="small"
                       placeholder="启用状态"
                       style="width: 90%"
                       clearable
            >
              <el-option label="启用" :value="true"></el-option>
              <el-option label="禁用" :value="false"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="类型">
            <el-select v-model="inputQuery.type"
                       size="small"
                       placeholder="类型"
                       style="width: 90%"
                       clearable
            >
              <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="5"></el-option>
              <el-option label="盘点转单" :value="4"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-divider content-position="center">生成出入库单</el-divider>
      <el-row style="margin-top: 20px">
        <el-col :span="11">
          <el-form-item label="目标出入库单" prop="targetIoAction">
            <el-select v-model="inputQuery.targetAction" placeholder="请选择" clearable size="small" style="width: 90%">
              <el-option
                v-for="item in targetTypes"
                :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="时间间隔(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 style="margin-bottom: 20px">
        <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-form-item>
        </el-col>
      </el-row>
      <el-divider content-position="center">生成业务单</el-divider>
      <el-row type="flex"  style="margin-top: 20px">
        <el-col :span="11">
          <el-form-item label="目标业务单" prop="targetBusAction">
            <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 style="float: left"> {{ item.originName }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="时间间隔（h）" prop="busBeforeTime">
            <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 :label="3">已审核</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="comments">
            <label slot="label">备&emsp;&emsp;注</label>
            <el-input v-model="inputQuery.remark" size="small" style="width: 90%" type="textarea"
                      row="3"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

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

<script>

import {getBusTypeList, getBusTypeListByUser} from "@/api/basic/busType";
import {getBusTypeChangeList} from "@/api/basic/busTypeChange";

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

  data() {
    return {
      filterQuery: {
        enabled: true,
        isBuType: true,
      },
      targetTypes: [],
      targetBusTypes: [],
      isAdd: false,
      formRules: {
        originName: [
          {
            required: true,
            message: "单据类型名称不能为空",
            trigger: "blur"
          }
        ],
        originAction: [
          {
            required: true,
            message: "单据类型代码不能为空",
            trigger: "blur"
          }
        ],
        targetAction: [
          {
            required: true,
            message: "目标单据类型不能为空",
            trigger: "blur"
          }
        ],
        enable: [
          {
            required: true,
            message: "请选择启用状态",
            trigger: "blur"
          }
        ],
        type: [
          {
            required: true,
            message: "请选择类型",
            trigger: "blur"
          }
        ],
      },
      typeMap: {
        1: "耗材领用",
        2: "产品申购",
        3: "采购计划",
        4: "盘点转单"
      },
    }
  },
  methods: {
    getBusType() {
      let params = {
        enable: true
      };
      getBusTypeList(params).then((res) => {
        if (res.code === 20000) {
          this.targetTypes = res.data.list || [];
        }
      })
    },
    getTargetBusType() {
      let query = {
        enable: true
      };
      getBusTypeChangeList(query).then((res) => {
        if (res.code === 20000) {
          this.targetBusTypes = res.data.list || [];
        }
      })
    },
  },

  created() {
    if (this.inputQuery.originAction == null) {
      this.isAdd = true;
      this.inputQuery.auditStatus = 2;
      this.inputQuery.busAuditStatus = 2;
    }
    this.getBusType();
    this.getTargetBusType();
  }
}
</script>

<style scoped>

</style>
