<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-select
          v-model="listQuery.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 label="单据状态">
        <el-select
          v-model="listQuery.stas"
          placeholder="请选择单据状态"
          clearable
        >
          <el-option label="已提交" value="B"> </el-option>
          <el-option label="已受理" value="Y"> </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" />
        <el-table-column label="单据状态" prop="stas">
          <template slot-scope="scope">
            <span v-if="scope.row.stas == 'B'">已提交</span>
            <span v-if="scope.row.stas == '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="deltCnt" />
        <el-table-column label="退货金额" prop="amt" />
        <el-table-column label="制单人" prop="docmker" />
        <el-table-column label="制单时间" prop="docmkDate" />
        <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 { getRetnOrdPage } from "@/api/purchasing-management/return-record.js";
import { getDrugSplerRlts } from "@/api/drugCataManage/index.js";
export default {
  components: {
    ylPagination
  },
  data() {
    return {
      splerOptions: [],
      splerloading: false,
      list: [],
      listLoading: false,
      listQuery: {
        //条件查询
        id: "",
        splerName: "",
        stas: "",
        current: 1,
        size: 10
      },
      total: 0 //分页
    };
  },

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

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

    //获取列表数据
    getData(type) {
      if (type == "search") {
        this.listQuery.current = 1;
      }
      this.listLoading = true;
      getRetnOrdPage(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.splerName = "";
      this.listQuery.stas = "";
      this.getData();
    },

    // 查看详情
    openDetail(row) {
      this.$router.push({
        path: "/purchasing-management/return-record-detail",
        query: {
          planType: row.planType,
          id: row.id,
          purcOrdId: row.purcOrdId,
          splerName: row.splerName,
          conerName: row.conerName,
          amt: row.amt,
          docmker: row.docmker,
          docmkDate: row.docmkDate,
          deltCnt: row.deltCnt,
          stas: row.stas
        }
      });
    }
  }
};
</script>

<style>
</style>