<template>
  <el-dialog
    append-to-body
    :title="title"
    :visible.sync="dialogFormVisible"
    width="900"
    @close="close"
  >
    <div class="stock-bill-container">
      <vab-query-form>
        <vab-query-form-left-panel :span="24">
          <el-form :inline="true" :model="queryForm" @submit.native.prevent>
            <el-form-item>
              <el-select
                v-model="queryForm.warehouse_name"
                clearable
                :placeholder="__('请选择')"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-input
                v-model="queryForm.item_id"
                :placeholder="__('请输入商品SKU编号')"
              />
            </el-form-item>
            <el-form-item>
              <el-button
                icon="el-icon-search"
                type="primary"
                @click="queryData"
              >
                {{ __('查询') }}
              </el-button>
            </el-form-item>
          </el-form>
        </vab-query-form-left-panel>
      </vab-query-form>

      <el-table v-loading="listLoading" border :data="list" height="400">
        <el-table-column
          align="center"
          :label="__('商品编号')"
          prop="item_id"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          :label="__('商品名称')"
          prop="product_name"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          :label="__('单位')"
          prop="unit_name"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          :label="__('规格')"
          prop="item_name"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          :label="__('所属仓库')"
          prop="warehouse_name"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          :label="__('出库日期')"
          prop="stock_bill_time"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          :label="__('出库数量')"
          prop="bill_item_quantity"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          :label="__('库存量')"
          prop="warehouse_item_quantity"
          show-overflow-tooltip
        />

        <el-table-column align="center" :label="__('操作')" width="120">
          <template #default="{ row }">
            <el-button type="text" @click="handlExamine(row)">
              {{ __('查看') }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        background
        :current-page="queryForm.pageNo"
        :layout="layout"
        :page-size="queryForm.pageSize"
        :total="total"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      />
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">{{ __('取消') }}</el-button>
      <Table ref="Table" />
    </div>
  </el-dialog>
</template>

<script>
  import { translateTitle as __ } from '@/utils/i18n'
  import Table from './StockTable'
  import { getList } from '@/api/stock/bill'

  export default {
    name: 'StockBillTable',
    components: { Table },
    data() {
      return {
        options: [
          {
            value: '默认',
            label: this.__('默认'),
          },
          {
            value: '西郊',
            label: this.__('西郊'),
          },
        ],
        value: '',
        list: [],
        listLoading: true,
        dialogFormVisible: false,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        title: '',
        queryForm: {
          pageNo: 1,
          pageSize: 20,
        },
      }
    },
    created() {},
    methods: {
      __,

      handlExamine(row) {
        this.$refs['Table'].handlExamine(row)
      },
      handleparticulars(row) {
        this.queryForm.item_id = row.item_id
        this.queryForm.warehouse_id = row.warehouse_id
        console.log(row.warehouse_id)
        this.fetchData()
        this.dialogFormVisible = true
      },

      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },
      queryData() {
        this.queryForm.pageNo = 1
        this.fetchData()
      },
      close() {
        this.dialogFormVisible = false
      },
      async fetchData() {
        this.listLoading = true
        const { data } = await getList(this.queryForm)
        this.list = data.items
        this.total = data.records
        this.listLoading = false
      },
    },
  }
</script>
