<template>
  <el-dialog
    append-to-body
    :title="title"
    :visible.sync="dialogFormVisible"
    width="1000px"
    @close="close"
  >
    <vab-query-form>
      <vab-query-form-right-panel :span="24">
        <el-button icon="el-icon-plus" type="primary" @click="">
          {{ __('同步到相同SPU下所有商品') }}
        </el-button>
      </vab-query-form-right-panel>
    </vab-query-form>
    <el-table border :data="list" height="610">
      <el-table-column
        align="center"
        :label="__('策略编号')"
        prop="policy_level_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('客户等级')"
        prop="customer_level_name"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('默认折扣')"
        show-overflow-tooltip
      >
        <template #default="{ row }">
          {{ row.customer_level_discountrate }}%
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="__('折扣（%）')"
        prop="policy_level_discountrate"
        show-overflow-tooltip
      />

      <el-table-column
        align="center"
        :label="__('起订量')"
        prop="policy_level_quantity_min"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('限定量')"
        prop="policy_level_quantity_max"
        show-overflow-tooltip
      />
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
  </el-dialog>
</template>
<script>
  import { translateTitle as __ } from '@/utils/i18n'

  import { doEdit, getList } from '@/api/product/pricing/policy/level'

  export default {
    name: 'PricingPolicyWholesaleTable',
    components: {},
    data() {
      return {
        list: [],
        form: {},
        listLoading: true,
        dialogFormVisible: false,
        title: '',
        total: 0,
        layout: 'total, sizes, prev, pager, next, jumper',
        queryForm: {
          pageNum: 1,
          pageSize: 20,
        },
      }
    },
    created() {},
    methods: {
      __,
      showTable(row) {
        this.queryForm.item_id = row.item_id
        this.dialogFormVisible = true
        this.fetchData()
      },

      close() {
        this.dialogFormVisible = false
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      queryData() {
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      async sChange(row) {
        const param = {
          policy_wholesale_id: row.policy_wholesale_id,
          policy_wholesale_enable: row.policy_wholesale_enable,
        }
        const { msg, status } = await doEdit(param)
        this.$baseMessage(msg, 'success', false, 'vab-hey-message-success')
      },
      async fetchData() {
        this.listLoading = true
        const { data } = await getList(this.queryForm)
        this.list = data.items
        this.total = data.records
        this.listLoading = false
      },
    },
  }
</script>
