wangxin 6 năm trước cách đây
mục cha
commit
25b03d7928

+ 4 - 0
app.wxss

@@ -12,4 +12,8 @@ page{
   border-radius: 50rpx;
   width: 420rpx;
   font-size: 35rpx;
+  height: 80rpx;
+  display: flex;
+  justify-content: center;
+  align-items: center;
 }

+ 8 - 0
components/cashdialog/index.js

@@ -18,6 +18,8 @@ Component({
   data: {
     // 弹窗显示控制
     isShow: false,
+    isHideErrMsg: true,
+    errMsg: '',
     cashCode: ''
   },
 
@@ -46,6 +48,12 @@ Component({
     getCashCode(){
       return this.data.cashCode;
     },
+    setErrMsg(isHide, _errMsg){
+      this.setData({
+        errMsg: _errMsg,
+        isHideErrMsg: isHide
+      })
+    },
     confirmEvent() {
       this.triggerEvent('customevent');
     }

+ 1 - 0
components/cashdialog/index.wxml

@@ -2,6 +2,7 @@
     <view class='dialog-mask' bindtap='hideDialog'></view>
     <view class='dialog-info'>
         <input class='dialog-content' placeholder-class='dialog-hint' placeholder='输入兑换码' type='text' bindinput ="cashCodeInput"></input>
+        <view class='dialog-errmsg' hidden='{{isHideErrmsg}}'>{{errMsg}}</view>
         <button class='dialog-footer' catchtap='confirmEvent'>{{confirmText}}</button>
     </view>
 </view>

+ 4 - 1
components/cashdialog/index.wxss

@@ -35,11 +35,14 @@
   border-top: 1rpx solid #E5E5E5;
   margin: 30rpx;
 }
+.dialog-errmsg {
+  color: #fc513f;
+}
 .dialog-footer{
     background: #539804;
     color: #fff;
     border-radius: 50rpx;
-    width: 200rpx;
+    width: 180rpx;
     font-size: 35rpx;
     margin-top: 60rpx;
     margin-bottom: 30rpx;

+ 16 - 5
template/carts/index.js

@@ -28,7 +28,12 @@ Page({
    */
   delOrder: function(e){
     var that = this;
-    var pid = e.currentTarget.dataset.id;
+    var pid;
+    if (e == null && arguments.length==2){
+      pid = arguments[1];
+    }else{
+      pid = e.currentTarget.dataset.id;
+    }
     var delfun = function(){
       that.dever.request('product.api.delCarts',{
         json: 1,
@@ -36,16 +41,16 @@ Page({
         product_id: pid
       },{
         success: function(data, res){
-          that.dever.alert('删除成功!');
+          that.dever.alert('删除商品成功!');
           that.onLoad();
         },
         fail: function(res){
-          that.dever.alert('删除失败!');
+          that.dever.alert('删除商品失败!');
         }
       });
     }
     wx.showModal({
-      content: '确认删除该订单吗?',
+      content: '确认删除该商品吗?',
       success: function(res){
         if (res.confirm){
           delfun();
@@ -62,7 +67,13 @@ Page({
     var list = this.data.list;
     for(var i=0; i<list.length; i++){
       if (list[i].product_id == id){
-        list[i].num = list[i].num-1<=0?1:list[i].num-1;
+        //list[i].num = list[i].num-1<=0?1:list[i].num-1;
+        if(list[i].num-1 <= 0){
+          list[i].num = 1;
+          this.delOrder(null, id);
+        }else{
+          list[i].num -= 1;
+        }
         break;
       }
     }

+ 2 - 3
template/carts/index.wxml

@@ -1,8 +1,5 @@
 <view class='top'>
   <view class='address' bindtap='chooseAddress'>
-    <!--<view>{{address}}</view>
-    <text class='tips'>填写收货地址</text>
-    <button class='nxh__button' bindtap='chooseAddress' >使用微信地址</button>-->
     <image class='left' src='/static/img/location2.png'></image>
     <view class='center' wx:if='{{isUseAddress}}'>
       <text>{{addrObj.userName}}</text>
@@ -14,7 +11,9 @@
     <!--兼容授权提醒-->
     <authdialog id='authdialog' title='授权提示' content='小程序需要您的授权才能提供更好的服务哦' confirmText='知道了'></authdialog>
   </view>
+
   <view class='address_line'></view>
+
   <view class='order' wx:for='{{list}}' wx:key='{{index}}' data-id='{{item.product.id}}' bindlongtap='delOrder'>
     <text class='title'>{{item.product.name}}</text>
     <view class='oper'>

+ 4 - 14
template/carts/index.wxss

@@ -2,7 +2,6 @@
   display: flex;
   flex-direction: column;
   justify-items: center;
-  text-align: center;
   margin-bottom: 100rpx;
 }
 .address {
@@ -12,10 +11,8 @@
   align-items: center;
 }
 .address_line {
-  height: 10rpx;
-  transform:skew(45deg);
-  margin: 0 15rpx 0 15rpx;
-  background: repeating-linear-gradient(to right, #f2f2f2 20rpx, #f0797c 60rpx, #6698fa 100rpx);
+  height: 15rpx;
+  background: #f2f2f2;
 }
 .address .left {
   width: 50rpx;
@@ -30,7 +27,8 @@
 .address .center text {
   display: flex;
   justify-content: left;
-  flex-wrap: wrap;
+  align-items: flex-start;
+  word-wrap: break-word;
 }
 .address .right{
   width: 50rpx;
@@ -46,14 +44,6 @@
   color: #707070;
   font-size: 35rpx;
 }
-/*.nxh__button {
-  background: #fff;
-  border:1rpx solid #539804;
-  color: #539804;
-  margin-top: 6rpx;
-  font-size: 30rpx;
-  width: 300rpx;
-}*/
 .order .split_line {
   margin:0 20rpx 0 30rpx;
   border-bottom: 1px solid #E5E5E5;

+ 2 - 5
template/cash/index.wxss

@@ -2,7 +2,6 @@
   display: flex;
   flex-direction: column;
   justify-items: center;
-  text-align: center;
   margin-bottom: 100rpx;
 }
 .address {
@@ -12,10 +11,8 @@
   align-items: center;
 }
 .address_line {
-  height: 10rpx;
-  transform:skew(45deg);
-  margin: 0 15rpx 0 15rpx;
-  background: repeating-linear-gradient(to right, #f2f2f2 20rpx, #f0797c 60rpx, #6698fa 100rpx);
+  height: 15rpx;
+  background: #f2f2f2;
 }
 .address .left {
   width: 50rpx;

+ 22 - 15
template/home/index.js

@@ -53,6 +53,7 @@ Page({
     var that = this;
     this.dever.isLogin(function (res) {
       if (res) {
+        that.cashdialog.setErrMsg(true, '');
         that.cashdialog.showDialog();
       } else {
         that.dever.location('login/index');
@@ -64,12 +65,27 @@ Page({
    * 跳转兑换页面
    */
   toCash: function(){
-    var code = this.cashdialog.getCashCode();
-    this.dever.log('toCash code', code);
-    if (code.length > 0) {
-      this.dever.location('cash/index?code=' + code);
+    var that = this;
+    var cashCode = this.cashdialog.getCashCode();
+
+    if (cashCode.length <= 0) {
+      that.cashdialog.setErrMsg(false, '请输入兑换码!');
+      return ;
     }
-    this.cashdialog.hideDialog();
+    that.dever.request('product.api.checkCode', {
+      json: 1,
+      signature: that.dever.getSignature(),
+      code: cashCode
+    }, {
+        success: function (data, res) {
+          that.cashdialog.hideDialog();
+          that.dever.location('cash/index?code=' + cashCode);
+        },
+        fail: function (res) {
+          that.dever.log('product.api.checkCode', res);
+          that.cashdialog.setErrMsg(false, res.data.msg);
+        }
+    });
   },
 
   /**
@@ -80,16 +96,7 @@ Page({
     var id = event.currentTarget.dataset.id;
     this.dever.isLogin(function(res){
       if(res){
-        that.dever.request('product.api.addCarts',{
-          json: 1,
-          signature: that.dever.getSignature(),
-          product_id: id,
-          num: 1
-        },{
-          success: function(data, res){
-            that.dever.location('carts/index?id=' + id);
-          }
-        });
+        that.dever.location('view/index?id=' + id);
       }else{
         that.dever.location('login/index');
       }

+ 1 - 1
template/home/index.wxml

@@ -4,7 +4,7 @@
         <view class="item_title">{{item.name}}</view>
         <view class="item_desc">
           <text class="price">¥ {{item.price}}</text>
-          <view class="button" catchtap='doBuy' data-id="{{item.id}}" data-name="{{item.name}}"><button class="nxh__button nxh__button2" size="mini">购买</button></view>
+          <button class="nxh__button nxh__button2" catchtap='doBuy' data-id="{{item.id}}" data-name="{{item.name}}">购买</button>
         </view>
     </view>
     <view class="item_null" wx:if='{{isShowNull}}'>

+ 9 - 8
template/home/index.wxss

@@ -1,5 +1,5 @@
 .page {
-  margin-bottom: 120rpx;
+  margin-bottom: 138rpx;
 }
 .page_item{
   border-radius: 5px;
@@ -22,11 +22,16 @@
   justify-content: space-between;
   padding: 0 30rpx 0 30rpx;
   align-items: center;
-  -ms-flex-item-align: center;
 }
 .item_desc .price {
   font-size:36rpx;
   color:#ff9900; 
+  display: flex;
+  flex-grow: 1;
+}
+.nxh__button2{
+  width: 180rpx;
+  margin-bottom: 25rpx;
 }
 .item_null {
   margin: 50rpx 30rpx 30rpx 30rpx;
@@ -52,18 +57,14 @@
 .item_null .right_line{
   background: linear-gradient(to left, #DBDBDB , #999);
 }
-
-.nxh__button2{
-  width: 180rpx;
-}
 .nxh__button3 {
   width: 300rpx;
 }
 .cash {
   position: fixed;
   bottom: 0rpx;
-  height: 120rpx;
-  width: 100%;
+  height: 138rpx;
+  width: 750rpx;
   background: #fff;
   display: flex;
   flex-direction: row;

+ 10 - 1
template/view/index.js

@@ -51,7 +51,16 @@ Page({
     var that = this;
     this.dever.isLogin(function (res) {
       if (res) {
-        that.dever.location('carts/index?id=' + that.product_id);
+        that.dever.request('product.api.addCarts', {
+          json: 1,
+          signature: that.dever.getSignature(),
+          product_id: that.product_id,
+          num: 1
+        }, {
+            success: function (data, res) {
+              that.dever.location('carts/index?id=' + that.product_id);
+            }
+          });
       } else {
         that.dever.location('login/index');
       }

+ 1 - 1
template/view/index.wxss

@@ -13,5 +13,5 @@
   justify-content: space-between;
 }
 .nxh__button {
-  width:280rpx;
+  width:300rpx;
 }