ProcessLocationZoneList.vue 11.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
<template>
  <div class="app-container">
    <!-- 搜索区域 -->
    <div class="filter-container">
      <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="请输入工序编码"
                @keyup.enter="handleQuery"
                allowClear
              />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="区域名称">
              <a-input
                v-model="queryParam.zoneName"
                placeholder="请输入区域名称"
                @keyup.enter="handleQuery"
                allowClear
              />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="是否启用">
              <j-dict-select-tag
                v-model="queryParam.enable"
                placeholder="请选择是否启用"
                dictCode="yn"
              />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item>
              <a-space>
                <a-button type="primary" @click="handleQuery" icon="search">查询</a-button>
                <a-button @click="handleReset" icon="reload">重置</a-button>
              </a-space>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator" style="margin-bottom: 20px;">
      <a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>
      <a-button type="warning" icon="download" @click="handleExport">导出</a-button>
      <a-button type="danger" icon="delete" @click="batchDel" :disabled="selectedRowKeys.length === 0">批量删除</a-button>

      <!-- Excel导入 -->
      <a-upload
        name="file"
        :showUploadList="false"
        :action="importExcelUrl"
        :headers="uploadHeaders"
        @change="handleImport"
        style="display: inline-block; margin-left: 8px;"
      >
        <a-button type="success" icon="upload">导入</a-button>
      </a-upload>
    </div>

    <!-- 数据表格 -->
    <div>
      <a-table
        :dataSource="dataSource"
        :columns="columns"
        :rowKey="record => record.id"
        :loading="loading"
        :pagination="pagination"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange"
        bordered
        size="middle"
      >
        <!-- 序号列 -->
        <span slot="index" slot-scope="text, record, index">
          {{ (pagination.current - 1) * pagination.pageSize + index + 1 }}
        </span>

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

        <!-- 是否允许溢出列 -->
        <span slot="allowOverflow" slot-scope="text">
          <a-tag :color="text === 1 ? 'green' : 'red'">
            {{ text === 1 ? '是' : '否' }}
          </a-tag>
        </span>

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

        <!-- 行范围列 -->
        <span slot="rowRange" slot-scope="text, record">
          <span v-if="record.rowStart || record.rowEnd">
            {{ record.rowStart || '不限' }}-{{ record.rowEnd || '不限' }}
          </span>
          <span v-else>不限</span>
        </span>

        <!-- 列范围列 -->
        <span slot="columnRange" slot-scope="text, record">
          <span v-if="record.columnStart || record.columnEnd">
            {{ record.columnStart || '不限' }}-{{ record.columnEnd || '不限' }}
          </span>
          <span v-else>不限</span>
        </span>

        <!-- 层范围列 -->
        <span slot="layerRange" slot-scope="text, record">
          <span v-if="record.layerStart || record.layerEnd">
            {{ record.layerStart || '不限' }}-{{ record.layerEnd || '不限' }}
          </span>
          <span v-else>不限</span>
        </span>

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

    <!-- 新增/编辑弹窗 -->
    <process-location-zone-modal
      ref="modalForm"
      @ok="modalFormOk"
    />
  </div>
</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',
        exportXlsUrl: '/processLocationZone/exportXls',
        importExcelUrl: '/processLocationZone/importExcel',
      },
      queryParam: {
        processCode: '',
        zoneName: '',
        enable: undefined
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 60,
          scopedSlots: { customRender: 'index' }
        },
        {
          title: '工序编码',
          align: 'center',
          dataIndex: 'processCode',
          width: 120
        },
        {
          title: '区域名称',
          align: 'center',
          dataIndex: 'zoneName',
          width: 120
        },
        {
          title: '优先级',
          align: 'center',
          dataIndex: 'priority',
          width: 80
        },
        {
          title: '巷道列表',
          align: 'center',
          dataIndex: 'roadWayList',
          width: 150
        },
        {
          title: '行范围',
          align: 'center',
          width: 120,
          scopedSlots: { customRender: 'rowRange' }
        },
        {
          title: '列范围',
          align: 'center',
          width: 120,
          scopedSlots: { customRender: 'columnRange' }
        },
        {
          title: '层范围',
          align: 'center',
          width: 120,
          scopedSlots: { customRender: 'layerRange' }
        },
        {
          title: '是否独占',
          align: 'center',
          dataIndex: 'isExclusive',
          width: 100,
          scopedSlots: { customRender: 'isExclusive' }
        },
        {
          title: '是否允许溢出',
          align: 'center',
          dataIndex: 'allowOverflow',
          width: 120,
          scopedSlots: { customRender: 'allowOverflow' }
        },
        {
          title: '是否启用',
          align: 'center',
          dataIndex: 'enable',
          width: 100,
          scopedSlots: { customRender: 'enable' }
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark',
          width: 150,
          ellipsis: true
        },
        {
          title: '操作',
          align: 'center',
          width: 200,
          fixed: 'right',
          scopedSlots: { customRender: 'action' }
        }
      ],
      dataSource: [],
      selectedRowKeys: [],
      loading: false,
      pagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30', '50', '100'],
        showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
        showSizeChanger: true,
        showQuickJumper: true
      }
    }
  },
  computed: {
    importExcelUrl() {
      return `${window._CONFIG['domianURL']}${this.url.importExcelUrl}`
    },
    uploadHeaders() {
      return {
        'X-Access-Token': this.$ls.get('Access-Token')
      }
    }
  },
  mounted() {
    this.loadData()
  },
  methods: {
    loadData() {
      this.loading = true
      const params = {
        ...this.queryParam,
        pageNo: this.pagination.current,
        pageSize: this.pagination.pageSize
      }

      getAction(this.url.list, params).then(res => {
        if (res.success) {
          this.dataSource = res.result.records || res.result
          this.pagination.total = res.result.total || 0
        } else {
          this.$message.error(res.message)
        }
      }).catch(error => {
        console.error(error)
        this.$message.error('加载数据失败')
      }).finally(() => {
        this.loading = false
      })
    },

    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.pagination.current = 1
      this.loadData()
    },

    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },

    handleAdd() {
      this.$refs.modalForm.add()
    },

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

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

    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() {
      if (this.selectedRowKeys.length === 0) {
        this.$message.warning('请选择要删除的数据')
        return
      }
      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)
        }
      })
    },

    handleExport() {
      // 导出Excel逻辑
      window.location.href = `${window._CONFIG['domianURL']}${this.url.exportXlsUrl}`
    },

    handleImport(info) {
      if (info.file.status === 'done') {
        if (info.file.response.success) {
          this.$message.success('导入成功')
          this.loadData()
        } else {
          this.$message.error(info.file.response.message || '导入失败')
        }
      } else if (info.file.status === 'error') {
        this.$message.error('导入失败')
      }
    },

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

<style scoped>
.filter-container {
  padding: 20px 20px 0 20px;
  background: #f8f9fa;
  border-radius: 4px;
  margin-bottom: 20px;
}
</style>