<template>
  <div>
    <el-form :inline="true" :model="filterQuery" class="query-form" size="mini">
      <el-row>
        <el-form-item class="query-form-item">
          <el-input
            v-model="filterQuery.batchNo"
            placeholder="生产批次号"
          ></el-input>
        </el-form-item>
        <el-form-item class="query-form-item">
          <span style="color: #000; margin-left: 10px; margin-right: 6px"
            >生产日期:</span
          >
          <el-date-picker
            v-model="value"
            type="daterange"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button-group>
            <el-button
              type="primary"
              icon="el-icon-refresh"
              @click="onReset"
            ></el-button>
            <el-button type="primary" icon="search" @click="onSubmit"
              >查询</el-button
            >
            <el-button
              type="primary"
              icon="search"
              @click="postOrders"
              :loading="mipsLoading"
              >更新加载</el-button
            >
          </el-button-group>
        </el-form-item>
      </el-row>
    </el-form>

    <el-table
      v-loading="loading"
      :data="list"
      @selection-change="handleSelectionChange"
      style="width: 100%"
    >
      <el-table-column type="selection" width="55" fixed></el-table-column>
      <el-table-column label="序号" type="index" fixed></el-table-column>
      <el-table-column label="订单编号" prop="orderNo" fixed></el-table-column>
      <el-table-column label="批次号" prop="batchNo" fixed></el-table-column>
      <el-table-column label="产品名称" prop="name" fixed></el-table-column>
      <el-table-column
        label="包装比例"
        prop="packRatio"
        fixed
      ></el-table-column>
      <el-table-column label="规格型号" prop="spec" fixed></el-table-column>
      <el-table-column label="订单状态" prop="closeFlag" fixed>
        <!-- <template slot-scope="scope">
          <span>{{ orderFlag[scope.row.closeFlag] }}</span>
        </template> -->
      </el-table-column>
      <el-table-column
        label="是否已更新加载"
        prop="isUpdate"
        fixed
      ></el-table-column>
      <el-table-column
        label="生产日期"
        prop="drugProductionDate"
        fixed
      ></el-table-column>
      <el-table-column
        label="失效日期"
        prop="drugShelfLifeToDate"
        fixed
      ></el-table-column>

      <el-table-column label="操作" fixed="right">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            @click.native.stop="deleteDialog(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      :page-size="filterQuery.limit"
      @current-change="handleCurrentChange"
      layout="prev, pager, next"
      :total="total"
    ></el-pagination>
  </div>
</template>

<script>
import { importMips, postMipsOrder } from "../../api/receipts/mipsOrder";

import {
  productList,
  addProduct,
  updateProduct,
  deleteProduct,
} from "../../api/receipts/product";

import { getCompany } from "../../api/warehouse/company";

export default {
  data() {
    return {
      filterQuery: {
        BatchNo: "",
        startTime: "",
        endTime: "",
        page: 1,
        limit: 20,
      },
      postQuery: {
        selectManuorderResponseList: [],
      },
      multipleSelection: [],
      value: "",
      total: 0,
      orderFlag: {
        0: "未完成",
        1: "已完成",
      },
      list: [],
      mipsLoading: false,
      returnOptions: [
        {
          value: 0,
          label: "未完成",
        },
        {
          value: 1,
          label: "已完成",
        },
      ],
    };
  },

  methods: {
    onReset() {
      this.$router.push({
        path: "",
      });
      this.filterQuery = {
        BatchNo: "",
        startTime: "",
        endTime: "",
        page: 1,
        limit: 20,
      };
      this.getList();
    },
    onSubmit() {
      if (this.value != null) {
        console.log(this.value);

        this.filterQuery.startTime = this.value[0];
        this.filterQuery.endTime = this.value[1];
      }
      this.getList();
    },
    handleSelectionChange(val) {
      console.log(val);
      this.multipleSelection = val;
    },
    getList() {
      this.loading = true;
      importMips(this.filterQuery)
        .then((response) => {
          this.loading = false;
          this.list = response.data.list || [];
          this.total = response.data.total || 0;
        })
        .catch(() => {
          this.loading = false;
          this.list = [];
          this.total = 0;
        });
    },

    postOrders() {
      this.loading = true;
      this.postQuery.selectManuorderResponseList = this.multipleSelection;
      if (this.postQuery.selectManuorderResponseList.length <= 1) {
        this.$message.warning("选择的订单需大于1");
        return;
      }
      postMipsOrder(this.postQuery)
        .then((response) => {
          this.loading = false;
          this.$emit("closeManuDialog", true);
        })
        .catch(() => {
          this.loading = false;
          this.$emit("closeManuDialog", false);
        });
    },

    handleSizeChange(val) {
      this.filterQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.filterQuery.page = val;
      this.getList();
    },
  },
  mounted() {},
  created() {
    this.getList();
  },
};
</script>