ソースを参照

添加商品图片

sharp-agezi 6 年 前
コミット
ec0addeb2a

+ 36 - 26
customized/pages/accounts/accounts.js

@@ -7,25 +7,25 @@ Page({
    * 页面的初始数据
    */
   data: {
-    goodsList:[],
+    goodsList: [],
     host: app.globalData.servsers,
-    amount:'',
-    address:{},// 地址为空
+    amount: '',
+    address: {}, // 地址为空
   },
 
-  onLoad(){
-    let that =this;
+  onLoad() {
+    let that = this;
     wx.request({
       url: host + '/adressapi/getdefaustAdress',
-      method:'get',
-      data:{
+      method: 'get',
+      data: {
         user_id: app.globalData.user_id
       },
       header: {
         'content-type': 'application/x-www-form-urlencoded'
       },
-      success(res){
-        console.log(res,"获取默认地址")
+      success(res) {
+        console.log(res, "获取默认地址")
         that.setData({
           address: res.data
         })
@@ -39,10 +39,11 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
-    let goodsList=[],that=this;
+    let goodsList = [],
+      that = this;
     let address = wx.getStorageSync('accountAddress');
-    console.log(address,"addressaddress")
-    if (address){
+    console.log(address, "addressaddress")
+    if (address) {
       that.setData({
         address: address
       })
@@ -89,13 +90,22 @@ Page({
   onShareAppMessage: function () {
 
   },
-  submitOrder(){
+  submitOrder() {
+    if (!this.data.address.consignee) {
+      wx.showToast({
+        title: '您还没有添加收货地址',
+        icon: 'none'
+      })
+      return;
+    }
     wx.showLoading({
-      title:'结算中...'
+      title: '结算中...'
     })
-    let that = this, goodsList = that.data.goodsList, address = that.data.address;
+    let that = this,
+      goodsList = that.data.goodsList,
+      address = that.data.address;
     //生成订单
-    goodsList.forEach(res=>{
+    goodsList.forEach(res => {
       res['userId'] = app.globalData.user_id; //'oovpNwjlsY6xx8ceCebFa1dOLd9E',
       res['adress'] = address.adress;
       res['area'] = address.area;
@@ -108,11 +118,11 @@ Page({
     });
     wx.request({
       url: host + '/createNewOrderCustomer',
-      method:'post',
+      method: 'post',
       data: {
-        shopCarList:JSON.stringify(goodsList)
+        shopCarList: JSON.stringify(goodsList)
       },
-      success(el){
+      success(el) {
         let res = el.data;
         console.log(res)
         wx.requestPayment({
@@ -121,9 +131,9 @@ Page({
           package: res.package,
           signType: res.signType,
           paySign: res.paySign,
-          success(res){
-            console.log(res,"结算结果")
-            if (res.errMsg === 'requestPayment:ok'){
+          success(res) {
+            console.log(res, "结算结果")
+            if (res.errMsg === 'requestPayment:ok') {
               // wx.showToast({
               //   title: '支付成功',
               // })
@@ -136,21 +146,21 @@ Page({
               })
             }
           },
-          fail(err){
+          fail(err) {
             wx.showToast({
               title: err.errMsg,
-              icon:'error'
+              icon: 'error'
             })
             console.log(err)
           },
-          complete(){
+          complete() {
             wx.hideLoading()
           }
         })
       }
     })
   },
-  addressBtn(){
+  addressBtn() {
     wx.navigateTo({
       url: '/customized/pages/address/address',
     })

+ 59 - 54
customized/pages/made/madeImg/madeImg.js

@@ -13,7 +13,7 @@ Page({
       left: 286,
       width: 270,
       height: 270,
-      
+
     },
     propSize: {
       top: '8cm',
@@ -21,30 +21,34 @@ Page({
       bottom: '8cm',
       left: '8cm',
     },
-    host:null,
+    host: null,
     obverseImgObject: {
-      '1': '/customized/images/customized/cup_black_big.png',/*正面 */
-      '2': '/customized/images/customized/cup_black_side.png',/*侧面面 */
-      '3': '/customized/images/customized/cup_black_handle.png',/*手柄 */
-      '4': '/customized/images/customized/cup_black_bottom.png',/*底部 */
+      '1': '/customized/images/customized/cup_black_big.png',
+      /*正面 */
+      '2': '/customized/images/customized/cup_black_side.png',
+      /*侧面面 */
+      '3': '/customized/images/customized/cup_black_handle.png',
+      /*手柄 */
+      '4': '/customized/images/customized/cup_black_bottom.png',
+      /*底部 */
     },
     fontContent: '可定制区域',
     madeImg: null, // 定制图 
     madeStatic: false, // 定制状态,表示是否已经定制了,false 表示没有定制
-    animationData: {},//旋转动画
-    imageArray:[],//请求数据后的图片列表
+    animationData: {}, //旋转动画
+    imageArray: [], //请求数据后的图片列表
     imageId: null, // 用户选中图片的id
-    imageSrc:null, // 选中图片后的路径
-    touch:{
+    imageSrc: null, // 选中图片后的路径
+    touch: {
       isActive: '1', // 1表示是正面
       src: null,
-      x:0,
-      y:0,
-      clientX:0,
-      clientY:0,
-      width:null, // 图片的宽度
-      height:null,
-      scale:1, // 图片宽高比例
+      x: 0,
+      y: 0,
+      clientX: 0,
+      clientY: 0,
+      width: null, // 图片的宽度
+      height: null,
+      scale: 1, // 图片宽高比例
       angle: 0, // 旋转度数
     }
   },
@@ -57,28 +61,28 @@ Page({
     that.animation = wx.createAnimation({
       timingFunction: 'step-start', // "linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end"
     })
-    if('id' in options){
+    if ('id' in options) {
       let cupNum = util.changeCup(options.id);
       let madeTouchImg = wx.getStorageSync('madeCupImgData' + options.id);
-      if (madeTouchImg){
+      if (madeTouchImg) {
         that.animation.rotate(madeTouchImg.angle).step();
         that.setData({
           touch: madeTouchImg,
           animationData: this.animation.export(),
           dataPositionObj: cupNum.dataPositionObj,
           propSize: cupNum.propSize,
-          madeStatic:true,
+          madeStatic: true,
         });
-      }else {
+      } else {
         that.setData({
           'touch.isActive': options.id,
           dataPositionObj: cupNum.dataPositionObj,
           propSize: cupNum.propSize
         });
       }
-      
 
-      
+
+
     }
   },
 
@@ -88,9 +92,9 @@ Page({
   onReady: function () {
     let that = this;
     that.setData({
-      host:host,
+      host: host,
     })
-    
+
   },
 
   /**
@@ -152,19 +156,19 @@ Page({
 
     // console.log(this.data.touch)
   },
-  imgDelete(){ // 图片删除
+  imgDelete() { // 图片删除
     let that = this;
     that.setData({
       'touch.src': null,
       madeStatic: false, // 表示已经有图片
     })
   },
-  imgEnlarge(e){
+  imgEnlarge(e) {
     let that = this;
-    console.log(e.detail.value,'eee')
+    console.log(e.detail.value, 'eee')
     that.setData({
       'touch.width': e.detail.value,
-      'touch.height': e.detail.value/that.data.touch.scale
+      'touch.height': e.detail.value / that.data.touch.scale
     })
   },
   imgRotate(e) { // 旋转
@@ -174,32 +178,33 @@ Page({
       'touch.angle': e.detail.value
     })
   },
-  getImgList(){ // 根据userid 获取图片列表
+  getImgList() { // 根据userid 获取图片列表
     // /queryCustomGoodsUserListByUserId
     wx.showLoading({
       title: '加载中...',
-      icon:'none'
+      icon: 'none'
     })
     let that = this
     wx.request({
-      url: host +'/queryCustomGoodsImg',
-      // data:{
-      //   userId: app.globalData.user_id,
-      // },
-      type:'get',
-      success(res){
-        console.log(res,'图片列表请求结束')
+      url: host + '/queryImgListByPlaceIdAndGoodsId',
+      data: {
+        customGoodsId: 1, // 商品id
+        customGoodsImgPlaceId: that.data.touch.isActive * 1 - 1
+      },
+      type: 'get',
+      success(res) {
+        console.log(res, '图片列表请求结束')
         that.setData({
-          imageArray:res.data
+          imageArray: res.data
         })
       },
-      complete(){
+      complete() {
         wx.hideLoading()
       }
     })
-   
+
   },
-  uploadImg(){
+  uploadImg() {
     console.log('点击上传图片');
     let that = this;
     wx.chooseImage({
@@ -212,27 +217,27 @@ Page({
           formData: {
             file: tempFilePaths[0],
             userId: app.globalData.user_id,
-            imgStatus:0,// 表示素材
+            imgStatus: 0, // 表示素材
           },
           success(res) {
-            console.log(res,'我上传完了')
+            console.log(res, '我上传完了')
             that.getImgList()
           }
         })
       }
     })
   },
-  selectImgBtn(e){
+  selectImgBtn(e) {
     console.log('选中图片', e.currentTarget.dataset.id);
     this.setData({
       imageId: e.currentTarget.dataset.id,
       imageSrc: e.currentTarget.dataset.src
     })
     // 'touch.src': e.currentTarget.dataset.src,
-      // madeStatic: true, // 表示已经有图片
+    // madeStatic: true, // 表示已经有图片
     // this.getScale(this, e.currentTarget.dataset.src);
   },
-  getScale(that,src){ // 获取图片的比例
+  getScale(that, src) { // 获取图片的比例
     wx.getImageInfo({
       src: src,
       success: function (res) {
@@ -246,9 +251,9 @@ Page({
       }
     })
   },
-  addImg(){ // 添加图片
+  addImg() { // 添加图片
     let that = this;
-    if (that.data.imageSrc){
+    if (that.data.imageSrc) {
       that.setData({
         'touch.src': that.data.imageSrc,
         madeStatic: true, // 表示已经有图片
@@ -261,10 +266,10 @@ Page({
       })
     }
   },
-  madeConfirm(){
+  madeConfirm() {
     // 确认设计
-    if (this.data.madeStatic){ // 设计完成存储数据
-      wx.setStorageSync('madeCupImgData'+this.data.touch.isActive, this.data.touch);
+    if (this.data.madeStatic) { // 设计完成存储数据
+      wx.setStorageSync('madeCupImgData' + this.data.touch.isActive, this.data.touch);
       wx.navigateBack()
       // wx.redirectTo({
       //   url: '/customized/pages/made/made?id=' + this.data.touch.isActive
@@ -272,8 +277,8 @@ Page({
     } else {
       wx.showToast({
         title: '您还没有选择图片进行设计',
-        icon:'none'
+        icon: 'none'
       })
-    } 
+    }
   }
 })

+ 51 - 0
customized/pages/order/order.js

@@ -120,5 +120,56 @@ Page({
         wx.hideLoading()
       }
     })
+  },
+  orderPay(e){ // 订单付款
+    console.log(e);
+    let item = e.currentTarget.dataset.item;//列表数据
+    wx.request({
+      url: host +'/weChatPay',
+      method: 'post',
+      header: {
+        'content-type': 'application/x-www-form-urlencoded'
+      },
+      data:{
+        orderCustomId: item.orderCustomId,
+        openId: app.globalData.openid,
+      },
+      success(el){
+        let res = el.data;
+        console.log(res)
+        wx.requestPayment({
+          timeStamp: res.timeStamp,
+          nonceStr: res.nonceStr,
+          package: res.package,
+          signType: res.signType,
+          paySign: res.paySign,
+          success(res) {
+            console.log(res, "结算结果")
+            if (res.errMsg === 'requestPayment:ok') {
+              // wx.showToast({
+              //   title: '支付成功',
+              // })
+              wx.redirectTo({
+                url: '/customized/pages/result/result?state=true',
+              })
+            } else {
+              wx.redirectTo({
+                url: '/customized/pages/result/result?state=false',
+              })
+            }
+          },
+          fail(err) {
+            wx.showToast({
+              title: err.errMsg,
+              icon: 'error'
+            })
+            console.log(err)
+          },
+          complete() {
+            wx.hideLoading()
+          }
+        })
+      }
+    })
   }
 })

+ 1 - 1
customized/pages/order/order.wxml

@@ -13,7 +13,7 @@
     </view>
     <!-- 操作按钮 -->
     <view class='f-box f-justify-content-end pad-t20 pad-b20 f-s30'>
-      <view class='order-btn bg-orange' wx:if="{{item.orderStatus === '0'}}">立即付款</view>
+      <view class='order-btn bg-orange' wx:if="{{item.orderStatus === '0'}}" data-item="{{item}}" bindtap='orderPay'>立即付款</view>
       <!-- <view class='order-btn bg-orange' wx:if="{{item.orderStatus === '3'}}">查看物流</view> -->
       <!-- <view class='order-btn bg-green' wx:if="{{item.orderStatus === '3'}}">确认收货</view> -->
     </view>