zhashaonan 7 rokov pred
rodič
commit
aecde62008

+ 82 - 6
pages/addAddress/addAddress.js

@@ -26,6 +26,9 @@ Page({
   data: {
     checked: true,
     areas: [],
+    tree: [],
+    cityIndex: 0,
+    districtIndex: 0,
     region: [],
     years: years,
     year: date.getFullYear(),
@@ -33,14 +36,17 @@ Page({
     month: 2,
     days: days,
     day: 2,
-    value: [9999, 1, 1]
+    value: [0, 0, 0],
+    oldval: [0, 0, 0],
+    citys: [],
+    districts: []
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-
+    this.getDatas()
   },
   toggleChecked() {
     this.setData({
@@ -54,14 +60,84 @@ Page({
     })
   },
   bindChange: function (e) {
+    console.log(e)
     const val = e.detail.value
+
+
+    // if (districtIndex != this.data.oldval[1] && cityIndex != 0) {
+    //   districtIndex = 0
+    // }
+    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
+      }
+    }
+    let cityIndex = val[0]
+    let districtIndex = val[1]
     this.setData({
-      year: this.data.years[val[0]],
-      month: this.data.months[val[1]],
-      day: this.data.days[val[2]]
+      oldval: val,
+      citys: this.data.tree[val[0]].children,
+      districts: this.data.tree[val[0]].children[val[1]].children
+    })
+    // this.setData({
+    //   oldval: val,
+    //   citys: this.data.tree[val[0]],
+    //   districts: this.data.tree[val[0].children[val[1]]
+    // })
+  },
+  getDatas() {
+    wx.showLoading({
+      title: '加载中',
+    })
+    var self = this
+    getReq({
+      act: 'app_update',
+      op: 'area',
+      curpage: 1
+    }, function (res) {
+      wx.hideLoading()
+      if (res.code == 200) {
+        console.log(res.datas.areas)
+        let tree = self.arrayToTree(res.datas.areas)
+        console.log(tree)
+        self.setData({
+          areas: res.datas.areas,
+          tree
+        })
+      }
+      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
   },
-  
 
   /**
    * 生命周期函数--监听页面初次渲染完成

+ 11 - 1
pages/addAddress/addAddress.wxml

@@ -80,7 +80,7 @@
     </view>
     <view class="bacfff" style="text-align:center">
       <picker-view indicator-style="" style="width: 100%; height: 300rpx;" value="{{value}}" bindchange="bindChange">
-        <picker-view-column>
+        <!-- <picker-view-column>
           <view wx:for="{{years}}" style="line-height: 68rpx">{{item}}年</view>
         </picker-view-column>
         <picker-view-column>
@@ -88,6 +88,16 @@
         </picker-view-column>
         <picker-view-column>
           <view wx:for="{{days}}" style="line-height: 68rpx">{{item}}日</view>
+        </picker-view-column> -->
+
+        <picker-view-column >
+          <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="{{citys}}" wx:key="*this" style="line-height: 68rpx">{{item.n}}</view>
+        </picker-view-column>
+        <picker-view-column>
+          <view wx:for="{{districts}}" wx:key="*this" style="line-height: 68rpx">{{item.n}}</view>
         </picker-view-column>
       </picker-view>
     </view>

+ 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({