From f12e6e15699a218eac7f770b3b5ecfbbde098e50 Mon Sep 17 00:00:00 2001 From: zzyuan <781948537@qq.com> Date: Tue, 27 May 2025 13:03:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/superStore/shopMaterial.js | 41 +-- .../components/MaterialDialog.vue | 235 ++++++++-------- src/views/superstore/shopMaterial/index.vue | 256 ++++++------------ src/views/superstore/superUitId/index.vue | 5 +- 4 files changed, 232 insertions(+), 305 deletions(-) diff --git a/src/api/superStore/shopMaterial.js b/src/api/superStore/shopMaterial.js index 4285224e..3b785b82 100644 --- a/src/api/superStore/shopMaterial.js +++ b/src/api/superStore/shopMaterial.js @@ -1,20 +1,20 @@ import request from '@/utils/request' // 商品类别 -export function systemMaterialTreeApi(data) { +export function shopMaterialTreeApi(data) { return request({ - url: '/smart-canteen/menu_material_category/getTree', - method: 'post', + url: '/smart-canteen/supermarket_material_type/list', + method: 'get', headers: { "merchant-id":"378915229716713472", }, - data: data + params: data }) } // 新增商品类别 export function addMaterialTypeApi(data) { return request({ - url: '/smart-canteen/menu_material_category/add', + url: '/smart-canteen/supermarket_material_type', method: 'post', headers: { "merchant-id":"378915229716713472", @@ -25,7 +25,7 @@ export function addMaterialTypeApi(data) { //修改商品类别 export function updateMaterialTypeApi(data) { return request({ - url: '/smart-canteen/menu_material_category/edit', + url: '/smart-canteen/supermarket_material_type/edit', method: 'post', headers: { "merchant-id":"378915229716713472", @@ -36,12 +36,11 @@ export function updateMaterialTypeApi(data) { //删除商品类别 export function removeMaterialTypeApi(data) { return request({ - url: '/smart-canteen/menu_material_category/del', + url: '/smart-canteen/supermarket_material_type/del/'+data.materialTypeId, method: 'post', headers: { "merchant-id":"378915229716713472", - }, - data: data + } }) } @@ -49,7 +48,7 @@ export function removeMaterialTypeApi(data) { // 查询商品列表 export function getMaterialListApi(data) { return request({ - url: '/smart-canteen/supermarket_product/list', + url: '/smart-canteen/supermarket_material/list', method: 'get', headers: { "merchant-id":"378915229716713472", @@ -61,7 +60,7 @@ export function getMaterialListApi(data) { // 新增商品 export function addMaterialApi(data) { return request({ - url: '/smart-canteen/supermarket_product', + url: '/smart-canteen/supermarket_material', method: 'post', headers: { "merchant-id":"378915229716713472", @@ -73,7 +72,7 @@ export function addMaterialApi(data) { // 编辑商品 export function updateMaterialApi(data) { return request({ - url: '/smart-canteen/supermarket_product/edit', + url: '/smart-canteen/supermarket_material/edit', method: 'post', headers: { "merchant-id":"378915229716713472", @@ -85,7 +84,7 @@ export function updateMaterialApi(data) { // 删除商品 export function removeMaterialApi(data) { return request({ - url: '/smart-canteen/supermarket_product/del/'+data.productId, + url: '/smart-canteen/supermarket_material/del/'+data.materialId, method: 'post', headers: { "merchant-id":"378915229716713472", @@ -103,23 +102,13 @@ export function batchRemoveMaterialApi(data) { }, data: data }) -} -// 批量修改商品 -export function batchUpdateMaterialApi(data) { - return request({ - url: '/smart-canteen/api/v1/menumaterial/material/batch/update/category', - method: 'post', - headers: { - "merchant-id":"378915229716713472", - }, - data: data - }) -} +} + // 根据区域ID-获取商品单位下拉选 //{current: 1, size: -1, ifListUse: 1, areaId: '421488254718578688'} export function getDrpUnitListApi(data) { return request({ - url: '/smart-canteen/supermarket_unit/list', + url: '/smart-canteen/supply_product_unit/list', method: 'get', headers: { "merchant-id":"378915229716713472", diff --git a/src/views/superstore/shopMaterial/components/MaterialDialog.vue b/src/views/superstore/shopMaterial/components/MaterialDialog.vue index c5252758..c3478407 100644 --- a/src/views/superstore/shopMaterial/components/MaterialDialog.vue +++ b/src/views/superstore/shopMaterial/components/MaterialDialog.vue @@ -12,10 +12,20 @@
- - + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + v-model="form.barCode" + placeholder="请输入条码" + maxlength="20" + show-word-limit + /> - - - - - + + + import { systemAreaTreeApi } from "@/api/base/area"; -import { systemMaterialTreeApi,getDrpUnitListApi } from "@/api/superStore/shopMaterial"; +import { shopMaterialTreeApi,getDrpUnitListApi } from "@/api/superStore/shopMaterial"; import { imgUpLoadTwo } from '@/api/system/upload' export default { name: "MaterialDialog", @@ -194,14 +191,14 @@ export default { treeTypeOptions:[],//类型树 unitOptions:[],//单位下拉 form: { - productName: '',//商品名称 + materialName: '',//商品名称 areaId: null,//所属区域 - materialId: null,//商品类别 + materialTypeId: null,//商品类别 materialType: 2, salesMode: '1',//计量类型 salePrice: '',//零售价(元) unitId: '',//商品单位 - prefPrice: '',//商品进价(元) + unitPrice: '',//商品进价(元) barCode: '',//条码 nutritionId:null,//营养信息 qualityType:"1",//保质期类型 @@ -215,10 +212,11 @@ export default { }, rules: { - productName: [{ required: true, message: '请输入商品名称', trigger: 'blur' }], + materialCode: [{ required: true, message: '请输入商品编号', trigger: 'blur' }], + materialName: [{ required: true, message: '请输入商品名称', trigger: 'blur' }], areaId: [{ required: true, message: '请选择所属区域', trigger: 'change' }], salePrice: [{ required: true, message: '请输入零售价', trigger: 'change' }], - materialId: [{ required: true, message: '请选择商品类别', trigger: 'change' }], + materialTypeId: [{ required: true, message: '请选择商品类别', trigger: 'change' }], salesMode: [{ required: true, message: '请选择计量类型', trigger: 'change' }], unitId: [{ required: true, message: '请选择商品单位', trigger: 'change' }], }, @@ -257,30 +255,52 @@ export default { }, //基础设置-选择区域 handleAreaChange(val){ - console.log(this.form) - this.form.materialId=null + console.log(this.form) this.getTypeTreeData() this.getDrpUnitList() }, //类型树 getTypeTreeData() { - let param = { - categoryType:2, - // ifAdd: 1, - // areaId:this.form.areaId - } - systemMaterialTreeApi(param).then((response) => { - this.treeTypeOptions = response.data; + shopMaterialTreeApi().then((response) => { + this.treeTypeOptions = this.handleTree(response.rows,'materialTypeId'); }); }, + handleTree(data, idKey, parentIdKey = 'parentId', childrenKey = 'children') { + // 用于存储节点数据的Map,以idKey为键 + const nodeMap = new Map(); + // 用于存储根节点的数组 + const rootNodes = []; + + // 遍历数据,构建nodeMap并找到根节点 + data.forEach(node => { + // 将节点添加到nodeMap中,并初始化children为空数组 + if(node.parentId==0){ + nodeMap.set(node[idKey], { ...node, [childrenKey]: [] }); + }else{ + nodeMap.set(node[idKey], { ...node }); + } + // 如果parentId为null或父节点不存在于nodeMap中,则该节点为根节点 + if (node[parentIdKey] === null || !nodeMap.has(node[parentIdKey])) { + // 将根节点添加到rootNodes数组中 + rootNodes.push(nodeMap.get(node[idKey])); + } else { + // 否则,将当前节点添加到其父节点的children列表中 + // 获取父节点 + const parentNode = nodeMap.get(node[parentIdKey]); + // 将当前节点添加到父节点的children列表中 + parentNode[childrenKey].push(nodeMap.get(node[idKey])); + } + }); + + // 返回根节点数组,它现在包含了完整的树形结构 + return rootNodes; + }, //单位类型拉下选 getDrpUnitList() { let param = { - weighType:this.form.salesMode, - // areaId: this.form.areaId||"" - // ifListUse: 1, - // current: 1, - // size: -1 + "weighType":this.form.salesMode, + "pageNum": 1, + "pageSize": 100 } this.form.unitId=null getDrpUnitListApi(param).then((response) => { @@ -302,16 +322,16 @@ export default { this.getTypeTreeData() this.getDrpUnitList() this.$set(this.form,"areaName",row.areaName) - this.$set(this.form,"materialId",row.materialId) + this.$set(this.form,"materialTypeId",row.materialTypeId) this.$set(this.form,"categoryName",row.categoryName) this.$set(this.form,"materialCode",row.materialCode) this.$set(this.form,"materialId",row.materialId) - this.$set(this.form,"productName",row.productName) + this.$set(this.form,"materialName",row.materialName) this.$set(this.form,"materialType",row.materialType) this.$set(this.form,"salesMode",row.salesMode+'') this.$set(this.form,"unitId",row.unitId) this.$set(this.form,"salePrice",Number((row.salePrice/100).toFixed(2))) - this.$set(this.form,"prefPrice",Number((row.prefPrice/100).toFixed(2))) + this.$set(this.form,"unitPrice",Number((row.unitPrice/100).toFixed(2))) this.$set(this.form,"barCode",row.barCode) if(row.qualityType){ this.$set(this.form,"qualityType",row.qualityType+"") @@ -337,10 +357,10 @@ export default { if (valid) { this.loading=true this.form.salePrice = Number(this.form.salePrice)*100; - this.form.prefPrice = Number(this.form.prefPrice)*100; + this.form.unitPrice = Number(this.form.unitPrice)*100; setTimeout(()=>{ this.$set(this.form,"salePrice",Number((this.form.salePrice/100).toFixed(2))) - this.$set(this.form,"prefPrice",Number((this.form.prefPrice/100).toFixed(2))) + this.$set(this.form,"unitPrice",Number((this.form.unitPrice/100).toFixed(2))) this.loading=false },2000) this.$emit('submit', this.form); @@ -359,14 +379,13 @@ export default { reset() { this.form = { - productName: '',//商品名称 + materialName: '',//商品名称 areaId: null,//所属区域 - materialId: null,//商品类别 - materialType: 2, + materialTypeId: null,//商品类别 salesMode: '1',//计量类型 unitId: '',//商品单位 salePrice: '',//商品售价(元) - prefPrice: '',//商品进价(元) + unitPrice: '',//商品进价(元) barCode: '',//条码 str:[],//营养信息类型 nutritionId:null,//营养信息 diff --git a/src/views/superstore/shopMaterial/index.vue b/src/views/superstore/shopMaterial/index.vue index ebbf90dc..4c368b56 100644 --- a/src/views/superstore/shopMaterial/index.vue +++ b/src/views/superstore/shopMaterial/index.vue @@ -27,9 +27,10 @@ :expand-on-click-node="false" :filter-node-method="filterNode" ref="typeTree" - node-key="id" + node-key="materialTypeId" highlight-current @node-click="handleNodeClick" + @check-change="handleCheckChange" > {{ @@ -41,7 +42,7 @@ @@ -59,7 +60,7 @@ size="mini" icon="el-icon-delete" style="color: #f56c6c" - v-if="data.parentId != '-1'" + v-if="data.parentId != '0'" @click.stop="() => removeTreeNode(data)" > @@ -88,9 +89,18 @@ }" clearable> - + + + + - - - + 批量删除 - - + - +