From 8d017ba703be8999c9d9179491e7d0a129bc4499 Mon Sep 17 00:00:00 2001
From: tianyi <13521030702@163.com>
Date: Wed, 6 May 2026 18:01:39 +0800
Subject: [PATCH] 1
---
pages/goods/addGoods.vue | 933 ++++++++++++++++++++++++++++++++++++++-
pages/login/login.vue | 2 +
pages/shop/addGoods.vue | 268 ++++++-----
pages/shop/goodsList.vue | 19 +-
4 files changed, 1094 insertions(+), 128 deletions(-)
diff --git a/pages/goods/addGoods.vue b/pages/goods/addGoods.vue
index 84ff60f..3c63382 100644
--- a/pages/goods/addGoods.vue
+++ b/pages/goods/addGoods.vue
@@ -1,39 +1,155 @@
+
+
+
+
+
+
+ 新增商品
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 删除
+
+
+ 新增拼团
+
+
+
+
+
+
+ {{value[0]}}(可选{{value[1].canbuy || 1}}个):
+
+ {{item}}、
+
+
+
+ 选择属性
+
-
-
-
-
-
-
+
+
+
+ 全时段售卖
+ 自定义时段
+
+
+
+ {{formData.sellBeginTime}}
+
+ -
+
+ {{formData.sellEndTime}}
+
-
-
+
+
+ 否
+ 是
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -41,29 +157,802 @@
export default {
data() {
return {
+ dataList: {},
+ modalType:0,
+ maxSelect:1,
+ currentCanbuy:1,
+ canbuyMap:{},
+ categoryData:[],
+ categoryIndex: 0,
+ modalclassType:'',
+ categorySonData:[],
+ specValueArr:[],
+ attrValueArr:[],
+ editorIns: null,
+ typeItem: {},
formData: {
- productName: '',
- productPicture: '',
- categoryId: '',
- productPictures: []
+ id: '',
+ shopId: '',
+ attrId:'',
+ categoryId: '', //商品分类id
+ categoryName: '', //商品分类名称
+ productPicture: '', //商品图标
+ productName: '', //商品名称
+ orderFiled: '', //商品名称
+ lunchBox: 0, //餐盒
+ startPayNum: '', //起售数量
+ attributeListPrice: [{ //商品规格
+ specPrice: "",
+ specNum: 9999
+ }],
+ shopId:'',
+ sellTime: 0, //可售时间
+ isMoreBuy: 0,
+ sellBeginTime: '', //可售时段自定义---开始时间
+ sellEndTime: '', //可售时段自定义---结束时间
+ attributeList: '',
+ productGroupBuyPrices: [],
+ attributeList1: new Map(), //商品属性
+ productIntro: "" //详细图文
+ },
+ rules: {
+ productName: {
+ rules: [{
+ required: true,
+ errorMessage: '请输入名称',
+ }]
+ },
+ categoryId: {
+ rules: [{
+ required: true,
+ errorMessage: '请选择商品分类',
+ }, ],
+ },
},
}
+ },
+ filters: {
+
},
onShow() {
+ this.attrId = uni.getStorageSync('attrId');
+ uni.authorize({
+ scope: 'scope.writePhotosAlbum',
+ success() {
+ },
+ fail() {
+ uni.showToast({
+ title: "您未授权,图片上传功能可能会出现错误",
+ icon: 'none'
+ })
+ }
+ })
+ this.typeItem = JSON.parse(JSON.stringify(this.typeItem)) || ''
+ if (this.typeItem) {
+ this.formData.categoryId = this.typeItem.id
+ }
+ this.formData.shopId = uni.getStorageSync('shopId')
},
onLoad(option) {
-
+ this.getGategoryList()
+ if (option.dataList != undefined && option.dataList != null && option.dataList != 'undefined') {
+ this.dataList = JSON.parse(option.dataList)
+
+ this.NB.sendRequest("/app/product/getById/" + this.dataList.id, {}, false, 'POST', 'application/x-www-form-urlencoded').then((res) => {
+ if (res.code == 200) {
+ this.modalType = 1
+ this.formData.id = res.result.id
+ this.formData.shopId = res.result.shopId
+ this.formData.categoryName = res.result.categoryName
+ this.formData.orderFiled = res.result.orderFiled
+ this.formData.lunchBox = res.result.lunchBox
+ this.formData.startPayNum = res.result.startPayNum
+ this.formData.attributeListPrice = JSON.parse(res.result.attributeListPrice)
+ this.formData.shopId = res.result.shopId
+ this.formData.sellTime = res.result.sellBeginTime !=''?1:0
+ this.formData.isMoreBuy = res.result.isMoreBuy
+ this.formData.sellBeginTime = res.result.sellBeginTime
+ this.formData.sellEndTime = res.result.sellEndTime
+ this.formData.attributeList = res.result.attributeList
+ this.formData.productGroupBuyPrices = res.result.productGroupBuyPrices
+ this.formData.attributeList1 = new Map()
+ this.formData.productName = res.result.productName
+ this.formData.productPicture = res.result.productPicture
+ this.formData.productIntro = res.result.productIntro
+ this.formData.categoryId = res.result.categoryId
+ this.edit(this.formData)
+ } else {
+ uni.showToast({
+ title: res.message,
+ icon: 'none'
+ })
+ }
+ uni.hideLoading()
+ }).catch((res) => {})
+ }
},
methods: {
-
+ /**
+ * 获取输入内容
+ * @param {Object} e {html,text} 内容的html文本,和text文本
+ */
+ inputOver(e) {
+ // 可以在此处获取到编辑器已编辑的内容
+ console.log('==== inputOver :', e)
+ this.productIntro = e
+ },
+ /**
+ * 超出最大内容限制
+ * @param {Object} e {html,text} 内容的html文本,和text文本
+ */
+ overMax(e) {
+ // 若设置了最大字数限制,可在此处触发超出限制的回调
+ console.log('==== overMax :', e)
+ },
+ /**
+ * 编辑器就绪
+ * @param {Object} editor 编辑器实例,你可以自定义调用editor实例的方法
+ * @tutorial editor组件 https://uniapp.dcloud.net.cn/component/editor.html#editor-%E7%BB%84%E4%BB%B6
+ * @tutorial 相关api https://uniapp.dcloud.net.cn/api/media/editor-context.html
+ */
+ initEditor(editor) {
+ this.editorIns = editor // 保存编辑器实例
+ // 保存编辑器实例后,可以在此处获取后端数据,并赋值给编辑器初始化内容
+
+ },
+ /**
+ * 直接运行示例工程插入图片无法正常显示的看这里
+ * 因为插件默认采用云端存储图片的方式
+ * 以$emit('upinImage', tempFiles, this.editorCtx)的方式回调
+ * @param {Object} tempFiles
+ * @param {Object} editorCtx
+ */
+ upinImage(tempFiles, editorCtx) {
+ /**
+ * 本地临时插入图片预览
+ * 注意:这里仅是示例本地图片预览,因为需要将图片先上传到云端,再将图片插入到编辑器中
+ * 正式开发时,还请将此处注释,并解开下面 使用 uniCloud.uploadFile 上传图片的示例方法 的注释
+ * @tutorial https://uniapp.dcloud.net.cn/api/media/editor-context.html#editorcontext-insertimage
+ */
+ // #ifdef MP-WEIXIN
+ // 注意微信小程序的图片路径是在tempFilePath字段中
+ editorCtx.insertImage({
+ src: tempFiles[0].tempFilePath,
+ width: '80%', // 默认不建议铺满宽度100%,预留一点空隙以便用户编辑
+ success: function() {}
+ })
+ // #endif
+
+ // #ifndef MP-WEIXIN
+ editorCtx.insertImage({
+ src: tempFiles[0].path,
+ width: '80%', // 默认不建议铺满宽度100%,预留一点空隙以便用户编辑
+ success: function() {}
+ })
+ // #endif
+
+ /**
+ * 使用 uniCloud.uploadFile 上传图片的示例方法(可适用多选上传)
+ * 正式开发环境中,请将上面 本地临时插入图片预览 注释后,模仿以下写法
+ */
+ // tempFiles.forEach(async (item) => {
+ // uni.showLoading({
+ // title: '上传中请稍后',
+ // mask: true
+ // })
+ // let upfile = await uniCloud.uploadFile({
+ // filePath: item.path,
+ // // 同名会导致报错 policy_does_not_allow_file_overwrite
+ // // cloudPath可由 想要存储的文件夹/文件名 拼接,若不拼文件夹名则默认存储在cloudstorage文件夹中
+ // cloudPath: `cloudstorage/${item.name}`,
+ // cloudPathAsRealPath: true
+ // })
+ // editorCtx.insertImage({
+ // src: upfile.fileID,
+ // width: '80%', // 默认不建议铺满宽度100%,预留一点空隙以便用户编辑
+ // success: function () {
+ // uni.hideLoading()
+ // }
+ // })
+ // })
+ },
+ //跳转分类页
+ goGategoryLow() {
+ uni.navigateTo({
+ url: '/package1/myCenter/addType'
+ })
+ },
+ //初始化获取分类列表
+ getGategoryList() {
+ this.NB.sendRequest("/app/productCategory/list", {
+ shopId:uni.getStorageSync('shopId')
+ }, false, 'get', 'application/x-www-form-urlencoded').then((res) => {
+ if (res.code == 200) {
+ if (res.result.length > 0) {
+ if(this.formData.categoryId != '' && this.formData.categoryId != undefined){
+ for(let i=0;i {})
+ },
+ // 触发提交表单
+ submit() {
+ let that = this;
+ // this.$refs.form.validate((valid) => {
+ // if (valid) {
+ if (this.modalType == 0) {
+ // 添加 避免编辑后传入id等数据 记得删除
+ delete this.formData.id;
+ if(this.formData.isMoreBuy != 1){
+ this.formData.isMoreBuy = 0
+ }
+ this.formData.attributeListPrice = JSON.stringify(this.formData.attributeListPrice)
+ this.formData.attributeList = Object.fromEntries(this.formData.attributeList1)
+ this.formData.attributeList = JSON.stringify(this.formData.attributeList)
+
+ this.NB.sendRequest("/app/product/save",this.formData, false, 'post', 'application/json').then((res) => {
+ if (res.code == 200) {
+ uni.showToast({
+ title: "操作成功",
+ icon: 'none'
+ })
+ uni.navigateBack()
+ } else {
+ uni.showToast({
+ title: res.message,
+ icon: 'none'
+ })
+ }
+ uni.hideLoading()
+ }).catch((res) => {})
+ } else if (this.modalType == 1) {
+ // 编辑
+ this.formData.attributeListPrice = JSON.stringify(this.formData.attributeListPrice)
+ this.formData.attributeList = Object.fromEntries(this.formData.attributeList1)
+ this.formData.attributeList = JSON.stringify(this.formData.attributeList)
+ this.formData.productPictures = []
+
+ this.NB.sendRequest("/app/product/edit",this.formData, false, 'post', 'application/json').then((res) => {
+ if (res.code == 200) {
+ uni.showToast({
+ title: "操作成功",
+ icon: 'none'
+ })
+ uni.navigateBack()
+ } else {
+ uni.showToast({
+ title: res.message,
+ icon: 'none'
+ })
+ }
+ uni.hideLoading()
+ }).catch((res) => {})
+ }
+ // }
+ // });
+ },
+ back() {
+ uni.navigateBack()
+ },
+ checkisMoreBuy(type){
+ this.formData.isMoreBuy = type;
+ },
+ checkSellTime(type){
+ this.formData.sellTime = type;
+ },
+ selectDateRange(e,type){
+ if(type == 'start'){
+ this.formData.sellBeginTime = e.detail.value
+ }else{
+ this.formData.sellEndTime = e.detail.value
+ }
+ },
+ guigeSubmit(){
+ if(this.modalclassType == 'shuxing'){
+ // 保存当前分类的canbuy值
+ if(this.typeToAttrName){
+ this.canbuyMap[this.typeToAttrName] = parseInt(this.currentCanbuy) || 1
+ }
+ for(let i=0;i {
+ value.canbuy = value.canbuy || 1
+ this.canbuyMap[key] = value.canbuy
+ for(let i = 0;i {
+ if (res.code == 200) {
+ that.categoryData = res.result
+ for (var i = 0; i < that.categoryData.length; i++) {
+ that.categoryData[i].title = that.categoryData[i].attributeName
+ if (i == that.categoryIndex) {
+ that.categoryData[i].parentId = true
+ } else {
+ that.categoryData[i].parentId = false
+ }
+ }
+ //如果是选择属性,需要拿一个分类名,保存成parent
+ that.typeToAttrName = res.result[that.categoryIndex].title
+ // 恢复该分类之前设置的canbuy值
+ that.currentCanbuy = that.canbuyMap[that.typeToAttrName] || 1
+ that.getCateGorySon(res.result[that.categoryIndex].id)
+ } else {
+ uni.showToast({
+ title: res.message,
+ icon: 'none'
+ })
+ }
+ uni.hideLoading()
+ }).catch((res) => {})
+ },
+ getCateGorySon(id){
+ let that = this
+
+ this.NB.sendRequest("/app/productAttributeValue/selectByAttributeId",{
+ id: id,
+ }, false, 'get', 'application/x-www-form-urlencoded').then((res) => {
+ if (res.code == 200) {
+ that.categorySonData = res.result
+ for (var i = 0; i < that.categorySonData.length; i++) {
+ that.categorySonData[i].title = that.categorySonData[i].value
+ that.$set(that.categorySonData[i], 'checked', false)
+ }
+ if(that.modalclassType == 'shuxing'){
+ for (var i = 0; i < that.categorySonData.length; i++) {
+ for (var m = 0; m < that.attrValueArr.length; m++) {
+ if(that.attrValueArr[m].title == that.categorySonData[i].title && that.attrValueArr[m].parentName == that.typeToAttrName){
+ that.$set(that.categorySonData[i], 'checked', true)
+ }
+ }
+ }
+ }else{
+ //guige
+ for (var i = 0; i < that.categorySonData.length; i++) {
+ for (var m = 0; m < that.specValueArr.length; m++) {
+ if(that.specValueArr[m].id == that.categorySonData[i].id){
+ that.$set(that.categorySonData[i], 'checked', true)
+ }
+ }
+ }
+ }
+ console.log()
+ that.$forceUpdate(that.categorySonData)
+ that.$forceUpdate(that.categoryData)
+ } else {
+ uni.showToast({
+ title: res.message,
+ icon: 'none'
+ })
+ }
+ uni.hideLoading()
+ }).catch((res) => {})
+ },
+ deldantiaoguige(index){
+ for (var m = 0; m < this.specValueArr.length; m++) {
+ if(this.specValueArr[m].id == this.formData.attributeListPrice[index].id){
+ this.specValueArr.splice(m,1)
+ this.formData.attributeListPrice.splice(index,1)
+ console.log("11",this.formData.attributeListPrice)
+ if(this.formData.attributeListPrice.length == 1){
+ this.formData.attributeListPrice = []
+ this.formData.attributeListPrice.push({
+ specName:"",
+ specPrice:'',
+ specNum:9999
+ })
+ this.specValueArr = []
+ }
+ this.$forceUpdate()
+ return
+ }
+ }
+ },
+ delGroup(index){
+ this.formData.productGroupBuyPrices.splice(index,1)
+ },
+ changePrice(index){
+ this.specValueArr[index].specPrice = this.formData.attributeListPrice[index].specPrice
+ },
+ changeCount(index){
+ this.specValueArr[index].specNum = this.formData.attributeListPrice[index].specNum
+ },
+ addGroup(){
+ let data = {
+ groupCount:'',
+ groupPrice:0
+ }
+ this.formData.productGroupBuyPrices.push(data)
+ },
+ async upLoadFile(path) {
+ let that = this;
+ let hiver_token = uni.getStorageSync("hiver_token")
+ await uni.uploadFile({
+ url: that.tui.interfaceUrl() + '/upload/file',
+ filePath: path,
+ name: 'file',
+ header: {
+ "content-type": "multipart/form-data",
+ 'accessToken': hiver_token
+ },
+ formData: {},
+ success: (uploadFileRes) => {
+ let pathData = JSON.parse(uploadFileRes.data)
+ that.formData.productPicture = pathData.result
+ that.$forceUpdate()
+ },
+ fail: (err) => {
+ uni.hideLoading();
+ uni.showToast({
+ title: JSON.stringify(err),
+ icon: 'none'
+ })
+ }
+ });
+ await setTimeout(res => {
+ uni.hideLoading();
+ }, 1000)
+ }
}
}
\ No newline at end of file
diff --git a/pages/login/login.vue b/pages/login/login.vue
index c8433cc..1f7cc4f 100644
--- a/pages/login/login.vue
+++ b/pages/login/login.vue
@@ -316,6 +316,7 @@
//多店铺的时候点击选择需要登录的店铺
checkShop(item) {
let that = this;
+ console.log('item、有没有attrid1',item)
uni.getSystemInfo({
success: function (res1) {
that.NB.sendRequest('/auth/chooseShop', {
@@ -336,6 +337,7 @@
uni.setStorageSync('schoolShop',res.result.shop)
uni.setStorageSync('schoolShop',res.result.shop)
uni.setStorageSync('shopTakeaway',item.shopTakeaway)
+ uni.setStorageSync('attrId',item.shop.attrId)
uni.setStorageSync('area',JSON.stringify(item))
uni.setStorageSync("isShop",true)
setTimeout(() => {
diff --git a/pages/shop/addGoods.vue b/pages/shop/addGoods.vue
index ae56a7f..738e172 100644
--- a/pages/shop/addGoods.vue
+++ b/pages/shop/addGoods.vue
@@ -28,7 +28,6 @@
-
@@ -57,9 +56,9 @@
-
-
-
+
+
+ 删除
新增拼团
@@ -68,8 +67,8 @@
-
- {{value[0]}}:
+
+ {{value[0]}}(可选{{value[1].canbuy || 1}}个):
{{item}}、
@@ -126,16 +125,24 @@