<template>
  <a-card :bordered="false" class="supplierManagementList-wrap">
    <!-- 搜索条件 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
        <a-row :gutter="15">
          <a-col :md="6" :sm="24">
            <a-form-item label="供应商名称">
              <a-input id="supplierManagementList-bundleName" v-model.trim="queryParam.bundleName" allowClear placeholder="请输入供应商名称"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="状态">
              <v-select code="CHECK_ENABLE_STATE" id="supplierManagementList-state" v-model="queryParam.state" allowClear placeholder="请选择状态"></v-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="supplierManagementList-refresh">查询</a-button>
            <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="supplierManagementList-reset">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮 -->
    <div class="table-operator">
      <a-button id="supplierManagementList-add" type="primary" @click="handleEdit()">新增供应商</a-button>
    </div>
    <!-- 列表 -->
    <s-table
      class="sTable"
      ref="table"
      size="default"
      :rowKey="(record) => record.id"
      :columns="columns"
      :data="loadData"
      bordered>
      <!-- 状态 -->
      <template slot="state" slot-scope="text, record">
        <span>{{record.state == 1 ? '已启用' : '已禁用'}}</span>
      </template>
      <!-- 操作 -->
      <template slot="action" slot-scope="text, record">
        <a-button size="small" type="primary" @click="handleEdit(record)" id="supplierManagementList-edit-btn">编辑</a-button>
      </template>
    </s-table>
  </a-card>
</template>

<script>
import moment from 'moment'
// import { getProvince, getCityByPro, getDistrictByCity } from '@/api/data'
import { STable, VSelect } from '@/components'
export default {
  components: { STable, VSelect },
  data () {
    return {
      queryParam: { //  查询条件
        bundleName: '', //  供应商名称
        state: undefined,  //  状态
      },
      disabled: false, //  查询、重置按钮是否可操作
      columns: [
        { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
        { title: '供应商名称', dataIndex: 'productName', width: 200, align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
        { title: '地址', dataIndex: 'productOldNum', width: 160, align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
        { title: '联系人', dataIndex: 'productBrand', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '联系电话', dataIndex: 'productType', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '主营内容', dataIndex: 'inventoryNum', width: 180, align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
        { title: '创建时间', dataIndex: 'inventoryMoney', width: 180, align: 'center' },
        { title: '状态', scopedSlots: { customRender: 'state' }, width: 180, align: 'center' },
        { title: '操作', scopedSlots: { customRender: 'action' }, width: 240, align: 'center' }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        // return customerBundleDelayList( Object.assign(parameter, this.queryParam) ).then(res => {
        //   const data = res.data
        //   const no = (data.pageNo - 1) * data.pageSize
        //   for (var i = 0; i < data.list.length; i++) {
        //     data.list[i].no = no + i + 1
        //   }
        //   this.disabled = false
        //   return data
        // })
        const _this = this
        return new Promise(function(resolve, reject){
          const data = {
            pageNo: 1,
            pageSize: 10,
            list: [
              { id: '1', productNum: 'jgqp11111111111', productName: '产品1', productOldNum: 'jgqp111123545', productBrand: '箭冠品牌', productType: '产品分类1', inventoryNum: '5', inventoryMoney: '122' }
            ]
          }
          const no = (data.pageNo - 1) * data.pageSize
          for (var i = 0; i < data.list.length; i++) {
            data.list[i].no = no + i + 1
          }
          _this.disabled = false
          resolve(data)
        })
      },
    }
  },
  methods: {
    //  重置
    resetSearchForm () {
      this.queryParam.orderBundleNo = ''
      this.queryParam.orderBundle.custMobile = ''
      this.queryParam.bundleName = ''
      this.queryParam.itemName = ''
      this.oldTime = undefined
      this.newTime = undefined
      this.$refs.table.refresh(true)
    },
    //  新增/编辑
    handleEdit(row){
      if(row){  //  编辑
        this.$router.push({ path: `/basicData/supplierManagement/edit/${row.id}` })
      }else{  //  新增
        this.$router.push({ path: '/basicData/supplierManagement/add' })
      }
    },
  }
}
</script>

<style lang="less">
  .supplierManagementList-wrap{
    .sTable{
      table{
        width: auto;
      }
    }
  }
</style>