<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    width="1000px"
    @close="close"
  >
    <el-table
      v-loading="listLoading"
      border
      :data="list"
      height="500"
      width="60%"
    >
      <el-table-column
        align="center"
        :label="__('报价编号')"
        prop="supply_order_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('报价标题')"
        prop="supply_order_title"
        show-overflow-tooltip
        width="120"
      />
      <el-table-column
        align="center"
        :formatter="formatDatetime"
        :label="__('报价时间')"
        prop="supply_order_time"
        show-overflow-tooltip
        width="160"
      />
      <el-table-column
        align="center"
        :label="__('货品单价')"
        prop="product_unit_price"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :label="__('供应数量')"
        prop="supply_quantity"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :label="__('报价描述')"
        prop="supply_order_description"
        show-overflow-tooltip
        width="120"
      />
      <el-table-column
        align="center"
        :formatter="formatTaskState"
        :label="__('状态')"
        prop="supply_task_state"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :formatter="formatSelectedState"
        :label="__('中标状态')"
        prop="supply_is_selected"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :label="__('买家编号')"
        prop="buyer_user_id"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :label="__('买家姓名')"
        prop="buyer_user_name"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :label="__('所属供应商')"
        prop="supply_user_id"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :label="__('供应商名称')"
        prop="supply_user_name"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :label="__('货品所在地')"
        prop="supply_province"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :label="__('商品编号')"
        prop="item_id"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :label="__('货品名称')"
        prop="product_name"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :label="__('货品图片')"
        prop="supply_images"
        show-overflow-tooltip
        width="100px"
      >
        <template slot-scope="scope">
          <el-image
            v-show="scope.row.supply_images"
            :preview-src-list="[scope.row.supply_images]"
            :src="scope.row.supply_images"
            style="width: 35px; height: 35px"
          />
        </template>
      </el-table-column>
    </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 { getSupplyOrderList } from '@/api/purchase/order/base'
  import { renderTime } from '@/utils/date'

  export default {
    name: 'SupplyOrderBaseTable',
    components: {},
    data() {
      return {
        list: [],

        listLoading: true,
        dialogFormVisible: false,
        title: '',
        total: 0,
        layout: 'total, sizes, prev, pager, next, jumper',
        queryForm: {
          pageNum: 1,
          pageSize: 10,
        },
      }
    },
    created() {},
    methods: {
      __,
      showTable(row) {
        this.queryForm.purchase_order_id = row.purchase_order_id
        this.dialogFormVisible = true
        this.fetchData()
      },
      close() {
        this.queryForm = this.$options.data().queryForm
        this.dialogFormVisible = false
      },
      formatDatetime(row) {
        return renderTime(row.supply_order_time)
      },
      formatTaskState(row) {
        return row.supply_task_state === 2000
          ? this.__('竞标中')
          : row.supply_task_state === 2010
            ? this.__('已结束')
            : this.__('验收完成')
      },
      formatSelectedState(row) {
        return row.supply_is_selected == 1 ? '中标' : '被驳回'
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true
        const { data } = await getSupplyOrderList(this.queryForm)
        this.list = data.items
        this.total = data.records
        this.listLoading = false
      },
    },
  }
</script>
