wangxin 6 년 전
부모
커밋
239552ce87

+ 62 - 0
components/cashdialog/index.js

@@ -0,0 +1,62 @@
+Component({
+  options: {
+    multipleSlots: true // 在组件定义时的选项中启用多slot支持
+  },
+  /**
+   * 组件的属性列表
+   */
+  properties: {
+    // 弹窗标题
+    title: {
+      type: String,
+      value: '标题' // 默认值
+    },
+    // 弹窗内容
+    content: {
+      type: String,
+      value: '弹窗内容'
+    },
+
+    // 弹窗确认按钮文字
+    confirmText: {
+      type: String,
+      value: '确定'
+    }
+  },
+
+  /**
+   * 组件内私有数据
+   */
+  data: {
+    // 弹窗显示控制
+    isShow: false,
+    isError: false,
+    errmsg: '兑换码不正确!'
+  },
+
+  /**
+   * 组件的公有方法列表
+   */
+  methods: {
+
+    //隐藏弹框
+    hideDialog() {
+      this.setData({
+        isShow: !this.data.isShow
+      })
+    },
+    //展示弹框
+    showDialog() {
+      this.setData({
+        isShow: !this.data.isShow
+      })
+    },
+    cancel(){
+      this.hideDialog();
+    },
+    confirmEvent() {
+      this.hideDialog();
+    }
+
+  }
+})

+ 4 - 0
components/cashdialog/index.json

@@ -0,0 +1,4 @@
+{
+  "component": true,
+  "usingComponents": {}
+}

+ 8 - 0
components/cashdialog/index.wxml

@@ -0,0 +1,8 @@
+<view class='dialog-container' hidden="{{!isShow}}">
+    <view class='dialog-mask' bindtap='cancel'></view>
+    <view class='dialog-info'>
+        <input class='dialog-content' placeholder-class='dialog-hint' placeholder='输入兑换码' type='text'></input>
+        <text class='dialog-errmsg' hidden='{{isError}}'>{{errmsg}}</text>
+        <button class='dialog-footer' catchtap='confirmEvent'>兑换</button>
+    </view>
+</view>

+ 50 - 0
components/cashdialog/index.wxss

@@ -0,0 +1,50 @@
+.dialog-mask{
+  position: fixed;
+    z-index: 1000;
+    top: 0;
+    right: 0;
+    left: 0;
+    bottom: 0;
+    background: rgba(0, 0, 0, 0.3);
+}
+.dialog-info{
+    position: fixed;
+    z-index: 5000;
+    width: 90%;
+    max-width: 600rpx;
+    top: 50%;
+    left: 50%;
+    -webkit-transform: translate(-50%, -50%);
+    transform: translate(-50%, -50%);
+    background-color: #FFFFFF;
+    text-align: center;
+    border-radius: 3px;
+    overflow: hidden;
+    padding: 90rpx 0 30rpx;
+}
+.dialog-hint{
+    font-size: 50rpx;
+    color: #707070;
+}
+.dialog-content{
+  height: 100rpx;
+  padding: 30rpx;
+  font-size: 50rpx;
+  color: #333;
+  border-bottom: 1rpx solid #E5E5E5;
+  border-top: 1rpx solid #E5E5E5;
+  margin: 30rpx;
+}
+.dialog-errmsg {
+  color: #ff0000;
+  font-size: 35rpx;
+}
+.dialog-footer{
+    background: #539804;
+    color: #fff;
+    border-radius: 50rpx;
+    width: 200rpx;
+    font-size: 35rpx;
+    margin-top: 60rpx;
+    margin-bottom: 30rpx;
+}

+ 15 - 0
dever/core.js

@@ -48,6 +48,11 @@ var dever =
       return this.getSave('applet.bind');
     }
 
+    //获取登录签名串儿
+    ,getSignature: function(){
+      return this.getLoginInfo() != null ? this.getLoginInfo().signature : '';
+    }
+
     //设置服务器传过来的公共值
     ,setSetting : function(value)
     {
@@ -134,6 +139,16 @@ var dever =
         })
     }
 
+    /**
+     * 重定向页面
+     */
+    ,redirect: function(url){
+      this.log('redirect', url);
+      wx.redirectTo({
+        url: '../../template/' + url,
+      })
+    }
+
     //回退 delta 返回的页面数,如果 delta 大于现有页面数,则返回到首页。
     ,goBack: function(delta){
       if(typeof delta != 'number') delta = 1;

+ 84 - 20
template/carts/index.js

@@ -1,26 +1,25 @@
-// template/carts/index.js
 Page({
   dever: getApp().dever,
   authdialog: null,
+  product_ids: '',
+  product_num: '',
   data: {
-    isUseAddress: false
+    isUseAddress: false,
+    settlement: 0.00
   },
   onLoad: function (options) {
+    var that = this;
+    
     //获取自定义授权组件
-    this.authdialog = this.selectComponent("#authdialog");
-
-    //test - begin
-    var list = new Array();
-    for(var i=1; i<=10; i++){
-      var item = new Object();
-      item.name = i+'盒有机韭菜';
-      item.price = i*20;
-      item.id = i;
-      item.num = 1;
-      list.push(item);
-    }
-    this.dever.setList(this, list);
-    //test - end
+    that.authdialog = this.selectComponent("#authdialog");
+    that.dever.request('product.api.carts',{
+      signature: that.dever.getSignature()
+    },{
+      success: function(data, res){
+        that.dever.setList(that, data.carts);
+        that.doSettlement();
+      }
+    });
   },
 
   /**
@@ -28,11 +27,27 @@ Page({
    */
   delOrder: function(e){
     var that = this;
+    var pid = e.currentTarget.dataset.id;
+    var delfun = function(){
+      that.dever.request('product.api.delCarts',{
+        json: 1,
+        signature: that.dever.getSignature(),
+        product_id: pid
+      },{
+        success: function(data, res){
+          that.dever.alert('删除成功!');
+          that.onLoad();
+        },
+        fail: function(res){
+          that.dever.alert('删除失败!');
+        }
+      });
+    }
     wx.showModal({
       content: '确认删除该订单吗?',
       success: function(res){
         if (res.confirm){
-          that.dever.alert('删除订单失败!');
+          delfun();
         }
       }
     })
@@ -45,12 +60,13 @@ Page({
     var id = e.currentTarget.dataset.id;
     var list = this.data.list;
     for(var i=0; i<list.length; i++){
-      if (list[i].id == id){
+      if (list[i].product_id == id){
         list[i].num = list[i].num-1<=0?1:list[i].num-1;
         break;
       }
     }
     this.dever.setList(this, list);
+    this.doSettlement();
   },
   /**
    * 增加商品数量>1 and <=库存
@@ -59,12 +75,60 @@ Page({
     var id = e.currentTarget.dataset.id;
     var list = this.data.list;
     for (var i = 0; i < list.length; i++) {
-      if (list[i].id == id) {
-        list[i].num = list[i].num + 1;
+      if (list[i].product_id == id) {
+        ++list[i].num;
         break;
       }
     }
     this.dever.setList(this, list);
+    this.doSettlement();
+  },
+
+  /**
+   * 结算金额
+   */
+  doSettlement: function(){
+    var list = this.data.list;
+    var count=0;
+    for(var i=0; i<list.length; i++){
+      var product_id = list[i].product_id;
+      var pay_price = list[i].product.pay_price;
+      var num = list[i].num;
+      count += pay_price*num;
+      if(i==0){
+        this.product_ids += product_id;
+        this.product_num += num;
+      }else{
+        this.product_ids += ',' + product_id;
+        this.product_num += ',' + num;
+      }
+    }
+    this.dever.set(this, 'settlement', count.toFixed(2));
+  },
+
+  /**
+   * 去支付
+   */
+  doPay: function(e){
+    var that = this;
+    var addrObj = that.data.addrObj;
+    that.dever.request('product.api.buy',{
+      signature: that.dever.getSignature(),
+      product_id: that.product_ids,
+      num: that.product_num,
+      name: addrObj.userName,
+      address: addrObj.provinceName + addrObj.cityName + addrObj.countyName + addrObj.detailInfo,
+      mobile: addrObj.telNumber
+    },{
+      success:function(data, res){
+        that.dever.redirect('pay/index');
+        that.dever.log('doPay success', res);
+      },
+      fail: function(res){
+        that.dever.alert('支付失败!');
+        that.dever.log('doPay fail', res);
+      }
+    });
   },
 
   /**

+ 9 - 12
template/carts/index.wxml

@@ -12,26 +12,23 @@
     <view class='tips' wx:else><text>使用微信地址</text></view>
     <image class='right' src='/static/img/item-right.png'></image>
     <!--兼容授权提醒-->
-    <authdialog id='authdialog' 
-      title='授权提示' 
-      content='小程序需要您的授权才能提供更好的服务哦'
-      confirmText='知道了'>
-    </authdialog>
+    <authdialog id='authdialog' title='授权提示' content='小程序需要您的授权才能提供更好的服务哦' confirmText='知道了'></authdialog>
   </view>
-  <view class='order' wx:for='{{list}}' wx:key='{{index}}' bindlongtap='delOrder'>
-    <text class='title'>{{item.name}}</text>
+  <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'>
-      <text class='price'>¥ {{item.price}}</text>
+      <text class='price'>¥ {{item.product.price}}</text>
       <view class='edit-num'>
-        <image class='sub' src='/static/img/carts-sub.png' data-id='{{item.id}}' bindtap='doSub'></image>
+        <image class='sub' src='/static/img/carts-sub.png' data-id='{{item.product.id}}' bindtap='doSub'></image>
         <view class='num'>{{item.num}}</view>
-        <image class='add' src='/static/img/carts-add.png' data-id='{{item.id}}' bindtap='doAdd'></image>
+        <image class='add' src='/static/img/carts-add.png' data-id='{{item.product.id}}' bindtap='doAdd'></image>
       </view>
     </view>
     <view class='split_line'/>
   </view>
 </view>
 <view class='bottom'>
-  <view class='left'>合计 ¥297 元</view>
-  <view class='right'>立即支付</view>
+  <view class='left'>合计 ¥{{settlement}} 元</view>
+  <view class='right' bindtap='doPay'>立即支付</view>
 </view>

+ 6 - 1
template/carts/index.wxss

@@ -7,11 +7,16 @@
 }
 .address {
   padding: 40rpx 50rpx 30rpx 50rpx;
-  border-bottom: 5px solid #FBFBFB;
   display: flex;
   flex-direction: row;
   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);
+}
 .address .left {
   width: 50rpx;
   height: 50rpx;

+ 31 - 9
template/home/index.js

@@ -1,25 +1,31 @@
 Page({
   dever: getApp().dever,
+  cashdialog: null,
   pg: 1,
   data: {
-      
+    isShowNull: false
   },
   onLoad: function (options) {
     var that = this;
-    var sign = that.dever.getLoginInfo() != null ? that.dever.getLoginInfo().signature : '';
+    that.cashdialog = this.selectComponent("#cashdialog");
+    that.dever.set(that, 'loadMoreText', '正在加载');
     that.dever.request('product.api.home', {
       json: 1,
       pg: that.pg,
-      signature: sign
+      signature: that.dever.getSignature()
     },{
         success: function (data, res) {
-          if(that.pg > 1){
-            that.dever.appendList(that, data.product);
+          if (data.product.length > 0){
+            if(that.pg > 1){
+              that.dever.appendList(that, data.product);
+            }else{
+              that.dever.setList(that, data.product);
+            }
+            that.pg++;
+            that.dever.set(that, 'isShowNull', false);
           }else{
-            that.dever.setList(that, data.product);
+            that.dever.set(that, 'isShowNull', true);
           }
-          that.dever.stopPullDown();
-          that.pg++;
         }
     });
   },
@@ -36,6 +42,13 @@ Page({
     this.dever.location('view/index?id=' + id);
   },
 
+  /**
+   * 礼品卡兑换
+   */
+  cash: function(e){
+    this.cashdialog.showDialog();
+  },
+
   /**
    * 添加购物车
    */
@@ -44,7 +57,16 @@ Page({
     var id = event.currentTarget.dataset.id;
     this.dever.isLogin(function(res){
       if(res){
-        that.dever.location('carts/index?id=' + id);
+        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);
+          }
+        });
       }else{
         that.dever.location('login/index');
       }

+ 4 - 1
template/home/index.json

@@ -1,4 +1,7 @@
 {
   "navigationBarTitleText": "农小盒",
-  "enablePullDownRefresh": true
+  "enablePullDownRefresh": true,
+  "usingComponents": {
+    "cashdialog": "/components/cashdialog/index"
+  }
 }

+ 15 - 6
template/home/index.wxml

@@ -1,14 +1,23 @@
 <view class="page">
-    <view class="page__hd" wx:for="{{list}}" wx:key="{{index}}" bindtap="view" data-id="{{item.id}}">
-        <image class="pic" src="{{item.pic}}" mode="widthFix"></image>
-        <view class="page__title">{{item.name}}</view>
-        <view class="page__desc">
+    <view class="page_item" wx:for="{{list}}" wx:key="{{index}}" bindtap="view" data-id="{{item.id}}">
+        <image class="item_pic" src="{{item.pic}}" mode="widthFix"></image>
+        <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>
         </view>
     </view>
+    <view class="item_null" wx:if='{{isShowNull}}'>
+      <view class='left_line' />
+      <text class='text'>已经到底啦~^_^~</text>
+      <view class='right_line' />
+    </view>
     <view class='cash'>
       <button class='nxh__button nxh__button3' open-type="contact">在线客服</button>
-      <button class='nxh__button nxh__button3'>礼品卡兑换</button>
+      <button class='nxh__button nxh__button3' bindtap='cash'>礼品卡兑换</button>
     </view>
-</view>
+</view>
+
+<!-- 礼品卡兑换弹框 -->
+<cashdialog id='cashdialog' confirmText='知道了'>
+</cashdialog>

+ 32 - 12
template/home/index.wxss

@@ -1,25 +1,22 @@
 .page {
-  padding-bottom: 30rpx;
+  margin-bottom: 120rpx;
 }
-.page__hd
-{
+.page_item{
   border-radius: 5px;
   box-shadow: 0rpx 3rpx 5rpx #DBDBDB;
-  margin: 30rpx 30rpx 120rpx 30rpx;
+  margin: 30rpx;
   padding: 0rpx;
   overflow: hidden;
 }
-.pic
-{
+.item_pic{
   border-top-right-radius: 5px;
   border-top-left-radius: 5px;
   width:695rpx;
 }
-.page__title {
+.item_title {
   padding: 0 30rpx 0 30rpx;
 }
-.page__desc 
-{
+.item_desc {
   display: flex;
   flex-direction: row;
   justify-content: space-between;
@@ -27,11 +24,34 @@
   align-items: center;
   -ms-flex-item-align: center;
 }
-.price
-{
+.item_desc .price {
   font-size:36rpx;
   color:#ff9900; 
 }
+.item_null {
+  margin: 50rpx 30rpx 30rpx 30rpx;
+  padding: 0rpx;
+  height: 60rpx;
+  display: flex;
+  flex-direction: row;
+  align-items: center;
+  justify-content: center;
+}
+.item_null .text {
+  color: #707070;
+  margin: 0 20rpx 0 20rpx;
+  font-size: 35rpx;
+}
+.item_null .left_line, .right_line{
+  width: 120rpx;
+  height: 1rpx;
+}
+.item_null .left_line{
+  background: linear-gradient(to right, #DBDBDB , #999);
+}
+.item_null .right_line{
+  background: linear-gradient(to left, #DBDBDB , #999);
+}
 
 .nxh__button2{
   width: 180rpx;
@@ -49,4 +69,4 @@
   flex-direction: row;
   justify-content: space-around;
   align-items: center;
-}
+}

+ 9 - 3
template/pay/index.js

@@ -1,11 +1,17 @@
 Page({
-
+  dever: getApp().dever,
   data: {
     
   },
 
   onLoad: function (options) {
-    
+    //that.dever.getSignature()
+  },
+
+  /**
+   * 跳转海报分享页面,分享海报
+   */
+  toShare: function(){
+    this.dever.location('poster/index');
   }
-  
 })

+ 1 - 1
template/pay/index.wxml

@@ -1,4 +1,4 @@
 <image class='pay-ok' src='/static/img/ok.png'></image>
 <view class='pay-result-h1'>下单成功</view>
 <view class='pay-result-h2'>您的订单已经支付成功,马上为您发货!</view>
-<button class='share-friends nxh__button'>分享给朋友</button>
+<button class='share-friends nxh__button' bindtap='toShare'>分享给朋友</button>

+ 38 - 43
template/poster/index.js

@@ -1,65 +1,60 @@
 Page({
-
+  dever: getApp().dever,
   /**
    * 页面的初始数据
    */
   data: {
-    
+    imgUrl: ''
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    
-  },
-
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady: function () {
-    
-  },
-
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow: function () {
-    
-  },
-
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide: function () {
-    
-  },
-
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload: function () {
-    
-  },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh: function () {
-    
+    var that = this;
+    that.dever.request('product.api.poster',{
+      signature: that.dever.getSignature(),
+      path: '/template/view/index'
+    },{
+      success: function(data, res){
+        that.dever.set(that, 'imgUrl', data.pic);
+      }
+    });
   },
 
   /**
-   * 页面上拉触底事件的处理函数
+   * 保存好报分享到朋友圈
    */
-  onReachBottom: function () {
-    
+  savePoster: function(imgUrl){
+    var that = this;
+    wx.getImageInfo({
+      src: imgUrl,
+      success: function (sres){
+        that.dever.log('wx.getImageInfo', sres.path);
+        wx.saveImageToPhotosAlbum({
+          filePath: sres.path,
+          success: function (fres){
+            that.dever.log('wx.saveImageToPhotosAlbum', fres);
+          }
+        })
+      }
+    })
   },
 
   /**
    * 用户点击右上角分享
    */
-  onShareAppMessage: function () {
-    
+  onShareAppMessage: function (options) {
+    var that = this;
+    wx.showShareMenu({
+      withShareTicket: true,
+      success: function (res) {
+        that.dever.log('wx.showShareMenu success', res.data);
+      },
+      fail: function (res) {
+        that.dever.log('wx.showShareMenu fail', res.data);
+      }
+    }) ;
+    //options.from可以用来判断是从自定义button打开的转发页面,还是从右上角的打开的转发页面。
   }
 })

+ 3 - 3
template/poster/index.wxml

@@ -1,7 +1,7 @@
 <view class='content'>
-  <image mode='widthFix' src='/static/img/item-1.png'></image>
+  <image mode='widthFix' src='{{imgUrl}}'></image>
 </view>
 <view class='bottom'>
-  <button class='nxh__button nxh__button2'>保存海报分享朋友圈</button>
-  <button class='nxh__button'>转发分享给朋友</button>
+  <button class='nxh__button nxh__button2' bindtap='savePoster'>保存海报分享朋友圈</button>
+  <button class='nxh__button' open-type='share'>转发分享给朋友</button>
 </view>

+ 17 - 29
template/view/index.js

@@ -1,22 +1,25 @@
 Page({
   dever: getApp().dever,
-  product: null,
+  product_id: '',
   data: {
-    content: "",
-    product_id: ''
+    content: ''
   },
 
   onLoad: function (options) {
     var that = this;
-    that.setData({
-      id: options.id 
-    });
+    if(typeof options.scene == 'undefined'){
+      that.product_id = options.id;
+    }else{
+      var scene = decodeURIComponent(options.scene);
+      scene = scene.split(','); 
+      //var uid = scene[0]; 
+      that.product_id = scene[1];
+    }
     that.dever.request('product.api.view',{
-      signature: '',
-      id: options.id
+      signature: that.dever.getSignature(),
+      id: that.product_id
     }, {
         success: function (data, res) {
-          that.product = data.product;
           var temp = that.dever.html('content', data.product.content, that);
           that.setData({
             content: temp
@@ -26,35 +29,20 @@ Page({
   },
 
   /**
-   * 分享
+   * 跳转海报分享页面,分享海报
    */
-  onShareAppMessage: function (options){
-    wx.showShareMenu({
-      withShareTicket: true,
-      success: function(res){
-        //TODO 
-      },
-      fail: function(res){
-        //TODO 
-      }
-    })  
-    //options.from可以用来判断是从自定义button打开的转发页面,还是从右上角的打开的转发页面。
+  toShare: function(){
+    this.dever.location('poster/index');
   },
 
   /**
    * 立即购买
    */
-  doBuy: function(event){
+  doBuy: function(e){
     var that = this;
-    var id;
-    if (typeof (event) == 'object') {
-      id = event.currentTarget.dataset.id
-    } else {
-      id = event
-    }
     this.dever.isLogin(function (res) {
       if (res) {
-        that.dever.location('carts/index?id=' + id);
+        that.dever.location('carts/index?id=' + that.product_id);
       } else {
         that.dever.location('login/index');
       }

+ 2 - 2
template/view/index.wxml

@@ -6,6 +6,6 @@
   <template is="wxParse" data="{{wxParseData:content.nodes}}"/>
 </view>
 <view class='bottom'>
-  <button class='nxh__button' open-type='share'>分享给好友</button>
-  <button class='nxh__button' bindtap='doBuy' data-id="{{product_id}}">立即购买</button>
+  <button class='nxh__button' bindtap='toShare'>分享给好友</button>
+  <button class='nxh__button' bindtap='doBuy'>立即购买</button>
 </view>