<template>
  <el-card style="margin: 5px;margin-top: -20px">
    <el-form :model="formData" ref="dataForm" label-width="100px" style="margin-bottom: -15px">
      <el-button-group style="display: flex;margin: 0px 0 10px 80%; height: 35px" v-if="formName == 'audit'">
        <el-button type="primary" @click.native="AuditSubmit(2)">审核通过</el-button>
        <el-button type="primary" @click.native="AuditSubmit(3)">审核拒绝</el-button>
      </el-button-group>

      <el-row>
        <el-col :span="10">
          <el-form-item class="query-form-item" label="登记记录号:">
            <el-input v-model="formData.orderId"  auto-complete="off" :disabled="true" style="width: 90%"
                      clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item class="query-form-item" label="登记时间:">
            <el-input v-model="formData.createTime" auto-complete="off" :disabled="true" style="width: 90%"
                      clearable></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="10">
          <el-form-item class="query-form-item" label="登记部门:">
            <el-select v-model="formData.fromDeptCode" placeholder="请选择登记部门信息" style="width: 90%;" disabled
                       clearable>
              <el-option
                  v-for="item in deptList"
                  :key="item.name"
                  :label="item.name"
                  :value="item.code">
                <span style="float: left">{{ item.name }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.parentName }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="10" v-if="paramValue == 0">
          <el-form-item class="query-form-item" label="出库仓库:">
            <el-select v-model="formData.fromInvCode" placeholder="请选择出库仓库信息" style="width: 90%" disabled
                       clearable>
              <el-option
                  v-for="item in invList"
                  :key="item.name"
                  :label="item.name"
                  :value="item.code">
                <span style="float: left">{{ item.name }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.code }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-table :data="detailList" style="width: 100%;margin-top: 20px;" highlight-current-row border max-height="300"
                height="300">
        <el-table-column label="序号" type="index" width="50"></el-table-column>
        <!--          <el-table-column label="条码" width="180" prop="originCode" show-overflow-tooltip></el-table-column>-->
        <el-table-column width="150" label="产品通用名称" prop="productName" show-overflow-tooltip></el-table-column>
        <el-table-column width="150" label="规格型号" prop="ggxh" show-overflow-tooltip></el-table-column>
        <el-table-column width="150" label="DI/物资编码" prop="nameCode" show-overflow-tooltip></el-table-column>
        <el-table-column label="批次号" prop="batchNo" width="200"></el-table-column>
        <el-table-column label="生产日期" prop="productionDate" width="150"></el-table-column>
        <el-table-column label="失效日期" prop="expireDate" width="150"></el-table-column>
        <el-table-column label="生产企业" prop="ylqxzcrbarmc" show-overflow-tooltip></el-table-column>
        <el-table-column label="注册/备案号" prop="zczbhhzbapzbh" show-overflow-tooltip></el-table-column>
        <el-table-column label="供应商" prop="supName" show-overflow-tooltip></el-table-column>
      </el-table>

      <pagination
          style="margin-bottom: 30px"
          v-show="detailTotal>0"
          :total="detailTotal"
          :limit.sync="detailQuery.limit"
          :page.sync="detailQuery.page"
          @pagination="getDetailList"
      ></pagination>

    </el-form>
  </el-card>
</template>

<script>
import {getDeptListByUser} from "@/api/auth/authDept";
import {isBlank} from "@/utils/strUtil";
import {filterSubAll} from "@/api/system/invSubWarehouse";
import {getDeviceReceiveOrderDetailList, updateDeviceReceiveOrderStatus} from "@/api/inventory/deviceReceiveOrder";

export default {
  name: "DeviceReceiveOrderAuditMoify",
  props: {
    receiveQuery: {
      type: Object,
      required: true,
    },
    closeDialog: {
      type: Function,
      required: true,
    },
    formName: {
      type: Function,
      required: true,
    }
  },
  data() {
    return {
      formData: {
        id: null,
        orderId: null,
        createTime: null,
        fromInvCode: null,
        fromInvSpaceCode: null,
        receiveUser: null,
        status: 0,
        code: null,
      },
      detailQuery: {
        orderIdFk: null,
        page: 1,
        limit: 20,
      },
      detailList: [],
      invList: [],
      deptList: [],
      detailTotal: 0,
      paramValue: null
    }
  },
  methods: {
    getDeptList() {
      getDeptListByUser().then((res) => {
        this.deptList = res.data || [];
      });
    },
    getInvList() {
      filterSubAll().then((res) => {
        if (res.code === 20000) {
          this.invList = res.data || [];
        }
      });
    },
    getDetailList() {
      getDeviceReceiveOrderDetailList(this.detailQuery).then((res) => {
        if (res.code === 20000) {
          this.detailList = res.data.list || [];
          this.detailTotal = res.data.total || 0;
        } else {
          this.detailList = [];
          this.detailTotal = 0;
        }
      }).catch(() => {
        this.detailList = [];
        this.detailTotal = 0;
      });
    },
    AuditSubmit(status) {
      let params = {
        id: this.formData.id,
        status: status
      };
      updateDeviceReceiveOrderStatus(params).then((res) => {
        if (res.code === 20000) {
          this.$message.success("审核通过！");
          this.closeDialog();
        } else {
          this.$message.error(res.message);
        }
      }).catch((error) => {
        this.$message.error(error.message);
      })
    }
  },
  created() {
    this.formData.id = this.receiveQuery.id
    this.formData.orderId = this.receiveQuery.orderId
    this.formData.fromDeptCode = this.receiveQuery.fromDeptCode
    this.formData.fromInvCode = this.receiveQuery.fromInvCode
    this.formData.createTime = this.receiveQuery.createTime
    this.getDeptList();
    this.getInvList()
    this.detailQuery.orderIdFk = this.formData.orderId
    this.getDetailList()
  },
}
</script>

<style scoped>

</style>
