绿满眶商城微信小程序-uniapp
peng
2025-10-13 3a2524692711cf35fc142881b2837368ae2c3d25
定制商品
5个文件已修改
88 ■■■■■ 已修改文件
api/order.js 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages.json 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/order/myOrder.vue 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/order/orderDetail.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/product/m-buy/goods.vue 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/order.js
@@ -82,6 +82,17 @@
  });
}
/**
 * 获取订单定制信息
 * @param orderSn 订单编号
 */
export function getOrderCustomize(orderSn) {
  return http.request({
    url: `/order/order/customize/${orderSn}`,
    method: Method.GET,
    needToken: true,
  });
}
/**
 * 获取订单详情
 * @param orderSn 订单编号
 */
pages.json
@@ -1865,6 +1865,13 @@
                  "u-empty": "view"
                }
            }
        },
        {
            "path" : "constomize/constomize",
            "style" :
            {
                "navigationBarTitleText" : "定制信息"
            }
        }
      ]
    },
pages/order/myOrder.vue
@@ -172,7 +172,7 @@
                    shape="circle"
                    class="cancel-btn"
                    size="mini"
                    v-if="order.orderStatus === 'COMPLETED'&& order.orderType !=='VIRTUAL'"
                    v-if="order.orderStatus === 'COMPLETED'&& order.orderType !=='VIRTUAL'&& order.customizeFlag !=='CUSTOMIZE'"
                    @click="buyBack(order)"
                  >
                    再来一单
@@ -470,7 +470,7 @@
      opencustomize(order){
          console.log(order)
              uni.navigateTo({
                  url:"/pages/order/cardPack?sn=" + order.sn
                  url:"/pages/order/constomize/constomize?sn=" + order.sn
              })  
      },
      //再来一单
pages/order/orderDetail.vue
@@ -149,7 +149,7 @@
            @click="ByUserMessage(order)">查看拼团信息</view>
            <view class="customer-service"
            @click="contact(order.storeId)">联系客服</view>
            <view class="customer-service" v-if="order.orderStatus==='COMPLETED' && order.orderType !=='VIRTUAL'"
            <view class="customer-service" v-if="order.orderStatus==='COMPLETED' && order.orderType !=='VIRTUAL'&& order.customizeFlag !=='CUSTOMIZE'"
            @click="buyBack"
            >再来一单</view>
        </view>
pages/product/m-buy/goods.vue
@@ -604,6 +604,10 @@
            this.formValues.templateId = this.consumizetemplateInfo.id;
            this.formValues.templateName = this.consumizetemplateInfo.name;
            
            // 查找对应的模板字段以获取contentType
            const templateItem = this.consumizetemplateInfo.templateConstomizeTitles.find(item => item.id === fieldId);
            const contentType = templateItem ? templateItem.contentType : '';
            // 查找是否已存在该字段
            const existingIndex = this.formValues.templateForm.findIndex(item => item.id === fieldId);
            
@@ -612,6 +616,7 @@
                this.$set(this.formValues.templateForm, existingIndex, {
                    id: fieldId,
                    templateTitle: templateTitle,
                    contentType: contentType, // 添加contentType
                    value: value
                });
            } else {
@@ -619,6 +624,7 @@
                this.formValues.templateForm.push({
                    id: fieldId,
                    templateTitle: templateTitle,
                    contentType: contentType, // 添加contentType
                    value: value
                });
            }
@@ -736,6 +742,14 @@
         * 添加到购物车或购买
         */
        addToCartOrBuy(val) {
            // 检查商品是否需要模板并且模板数据是否完整
            if (this.consumizetemplateInfo && this.consumizetemplateInfo.id) {
                const isValid = this.validateTemplateData();
                if (!isValid) {
                    return;
                }
            }
            console.log(JSON.stringify(this.formValues))
            if (!this.selectSkuList) {
                // 使用setTimeout延迟显示提示,避免影响弹窗
@@ -795,6 +809,56 @@
                });
            }
        },
        /**
         * 验证模板数据是否完整
         */
        validateTemplateData() {
            // 检查模板图片是否已选择(如果有模板图片)
            if (this.consumizetemplateInfo.templateImgs &&
                this.consumizetemplateInfo.templateImgs.length > 0 &&
                this.selectedImageObjects.length === 0) {
                setTimeout(() => {
                    uni.showToast({
                        title: '请选择模板图片',
                        icon: 'none'
                    });
                }, 100);
                return false;
            }
            // 检查动态表单项是否已填写
            if (this.consumizetemplateInfo.templateConstomizeTitles) {
                for (const item of this.consumizetemplateInfo.templateConstomizeTitles) {
                    const formItem = this.formValues.templateForm.find(formItem => formItem.id === item.id);
                    // 如果表单项不存在或者值为空
                    if (!formItem || !formItem.value || formItem.value.trim() === '') {
                        setTimeout(() => {
                            uni.showToast({
                                title: `请填写${item.templateTitle}`,
                                icon: 'none'
                            });
                        }, 100);
                        return false;
                    }
                    // 特别检查图片类型的表单项是否有上传
                    if (item.contentType === 'IMAGE' &&
                        (!this.imagePreviewUrls[item.id] || this.imagePreviewUrls[item.id].trim() === '')) {
                        setTimeout(() => {
                            uni.showToast({
                                title: `请上传${item.templateTitle}`,
                                icon: 'none'
                            });
                        }, 100);
                        return false;
                    }
                }
            }
            return true;
        },
        formatSku(list) {
            // 格式化数据
            let arr = [{}];