<template>
  <div class="common-box">
    <!--条件-->
    <el-form :model="listQuery" ref="queryForm" :inline="true">
      <el-form-item label="配送单号">
        <el-input
          v-model="listQuery.purcOrdId"
          placeholder="请输入配送单号"
        ></el-input>
      </el-form-item>
      <el-form-item label="单据状态">
        <el-select
          v-model="listQuery.purcOrdStas"
          placeholder="请选择单据状态"
          clearable
        >
          <el-option label="未出库" value="A"> </el-option>
          <el-option label="已出库" value="C"> </el-option>
          <el-option label="已验收" value="R"> </el-option>
          <el-option label="结束订单" value="Y"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="当前状态">
        <el-select
          v-model="listQuery.delvOrdStas"
          placeholder="请选择当前状态"
          clearable
        >
          <!-- <el-option label="未受理" value="A"> </el-option>
          <el-option label="已受理" value="B"> </el-option>
          <el-option label="被驳回" value="R"> </el-option> -->
          <el-option label="未入库" value="C"> </el-option>
          <!-- <el-option label="部分出库" value="D"> </el-option> -->
          <el-option label="已入库" value="Y"> </el-option>
          <!-- <el-option label="部分入库" value="P"> </el-option> -->
        </el-select>
      </el-form-item>
      <el-form-item label="制单日期">
        <el-date-picker
          v-model="listQuery.docmkDate"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 230px"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </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>
    <!--列表-->
    <div>
      <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>
        <el-table-column label="配送单号" prop="delvOrdId" />
        <el-table-column label="单据状态" prop="purcOrdStas">
          <template slot-scope="scope">
            <span v-if="scope.row.purcOrdStas == 'A'">未出库</span>
            <span v-if="scope.row.purcOrdStas == 'C'">已出库</span>
            <span v-if="scope.row.purcOrdStas == 'R'">已验收</span>
            <span v-if="scope.row.purcOrdStas == 'Y'">结束订单</span>
          </template>
        </el-table-column>
        <el-table-column label="当前状态" prop="delvOrdStas">
          <template slot-scope="scope">
            <!-- <span v-if="scope.row.delvOrdStas == 'A'">未受理</span>
            <span v-if="scope.row.delvOrdStas == 'B'">已受理</span>
            <span v-if="scope.row.delvOrdStas == 'R'">被驳回</span> -->
            <span v-if="scope.row.delvOrdStas == 'C'">未入库</span>
            <!-- <span v-if="scope.row.delvOrdStas == 'D'">部分出库</span> -->
            <span v-if="scope.row.delvOrdStas == 'Y'">已入库</span>
            <!-- <span v-if="scope.row.delvOrdStas == 'P'">部分入库</span> -->
          </template>
        </el-table-column>
        <el-table-column label="明细条数" prop="detlCnt" />
        <el-table-column label="采购总金额" prop="amt" />
        <el-table-column label="供应商" prop="splerName" />
        <el-table-column label="制单日期" prop="docmkDate" />
        <el-table-column fixed="right" label="操作" width="80">
          <template slot-scope="scope">
            <el-button type="text" @click="openDetail(scope.row)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!--分页-->
    <yl-pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.current"
      :limit.sync="listQuery.size"
      @pagination="getData"
    />
  </div>
</template>

<script>
import ylPagination from "@/components/yl-pagination";
import { getOrgDelvOrdPage } from "@/api/storeroom/check-warehouse";
export default {
  components: {
    ylPagination
  },
  data() {
    return {
      list: [],
      listLoading: false,
      listQuery: {
        //条件查询
        purcOrdId: "",
        purcOrdStas: "",
        delvOrdStas: "",
        docmkDate: [],
        docmkDateStart: "",
        docmkDateEnd: "",
        current: 1,
        size: 10
      },
      total: 0 //分页
    };
  },

  created() {
    this.getData();
  },

  methods: {
    //获取列表数据
    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];
      this.listLoading = false;
      getOrgDelvOrdPage(this.listQuery)
        .then((response) => {
          this.list = response.data.records;
          this.total = response.data.total;
          this.listLoading = false;
        })
        .catch((err) => {
          this.listLoading = false;
        });
    },

    reset() {
      this.listQuery.purcOrdId = "";
      this.listQuery.purcOrdStas = "";
      this.listQuery.delvOrdStas = "";
      this.listQuery.docmkDate = [];
      this.listQuery.docmkDateStart = "";
      this.listQuery.docmkDateEnd = "";
      this.getData();
    },

    // 详情
    openDetail(row) {
      this.$router.push({
        path: "/storeroom/check-warehouse-detail",
        query: {
          delvOrdId: row.delvOrdId,
          purcOrdId: row.purcOrdId,
          splerName: row.splerName,
          purcOrdStas: row.purcOrdStas
        }
      });
    }
  }
};
</script>

<style>
</style>