<template>
  <div>
    <!-- 搜索 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item :label="soByType ? '采购时间' : '领料时间'" prop="searchTimeArray">
        <el-date-picker
          value-format="yyyy-MM-dd HH:mm:ss"
          v-model="queryParams.searchTimeArray"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="关键字" prop="soNo">
        <el-input v-model="queryParams.soNo" style="width: 18rem" placeholder="请输入单号、商品名称或编码"/>
      </el-form-item>
      <el-form-item v-if="soByType" label="规格" prop="standard">
        <el-input v-model="queryParams.standard" style="width: 18rem" placeholder="请输入规格"/>
      </el-form-item>
      <el-form-item :label="soByType ? '采购门店' : '领料门店'" prop="corpId">
        <CorpChoose v-model="queryParams.corp" />
      </el-form-item>
      <el-form-item v-if="soByType" label="所属库位" prop="warehouseId">
        <WarehouseChoose v-model="queryParams.warehouseId" @selected="getWarehouse"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="handleResetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 操作 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-download" size="mini"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch"></right-toolbar>
    </el-row>
    <!-- 表格 -->
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="序号" align="center">
        <template scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单号" align="center" prop="soId" width="200" />
      <el-table-column label="商品名称" align="center" prop="soNo" width="180" />
      <el-table-column :label="soByType ? '采购员' : '领料人'" align="center" prop="soNo" width="180" />
      <el-table-column label="商品编码" align="center" prop="soNo" width="180" />
      <el-table-column v-if="soByType" label="条形码" align="center" prop="soNo" width="180" />
      <el-table-column label="规格" align="center" prop="soNo" width="180" />
      <el-table-column label="数量" align="center" prop="itemCount" width="150" />
      <el-table-column :label="soByType ? '进价' : '成本'" align="center" prop="itemCount" width="150" />
      <el-table-column label="合计" align="center" prop="itemCount" width="150" />
      <el-table-column v-if="soByType" label="供应商" align="center" prop="itemCount" width="180" />
      <el-table-column :label="soByType ? '采购仓库' : '仓库'" align="center" prop="itemCount" width="150" />
      <el-table-column label="所属门店" align="center" prop="itemCount" width="180" />
      <el-table-column :label="soByType ? '入库时间' : '领料时间'" align="center" prop="itemCount" width="150" />
      <el-table-column label="备注" align="center" prop="itemCount" width="180" />
    </el-table>
    <!-- 分页 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
    />
  </div>
</template>

<script>
import CorpChoose from "@/views/repair/Components/CorpChoose.vue";
import WarehouseChoose from "@/views/repair/Components/WarehouseChoose.vue";
import {getSoiPage} from "@/api/repair/stockOperate/stockOperateItem";

export default {
  name: "SoiTable",
  components: {WarehouseChoose, CorpChoose},
  props: {
    soByType: {
      type: Boolean,
      defaultValue: true,
      required: true
    },
  },
  watch:{
    'queryParams.corp'(val){
      this.queryParams.corpId = val ? val.id : null
    }
  },
  data() {
    return {
      queryParams:{
        pageNo: 1,
        pageSize: 10,
        searchTimeArray:[],
        soNo: null,
        corpId: null,
        soiType: this.soByType ? "01" : "02",
        warehouseId: null,
        corp: null,
      },
      showSearch: true,
      loading: false,
      list: [],
      total: 0,
    }
  },
  mounted() {
    this.pageSoi()
  },
  methods: {
    // 库位选择
    getWarehouse(data){
    },
    // 分页
    async pageSoi(){
      try {
        this.loading = true
        const res = await getSoiPage(this.queryParams)
        this.list = res.data.records
        this.total = res.data.total
      }finally {
        this.loading = false
      }
    },
    // 搜索
    handleQuery(){
      this.queryParams.pageNo = 1
      this.pageSoi()
    },
    // 重置
    handleResetQuery(){
      this.resetForm('queryForm')
      this.queryParams.corp = null
      this.handleQuery()
    }
  }
}
</script>

<style scoped lang="scss">

</style>
