| | |
| | | <template> |
| | | <a-card :bordered="false"> |
| | | <!-- 查询区域 --> |
| | | <div class="table-page-search-wrapper"> |
| | | <a-form layout="inline" @keyup.enter.native="searchQuery"> |
| | | <a-row :gutter="24"> |
| | | <a-col :md="6" :sm="8"> |
| | | <a-form-item label="刀具编码"> |
| | | <a-input placeholder="请输入刀具编码" v-model="queryParam.cuttingId" /> |
| | | </a-form-item> |
| | | </a-col> |
| | | <a-col :md="6" :sm="8"> |
| | | <a-form-item label="工件材质"> |
| | | <a-input placeholder="请输入工件材质" v-model="queryParam.workpieceMaterial" /> |
| | | </a-form-item> |
| | | </a-col> |
| | | <a-col |
| | | :md="6" |
| | | :sm="8" |
| | | > |
| | | <span |
| | | style="float: left;overflow: hidden;" |
| | | class="table-page-search-submitButtons" |
| | | > |
| | | <a-button |
| | | type="primary" |
| | | @click="searchQuery" |
| | | icon="search" |
| | | >查询</a-button> |
| | | <a-button |
| | | type="primary" |
| | | @click="searchReset" |
| | | icon="reload" |
| | | style="margin-left: 8px" |
| | | >重置</a-button> |
| | | </span> |
| | | </a-col> |
| | | </a-row> |
| | | </a-form> |
| | | </div> |
| | | <!-- 查询区域-END --> |
| | | |
| | | <!-- 操作按钮区域 --> |
| | | <div class="table-operator"> |
| | | <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> |
| | | <a-button type="primary" icon="download" @click="handleExportXls('额定寿命')">导出</a-button> |
| | | <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel"> |
| | | <a-button type="primary" icon="import">导入</a-button> |
| | | </a-upload> |
| | | <!-- 新增按钮 --> |
| | | <div class="table-operator" style="margin-bottom: 10px;"> |
| | | <a-button |
| | | @click="handleAdd" |
| | | type="primary" |
| | | icon="plus" |
| | | :disabled="!selectedCuttingId || selectedCuttingId === '' || selectedCuttingId === '-1'" |
| | | > |
| | | 新增 |
| | | </a-button> |
| | | </div> |
| | | |
| | | <!-- table区域-begin --> |
| | | <div> |
| | | <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;"> |
| | | <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项 |
| | | <a style="margin-left: 24px" @click="onClearSelected">清空</a> |
| | | </div> |
| | | |
| | | <a-table |
| | | ref="table" |
| | | size="middle" |
| | |
| | | :dataSource="dataSource" |
| | | :pagination="ipagination" |
| | | :loading="loading" |
| | | :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" |
| | | class="j-table-force-nowrap" |
| | | @change="handleTableChange"> |
| | | |
| | |
| | | </a-button> |
| | | </template> |
| | | |
| | | <span slot="action" slot-scope="text, record"> |
| | | <a @click="handleEdit(record)">编辑</a> |
| | | <!-- 可编辑单元格 --> |
| | | <template |
| | | v-for="col in ['workpieceMaterial', 'ratedLife']" |
| | | :slot="col" |
| | | slot-scope="text, record" |
| | | > |
| | | <div :key="col"> |
| | | <a-input |
| | | v-if="record.editable" |
| | | style="margin: -5px 0" |
| | | :value="text" |
| | | @change="e => handleChange(e.target.value, record.id, col)" |
| | | /> |
| | | <template v-else> |
| | | {{ text }} |
| | | </template> |
| | | </div> |
| | | </template> |
| | | |
| | | <a-divider type="vertical" /> |
| | | <a-dropdown> |
| | | <a class="ant-dropdown-link">更多 <a-icon type="down" /></a> |
| | | <a-menu slot="overlay"> |
| | | <a-menu-item> |
| | | <a @click="handleDetail(record)">详情</a> |
| | | </a-menu-item> |
| | | <a-menu-item> |
| | | <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)"> |
| | | <a>删除</a> |
| | | </a-popconfirm> |
| | | </a-menu-item> |
| | | </a-menu> |
| | | </a-dropdown> |
| | | <!-- 操作列 --> |
| | | <span slot="action" slot-scope="text, record"> |
| | | <div class="editable-row-operations"> |
| | | <span v-if="record.editable"> |
| | | <a-popconfirm title="确定保存?" @confirm="() => save(record.id)"> |
| | | <a>保存</a> |
| | | </a-popconfirm> |
| | | <a style="margin-left: 8px" @click="() => cancel(record.id)">取消</a> |
| | | </span> |
| | | <span v-else> |
| | | <a :disabled="editingKey !== ''" @click="() => edit(record.id)">编辑</a> |
| | | <a-divider type="vertical" /> |
| | | <a-dropdown> |
| | | <a class="ant-dropdown-link">更多 <a-icon type="down" /></a> |
| | | <a-menu slot="overlay"> |
| | | <a-menu-item> |
| | | <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)"> |
| | | <a>删除</a> |
| | | </a-popconfirm> |
| | | </a-menu-item> |
| | | </a-menu> |
| | | </a-dropdown> |
| | | </span> |
| | | </div> |
| | | </span> |
| | | |
| | | </a-table> |
| | |
| | | </template> |
| | | |
| | | <script> |
| | | import '@/assets/less/TableExpand.less' |
| | | import { mixinDevice } from '@/utils/mixin' |
| | | import { JeecgListMixin } from '@/mixins/JeecgListMixin' |
| | | import { putAction, getAction, postAction } from '@/api/manage' |
| | | import RatedLifeModal from './modules/RatedLifeModal' |
| | | |
| | | import '@/assets/less/TableExpand.less' |
| | | import { mixinDevice } from '@/utils/mixin' |
| | | import { JeecgListMixin } from '@/mixins/JeecgListMixin' |
| | | import RatedLifeModal from './modules/RatedLifeModal' |
| | | |
| | | export default { |
| | | name: 'RatedLifeList', |
| | | mixins:[JeecgListMixin, mixinDevice], |
| | | components: { |
| | | RatedLifeModal |
| | | }, |
| | | data () { |
| | | return { |
| | | description: '额定寿命管理页面', |
| | | // 表头 |
| | | columns: [ |
| | | { |
| | | title: '#', |
| | | dataIndex: '', |
| | | key:'rowIndex', |
| | | width:60, |
| | | align:"center", |
| | | customRender:function (t,r,index) { |
| | | return parseInt(index)+1; |
| | | } |
| | | }, |
| | | { |
| | | title:'刀具编码', |
| | | align:"center", |
| | | dataIndex: 'cuttingId', |
| | | sorter: true |
| | | }, |
| | | { |
| | | title:'工件材质', |
| | | align:"center", |
| | | dataIndex: 'workpieceMaterial' |
| | | }, |
| | | { |
| | | title:'额定寿命', |
| | | align:"center", |
| | | dataIndex: 'ratedLife' |
| | | }, |
| | | { |
| | | title: '操作', |
| | | dataIndex: 'action', |
| | | align:"center", |
| | | fixed:"right", |
| | | width:147, |
| | | scopedSlots: { customRender: 'action' } |
| | | export default { |
| | | name: 'RatedLifeList', |
| | | mixins:[JeecgListMixin, mixinDevice], |
| | | components: { |
| | | RatedLifeModal |
| | | }, |
| | | props: { |
| | | selectedCuttingId: { |
| | | type: String, |
| | | default: '' |
| | | } |
| | | }, |
| | | data () { |
| | | return { |
| | | description: '额定寿命管理页面', |
| | | editingKey: '', |
| | | // 表头 |
| | | columns: [ |
| | | { |
| | | title: '#', |
| | | dataIndex: '', |
| | | key:'rowIndex', |
| | | width:60, |
| | | align:"center", |
| | | customRender:function (t,r,index) { |
| | | return parseInt(index)+1; |
| | | } |
| | | ], |
| | | url: { |
| | | list: "/cms/ratedLife/list", |
| | | delete: "/cms/ratedLife/delete", |
| | | deleteBatch: "/cms/ratedLife/deleteBatch", |
| | | exportXlsUrl: "/cms/ratedLife/exportXls", |
| | | importExcelUrl: "cms/ratedLife/importExcel", |
| | | |
| | | }, |
| | | dictOptions:{}, |
| | | superFieldList:[], |
| | | { |
| | | title:'刀具编码', |
| | | align:"center", |
| | | dataIndex: 'cuttingId_dictText', |
| | | sorter: true |
| | | }, |
| | | { |
| | | title:'工件材质', |
| | | align:"center", |
| | | dataIndex: 'workpieceMaterial', |
| | | scopedSlots: { customRender: 'workpieceMaterial' } |
| | | }, |
| | | { |
| | | title:'额定寿命', |
| | | align:"center", |
| | | dataIndex: 'ratedLife', |
| | | scopedSlots: { customRender: 'ratedLife' } |
| | | }, |
| | | { |
| | | title: '操作', |
| | | dataIndex: 'action', |
| | | align:"center", |
| | | scopedSlots: { customRender: 'action' }, |
| | | width: 200, |
| | | } |
| | | ], |
| | | url: { |
| | | list: "/cms/ratedLife/list", |
| | | delete: "/cms/ratedLife/delete", |
| | | deleteBatch: "/cms/ratedLife/deleteBatch", |
| | | exportXlsUrl: "/cms/ratedLife/exportXls", |
| | | importExcelUrl: "cms/ratedLife/importExcel", |
| | | edit: "/cms/ratedLife/edit", |
| | | add: "/cms/ratedLife/add" |
| | | }, |
| | | dictOptions:{}, |
| | | superFieldList:[], |
| | | } |
| | | }, |
| | | created() { |
| | | this.getSuperFieldList(); |
| | | }, |
| | | computed: { |
| | | importExcelUrl: function(){ |
| | | return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`; |
| | | }, |
| | | }, |
| | | methods: { |
| | | initDictConfig(){ |
| | | }, |
| | | getRatedLife(cuttingId) { |
| | | this.queryParam.cuttingId = cuttingId; |
| | | // this.ipagination.current = 1; |
| | | this.loadData(1); |
| | | }, |
| | | getSuperFieldList(){ |
| | | let fieldList=[]; |
| | | fieldList.push({type:'string',value:'cuttingId',text:'刀具ID'}) |
| | | fieldList.push({type:'string',value:'workpieceMaterial',text:'工件材质'}) |
| | | fieldList.push({type:'number',value:'ratedLife',text:'额定寿命'}) |
| | | this.superFieldList = fieldList |
| | | }, |
| | | |
| | | // 新增行 |
| | | handleAdd() { |
| | | // 如果已经在编辑状态,自动取消当前编辑项 |
| | | if (this.editingKey !== '') { |
| | | // 查找正在编辑的记录并取消编辑 |
| | | const editingRecord = this.dataSource.find(item => item.id === this.editingKey); |
| | | if (editingRecord) { |
| | | this.cancel(this.editingKey); |
| | | } |
| | | } |
| | | |
| | | // 创建新的空数据项 |
| | | const newRow = { |
| | | id: 'new_' + new Date().getTime(), // 临时ID |
| | | cuttingId: this.queryParam.cuttingId, |
| | | workpieceMaterial: '', |
| | | ratedLife: '', |
| | | editable: true, |
| | | isNew: true // 标记为新添加的行 |
| | | }; |
| | | |
| | | // 将新行插入到数据源开头 |
| | | this.dataSource = [newRow, ...this.dataSource]; |
| | | this.editingKey = newRow.id; |
| | | }, |
| | | |
| | | // 编辑行数据 |
| | | edit(key) { |
| | | // 先保存当前数据的副本 |
| | | const newData = [...this.dataSource]; |
| | | const target = newData.find(item => key === item.id); |
| | | this.editingKey = key; |
| | | |
| | | if (target) { |
| | | target.editable = true; |
| | | this.dataSource = newData; |
| | | } |
| | | }, |
| | | created() { |
| | | this.getSuperFieldList(); |
| | | |
| | | // 保存编辑的数据 |
| | | save(key) { |
| | | const newData = [...this.dataSource]; |
| | | const target = newData.find(item => key === item.id); |
| | | |
| | | if (target) { |
| | | delete target.editable; |
| | | this.dataSource = newData; |
| | | |
| | | // 判断是新增还是编辑 |
| | | if (target.isNew) { |
| | | // 新增操作 |
| | | const params = { ...target }; |
| | | delete params.id; |
| | | delete params.isNew; |
| | | // 删除创建时间字段,让后端自动生成 |
| | | delete params.createTime; |
| | | delete params.updateTime; |
| | | |
| | | postAction(this.url.add, params).then(res => { |
| | | if (res.success) { |
| | | this.$message.success('新增成功'); |
| | | this.editingKey = ''; |
| | | this.loadData(); // 重新加载数据 |
| | | } else { |
| | | this.$message.error(res.message); |
| | | } |
| | | }).catch(err => { |
| | | this.$message.error('新增失败'); |
| | | console.log(err); |
| | | }); |
| | | } else { |
| | | // 编辑操作 - 只发送需要更新的字段 |
| | | const params = { |
| | | id: target.id, |
| | | cuttingId: target.cuttingId, |
| | | workpieceMaterial: target.workpieceMaterial, |
| | | ratedLife: target.ratedLife, |
| | | }; |
| | | |
| | | putAction(this.url.edit, params).then(res => { |
| | | if (res.success) { |
| | | this.$message.success('保存成功'); |
| | | this.editingKey = ''; |
| | | this.loadData(); // 重新加载数据 |
| | | } else { |
| | | this.$message.error(res.message); |
| | | } |
| | | }).catch(err => { |
| | | this.$message.error('保存失败'); |
| | | console.log(err); |
| | | }); |
| | | } |
| | | } |
| | | }, |
| | | computed: { |
| | | importExcelUrl: function(){ |
| | | return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`; |
| | | }, |
| | | |
| | | // 取消编辑 |
| | | cancel(key) { |
| | | const newData = [...this.dataSource]; |
| | | const targetIndex = newData.findIndex(item => key === item.id); |
| | | this.editingKey = ''; |
| | | |
| | | if (targetIndex >= 0) { |
| | | // 如果是新增的行,直接删除 |
| | | if (newData[targetIndex].isNew) { |
| | | newData.splice(targetIndex, 1); |
| | | this.dataSource = newData; |
| | | } else { |
| | | // 如果是编辑的行,从后端重新获取数据以恢复原始值 |
| | | const target = newData[targetIndex]; |
| | | getAction(this.url.list, { id: key }).then(res => { |
| | | if(res.success && res.result.records.length > 0) { |
| | | const originalData = res.result.records[0]; |
| | | Object.keys(target).forEach(key => { |
| | | if(key !== 'editable') { |
| | | target[key] = originalData[key]; |
| | | } |
| | | }); |
| | | delete target.editable; |
| | | this.dataSource = newData; |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | }, |
| | | methods: { |
| | | initDictConfig(){ |
| | | }, |
| | | getSuperFieldList(){ |
| | | let fieldList=[]; |
| | | fieldList.push({type:'string',value:'cuttingId',text:'刀具ID'}) |
| | | fieldList.push({type:'string',value:'workpieceMaterial',text:'工件材质'}) |
| | | fieldList.push({type:'number',value:'ratedLife',text:'额定寿命'}) |
| | | this.superFieldList = fieldList |
| | | |
| | | // 处理单元格值变化 |
| | | handleChange(value, key, column) { |
| | | const newData = [...this.dataSource]; |
| | | const target = newData.find(item => key === item.id); |
| | | |
| | | if (target) { |
| | | target[column] = value; |
| | | this.dataSource = newData; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style scoped> |
| | | @import '~@assets/less/common.less'; |
| | | </style> |
| | | @import '~@assets/less/common.less'; |
| | | |
| | | .editable-row-operations a { |
| | | margin-right: 8px; |
| | | } |
| | | </style> |