Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
7
7-Eleven
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
高淑倩
7-Eleven
Commits
b039a797
Commit
b039a797
authored
Aug 19, 2019
by
赵雅纹
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
地区选择
parent
1f11525c
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
182 additions
and
5 deletions
+182
-5
app.js
src/app.js
+2
-0
addAddress.js
src/pages/addAddress/addAddress.js
+87
-2
addAddress.wxml
src/pages/addAddress/addAddress.wxml
+6
-3
addAddress.wxss
src/pages/addAddress/addAddress.wxss
+6
-0
city.js
src/utils/city.js
+0
-0
wxService.js
src/utils/wxService.js
+81
-0
No files found.
src/app.js
View file @
b039a797
...
...
@@ -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
,
...
...
src/pages/addAddress/addAddress.js
View file @
b039a797
// 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
}
},
/**
...
...
src/pages/addAddress/addAddress.wxml
View file @
b039a797
...
...
@@ -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>
...
...
src/pages/addAddress/addAddress.wxss
View file @
b039a797
...
...
@@ -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
src/utils/city.js
0 → 100644
View file @
b039a797
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/utils/wxService.js
View file @
b039a797
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment