<template>
  <div class="app-container">
    <div>
      <!-- 筛选条件 -->
      <Collapse :screen-form="searchForm">
        <template #right_btn>
          <el-button size="mini" @click="clearFn">清空</el-button>
          <el-button size="mini" type="primary" @click="searchFn">搜索</el-button>
        </template>

        <template #search>
          <el-form ref="searchForm" :model="searchForm" label-width="100px" size="mini" label-position="left">
            <el-row :gutter="20">
              <el-col :xs="24" :sm="12" :lg="6">
                <el-form-item label="仓库名称" prop="correspondName">
                  <el-select v-model="searchForm.correspondName" clearable filterable placeholder="请选择经销商名称">
                    <el-option
                      v-for="item in options"
                      :key="item.dictCode"
                      :label="item.dictValue"
                      :value="item.dictValue">
                    </el-option>
                  </el-select>
                  <!-- <el-input v-model="searchForm.correspondName" placeholder="请输入经销商名称"></el-input> -->
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="12" :lg="6">
                <el-form-item label="物料名称" prop="materialName">
                  <el-input v-model="searchForm.materialName" placeholder="请输入经销商名称"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="12" :lg="6">
                <el-form-item label="物料编码" prop="materialNumber">
                  <el-input v-model="searchForm.materialNumber" placeholder="请输入经销商名称"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="12" :lg="6">
                <el-form-item label="规格型号" prop="specification">
                  <el-input v-model="searchForm.specification" placeholder="请输入经销商名称"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </template>
      </Collapse>

      <!-- 按钮 -->
      <div class="btn-group clearfix">
        <div class="fl"></div>
        <div class="fr">
          <div style="display: flex;">
            <ExportButton :exUrl="'stock/startAcc/stockExport'" :exParams="exParams" exText="导出一" />
            <div style="width:10px"></div>
            <ExportButton :exUrl="'stock/startAcc/stockExport2'" :exParams="exParams" exText="导出二" />
            <div style="width:10px"></div>
            <ExportButton :exUrl="'stock/startAcc/stockExport3'" :exParams="exParams" exText="导出三" />
          </div>
        </div>
      </div>

      <div class="mymain-container">
        <!-- 列表 -->
        <div class="table">
          <el-table v-loading="listLoading" :data="dataList" element-loading-text="Loading" border fit
            highlight-current-row stripe show-summary :summary-method="getSummaries">
            <el-table-column align="left" label="仓库名称" prop="stockName" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="存货类别" prop="categoryName" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="物料编码" prop="materialNumber" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="产品编码" prop="materialOldNumber" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="物料名称" prop="materialName" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="规格型号" prop="spec" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="广州可用数量" prop="gzOnNumber" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="佛山可用数量" prop="fsOnNumber" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="总可用数量" prop="allOnNumber" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="广州开单未提数量" prop="gzNeverNumber" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="佛山开单未提数量" prop="fsNeverNumber" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="总开单未提数量" prop="allNeverNumber" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="广州结存数量" prop="gzNumber" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="佛山结存数量" prop="fsNumber" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="总结存数量" prop="allNumber" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="广州实际库存" prop="gzTheTimeNumber" min-width="160" show-overflow-tooltip>
            </el-table-column>
            <el-table-column align="left" label="佛山实际库存" prop="fsTheTimeNumber" min-width="160" show-overflow-tooltip>
            </el-table-column>
          </el-table>
        </div>
        <!-- 分页 -->
        <div class="fr">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="currentPage" :page-sizes="[10, 20, 30, 50]" :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper" :total="listTotal">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { stockStartAccStock } from '@/api/guangFoInventory'
import selectData from "@/components/template/selectData.js"
export default {
  components: {},
  data() {
    return {
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页数量
      listTotal: 0, // 列表
      listLoading: false, // 列表加载loading
      searchForm: {
        correspondName: '',
        materialName: '',
        materialNumber: '',
        specification: ''
      },
      dataList: [],
      statusList: [],
      currentStatus: '',
      options:[]
    }
  },
  computed: {
    exParams() {
      return {
        ...this.searchForm
      }
    }
  },
  async created() {
    await this.getList({ pageNumber: 1, pageSize: 10 })
    selectData.STOCK().then(res=>{
      this.options = res.data
    })
  },
  methods: {
    // 更改每页数量
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.getList({
        ...this.searchForm,
        pageNumber: this.currentPage,
        pageSize: this.pageSize
      })
    },
    // 更改当前页
    handleCurrentChange(val) {
      this.currentPage = val
      this.getList({
        ...this.searchForm,
        pageNumber: this.currentPage,
        pageSize: this.pageSize
      })
    },
    //搜索功能
    async searchFn() {
      this.currentPage = 1
      await this.getList({
        ...this.searchForm,
        pageNumber: this.currentPage,
        pageSize: this.pageSize
      })
    },
    //重置
    clearFn() {
      this.$refs.searchForm.resetFields()
    },
    //获取列表数据
    async getList(data) {
      const res = await stockStartAccStock(data)
      this.dataList = res.data.records
      this.listTotal = res.data.total
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index < 6) {
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index];
        }
      });
      return sums;
    }
  }
}
</script>

<style lang="scss" scoped>
.selectStyle {
  width: 100%;
}

::v-deep .el-textarea__inner {
  resize: none;
}

::v-deep .el-form {
  .inputStyle {
    width: 80%;
  }
}

::v-deep .dialog-footer {
  display: flex;
  justify-content: center;
}

::v-deep .el-dialog__header {
  background-color: #dddddd;
}

.inp {
  margin: 0 12px;
}

.right {
  margin-top: 12px;
  float: right;
}

.table {
  margin-top: 12px;
}

.search {
  display: flex;
  margin-top: 12px;

  ::v-deep .el-input {
    width: 50%;
    margin-right: 12px;
  }
}

.import-btn {
  display: inline-block;
  margin-left: 10px;
}
</style>
