Commit b039a797 by 赵雅纹

地区选择

parent 1f11525c
......@@ -3,6 +3,7 @@ import { cEvent } from './utils/event.js'
const Promise = require('lib/bluebird')
var utils = require('utils/util.js')
var commonFunc = require('utils/common.js')
var cityJson = require('utils/city.js')
var wxService = require('utils/wxService')
let config = require('./configScreen/configScreen');
const envInfo = require('config/index').envInfo
......@@ -109,6 +110,7 @@ App({
imageUrl: envInfo.imgCtx, //图片地址
isFullSucreen: false, // 当前设备是否为 FullSucreen
commonFunc: commonFunc,
cityJson: cityJson,
// brandId: 2711,
// brandId: 2005,
brandId: 1001,
......
// pages/addAddress/addAddress.js
Page({
const wxService = require('../../utils/wxService')
wxService.page({
/**
* 页面的初始数据
*/
data: {
isSelect:true,
addressId:''
citys: null,
cityView: '',
isDefault: 0,
formData: {},
selectCityName: ['', ''],
multiIndex: [0, 0, 0],
focus: false
},
/**
......@@ -27,7 +35,84 @@ Page({
title: '新增地址'
})
}
this.init(options)
},
init(options) {
const id = options.id
if (id) {
const addressItem = pageParmas.getObject('addressItem')
if (addressItem) {
let cityView = ''
if (addressItem.districtName) {
cityView = addressItem.districtName.replace(/,/g, ' ')
}
this.setData({
formData: addressItem,
isDefault: addressItem.isDefault,
id,
cityView
})
}
}
wxService.getC1().then((c1) => {
return wxService.Promise.all([wxService.Promise.resolve(c1), wxService.getC2ByC1('北京'), wxService.getC3ByC2('北京北京市')])
}).then(res => {
const citys = res.map(item => {
return [...item]
})
this.setData({
citys
})
})
},
bindMultiPickerChange(e) {
const citys = this.data.citys
const multiIndex = e.detail.value
if (citys) {
const cityView = [citys[0][multiIndex[0]], citys[1][multiIndex[1]], citys[2][multiIndex[2]]].join(' ')
this.setData({
multiIndex,
cityView
})
}
},
bindMultiPickerColumnChange(e) {
const detail = e.detail
const index = detail.value
let cityName = ''
switch (detail.column) {
case 0:
cityName = this.data.citys[0][index]
this.data.selectCityName[0] = cityName
wxService.getC2ByC1(cityName)
.then(item => {
let c2 = [...item]
this.data.selectCityName[1] = c2[0]
return wxService.Promise.all([wxService.Promise.resolve(item), wxService.getC3ByC2(this.data.selectCityName.join(''))])
}).then((res) => {
this.setData({
'citys[1]': [...res[0]],
'citys[2]': [...res[1]]
})
})
break
case 1:
cityName = this.data.citys[1][index]
this.data.selectCityName[1] = cityName
wxService.getC3ByC2(this.data.selectCityName.join(''))
.then(item => {
this.setData({
'citys[2]': [...item]
})
})
break
default:
break
}
},
/**
......
......@@ -12,9 +12,12 @@
</view>
<view class="form">
<view class="form-label">地区</view>
<picker mode="region" bindchange="bindRegionChange" value="{{region}}" custom-item="{{customItem}}" class="form-input">
<view class="{{haveAddress ? 'picker' : 'placeholder-picker'}}">
请选择地区
<picker mode="multiSelector" bindchange="bindMultiPickerChange" bindcolumnchange="bindMultiPickerColumnChange" value="{{multiIndex}}" range="{{citys}}">
<view class="form-picker" wx:if="{{cityView}}">
{{cityView}}
</view>
<view wx:if="{{!cityView}}">
<input class='form-input' placeholder-class="placeholder-picker" type="text" disabled placeholder="请选择地区" />
</view>
</picker>
</view>
......
......@@ -60,3 +60,8 @@
color: #333333;
font-size: 25rpx;
}
.form-picker{
height: 82rpx;
line-height: 82rpx;
margin-left: 52rpx;
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,6 +3,7 @@ import {
getC1,
getC2,
getC3,
handler2citys,
needOpenCard,
getCurrentRouter
} from './helper'
......@@ -15,6 +16,7 @@ import Http from './Http'
const Promise = require('../lib/bluebird')
const config = require('../config/index').envInfo
import utils from './util'
const citysData = require('./city.js')
let openCardLister = null
/**
* 单例
......@@ -644,6 +646,85 @@ class WXService extends Http {
return false
})
}
getCitysEnterty() {
const citys = citysData
let list = {}
if (this.citysEntertys) {
list = this.citysEntertys
} else {
for (const key in citys) {
if (citys.hasOwnProperty(key)) {
const element = citys[key]
handler2citys({
city: element,
result: { name: [], code: [] },
list
})
}
}
}
return list
}
getC1() {
return getC1().then((res) => {
return res
}).catch(() => {
if (this instanceof WXService) {
this.getCitysEnterty()
} else {
const wxService = new WXService()
wxService.getCitysEnterty()
}
return getC1().then((res) => {
return res
})
})
}
getC2ByC1(c1Name) {
return getC2(c1Name).catch(() => {
if (this instanceof WXService) {
this.getCitysEnterty()
} else {
const wxService = new WXService()
wxService.getCitysEnterty()
}
return getC2(c1Name)
})
}
getC3ByC2(c2Name) {
return getC3(c2Name).catch(() => {
if (this instanceof WXService) {
this.getCitysEnterty()
} else {
const wxService = new WXService()
wxService.getCitysEnterty()
}
return getC3(c2Name)
})
}
getCityCode(c1, c2, c3) {
function getKey(...args) {
return args
.join('###')
}
const key = getKey(c1, c2, c3)
let result = ''
let list = {}
if (this instanceof WXService) {
list = this.getCitysEnterty()
} else {
const wxService = new WXService()
list = wxService.getCitysEnterty()
}
result = list[key]
return result
}
}
const wxService = new WXService()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment