<template>
  <a-card class="electronicScale-container" :bordered="false">
    <!-- 搜索框 -->
    <div class="electronicScale-container-searchForm">
      <a-form-model :model="searchForm" layout="inline" ref="searchForm">
        <a-row :gutter="24">
          <a-col :xs="24" :sm="12" :md="8" :lg="6">
            <a-form-model-item label="设备MAC码" :label-col="{span:7}" :wrapper-col="{span:17}">
              <a-input v-model="searchForm.MAC" placeholder="请输入设备MAC码" oninput="value=value.toUpperCase()" :maxLength="30"/>
            </a-form-model-item>
          </a-col>
          <a-col :xs="24" :sm="12" :md="8" :lg="6">
            <a-button class="handle-btn serach-btn" type="primary" @click="$refs.table.refresh(true)">查询</a-button>
            <a-button class="handle-btn" type="" @click="handleReset">重置</a-button>
          </a-col>
        </a-row>
      </a-form-model>
    </div>
    <!-- 新增 -->
    <div class="electronicScale-container-add">
      <a-button type="primary" icon="plus" @click="openModal">新增</a-button>
    </div>
    <!-- 合计 -->
    <a-alert type="info" showIcon style="margin-bottom:15px">
      <div class="ftext" slot="message">总计<span> {{ }} </span>条，乐豆变动量总计<span> {{ }} </span>个</div>
    </a-alert>
    <!-- 列表 -->
    <a-table ref="table" :rowKey="(record) => record.id" :columns="columns" :data-source="data" bordered>
      <span slot="action" slot-scope="text,record">
        <a-icon type="edit" title="编辑" class="actionBtn icon-blues" @click="handleEdit(record)"/>
        <a-icon type="delete" title="删除" class="actionBtn icon-red" @click="delect(record)"/>
      </span>
    </a-table>
    <!-- 新增/编辑弹窗 -->
    <addElectronicScale :visible="isOpenModal" :id="itemId" @refresh="refreshTable" @close="isOpenModal=false"></addElectronicScale>
  </a-card>
</template>

<script>
import { STable } from '@/components'
import addElectronicScale from './addElectronicScale.vue'
const columns = [{ title: '序号', dataIndex: 'no', width: 60, align: 'center' },
  { title: '创建时间', dataIndex: 'createDate', width: 100, align: 'center' },
  { title: '设备MAC码', dataIndex: 'MAC', width: 100, align: 'center' },
  { title: '设备名称', dataIndex: 'name', width: 100, align: 'center', customRender: (text) => { return text || '--' } },
  { title: '设备编号', dataIndex: 'num', width: 100, align: 'center', customRender: (text) => { return text || '--' } },
  { title: '设备型号', dataIndex: 'org', width: 100, align: 'center', customRender: (text) => { return text || '--' } },
  { title: '生产厂家', dataIndex: 'changjia', width: 100, align: 'center', customRender: (text) => { return text || '--' } },
  { title: '操作', dataIndex: 'action', width: 100, align: 'center', scopedSlots: { customRender: 'action' } }
]
const data = [{ createDate: '2020-01-05', MAC: '22210245224555', name: '电子秤', num: '2222554585877', org: 'X-001', changjia: '上海电子厂' },
  { createDate: '2020-01-05', MAC: '22210245224555', name: '电子秤', num: '2222554585877', org: 'X-001', changjia: '上海电子厂' },
  { createDate: '2020-01-05', MAC: '22210245224555', name: '电子秤', num: '2222554585877', org: 'X-001', changjia: '上海电子厂' },
  { createDate: '2020-01-05', MAC: '22210245224555', name: '电子秤', num: '2222554585877', org: 'X-001', changjia: '上海电子厂' }]
export default {
  components: { STable, addElectronicScale },
  data () {
    return {
      searchForm: {
        MAC: ''
      },
	  columns,
	  data,
	  isOpenModal: false, // 默认弹窗关闭
	  itemId: '' // 编辑行id
      // 列表表头
      // columns: [{ title: '序号', dataIndex: 'no', width: 60, align: 'center' },
      //   { title: '创建时间', dataIndex: 'createDate', width: 100, align: 'center' },
      //   { title: '设备MAC码', dataIndex: 'MAC', width: 100, align: 'center' },
      //   { title: '设备名称', dataIndex: 'name', width: 100, align: 'center' },
      //   { title: '设备编号', dataIndex: 'num', width: 100, align: 'center' },
      //   { title: '设备型号', dataIndex: 'org', width: 100, align: 'center' },
      //   { title: '生产厂家', dataIndex: 'changjia', width: 100, align: 'center' },
      //   { title: '操作', dataIndex: 'action', width: 100, align: 'center' }
      // ]
	  // data: [{ createDate: '2020-01-05', MAC: '22210245224555', name: '电子秤', num: '2222554585877', org: 'X-001', changjia: '上海电子厂' }]
	  // 加载数据方法 必须为 Promise 对象
	  // loadData: parameter => {
	  //   // return getBoxList(Object.assign(parameter, this.queryParam)).then(res => {
	  //   //   if (res.status == 200) {
	  //   //     const no = (res.data.pageNo - 1) * res.data.pageSize
	  //   //     for (let i = 0; i < res.data.list.length; i++) {
	  //   //       const _item = res.data.list[i]
	  //   //       _item.no = no + i + 1
	  //   //     }
	  //   //     return res.data
	  //   //   }
	  //   // })
	  // }
    }
  },
  methods: {
    // 重置
    handleReset () {
		this.searchForm= {
        MAC: ''
      }
    },
    // 新增
    openModal () {
      this.isOpenModal = true
		console.log('新增')
    },
    // 编辑
    handleEdit (record) {
      this.isOpenModal = true
		console.log('编辑')
    },
    // 删除
    delect () {
			this.$confirm({
				title: '警告',
				centered: true,
				content: '删除后无法恢复，确认删除?',
				okText: '确定',
				cancelText: '取消',
				onOk() {
				}
			})
    },
    // 保存或编辑后刷新列表
    refreshTable () {
      // 编辑
      if (this.itemId) {
			this.$refs.table.refresh()
      } else {
        // 保存
			this.$refs.table.refresh(true)
      }
    }
  }
}
</script>

<style lang="less" scoped>
	.electronicScale-container {
		.electronicScale-container-searchForm {
			.ant-form-inline .ant-form-item {
				width: 100%;
			}
		}

		// 查询按钮
		.handle-btn {
			margin-top: 4px;
		}

		.serach-btn {
			margin-right: 10px;
		}

		.electronicScale-container-add {
			margin: 15px 0;
		}
	}
</style>
