Kaynağa Gözat

加入购物车

sharp-agezi 6 yıl önce
ebeveyn
işleme
b6b9c3e142

+ 2 - 1
app.json

@@ -97,7 +97,8 @@
         "pages/made/madeImg/madeImg",
         "pages/made/madeFont/madeFont",
         "pages/made/comb/comb",
-        "pages/canvas/canvas"
+        "pages/canvas/canvas",
+        "pages/made/car/car"
       ]
     }
   ],

+ 83 - 0
customized/pages/made/car/car.js

@@ -0,0 +1,83 @@
+// customized/pages/made/car/car.js
+let app = getApp();
+let host = app.globalData.servsers; // 请求的url
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    carList:[],// 购物车列表数组
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+    this.getCarlist(this)
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  },
+  getCarlist(that){
+    wx.request({
+      url: host +'/queryShopCar',
+      method:'post',
+      header: {
+        'content-type': 'application/x-www-form-urlencoded'
+      },
+      data:{
+        userId: app.globalData.user_id,
+      },
+      success:function(res){
+        console.log('购物车列表数据',res)
+      }
+    })
+  }
+})

+ 3 - 0
customized/pages/made/car/car.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 39 - 0
customized/pages/made/car/car.wxml

@@ -0,0 +1,39 @@
+<view>
+  <!-- 购物车列表 -->
+  <view class='car-box '>
+    <view  class='car-list  bg-white'>
+    <view class='f-box car-auto'>
+        <checkbox-group class="car-checkbox f-box f-align-items-center" bindchange="checkboxChange">
+          <label class="checkbox">
+            <checkbox checked="true" />
+          </label>
+        </checkbox-group>
+        <view class='f-item'>
+          <text>奶钢-黑色 350ml</text>
+          <view  class='f-box f-align-items-center' style='margin:20rpx 0;'>
+            <text class='f-item'>¥123.00</text>
+            <view class='car-numBtn f-box'>
+              <view bindtap='subtraction'>-</view>
+              <input value="1"/>
+              <view bindtap='add'>+</view>
+            </view>
+          </view>
+          <!-- 图片list -->
+          <view class='f-box car-img-list'>
+            <image src='https://dlz.info666.com/temp/8c44130a-6eb7-452a-bf67-0998c62977dc.png' mode="aspectFit"></image>
+            <image src='https://dlz.info666.com/temp/8c44130a-6eb7-452a-bf67-0998c62977dc.png' mode="aspectFit"></image>
+          </view>
+        </view>
+      </view>
+    </view>
+  </view>
+</view>
+
+<view class='footer bg-white'>
+  <view  class='car-footer'>
+    <view  class='car-auto f-box'>
+      <view class='f-item f-s30'>订单金额:¥123</view>
+      <view class='f-s32 f-item car-btn bg-orange c-white'>提交订单</view>
+    </view>
+  </view>
+</view>

+ 47 - 0
customized/pages/made/car/car.wxss

@@ -0,0 +1,47 @@
+/* customized/pages/made/car/car.wxss */
+.car-checkbox{
+  width:100rpx;
+}
+.car-auto{
+  margin:0 25rpx;
+}
+.car-img-list image{
+  width:140rpx;
+  height:140rpx;
+  margin:5rpx;
+}
+.car-list{
+  padding:20rpx;
+  margin:20rpx;
+}
+.car-numBtn{
+  width:244rpx;
+  border:2rpx solid #e0e0e0;
+  text-align: center;
+}
+.car-numBtn view, .car-numBtn input{
+  width:80rpx;
+  height:80rpx;
+}
+.car-numBtn view{
+  font-size:50rpx;
+}
+.car-numBtn input{
+  border-right:2rpx solid #e0e0e0;
+}
+.car-numBtn view:first-child{
+  border-right:2rpx solid #e0e0e0;
+}
+
+.footer{
+  position: fixed;
+  color:#333;
+  width:100%;
+  hieght:100%;
+  line-height:100rpx;
+  bottom:0;
+  left:0;
+}
+.car-btn{
+  text-align: center;
+}

+ 112 - 47
customized/pages/made/comb/comb.js

@@ -1,5 +1,7 @@
 // customized/pages/made/combination/combination.js
 import * as util from '../../../../utils/util.js'
+let app = getApp();
+let host = app.globalData.servsers; // 请求的url
 Page({
 
   /**
@@ -57,6 +59,7 @@ Page({
       '4':'底部',
     },
     buildSrcArray: [],
+    customGoodsImg:"",
 
   },
 
@@ -84,46 +87,42 @@ Page({
    */
   onReady: function () {
 
+    wx.showLoading({
+      title: '图片合成中...'
+    })
+    let that = this, result = true;
+    // for (let i = 1; i <= 4; i++) {
+    //   if (wx.getStorageSync('madeCupImgData' + i) || wx.getStorageSync('madeCupFontData' + i)) {
+    //     console.log(i, "iiiii")
+    //     that.getCombImg(that, i);
+    //   }
+    // }
+
+    if (wx.getStorageSync('madeCupImgData1') || wx.getStorageSync('madeCupFontData1')) {
+      that.getCombImg(that, 1);
+      result = false
+    } else if (wx.getStorageSync('madeCupImgData2') || wx.getStorageSync('madeCupFontData2')) {
+      that.getCombImg(that, 2);
+      result = false
+    } else if (wx.getStorageSync('madeCupImgData3') || wx.getStorageSync('madeCupFontData3')) {
+      that.getCombImg(that, 3);
+      result = false
+    } else if (wx.getStorageSync('madeCupImgData4') || wx.getStorageSync('madeCupFontData4')) {
+      that.getCombImg(that, 4);
+      result = false
+    }
 
+    if (result) {
+      wx.hideLoading();
+    }
   },
 
   /**
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
-    // this.getCombImg(this);
-    // if (this.buildSrcArray.length === 0){
-      wx.showLoading({
-        title: '图片合成中...'
-      })
-      let that = this,result = true;
-      // for (let i = 1; i <= 4; i++) {
-      //   if (wx.getStorageSync('madeCupImgData' + i) || wx.getStorageSync('madeCupFontData' + i)) {
-      //     console.log(i, "iiiii")
-      //     that.getCombImg(that, i);
-      //   }
-      // }
-      
-      if (wx.getStorageSync('madeCupImgData1') || wx.getStorageSync('madeCupFontData1')) {
-        that.getCombImg(that, 1);
-        result = false
-      } else if (wx.getStorageSync('madeCupImgData2') || wx.getStorageSync('madeCupFontData2')) {
-        that.getCombImg(that, 2);
-        result = false
-      } else if (wx.getStorageSync('madeCupImgData3') || wx.getStorageSync('madeCupFontData3')) {
-        that.getCombImg(that, 3);
-        result = false
-      }else if (wx.getStorageSync('madeCupImgData4') || wx.getStorageSync('madeCupFontData4')) {
-        that.getCombImg(that, 4);
-        result = false
-      }
   
-    if (result){
-      wx.hideLoading();
-    }
-    // }
-    
-
+  
   },
 
   /**
@@ -282,24 +281,27 @@ Page({
             wx.canvasToTempFilePath({
               canvasId: 'comb-canvas' + i,
               success: function (res) {
-                console.log(res, "合成成功");
-                let buildSrcArray = that.data.buildSrcArray;
+                that.uploadFile(res.tempFilePath,that,function(data){
+                  console.log(res, "合成成功");
+                  let buildSrcArray = that.data.buildSrcArray;
 
-                buildSrcArray.push({
-                  src:res.tempFilePath,
-                  isActive:i,
+                  buildSrcArray.push({
+                    src: res.tempFilePath,
+                    isActive: i,
                   });
-                console.log(buildSrcArray, "buildSrcArray")
-                that.setData({
-                  buildSrcArray: buildSrcArray
+                  console.log(buildSrcArray, "buildSrcArray")
+                  that.setData({
+                    buildSrcArray: buildSrcArray,
+                  })
+                  console.log(that.data.buildSrcArray, "buildSrcArray")
+                  if (i < 4) {
+                    i = i + 1
+                    that.getCombImg(that, i);
+                  } else {
+                    wx.hideLoading()
+                  }
                 })
-                console.log(that.data.buildSrcArray, "buildSrcArray")
-                if (i < 4) {
-                  i = i + 1
-                  that.getCombImg(that, i);
-                } else {
-                  wx.hideLoading()
-                }
+                
               },
               fail: function (err) {
                 console.log(err, "合成失败")
@@ -318,5 +320,68 @@ Page({
       }
     }
     
+  },
+  addImgRouter(){ // add car
+  let that = this;
+    console.log(that.data.customGoodsImg,"that.data.customGoodsImg")
+    
+    wx.request({
+      url: host + '/addShopCar',
+      method:'post',
+      header: {
+        'content-type': 'application/x-www-form-urlencoded'
+      },
+      data:{
+        customGoodsImg: that.data.customGoodsImg.substring(0, that.data.customGoodsImg.length-1),
+        customGoodsName:'奶缸-黑色 350ml',
+        customGoodsNum: 1,
+        userId: app.globalData.user_id,
+      },
+      success:function(res){
+        console.log(res,"加入购物车")
+        if(res.data ==='success'){
+          wx.showModal({
+            title: '提示',
+            content: '加入购物车成功,是否去购物车结算商品?',
+           
+            success:function(res){
+              if (res.confirm) {
+                console.log('用户点击确定')
+                wx.redirectTo({
+                  url: '/customized/pages/made/car/car',
+                })
+              } else if (res.cancel) {
+                console.log('用户点击取消')
+              }
+            }
+          })
+        }
+      }
+    })
+  },
+  uploadFile(path,that,cb){
+    let customGoodsImg = that.data.customGoodsImg;
+    wx.uploadFile({
+      url: host + 'fileUpload',
+      filePath: path,
+      name: 'file',
+      formData: {
+        file: path,
+        userId: app.globalData.user_id,
+        imgStatus: 1,// 表示合成
+      },
+      success: function (res) {
+        console.log(res, "rrrr");
+        customGoodsImg += res.data+',';
+        that.setData({
+          customGoodsImg: customGoodsImg
+        })
+        cb(true)
+      },
+      fail: function (res) {
+        cb(false)
+      }
+    })
   }
+
 })

+ 2 - 1
customized/pages/made/madeImg/madeImg.js

@@ -199,12 +199,13 @@ Page({
       success(res) {
         const tempFilePaths = res.tempFilePaths
         wx.uploadFile({
-          url: host + '/fileUpload', // 仅为示例,非真实的接口地址
+          url: host + 'fileUpload', // 仅为示例,非真实的接口地址
           filePath: tempFilePaths[0],
           name: 'file',
           formData: {
             file: tempFilePaths[0],
             userId: app.globalData.user_id,
+            imgStatus:0,// 表示素材
           },
           success(res) {
             console.log(res,'我上传完了')

+ 8 - 1
project.config.json

@@ -28,7 +28,7 @@
 			"list": []
 		},
 		"miniprogram": {
-			"current": 4,
+			"current": 6,
 			"list": [
 				{
 					"id": 0,
@@ -65,6 +65,13 @@
 					"name": "canvas",
 					"pathName": "customized/pages/canvas/canvas",
 					"query": ""
+				},
+				{
+					"id": 6,
+					"name": "car",
+					"pathName": "customized/pages/made/car/car",
+					"query": "",
+					"scene": null
 				}
 			]
 		}