<template>
  <div class="common-box">
    <!--条件-->
    <el-form :model="listQuery" ref="queryForm" :inline="true">
      <el-form-item label="订单号">
        <el-input v-model="listQuery.id" placeholder="请输入订单号"></el-input>
      </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 label="订单类型">
        <el-select
          v-model="listQuery.planType"
          placeholder="请选择订单类型"
          clearable
        >
          <el-option
            v-for="item in typeList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="当前状态">
        <el-select
          v-model="listQuery.stas"
          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>
        <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="id" min-width="250" />
        <el-table-column label="订单类型" prop="planType" width="150" />
        <el-table-column label="供应商" prop="splerName" width="250" />
        <el-table-column label="业务员" prop="conerName" width="150" />
        <el-table-column label="明细条数" prop="detlCnt" width="150" />
        <el-table-column label="金额" prop="purcAmt" width="150" />
        <el-table-column label="采购计划" prop="purcPlanId" width="250" />
        <el-table-column label="制单人" prop="docmker" width="150" />
        <el-table-column label="制单时间" prop="docmkDate" width="150" />
        <el-table-column label="当前状态" prop="stas" width="100" fixed="right">
          <template slot-scope="scope">
            <span v-if="scope.row.stas == 'A'">未受理</span>
            <span v-if="scope.row.stas == 'B'">已受理</span>
            <span v-if="scope.row.stas == 'R'">被驳回</span>
            <span v-if="scope.row.stas == 'C'">已出库</span>
            <span v-if="scope.row.stas == 'D'">部分出库</span>
            <span v-if="scope.row.stas == 'Y'">已入库</span>
            <!-- <span v-if="scope.row.stas == 'P'">部分入库</span> -->
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="150">
          <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 { getOrderList } from "@/api/purchasing-management/procurement-order-management";
export default {
  components: {
    ylPagination
  },
  data() {
    return {
      typeList: [
        { value: "补点", label: "补点" },
        { value: "临时", label: "临时" },
        { value: "月度", label: "月度" },
        { value: "季度", label: "季度" },
        { value: "年度", label: "年度" }
      ],
      list: [],
      listLoading: false,
      listQuery: {
        //条件查询
        id: "",
        docmkDate: [],
        docmkDateStart: "",
        docmkDateEnd: "",
        planType: "",
        stas: "",
        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];
      getOrderList(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.id = "";
      this.listQuery.docmkDate = [];
      this.listQuery.docmkDateStart = "";
      this.listQuery.docmkDateEnd = "";
      this.listQuery.planType = "";
      this.listQuery.stas = "";
      this.getData();
    },

    // 详情
    openDetail(row) {
      this.$router.push({
        path: "/purchasing-management/procurement-order-management-detail",
        query: {
          id: row.id,
          planType: row.planType,
          purcAmt: row.purcAmt,
          splerName: row.splerName,
          docmker: row.docmker,
          docmkDate: row.docmkDate,
          conerName: row.conerName,
          purcPlanId: row.purcPlanId
        }
      });
    }
  }
};
</script>

<style>
</style>