liukangdong
2024-09-29 b2d360d9113b6955287108ca9e90d76a1f3c1419
wechat_jiaxuan/pages/design/design.js
@@ -1,3 +1,4 @@
// import { areaList } from '@vant/area-data';
import {
  getDictData,
  getArea,
@@ -11,12 +12,13 @@
   * 页面的初始数据
   */
  data: {
    guideName: '',
    name: '',
    phone: '',
    phone: '',
    showAreaList: false,
    areaList: [],
    addr: {},
    addrValues:[],
    fieldNames: {
      text: 'name',
      value: 'id',
@@ -29,6 +31,9 @@
  },
  onLoad(options) {
    this.initData()
    if(options.name){
      this.setData({ guideName: options.name })
    }
    qqmapsdk = new QQMapWX({
      key: 'HIDBZ-2QXL4-TAWUD-XET6Q-EKTJE-CCBSQ'
    });
@@ -36,23 +41,47 @@
      success: (res) => {
        console.log('res', res);
        let addr = {
          // provinceCode: codes[0] + '00',
          provinceCode: res.result.ad_info.adcode.slice(0,2) + '000000',
          provinceName: res.result.ad_info.province,
          // cityCode: codes[1] + '00',
          cityCode: res.result.ad_info.adcode.slice(0,4) + '0000',
          cityName: res.result.ad_info.city,
          // areaCode: codes[2] + '00',
          areaCode: res.result.ad_info.adcode + '00',
          areaName: res.result.ad_info.district,
        }
        this.setData({ addr })
        this.setData({ addr,addrValues:
          [res.result.ad_info.adcode.slice(0,2) + '0000',
          res.result.ad_info.adcode.slice(0,4) + '00',
          res.result.ad_info.adcode]  })
      }
    })
    const member =  wx.getStorageSync('member')
    this.setData({
      phone: member.phone,
      name: member.name
    })
  },
  regionChange(e) {
    console.log(e)
    if(e.detail.value &&e.detail.value.length ==3){
      var tn = e.detail.label.split("-")
      const addr = {
        provinceCode: e.detail.value[0] ,
        provinceName: tn[0],
        cityCode:  e.detail.value[1] ,
        cityName:  tn[1],
        areaCode: e.detail.value[2] ,
        areaName:  tn[2]
      }
      this.setData({ addr, showAreaList: false })
      console.log('selectedOptions', addr);
    }
  },
  onSubmit() {
    const {
      name,
      phone,
      addr
      addr,
      guideName
    } = this.data
    if (!name) return wx.showToast({
      title: '请输入姓名',
@@ -70,23 +99,24 @@
      title: '请选择城市',
      icon: 'none'
    })
    console.log({
      name,
      phone,
      ...addr
    })
    saveFreeCustomizationApply({
      name,
      phone,
      username: guideName || null,
      ...addr
    }).then(res => {
      wx.showToast({
        title: '报名成功'
      })
      wx.switchTab({
        url: '/pages/index/index',
      })
      setTimeout(() => {
        wx.navigateBack()
      }, 1000)
    })
  },
  // 显示城市弹窗
  chooseCity () {
    this.setData({ showAreaList: !this.data.showAreaList })
    console.log('chooseCity', this.data.showAreaList);
  },
  onFinish(e) {
    const { selectedOptions, value } = e.detail;
@@ -103,6 +133,7 @@
  },
  positionChange (e) {
    console.log(e.detail.value)
    console.log(e.detail.code)
    const names = e.detail.value
    const codes = e.detail.code
    let addr = {
@@ -125,13 +156,17 @@
  onClose() {
    this.setData({ showAreaList: false })
  },
  onClick() {
    this.setData({ showAreaList: true })
  },
  initData() {
    getArea({
      "level": "",
      "pid": ""
    }).then(res => {
      this.setData({areaList: res.data})
    })
    // getArea({
    //   "level": "",
    //   "pid": ""
    // }).then(res => {
    //   this.setData({areaList: res.data})
    //   console.log(this.data.areaList)
    // })
    getDictData({
      code: 'WEIXIN_DEFAULT_IMGS',
      label: 'DESIGN_BANNER'