优化商品模块,使其能自动加载扩展字段的别名

This commit is contained in:
jishenghua 2025-03-25 23:45:36 +08:00
parent ecfbd396af
commit 0a3ce706c5
7 changed files with 67 additions and 72 deletions

View File

@ -46,7 +46,7 @@ const addDepot = (params)=>postAction("/depot/add",params);
const editDepot = (params)=>putAction("/depot/update",params);
const checkDepot = (params)=>getAction("/depot/checkIsNameExist",params);
//商品属性
const editMaterialProperty = (params)=>putAction("/materialProperty/update",params);
const addOrUpdateMaterialProperty = (params)=>postAction("/materialProperty/addOrUpdate",params);
//商品类型
const queryMaterialCategoryTreeList = (params)=>getAction("/materialCategory/getMaterialCategoryTree",params);
const queryMaterialCategoryById = (params)=>getAction("/materialCategory/findById",params);
@ -149,7 +149,7 @@ export {
addDepot,
editDepot,
checkDepot,
editMaterialProperty,
addOrUpdateMaterialProperty,
queryMaterialCategoryTreeList,
queryMaterialCategoryById,
checkMaterialCategory,

View File

@ -149,7 +149,6 @@ export const JeecgListMixin = {
});
return str;
},
onSelectChange(selectedRowKeys, selectionRows) {
this.selectedRowKeys = selectedRowKeys;
this.selectionRows = selectionRows;

View File

@ -418,14 +418,12 @@ export function replaceAll(text, checker, replacer) {
*/
export function getMpListShort(thisRows, checker, replacer) {
let mPropertyListShort = ''
let nativeNameStr = ''
let anotherNameStr = ''
for (let i = 0; i < thisRows.length; i++) {
if (thisRows[i].enabled) {
nativeNameStr += thisRows[i].nativeName + ",";
}
anotherNameStr += thisRows[i].anotherName + ",";
}
if (nativeNameStr) {
mPropertyListShort = nativeNameStr.substring(0, nativeNameStr.length - 1);
if (anotherNameStr) {
mPropertyListShort = anotherNameStr.substring(0, anotherNameStr.length - 1);
}
return mPropertyListShort
}

View File

@ -59,17 +59,17 @@
</a-form-item>
</a-col>
<a-col :md="6" :sm="24">
<a-form-item label="扩展1" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-form-item :label="queryTitle.mp1" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-input placeholder="请输入扩展1查询" v-model="queryParam.otherField1"></a-input>
</a-form-item>
</a-col>
<a-col :md="6" :sm="24">
<a-form-item label="扩展2" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-form-item :label="queryTitle.mp2" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-input placeholder="请输入扩展2查询" v-model="queryParam.otherField2"></a-input>
</a-form-item>
</a-col>
<a-col :md="6" :sm="24">
<a-form-item label="扩展3" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-form-item :label="queryTitle.mp3" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-input placeholder="请输入扩展3查询" v-model="queryParam.otherField3"></a-input>
</a-form-item>
</a-col>
@ -260,6 +260,11 @@
span: 18,
offset: 1
},
queryTitle: {
mp1: '扩展1',
mp2: '扩展2',
mp3: '扩展3'
},
// 查询条件
queryParam: {
categoryId: undefined,
@ -289,7 +294,7 @@
// 实际列
columns:[],
// 默认索引
defDataIndex:['action','mBarCode','name','standard','model','color','categoryName','materialOther','unit', 'stock',
defDataIndex:['action','mBarCode','name','standard','model','color','categoryName','unit', 'stock',
'purchaseDecimal','commodityDecimal','wholesaleDecimal','lowDecimal','enabled'],
// 默认列
defColumns: [
@ -358,7 +363,8 @@
created() {
this.model = Object.assign({}, {});
this.initColumnsSetting()
this.loadTreeData();
this.loadTreeData()
this.handleChangeOtherField()
},
computed: {
importExcelUrl: function () {
@ -391,6 +397,29 @@
Vue.ls.remove('materialColumns')
this.initColumnsSetting()
},
//动态替换扩展字段
handleChangeOtherField() {
let mpStr = getMpListShort(Vue.ls.get('materialPropertyList'))
if(mpStr) {
let mpArr = mpStr.split(',')
if(mpArr.length ===3) {
this.queryTitle.mp1 = mpArr[0]
this.queryTitle.mp2 = mpArr[1]
this.queryTitle.mp3 = mpArr[2]
for (let i = 0; i < this.defColumns.length; i++) {
if(this.defColumns[i].dataIndex === 'otherField1') {
this.defColumns[i].title = mpArr[0]
}
if(this.defColumns[i].dataIndex === 'otherField2') {
this.defColumns[i].title = mpArr[1]
}
if(this.defColumns[i].dataIndex === 'otherField3') {
this.defColumns[i].title = mpArr[2]
}
}
}
}
},
loadTreeData(){
let that = this;
let params = {};

View File

@ -3,25 +3,6 @@
<a-row :gutter="24">
<a-col :md="24">
<a-card :style="cardStyle" :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="名称" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
<a-input placeholder="请输入名称查询" v-model="queryParam.name"></a-input>
</a-form-item>
</a-col>
<span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
<a-col :md="6" :sm="24">
<a-button type="primary" @click="searchQuery">查询</a-button>
<a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
</a-col>
</span>
</a-row>
</a-form>
</div>
<!-- table区域-begin -->
<div>
<a-table
@ -37,11 +18,6 @@
<span slot="action" slot-scope="text, record">
<a @click="handleEdit(record)">编辑</a>
</span>
<!-- 状态渲染模板 -->
<template slot="customRenderFlag" slot-scope="enabled">
<a-tag v-if="enabled==1" color="green">启用</a-tag>
<a-tag v-if="enabled==0" color="orange">禁用</a-tag>
</template>
</a-table>
</div>
<!-- table区域-end -->
@ -55,6 +31,8 @@
import MaterialPropertyModal from './modules/MaterialPropertyModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JDate from '@/components/jeecg/JDate'
import { getAction } from '@/api/manage'
import Vue from 'vue'
export default {
name: "MaterialPropertyList",
mixins:[JeecgListMixin],
@ -88,16 +66,11 @@
{
title: '操作',
dataIndex: 'action',
width: 200,
width: 100,
align:"center",
scopedSlots: { customRender: 'action' },
},
{title: '名称', dataIndex: 'nativeName', width: 100},
{
title: '是否启用', dataIndex: 'enabled', width: 100, align: "center",
scopedSlots: { customRender: 'customRenderFlag' }
},
{title: '排序', dataIndex: 'sort', width: 100},
{title: '别名', dataIndex: 'anotherName', width: 100}
],
url: {
@ -111,7 +84,23 @@
},
methods: {
loadData(arg) {
let params = this.getQueryParams() //查询条件
this.loading = true
getAction(this.url.list, params).then((res) => {
if (res.code===200) {
this.dataSource = res.data.rows
this.ipagination.total = res.data.total
Vue.ls.set('materialPropertyList', res.data.rows, 7 * 24 * 60 * 60 * 1000);
} else if(res.code===510){
this.$message.warning(res.data)
} else {
this.$message.warning(res.data.message)
}
this.loading = false
this.onClearSelected()
})
},
}
}
</script>

View File

@ -118,17 +118,17 @@
</a-col>
</a-row>
<a-row class="form-row" :gutter="24">
<a-col :lg="6" :md="6" :sm="6" v-if="mpShort.otherField1.enabled">
<a-col :lg="6" :md="6" :sm="6">
<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="mpShort.otherField1.name">
<a-input v-decorator.trim="[ 'otherField1' ]" />
</a-form-item>
</a-col>
<a-col :lg="6" :md="6" :sm="6" v-if="mpShort.otherField2.enabled">
<a-col :lg="6" :md="6" :sm="6">
<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="mpShort.otherField2.name">
<a-input v-decorator.trim="[ 'otherField2' ]" />
</a-form-item>
</a-col>
<a-col :lg="6" :md="6" :sm="6" v-if="mpShort.otherField3.enabled">
<a-col :lg="6" :md="6" :sm="6">
<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="mpShort.otherField3.name">
<a-input v-decorator.trim="[ 'otherField3' ]" />
</a-form-item>
@ -1107,21 +1107,14 @@
loadParseMaterialProperty() {
let mpList = Vue.ls.get('materialPropertyList')
for (let i = 0; i < mpList.length; i++) {
if (mpList[i].nativeName === "制造商") {
this.mpShort.mfrs.name = mpList[i].anotherName
this.mpShort.mfrs.enabled = mpList[i].enabled
}
if (mpList[i].nativeName === "扩展1") {
this.mpShort.otherField1.name = mpList[i].anotherName
this.mpShort.otherField1.enabled = mpList[i].enabled
}
if (mpList[i].nativeName === "扩展2") {
this.mpShort.otherField2.name = mpList[i].anotherName
this.mpShort.otherField2.enabled = mpList[i].enabled
}
if (mpList[i].nativeName === "扩展3") {
this.mpShort.otherField3.name = mpList[i].anotherName
this.mpShort.otherField3.enabled = mpList[i].enabled
}
}
},

View File

@ -17,13 +17,7 @@
<a-spin :spinning="confirmLoading">
<a-form :form="form">
<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="名称">
<a-input placeholder="请输入名称" v-decorator.trim="[ 'nativeName' ]" :readOnly="model.id"/>
</a-form-item>
<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="是否启用">
<a-switch checked-children="启用" un-checked-children="禁用" v-model="enabledSwitch" @change="onChange"></a-switch>
</a-form-item>
<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="排序">
<a-input placeholder="请输入排序" v-decorator.trim="[ 'sort', validatorRules.sort]" />
{{model.nativeName}}
</a-form-item>
<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="别名">
<a-input placeholder="请输入别名" v-decorator.trim="[ 'anotherName' ]" />
@ -36,7 +30,7 @@
<script>
import pick from 'lodash.pick'
import {mixinDevice} from '@/utils/mixin'
import {editMaterialProperty } from '@/api/api'
import {addOrUpdateMaterialProperty } from '@/api/api'
export default {
name: "MaterialPropertyModal",
mixins: [mixinDevice],
@ -45,7 +39,6 @@
title:"操作",
visible: false,
model: {},
enabledSwitch: true, //是否启用
labelCol: {
xs: { span: 24 },
sm: { span: 5 },
@ -69,9 +62,6 @@
created () {
},
methods: {
onChange(checked) {
this.model.enabled = checked
},
add () {
this.edit({});
},
@ -79,11 +69,8 @@
this.form.resetFields();
this.model = Object.assign({}, record);
this.visible = true;
if(record.enabled!=null){
this.enabledSwitch = record.enabled?true:false;
}
this.$nextTick(() => {
this.form.setFieldsValue(pick(this.model,'nativeName', 'enabled', 'sort', 'anotherName'))
this.form.setFieldsValue(pick(this.model,'nativeName', 'anotherName'))
});
},
close () {
@ -99,7 +86,7 @@
let formData = Object.assign(this.model, values);
let obj;
if(this.model.id){
obj=editMaterialProperty(formData);
obj=addOrUpdateMaterialProperty(formData);
}
obj.then((res)=>{
if(res.code === 200){