<template>
  <!-- 采购订单出库 -->
  <div class="common-box">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="待出库" name="first">
        <el-form :model="listQuery" ref="queryForm" :inline="true">
          <el-form-item label="采购单号" prop="id">
            <el-input v-model="listQuery.id" placeholder="请输入采购单号"></el-input>
          </el-form-item>
          <el-form-item label="医院名称" prop="branchName">
            <el-input v-model="listQuery.branchName" placeholder="请输入医院名称"></el-input>
          </el-form-item>
          <el-form-item label="采购时间" prop="docmkDate">
            <el-date-picker
              v-model="listQuery.docmkDate"
              type="daterange"
              range-separator="至"
              :editable="false"
              value-format="yyyy-MM-dd"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              style="width: 230px"
            />
          </el-form-item>
          <!-- <el-form-item label="当前状态" prop="stas">
                <el-select
                    v-model="listQuery.stas"
                    placeholder="请选择"
                    clearable
                >
                    <el-option
                        v-for="item in stasOptions"
                        :key="item.value"
                        :label="item.lable"
                        :value="item.value"
                    ></el-option>
                </el-select>
            </el-form-item> -->
          <el-form-item>
            <el-button type="primary" @click="getData('search')">查询 </el-button>
            <el-button @click="reset">重置</el-button>
          </el-form-item>
        </el-form>
        <el-table
          v-loading="listLoading"
          element-loading-text="加载中"
          :data="list"
          fit
          stripe
          border
        >
          <template slot="empty">
            <img src="@/assets/nopage.png" alt />
            <p>暂无数据</p>
          </template>
          <el-table-column fixed type="index" label="序号" width="60" />
          <el-table-column label="订单编号" prop="id" />
          <el-table-column label="订单种类" prop="detlCnt" />
          <el-table-column label="订单总数量" prop="qtySum" />
          <el-table-column label="剩余出库量" prop="delvCnt" />
          <el-table-column label="订单总金额" prop="purcAmt" />
          <el-table-column label="医院名称" prop="branchName" />
          <el-table-column label="部门名称" prop="deptName" />
          <el-table-column label="采购员" prop="docmker" />
          <el-table-column label="采购时间" prop="docmkDate" width="140" />
          <el-table-column label="状态" prop="stas">
            <!-- <template #default="{ row }">
              <span v-if="row.stas == 'A'">未受理</span>
              <span v-if="row.stas == 'B'">未出库</span>
              <span v-if="row.stas == 'R'">被驳回</span>
              <span v-if="row.stas == 'C'">已出库</span>
              <span v-if="row.stas == 'D'">部分出库</span>
              <span v-if="row.stas == 'Y'">已入库</span>
              <span v-if="row.stas == 'P'">部分入库</span>
            </template> -->
          </el-table-column>
          <el-table-column label="操作" width="100">
            <template slot-scope="scope">
              <el-button type="text" @click="handleDetail(scope.row)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--分页-->
        <yl-pagination
          v-show="total > 0"
          :total="total"
          :page.sync="listQuery.current"
          :limit.sync="listQuery.size"
          @pagination="getData"
        />
      </el-tab-pane>
      <el-tab-pane label="已出库" name="second">
        <el-form :model="listQueryC" ref="queryFormC" :inline="true">
          <el-form-item label="出库单号" prop="delvOrdId">
            <el-input
              v-model="listQueryC.delvOrdId"
              placeholder="请输入出库单号"
            ></el-input>
          </el-form-item>
          <el-form-item label="关联采购单" prop="purcOrdId">
            <el-input
              v-model="listQueryC.purcOrdId"
              placeholder="请输入关联采购单"
            ></el-input>
          </el-form-item>
          <el-form-item label="医院名称" prop="branchName">
            <el-input
              v-model="listQueryC.branchName"
              placeholder="请输入医院名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="出库时间" prop="docmkDate">
            <el-date-picker
              v-model="listQueryC.docmkDate"
              type="daterange"
              range-separator="至"
              :editable="false"
              value-format="yyyy-MM-dd"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              style="width: 230px"
            />
          </el-form-item>
          <!-- <el-form-item label="当前状态" prop="purcOrdStas">
                <el-select
                    v-model="listQuery.purcOrdStas"
                    placeholder="请选择"
                    clearable
                >
                    <el-option
                        v-for="item in stasOptions"
                        :key="item.value"
                        :label="item.lable"
                        :value="item.value"
                    ></el-option>
                </el-select>
            </el-form-item> -->
          <el-form-item>
            <el-button type="primary" @click="getDataC('search')">查询 </el-button>
            <el-button @click="resetC">重置</el-button>
          </el-form-item>
        </el-form>
        <el-table
          v-loading="listLoading"
          element-loading-text="加载中"
          :data="listC"
          fit
          stripe
          border
        >
          <template slot="empty">
            <img src="@/assets/nopage.png" alt />
            <p>暂无数据</p>
          </template>
          <el-table-column fixed type="index" label="序号" width="60" />
          <el-table-column label="出库单号" prop="delvOrdId" />
          <el-table-column label="关联采购单" prop="purcOrdId" />
          <el-table-column label="采购品种数" prop="detlCnt" />
          <el-table-column label="采购总数量" prop="qtySum" />
          <el-table-column label="本次出库量" prop="bcckl" />
          <el-table-column label="客户验收数量" prop="shppCnt" width="80" />
          <el-table-column label="剩余出库量" prop="toDelvCnt" />
          <el-table-column label="医院名称" prop="branchName" />
          <el-table-column label="部门名称" prop="deptName" />
          <el-table-column label="出库员" prop="docmker" />
          <el-table-column label="出库时间" prop="docmkDate" width="140" />
          <el-table-column label="状态" prop="delvOrdStas" width="100">
            <template #default="{ row }">
              <span v-if="row.delvOrdStas == 'A'">未受理</span>
              <span v-if="row.delvOrdStas == 'B'">已受理</span>
              <span v-if="row.delvOrdStas == 'R'">被驳回</span>
              <span v-if="row.delvOrdStas == 'C'">已出库</span>
              <span v-if="row.delvOrdStas == 'D'">部分出库</span>
              <span v-if="row.delvOrdStas == 'Y'">结束订单</span>
              <span v-if="row.delvOrdStas == 'P'">部分入库</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="100">
            <template slot-scope="scope">
              <el-button type="text" @click="handleDetailC(scope.row)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--分页-->
        <yl-pagination
          v-show="totalC > 0"
          :total="totalC"
          :page.sync="listQueryC.current"
          :limit.sync="listQueryC.size"
          @pagination="getDataC"
        />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import ylPagination from "@/components/yl-pagination";
import {
  getMcsOrdDck,
  getSplerMcsDelvOrdPage
} from "@/api/orderManage-sup/index";
export default {
  components: {
    ylPagination,
  },
  data() {
    return {
      activeName:"first",
      listQuery: {
        current: 1,
        size: 10,
        id: "",
        branchName:"",
        docmkDateStart: "",
        docmkDateEnd: "",
        docmkDate: [],
        stas: "",
      },
      listQueryC: {
        current: 1,
        size: 10,
        purcOrdId:"",
        branchName:"",
        docmkDate:"",
        delvOrdId:"",
        docmkDateEnd:"",
        branchName:"",
      },
      stasOptions: [
        // {value: 'A', lable: "未受理"},
        { value: "B", lable: "未出库" },
        // {value: 'R', lable: "被驳回"},
        { value: "C", lable: "已出库" },
        { value: "D", lable: "部分出库" },
        // {value: 'Y', lable: "已入库"},
        // {value: 'P', lable: "部分入库"}
      ],
      listLoading: false,
      list: [],
      listC:[],
      total: 0,
      totalC:0,
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    handleClick(tab) {
      console.log(tab.name, "name");
      if (tab.name == "first") {
        this.getData();
      } else {
        this.getDataC();
      }
    },
    getData(type) {
      if (type == "search") {
        this.listQuery.current = 1;
      }
      this.listLoading = true;
      this.listQuery.docmkDateStart = this.listQuery.docmkDate[0];
      this.listQuery.docmkDateEnd = this.listQuery.docmkDate[1];
      getMcsOrdDck(this.listQuery)
        .then((res) => {
          this.list = res.data.records;
          this.total = res.data.total;
          this.listLoading = false;
        })
        .catch((err) => {
          this.listLoading = false;
        });
    },
    reset() {
      this.$refs.queryForm.resetFields();
      this.getData();
    },
    // 详情
    handleDetail(row) {
      this.$router.push({
        name: "deliveryDetail",
        query: {
          deptName:row.deptName,
          deptId:row.deptId,
          id: row.id,
          detlCnt: row.detlCnt,
          qtySum:row.qtySum,
          purcAmt:row.purcAmt,
          docmker: row.docmker,
          docmkDate: row.docmkDate,
          stas: row.stas,
          branchName:row.branchName
        },
      });
    },
    getDataC(type) {
      if (type == "search") {
        this.listQueryC.current = 1;
      }
      this.listLoading = true;
      this.listQueryC.docmkDateStart = this.listQueryC.docmkDate[0];
      this.listQueryC.docmkDateEnd = this.listQueryC.docmkDate[1];
      getSplerMcsDelvOrdPage(this.listQueryC)
        .then((res) => {
          this.listC = res.data.records;
          this.totalC = res.data.total;
          this.listLoading = false;
        })
        .catch((err) => {
          this.listLoading = false;
        });
    },
    resetC() {
      this.$refs.queryFormC.resetFields();
      this.getDataC();
    },
    // 详情
    handleDetailC(row) {
      console.log(row);
      this.$router.push({
        name: "alreadyDetail",
        query: {
          delvOrdId: row.delvOrdId,
          purcOrdId: row.purcOrdId,
          detlCnt: row.detlCnt,
          docmker: row.docmker,
          deptName:row.deptName,
          docmkDate: row.docmkDate,
          delvOrdStas: row.delvOrdStas,
          branchName:row.branchName,
          qtySum:row.qtySum,
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
