<template>
  <div class="common-box">
    <!--条件-->
    <el-form :model="orderListQuery" ref="queryForm" :inline="true">
      <el-form-item label="配送单号">
        <el-input
          v-model="orderListQuery.delvOrdId"
          placeholder="请输入配送单号"
        ></el-input>
      </el-form-item>
      <el-form-item label="制单时间">
        <el-date-picker
          v-model="orderListQuery.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="orderListQuery.splerName"
          placeholder="请选择供应商"
          clearable
          filterable
          remote
          :remote-method="remoteMethod"
          :loading="splerloading"
        >
          <el-option
            v-for="item in splerOptions"
            :key="item.splerId"
            :label="item.splerName"
            :value="item.splerId"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getOrderData('search')"
          >查询
        </el-button>
        <el-button @click="orderReset()">重置</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <div>
      <el-table
        v-loading="orderListLoading"
        element-loading-text="加载中"
        :data="orderList"
        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" width="180" />
        <!-- <el-table-column label="单据状态" prop="purcOrdStas">
          <template slot-scope="scope">
            <span v-if="scope.row.purcOrdStas == 'B'">已提交</span>
            <span v-if="scope.row.purcOrdStas == 'Y'">已受理</span>
          </template>
        </el-table-column> -->
        <el-table-column label="订单类型" prop="planType" />
        <el-table-column label="供应商" prop="splerName" />
        <el-table-column label="业务员" prop="conerName" />
        <el-table-column label="明细条数" prop="detlCnt" />
        <el-table-column label="金额" prop="amt" />
        <el-table-column label="采购计划" prop="purcPlanId" />
        <el-table-column label="制单人" prop="docmker" />
        <el-table-column label="制单时间" prop="docmkDate" width="150" />
        <el-table-column fixed="right" label="操作" width="150">
          <template slot-scope="scope">
            <el-button type="text" @click="openDetail(scope.row)"
              >详情</el-button
            >
            <el-button
              type="text"
              class="orange"
              @click="goApplyReturn(scope.row)"
              >申请退货</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>

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

<script>
import ylPagination from "@/components/yl-pagination";
import { getOrgDelvOrdStoInPage } from "@/api/purchasing-management/return-report.js";
import { getDrugSplerRlts } from "@/api/drugCataManage/index.js";
export default {
  components: {
    ylPagination
  },
  data() {
    return {
      splerOptions: [],
      splerloading: false,
      orderList: [],
      orderListLoading: false,
      orderListQuery: {
        //条件查询
        delvOrdId: "",
        docmkDate: "",
        splerName: "",
        current: 1,
        size: 10
      },
      orderTotal: 0 //分页
    };
  },

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

  methods: {
    remoteMethod(query) {
      if (query !== "") {
        this.splerloading = true;
        getDrugSplerRlts({
          current: 1,
          size: 1000,
          splerName: this.orderListQuery.splerName
        })
          .then((response) => {
            this.splerOptions = response.data.records;
            this.splerloading = false;
          })
          .catch((err) => {
            this.splerloading = false;
          });
      } else {
        this.splerOptions = [];
      }
    },

    //获取列表数据
    getOrderData(type) {
      if (type == "search") {
        this.orderListQuery.current = 1;
      }
      this.orderListLoading = true;
      getOrgDelvOrdStoInPage(this.orderListQuery)
        .then((response) => {
          this.orderList = response.data.records;
          this.orderTotal = response.data.total;
          this.orderListLoading = false;
        })
        .catch((err) => {
          this.orderListLoading = false;
        });
    },

    orderReset() {
      this.orderListQuery.delvOrdId = "";
      this.orderListQuery.docmkDate = "";
      this.orderListQuery.splerName = "";
      this.getOrderData();
    },

    // 详情
    openDetail(row) {
      this.$router.push({
        path: "/purchasing-management/return-report-detail",
        query: {
          delvOrdId: row.delvOrdId,
          purcOrdId: row.purcOrdId,
          detlCnt: row.detlCnt,
          amt: row.amt,
          splerName: row.splerName,
          conerName: row.conerName,
          docmker: row.docmker,
          docmkDate: row.docmkDate,
          delvOrdStas: row.delvOrdStas,
          // purcOrdStas: row.purcOrdStas,
          purcPlanId: row.purcPlanId,
          planType: row.planType
        }
      });
    },

    // 申请退货
    goApplyReturn(row) {
      this.$router.push({
        path: "/purchasing-management/return-report-detail",
        query: {
          delvOrdId: row.delvOrdId,
          purcOrdId: row.purcOrdId,
          detlCnt: row.detlCnt,
          amt: row.amt,
          splerName: row.splerName,
          conerName: row.conerName,
          docmker: row.docmker,
          docmkDate: row.docmkDate,
          delvOrdStas: row.delvOrdStas,
          // purcOrdStas: row.purcOrdStas,
          purcPlanId: row.purcPlanId,
          planType: row.planType,
          flag: 1
        }
      });
    }
  }
};
</script>

<style>
</style>