<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-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.sbmtDate"
          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 class="right-button">
      <el-button
        class="lake-Blue"
        type="primary"
        icon="el-icon-plus"
        @click="manOutbound"
        >手动出库
      </el-button>
    </div> -->
    <!--列表-->
    <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 == '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="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 { getAppyOrdPage } from "@/api/storeroom/shipped-out";
export default {
  components: {
    ylPagination
  },
  data() {
    return {
      list: [],
      listLoading: false,
      listQuery: {
        //条件查询
        id: "",
        orgName: "",
        stas: "",
        sbmtDate: [],
        sbmtDateStart: "",
        sbmtDateEnd: "",
        current: 1,
        size: 10
      },
      total: 0 //分页
    };
  },

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

  methods: {
    //获取列表数据
    getData(type) {
      if (type == "search") {
        this.listQuery.current = 1;
      }
      this.listLoading = true;
      this.listQuery.sbmtDateStart = this.listQuery.sbmtDate[0];
      this.listQuery.sbmtDateEnd = this.listQuery.sbmtDate[1];
      getAppyOrdPage(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.orgName = "";
      this.listQuery.stas = "";
      this.listQuery.sbmtDate = [];
      this.listQuery.sbmtDateStart = "";
      this.listQuery.sbmtDateEnd = "";
      this.getData();
    },

    // 详情
    openDetail(row) {
      this.$router.push({
        path: "/storeroom/shipped-out-detail",
        query: {
          id: row.id,
          stas: row.stas,
          orgName: row.orgName,
          docmker: row.docmker,
          docmkDate: row.docmkDate
        }
      });
    },

    // 手动出库
    manOutbound() {
      this.$router.push({
        path: "/storeroom/shipped-out-manoutbound"
        // query:{
        // 	id:row.id
        // }
      });
    }
  }
};
</script>

<style>
</style>