Przeglądaj źródła

Merge branch 'master' of https://gitee.com/huangg/panda_beauty_makeup_small_program

* 'master' of https://gitee.com/huangg/panda_beauty_makeup_small_program:
  address
  address
huanggang 7 lat temu
rodzic
commit
8b636cc4a1

+ 212 - 35
pages/addAddress/addAddress.js

@@ -1,21 +1,4 @@
 // pages/addAddress/addAddress.js
-const date = new Date()
-const years = []
-const months = []
-const days = []
-
-for (let i = 1990; i <= date.getFullYear(); i++) {
-  years.push(i)
-}
-
-for (let i = 1; i <= 12; i++) {
-  months.push(i)
-}
-
-for (let i = 1; i <= 31; i++) {
-  days.push(i)
-}
-
 const getReq = require('./../../config.js').getReq
 
 Page({
@@ -26,42 +9,236 @@ Page({
   data: {
     checked: true,
     areas: [],
-    region: [],
-    years: years,
-    year: date.getFullYear(),
-    months: months,
-    month: 2,
-    days: days,
-    day: 2,
-    value: [9999, 1, 1]
+    tree: [],
+    value: [0, 0, 0],
+    oldval: [0, 0, 0],
+    citys: [],
+    districts: [],
+    animation_flag: false,
+    province: '',
+    city: '',
+    district: '',
+    name: '',
+    mob_phone: '',
+    address: ''
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-
+    this.getDatas()
   },
   toggleChecked() {
     this.setData({
       checked: !this.data.checked
     })
   },
-  bindRegionChange: function (e) {
-    // console.log('picker发送选择改变,携带值为', e.detail.value)
+  bindChange: function (e) {
+    const val = e.detail.value
+    if (this.data.oldval[0] != val[0]) {
+      val[1] = 0
+      val[2] = 0
+    } else {    //若省份column未做滑动,地级市做了滑动则定位区县第一位
+      if (this.data.oldval[1] != val[1]) {
+        val[2] = 0
+      }
+    }
     this.setData({
-      region: e.detail.value
+      value: val,
+      citys: this.data.tree[val[0]].children,
+      districts: this.data.tree[val[0]].children[val[1]].children
     })
   },
-  bindChange: function (e) {
-    const val = e.detail.value
+  getDatas() {
+    wx.showLoading({
+      title: '加载中',
+    })
+    var self = this
+    getReq({
+      act: 'app_update',
+      op: 'area',
+      curpage: 1
+    }, function (res) {
+      wx.hideLoading()
+      if (res.code == 200) {
+        let tree = self.arrayToTree(res.datas.areas)
+        self.setData({
+          areas: res.datas.areas,
+          tree,
+          citys: tree[0].children,
+          districts: tree[0].children[0].children
+        })
+      }
+      else {
+        wx.showToast({
+          icon: 'none',
+          title: res.message,
+          duration: 2000
+        })
+      }
+    })
+  },
+  arrayToTree(array) {
+    let result = [], hash = {}, children = 'children'
+    array.forEach((item, index) => {
+      hash[item.aid] = item
+    })
+
+    array.forEach((item, index) => {
+      let pid = item.pid
+      if (pid == 0) {
+        result.push(item)
+      }
+      else {
+        let hashvp = hash[item.pid]
+        if (!hashvp[children]) {
+          hashvp[children] = []
+        }
+        hashvp[children].push(item)
+      }
+    })
+    return result
+  },
+  animation_flag(e) {
+    let flag = e.currentTarget.dataset.flag
+    let animation_flag = flag == 'true' ? true : false
+    let val = this.data.oldval
+
+    this.setData({
+      animation_flag,
+      value: val,
+      citys: this.data.tree[val[0]].children,
+      districts: this.data.tree[val[0]].children[val[1]].children
+    })
+  },
+  setAddress() {
+    let val = this.data.value
+    let province = this.data.tree[val[0]]
+    let city = province.children[val[1]]
+    let district = province.children[val[1]].children[val[2]]
+
     this.setData({
-      year: this.data.years[val[0]],
-      month: this.data.months[val[1]],
-      day: this.data.days[val[2]]
+      animation_flag: false,
+      oldval: val,
+      province,
+      city,
+      district
     })
   },
-  
+  commmitAddress() {
+    let self = this
+    let name = this.trim(this.data.name)
+    let phone = this.trim(this.data.mob_phone)
+    let address = this.trim(this.data.address)
+    let province = this.data.province
+
+    if (!name) {
+      wx.showToast({
+        icon: 'none',
+        title: "请填写您的收货人名称",
+        duration: 1500
+      })
+      return
+    }
+    if (!(/^1(3|4|5|7|8)\d{9}$/.test(phone))) {
+      wx.showToast({
+        icon: 'none',
+        title: "请填写您的手机号",
+        duration: 1500
+      })
+      return
+    }
+
+    if (!province) {
+      wx.showToast({
+        icon: 'none',
+        title: "请选择您的收货地址",
+        duration: 1500
+      })
+      return
+    }
+    if (!address) {
+      wx.showToast({
+        icon: 'none',
+        title: "请填写的您的详细收货地址",
+        duration: 1500
+      })
+      return
+    }
+
+    getReq({
+      act: 'member_address',
+      op: 'address_add',
+      curpage: 1,
+      true_name: name,
+      address,
+      mob_phone: phone,
+      area_id: this.data.district.aid
+    }, function (res) {
+      wx.hideLoading()
+      if (res.code == 200) {
+        let address_id = res.datas.address_id
+        let is_default = self.data.checked ? 1 : 0
+        getReq({
+          act: 'member_address',
+          op: 'set_default',
+          curpage: 1,
+          address_id,
+          is_default
+        }, function (response) {
+          wx.hideLoading()
+          if (response.code == 200) {
+            wx.navigateBack()
+          }
+          else {
+            wx.showToast({
+              icon: 'none',
+              title: response.message,
+              duration: 2000
+            })
+          }
+        })
+      }
+      else {
+        wx.showToast({
+          icon: 'none',
+          title: res.message,
+          duration: 2000
+        })
+      }
+    })
+
+
+
+  },
+  trim(str) {
+    str = str.replace(/\s+/g, "")
+    return str
+  },
+  bindKeyInput(e) {
+    let valueType = e.currentTarget.dataset.value
+    let value = e.detail.value
+    switch (valueType) {
+      case 'name':
+        this.setData({
+          name: value
+        })
+        break;
+      case 'phone':
+        this.setData({
+          mob_phone: value
+        })
+        break;
+      case 'address':
+        this.setData({
+          address: value
+        })
+        break;
+      default:
+        break;
+    }
+  },
 
   /**
    * 生命周期函数--监听页面初次渲染完成

+ 20 - 37
pages/addAddress/addAddress.wxml

@@ -5,7 +5,7 @@
     <view class="info_cell vux-1px-b">
       <view class="info_cell_lable">收件人:</view>
       <view class="info_cell_content">
-        <input placeholder="请输入收件人" />
+        <input placeholder="请输入收件人" value="{{name}}" bindinput="bindKeyInput" data-value="name" />
       </view>
     </view>
   </view>
@@ -14,45 +14,28 @@
     <view class="info_cell vux-1px-b">
       <view class="info_cell_lable">手机号码:</view>
       <view class="info_cell_content">
-        <input placeholder="请输入手机号码" />
+        <input placeholder="请输入手机号码" value="{{mob_phone}}" bindinput="bindKeyInput" data-value="phone" />
       </view>
     </view>
   </view>
 
-  <view class="info_cell-wrap bacfff">
-    <picker mode="region" bindchange="bindRegionChange" value="{{region}}">
-      <view class="info_cell vux-1px-b">
-        <view class="info_cell_lable">地区:</view>
-        <view class="info_cell_content common_cell_arrow">
-          <text>{{region[0]}}</text>
-          <text class="ml8">{{region[1]}}</text>
-          <text class="ml8">{{region[2]}}</text>
-        </view>
+  <view class="info_cell-wrap bacfff" bindtap='animation_flag' data-flag="true">
+    <view class="info_cell vux-1px-b">
+      <view class="info_cell_lable">地区:</view>
+      <view class="info_cell_content common_cell_arrow">
+        <text>{{province.n}}</text>
+        <text class="ml8">{{city.n}}</text>
+        <text class="ml8">{{district.n}}</text>
       </view>
-    </picker>
-  </view>
-
-  <!-- <view class="info_cell-wrap bacfff">
-   <view>{{year}}年{{month}}月{{day}}日</view>
-    <picker-view indicator-style="height: 50rpx;" style="width: 100%; height: 300rpx;" value="{{value}}" bindchange="bindChange">
-      <picker-view-column>
-        <view wx:for="{{years}}" style="line-height: 50rpx">{{item}}年</view>
-      </picker-view-column>
-      <picker-view-column>
-        <view wx:for="{{months}}" style="line-height: 50rpx">{{item}}月</view>
-      </picker-view-column>
-      <picker-view-column>
-        <view wx:for="{{days}}" style="line-height: 50rpx">{{item}}日</view>
-      </picker-view-column>
-    </picker-view>
+    </view>
 
-  </view> -->
+  </view>
 
   <view class="info_cell-wrap bacfff">
     <view class="info_cell">
       <view class="info_cell_lable">详细地址:</view>
       <view class="info_cell_content">
-        <input auto-focus placeholder="请输入详细地址" />
+        <input auto-focus placeholder="请输入详细地址" value="{{address}}" bindinput="bindKeyInput" data-value="address" />
       </view>
     </view>
   </view>
@@ -70,28 +53,28 @@
   </view>
 
 
-  <view class="picker_mask"></view>
 
 
-  <view class="picker_container">
+  <view class="picker_mask {{animation_flag ? 'show_popup' : ''}}" bindtap='animation_flag' data-flag="false"></view>
+  <view class="picker_container {{animation_flag ? 'show_animation' : ''}}">
     <view class="picker_header">
-      <view class="picker_cancel">取消</view>
-      <view>完成</view>
+      <view class="picker_cancel" bindtap='animation_flag' data-flag="false">取消</view>
+      <view bindtap='setAddress'>完成</view>
     </view>
     <view class="bacfff" style="text-align:center">
       <picker-view indicator-style="" style="width: 100%; height: 300rpx;" value="{{value}}" bindchange="bindChange">
         <picker-view-column>
-          <view wx:for="{{years}}" style="line-height: 68rpx">{{item}}年</view>
+          <view wx:for="{{tree}}" wx:key="*this" style="line-height: 68rpx" data-sign="province">{{item.n}}</view>
         </picker-view-column>
         <picker-view-column>
-          <view wx:for="{{months}}" style="line-height: 68rpx">{{item}}月</view>
+          <view wx:for="{{citys}}" wx:key="*this" style="line-height: 68rpx">{{item.n}}</view>
         </picker-view-column>
         <picker-view-column>
-          <view wx:for="{{days}}" style="line-height: 68rpx">{{item}}日</view>
+          <view wx:for="{{districts}}" wx:key="*this" style="line-height: 68rpx">{{item.n}}</view>
         </picker-view-column>
       </picker-view>
     </view>
   </view>
 
-  <!-- <view class="add_address_btn">确认</view> -->
+  <view class="add_address_btn" bindtap='commmitAddress'>确认</view>
 </view>

+ 14 - 1
pages/addAddress/addAddress.wxss

@@ -79,16 +79,29 @@
   height: 100%;
   width: 100%;
   background-color: rgba(0, 0, 0, 0.6);
+  z-index: -1;
+  opacity: 0;
+}
+.picker_mask.show_popup {
   z-index: 99;
+  opacity: 1;
 }
+
 .picker_container {
   position: fixed;
   left: 0;
   right: 0;
   bottom: 0;
   z-index: 100;
+   -webkit-transition: all 0.1s;
+  transition: all 0.1s;
+  -webkit-transform: translateY(110%);
+  transform: translateY(110%);
+}
+.show_animation {
+  -webkit-transform: translateY(0);
+  transform: translateY(0);
 }
-
 .picker_header {
   display: -webkit-flex;  
   display: flex;

+ 2 - 60
pages/address/address.js

@@ -7,65 +7,7 @@ Page({
    * 页面的初始数据
    */
   data: {
-    address_list: [],
-    test_list: [
-      {
-        "address_id": "6386",
-        "member_id": "36490",
-        "true_name": "江海苗",
-        "area_id": "145",
-        "city_id": "39",
-        "area_info": "上海\t上海市\t徐汇区",
-        "handled": "0",
-        "address": "番禺路876号丽人丽妆",
-        "tel_phone": "",
-        "mob_phone": "13911129867",
-        "is_default": "1",
-        "dlyp_id": "0"
-      },
-      {
-        "address_id": "5630",
-        "member_id": "36490",
-        "true_name": "江海苗",
-        "area_id": "44",
-        "city_id": "36",
-        "area_info": "北京\t北京市\t海淀区",
-        "handled": "0",
-        "address": "清华大学",
-        "tel_phone": "",
-        "mob_phone": "18911779278",
-        "is_default": "0",
-        "dlyp_id": "0"
-      },
-      {
-        "address_id": "4184",
-        "member_id": "36490",
-        "true_name": "江海苗",
-        "area_id": "44",
-        "city_id": "36",
-        "area_info": "北京\t北京市\t海淀区",
-        "handled": "11",
-        "address": "西三旗建材城西路27号一单元",
-        "tel_phone": "",
-        "mob_phone": "13911129867",
-        "is_default": "0",
-        "dlyp_id": "0"
-      },
-      {
-        "address_id": "517",
-        "member_id": "36490",
-        "true_name": "江海苗",
-        "area_id": "145",
-        "city_id": "39",
-        "area_info": "上海\t上海市\t徐汇区",
-        "handled": "11",
-        "address": "番禺路900号",
-        "tel_phone": "",
-        "mob_phone": "13911129867",
-        "is_default": "0",
-        "dlyp_id": "0"
-      }
-    ]
+    address_list: []
   },
 
   /**
@@ -101,7 +43,7 @@ Page({
     })
   },
   check_address(e) {
-    let dataset = e.currentTarget.dataset 
+    let dataset = e.currentTarget.dataset
     let { address } = dataset
     let true_name = dataset.truename
     let mob_phone = dataset.mobphone

+ 0 - 12
pages/address/address.wxml

@@ -11,18 +11,6 @@
       <text class="ml16">{{item.area_info}}{{item.address}}</text>
     </view>
   </view>
-
-  <!-- <view class="adress_wrap vux-1px-b" wx:for="{{test_list}}" wx:for-index="idx" wx:key="idx" bindtap='check_address' data-truename="{{item.true_name}}" data-mobphone="{{item.mob_phone}}" data-areainfo="{{item.area_info}}" data-address="{{item.address}}"
-    data-addressid="{{item.address_id}}">
-    <view class="address_line">
-      <text>{{item.true_name}}</text>
-      <text class="ml8">{{item.mob_phone}}</text>
-    </view>
-    <view class="address_line mt8">
-      <text class="coleb4e4f mr16" wx:if="{{item.is_default == 1}}">[默认地址]</text>
-      <text>{{item.area_info}}{{item.address}}</text>
-    </view>
-  </view> -->
   <navigator url="/pages/addAddress/addAddress">
     <view class="add_address_btn">添加地址</view>
   </navigator>

+ 1 - 0
pages/address/address.wxss

@@ -24,4 +24,5 @@
   line-height: 92rpx;
   text-align: center;
   font-size: 30rpx;
+  z-index: 9;
 }

+ 11 - 4
pages/details/details.js

@@ -45,17 +45,24 @@ Page({
     }, function (res) {
       wx.hideLoading()
       if (res.code == 200) {
-        let oneSummary = self.getOneSummary(res.datas.summary,goods_id)
+        let oneSummary = self.getOneSummary(res.datas.summary, goods_id)
         self.setData({
           datas: res.datas,
           getOneSummary: oneSummary,
           imgUrls: res.datas.common_info.images
         })
-        
+
+      }
+      else {
+        wx.showToast({
+          icon: 'none',
+          title: res.message,
+          duration: 2000
+        })
       }
     })
   },
-  getOneSummary(sumarys,goods_id) {
+  getOneSummary(sumarys, goods_id) {
     let getOneSummary = sumarys.filter((item, index) => {
       return item.goods_id == goods_id
     })
@@ -121,7 +128,7 @@ Page({
         op: 'addex',
         quantity: this.data.goodsNumber,
         goods_id: this.data.getOneSummary.goods_id
-      },function(res) {
+      }, function (res) {
         wx.hideLoading()
         if (res.code == 200) {
           wx.showToast({