<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="调拨时间" prop="searchTimeArray">
        <el-date-picker
          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 label="调出门店" prop="outCorpId">
        <CorpChoose v-model="queryParams.outCorp" />
      </el-form-item>
      <el-form-item label="调入门店" prop="inCorpId">
        <CorpChoose v-model="queryParams.inCorp"/>
      </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="handleReset">重置</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="stId" width="180" />
      <el-table-column label="商品名称" align="center" prop="goodsId" width="180" />
      <el-table-column label="规格" align="center" prop="soNo" width="180" />
      <el-table-column label="商品编码" align="center" prop="soNo" width="180" />
      <el-table-column v-if="!stByType" label="条形码" align="center" prop="soNo" width="180" />
      <el-table-column label="数量" align="center" prop="itemCount" width="150" />
      <el-table-column label="成本" align="center" prop="itemCount" width="150" />
      <el-table-column label="合计成本" align="center" prop="itemCount" width="150" />
      <el-table-column v-if="stByType" label="出库金额" align="center" prop="itemCount" width="150" />
      <el-table-column label="合计金额" align="center" prop="itemCount" width="150" />
      <el-table-column label="负责人" align="center" prop="itemCount" width="150" />
      <el-table-column label="调出门店" align="center" prop="itemCount" width="180" />
      <el-table-column label="调出仓库" align="center" prop="itemCount" width="180" />
      <el-table-column label="调入门店" align="center" prop="itemCount" width="180" />
      <el-table-column label="调入仓库" align="center" prop="itemCount" width="180" />
      <el-table-column label="调拨时间" align="center" prop="itemCount" width="180" />
      <el-table-column label="备注" align="center" prop="remark" width="180" />
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
    />
  </div>
</template>

<script>
import {getStiPage} from "@/api/repair/stockTransfer/stockTransferItem";
import CorpChoose from "@/views/repair/Components/CorpChoose.vue";

export default {
  name: "StiTable",
  components: {CorpChoose},
  props:{
    stByType:{
      type: Boolean,
      defaultValue: true,
      required: true
    }
  },
  watch:{
    'queryParams.outCorp'(val){
      this.queryParams.outCorpId = val ? val.id : null
    },
    'queryParams.inCorp'(val){
      this.queryParams.inCorpId = val ? val.id : null
    }
  },
  data() {
    return {
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        searchTimeArray: [],
        outCorp: null,
        outCorpId: null,
        inCorp: null,
        inCorpId: null
      },
      showSearch: true,
      loading: false,
      list: [],
      total: 0,
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    async getList(){
      const res = await getStiPage(this.queryParams)
      this.list = res.data.records
      this.total = res.data.total
    },
    handleQuery(){
      this.queryParams.pageNo = 1
      this.getList()
    },
    handleReset(){
      this.resetForm("queryForm")
      this.queryParams.outCorp = null
      this.queryParams.inCorp = null
      this.handleQuery()
    }
  }
}
</script>

<style scoped lang="scss">

</style>
