<template>
  <div class="common-box">
    <!--条件-->
    <el-form :model="listQuery" ref="queryForm" :inline="true">
      <el-form-item label="单据编码">
        <el-input
          v-model="listQuery.appyId"
          placeholder="请输入单据编码"
        ></el-input>
      </el-form-item>
      <el-form-item label="申领单位">
        <el-input
          v-model="listQuery.orgName"
          placeholder="请选择申领单位"
        ></el-input>
      </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="P"> </el-option>
          <el-option label="已出库" value="Y"> </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="appyId" />
        <el-table-column label="单据状态" prop="stas">
          <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 == 'P'">部分出库</span>
            <span v-if="scope.row.stas == 'Y'">已出库</span>
          </template>
        </el-table-column>
        <el-table-column label="申领单位" prop="orgName" />
        <el-table-column label="出库类型" prop="stooutType">
          <template slot-scope="scope">
            <span v-if="scope.row.stooutType == '0'">自动出库</span>
            <span v-if="scope.row.stooutType == '1'">手动出库</span>
          </template>
        </el-table-column>
        <el-table-column label="明细条数" prop="detlCnt" />
        <el-table-column label="制单人" prop="docmker" />
        <el-table-column label="制单时间" prop="docmkDate" />
        <el-table-column fixed="right" label="操作" width="100">
          <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 { getDrugStoout } from "@/api/storeroom/outbound.js";
export default {
  components: {
    ylPagination
  },
  data() {
    return {
      list: [],
      listLoading: false,
      listQuery: {
        //条件查询
        appyId: "",
        orgName: "",
        stas: "",
        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;
      getDrugStoout(this.listQuery)
        .then((response) => {
          this.list = response.data.records;
          this.total = response.data.total;
          this.listQuery.docmkDateStart = this.listQuery.docmkDate[0];
          this.listQuery.docmkDateEnd = this.listQuery.docmkDate[1];
          this.listLoading = false;
        })
        .catch((err) => {
          this.listLoading = false;
        });
    },
    reset() {
      this.listQuery.appyId = "";
      this.listQuery.orgName = "";
      this.listQuery.stas = "";
      this.listQuery.docmkDate = [];
      this.listQuery.docmkDateStart = "";
      this.listQuery.docmkDateEnd = "";
      this.getData();
    },

    // 详情
    openDetail(row) {
      this.$router.push({
        path: "/storeroom/outbound-detail",
        query: {
          stooutId: row.id,
          appyId: row.appyId,
          stas: row.stas,
          orgName: row.orgName,
          docmkDate: row.docmkDate
        }
      });
    }
  }
};
</script>

<style>
</style>