expectLocation.js 8.0 KB
// pages/expectLocation/expectLocation.j
var app = getApp()
Page({

   /**
    * 页面的初始数据
    */
   data: {
      provinceStr: [],
      provinceIndex: 0,
      cityStr: ['市'],
      cityIndex: 0,
      districtStr: ['区县'],
      districtIndex: 0,
      streetStr: ['街道'],
      streetIndex: 0,

      detailedAddressVal: ""
   },
   // 确定提交
   confirm() {
      wx.showLoading({
         title: '加载中',
      })
      // 三问省一级
      var provinceStr = this.data.provinceStr[this.data.provinceIndex];
      console.log(provinceStr)
      // 三问市一级
      var cityStr = this.data.cityStr[this.data.cityIndex];
      console.log(cityStr)
      // 三问区县一级
      var districtStr = this.data.districtStr[this.data.districtIndex];
      console.log(districtStr)
      // 三问街道一级
      var streetStr = this.data.streetStr[this.data.streetIndex];
      console.log(streetStr)
      // 三问详细地址
      var detailedAddressVal = this.data.detailedAddressVal;
      console.log(detailedAddressVal)
      if (provinceStr != "省") {
         if (cityStr != "市") {
            if (districtStr != "区县") {
               if (streetStr != "街道") {
                  if (detailedAddressVal != "") {
                     console.log(this.data.province[this.data.provinceIndex - 1].province_id)
                     console.log(this.data.city[this.data.cityIndex - 1].city_id)
                     console.log(this.data.district[this.data.districtIndex - 1].county_id)
                     console.log(this.data.street[this.data.streetIndex - 1].town_id)
                     app.ajax("SurveySpot/updateMyHopeSpot", {
                        unique_id: app.globalData.unique_id,
                        province: provinceStr,
                        city: cityStr,
                        county: districtStr,
                        town: streetStr,
                        address: detailedAddressVal,
                        province_id: this.data.province[this.data.provinceIndex - 1].province_id,
                        city_id: this.data.city[this.data.cityIndex - 1].city_id,
                        county_id: this.data.district[this.data.districtIndex - 1].county_id,
                        town_id: this.data.street[this.data.streetIndex - 1].town_id
                     }, (res) => {
                        console.log(res)
                        if (res.data.status == true) {

                           wx.showToast({
                              title: res.data.msg,
                              icon: 'success',
                              duration: 2000
                           })
                           setTimeout(function () {
                              wx.navigateBack({})
                           }, 2000)
                        } else {
                           wx.showModal({
                              title: '提示',
                              content: res.data.msg,
                              success: function (res) {
                                 if (res.confirm) {
                                    console.log('用户点击确定')
                                 } else if (res.cancel) {
                                    console.log('用户点击取消')
                                 }
                              }
                           })
                        }
                     })
                  } else {
                     wx.showLoading({
                        title: '填写详细地址',
                        duration: 1000,
                        mask: true
                     })
                  }
               } else {
                  wx.showLoading({
                     title: '填写街道信息',
                     duration: 1000,
                     mask: true
                  })
               }
            } else {
               wx.showLoading({
                  title: '填写县级信息',
                  duration: 1000,
                  mask: true
               })
            }
         } else {
            wx.showLoading({
               title: '填写市级信息',
               duration: 1000,
               mask: true
            })
         }
      } else {
         wx.showLoading({
            title: '填写省级信息',
            duration: 1000,
            mask: true
         })
      }
   },
   // 第三问街道
   bindPickerChange5(e) {
      this.setData({
         streetIndex: e.detail.value
      })
   },
   // 第三问区县一级
   bindPickerChange4(e) {
      this.setData({
         districtIndex: e.detail.value
      })
      var county_id = this.data.district[parseInt(e.detail.value) - 1].county_id
      app.ajax("AjaxPosition/town", {
         county_id: county_id
      }, (res) => {
         console.log(res)
         if (res.data.status == true) {
            var data = res.data.data
            var streetStr = ['街道']
            for (let n in data) {
               streetStr.push(data[n].town_name)
            }
            this.setData({
               streetStr: streetStr,
               street: data,
            })
         }
      }, (res) => { })
   },
   //   第三问市一级
   bindPickerChange3(e) {
      this.setData({
         cityIndex: e.detail.value
      })
      var province_id = this.data.city[parseInt(e.detail.value) - 1].city_id
      app.ajax("AjaxPosition/county", {
         city_id: province_id
      }, (res) => {
         console.log(res)
         if (res.data.status == true) {
            var data = res.data.data
            var districtStr = ['区县']
            for (let n in data) {
               districtStr.push(data[n].county_name)
            }
            this.setData({
               districtStr: districtStr,
               district: data,
               // Fordistrict: data
            })
         }
      }, (res) => { })
   },
   //   第三问省一级
   bindPickerChange2(e) {
      console.log(parseInt(e.detail.value) - 1)
      this.setData({
         provinceIndex: e.detail.value
      })
      var province_id = this.data.province[parseInt(e.detail.value) - 1].province_id
      app.ajax("AjaxPosition/city", {
         province_id: province_id
      }, (res) => {
         console.log(res)
         if (res.data.status == true) {
            var data = res.data.data
            var cityStr = ['市']
            for (let n in data) {
               cityStr.push(data[n].city_name)
            }
            this.setData({
               cityStr: cityStr,
               city: data,
            })
         }
      }, (res) => { })
   },
   // 三问详细地址
   detailedAddress(e) {
      var val = e.detail.value;
      this.setData({
         detailedAddressVal: val
      })
   },
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {

   },

   /**
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady: function () {

   },

   /**
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
      //   省市区列表
      app.ajax("AjaxPosition/province", {}, (res) => {
         console.log("省一级")
         console.log(res)
         if (res.data.status == true) {
            var province = res.data.data;
            var provinceStr = ['省']

            for (let n in province) {
               provinceStr.push(province[n].province_name)
            }
            this.setData({
               province: res.data.data,
               Forprovince: res.data.data,
               provinceStr: provinceStr,
            })
            console.log(provinceStr)
         }

      }, (res) => { })
   },

   /**
    * 生命周期函数--监听页面隐藏
    */
   onHide: function () {

   },

   /**
    * 生命周期函数--监听页面卸载
    */
   onUnload: function () {

   },

   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh: function () {

   },

   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {

   },

   /**
    * 用户点击右上角分享
    */
   onShareAppMessage: function () {

   }
})