ProcessLocationZoneList.vue 7.84 KB
<template>
  <a-card :bordered="false" class="j-inner-table-wrapper">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" :model="queryParam">
        <a-row :gutter="16">
          <a-col :md="6" :sm="24">
            <a-form-item label="工序编码">
              <a-input
                v-model="queryParam.processCode"
                placeholder="请输入工序编码"
                allowClear
                @pressEnter="handleQuery"
              />
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="24">
            <a-form-item label="区域名称">
              <a-input
                v-model="queryParam.zoneName"
                placeholder="请输入区域名称"
                allowClear
                @pressEnter="handleQuery"
              />
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="24">
            <a-form-item label="是否启用">
              <j-dict-select-tag
                v-model="queryParam.enable"
                dictCode="yn"
                placeholder="请选择"
                allowClear
              />
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="24" style="text-align: right">
            <a-space>
              <a-button type="primary" @click="handleQuery">查询</a-button>
              <a-button @click="handleReset">重置</a-button>
            </a-space>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮 -->
    <div class="table-operator" style="margin: 16px 0">
      <a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>
      <a-button type="danger" icon="delete" :disabled="selectedRowKeys.length === 0" @click="batchDel">
        批量删除
      </a-button>
    </div>

    <!-- 表格 -->
    <a-table
      rowKey="id"
      bordered
      size="middle"
      :loading="loading"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="pagination"
      :rowSelection="rowSelection"
      @change="handleTableChange"
    >

      <!-- 序号 -->
      <span slot="index" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>

      <!-- 范围 -->
      <span slot="range" slot-scope="text, record">
        {{ formatRange(record.rowStart, record.rowEnd) }} /
        {{ formatRange(record.columnStart, record.columnEnd) }} /
        {{ formatRange(record.layerStart, record.layerEnd) }}
      </span>

      <!-- 是否 -->
      <span slot="yn" slot-scope="text">
        <a-tag :color="text === 1 ? 'green' : 'red'">
          {{ text === 1 ? '是' : '否' }}
        </a-tag>
      </span>

      <!-- 操作 -->
      <span slot="action" slot-scope="text, record">
        <a @click="handleEdit(record)">编辑</a>
        <a-divider type="vertical" />
        <a @click="handleDetail(record)">详情</a>
        <a-divider type="vertical" />
        <a-popconfirm title="确认删除?" @confirm="handleDelete(record.id)">
          <a style="color:#f5222d">删除</a>
        </a-popconfirm>
      </span>

    </a-table>

    <!-- 弹窗 -->
    <process-location-zone-modal ref="modalForm" @ok="modalFormOk" />

  </a-card>
</template>

<script>
import { getAction, deleteAction } from '@/api/manage'
import ProcessLocationZoneModal from './modules/ProcessLocationZoneModal'

export default {
  name: 'ProcessLocationZoneList',
  components: { ProcessLocationZoneModal },

  data() {
    return {
      url: {
        list: '/processLocationZone/list',
        delete: '/processLocationZone/delete',
        deleteBatch: '/processLocationZone/deleteBatch'
      },

      queryParam: {
        processCode: '',
        zoneName: '',
        enable: undefined
      },

      columns: [
        { title: '序号', width: 60, align: 'center', scopedSlots: { customRender: 'index' } },
        { title: '工序编码', dataIndex: 'processCode', align: 'center' },
        { title: '区域名称', dataIndex: 'zoneName', align: 'center' },
        { title: '巷道值', dataIndex: 'roadWayList', align: 'center' },
        { title: '优先级', dataIndex: 'priority', align: 'center', width: 80 },
        { title: '范围(行/列/层)', align: 'center', scopedSlots: { customRender: 'range' } },
        // { title: '独占', dataIndex: 'isExclusive', width: 80, align: 'center', scopedSlots: { customRender: 'yn' } },
        // { title: '是否溢出', dataIndex: 'allowOverflow', width: 80, align: 'center', scopedSlots: { customRender: 'yn' } },
        { title: '备注说明', dataIndex: 'remark', align: 'center' },
        { title: '启用', dataIndex: 'enable', width: 80, align: 'center', scopedSlots: { customRender: 'yn' } },
        { title: '操作', width: 160, align: 'center', fixed: 'right', scopedSlots: { customRender: 'action' } }
      ],

      dataSource: [],
      selectedRowKeys: [],

      pagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '50', '100'],
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条`
      },

      loading: false
    }
  },

  computed: {
    rowSelection() {
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: keys => (this.selectedRowKeys = keys)
      }
    }
  },

  mounted() {
    this.loadData()
  },

  methods: {
    /** 加载数据 */
    loadData() {
      this.loading = true
      getAction(this.url.list, this.buildParams())
        .then(res => {
          if (res.success) {
            this.dataSource = res.result.records || []
            this.pagination.total = res.result.total || 0
          } else {
            this.$message.error(res.message)
          }
        })
        .finally(() => (this.loading = false))
    },

    /** 分页参数 */
    buildParams() {
      return {
        ...this.queryParam,
        pageNo: this.pagination.current,
        pageSize: this.pagination.pageSize
      }
    },

    /** 分页变化 */
    handleTableChange(pagination) {
      this.pagination.current = pagination.current
      this.pagination.pageSize = pagination.pageSize
      this.loadData()
    },

    /** 查询 */
    handleQuery() {
      this.pagination.current = 1
      this.loadData()
    },

    /** 重置 */
    handleReset() {
      this.queryParam = {
        processCode: '',
        zoneName: '',
        enable: undefined
      }
      this.handleQuery()
    },

    /** 删除 */
    handleDelete(id) {
      deleteAction(this.url.delete, { id }).then(res => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.error(res.message)
        }
      })
    },

    /** 批量删除 */
    batchDel() {
      this.$confirm({
        title: '确认删除',
        content: '选中数据将被删除,是否继续?',
        onOk: () => {
          deleteAction(this.url.deleteBatch, { ids: this.selectedRowKeys.join(',') })
            .then(res => {
              if (res.success) {
                this.$message.success(res.message)
                this.selectedRowKeys = []
                this.loadData()
              } else {
                this.$message.error(res.message)
              }
            })
        }
      })
    },

    /** 范围格式化 */
    formatRange(start, end) {
      if (!start && !end) return '不限'
      return `${start || '-'} ~ ${end || '-'}`
    },

    /** 弹窗 */
    handleAdd() {
      this.$refs.modalForm.add()
    },

    handleEdit(record) {
      this.$refs.modalForm.edit(record)
    },

    handleDetail(record) {
      this.$refs.modalForm.edit(record)
      this.$nextTick(() => {
        this.$refs.modalForm.disableSubmit = true
      })
    },

    modalFormOk() {
      this.loadData()
    }
  }
}
</script>

<style scoped>
.table-page-search-wrapper {
  padding: 16px;
  background: #fafafa;
  border-radius: 4px;
}
</style>