123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- <template>
- <div v-if="isShow">
- <div class="address-picker-mask" bubble='true' @click="hide" :class="[isOpen?'show-address-picker-mask':'hide-address-picker-mask']"
- :style="{backgroundColor:maskColor,opacity:opacity}">
- </div>
-
- <div class="address-picker-container" ref="addressPickerEl" @click.stop="handleClick" :class="[isOpen?'show-address-picker':'hide-address-picker']">
-
-
- <div class="address-picker-container" @click.stop="handleClick" :class="[isOpen?'show-address-picker':'hide-address-picker']"
- :style="{transform:'translatey('+translatey+'px)'}">
-
- <div class="address-picker-button row between-center">
- <text class="address-picker-button-text" style="color: #777777;" @click="hide">取消</text>
- <text class="address-picker-button-text" style="color: #007AFF;" @click="confirmChange(value)">确认</text>
- </div>
- <picker-view class="address-picker-box" v-if="visible" :indicator-style="indicatorStyle" :value="value" @change="bindChange">
- <picker-view-column class="center">
- <div class="address-picker-item center" v-for="(item,index) in provinceList" :key="index">
- <text class="address-picker-item-text">{{item}}</text>
- </div>
- </picker-view-column>
- <picker-view-column>
- <div class="address-picker-item center" v-for="(item,index) in cityList" :key="index">
- <text class="address-picker-item-text">{{item}}</text>
- </div>
- </picker-view-column>
- <picker-view-column>
- <div class="address-picker-item center" v-for="(item,index) in areaList" :key="index">
- <text class="address-picker-item-text">{{item}}</text>
- </div>
- </picker-view-column>
- </picker-view>
- </div>
- </div>
- </template>
- <script>
-
- const animation = weex.requireModule('animation');
-
- export default {
- name: "itmisterAddressPicker",
- props: {
- maskColor: {
- type: String,
- default: 'rgba(0,0,0,0.3)'
- },
- addressIndex:{
- type:Array,
- default(){
- return [23,4,1]
- }
- }
- },
- data() {
- return {
- isShow: false,
- isOpen: false,
- translatey: 500,
- opacity: 0,
-
- visible: true,
- indicatorStyle: `height: ${Math.round(uni.getSystemInfoSync().screenWidth/(750/100))}px;`,
- value: [],
- cityData: require('../../static/city.json'),
-
- provinceList:[],
- cityList:[],
- areaList:[],
- }
- },
- mounted() {
- this.value = this.addressIndex;
- this.loadProvince(this.cityData);
- },
- methods: {
-
-
- confirmChange(val){
- let address = {
-
- province:this.provinceList[val[0]],
- city:this.cityList[val[1]],
- area:this.areaList[val[2]],
-
- provinceIndex:val[0],
- cityIndex:val[1],
- areaIndex:val[2]
- }
- this.$emit('confirmChange',address);
- this.hide();
- },
-
-
- bindChange(e) {
- const val = e.detail.value;
- this.value = [val[0],val[1],val[2]];
- this.loadCity(this.cityData[val[0]].city);
- },
-
-
- loadProvince(data){
- let newList = [];
- data.forEach(item => {
- newList.push(item.name);
- });
- this.provinceList = newList;
- this.loadCity(this.cityData[this.value[0]].city);
- },
- loadCity(data){
- let newList = [];
- data.forEach(item => {
- newList.push(item.name);
- });
- this.cityList = newList;
-
- if((data.length - 1) >= this.value[1]){
- this.loadArea(this.cityData[this.value[0]].city[this.value[1]].area);
- }else{
- this.loadArea(this.cityData[this.value[0]].city[0].area);
- }
-
- },
- loadArea(data){
- let newList = [];
- data.forEach(item => {
- newList.push(item);
- });
- this.areaList = newList;
- },
-
-
- show() {
-
- this.isShow = true;
-
-
- this.$nextTick(() => {
- setTimeout(() => {
-
-
- let ele = this.$refs.addressPickerEl;
-
-
-
- this.isOpen = true;
- this.opacity = 1;
-
-
-
- this.translatey = 0;
-
-
-
- animation.transition(ele, {
- styles: {
- transform: 'translate(0,0)',
- transformOrigin: 'center center'
- },
- duration: 250,
- timingFunction: 'ease',
- delay: 0
- });
-
- }, 10);
- });
- },
- hide() {
-
-
- let ele = this.$refs.addressPickerEl;
-
-
-
- this.isOpen = false;
- this.opacity = 0;
-
-
-
- this.translatey = 500;
- setTimeout(() => {
- this.isShow = false;
- }, 200);
-
-
-
- animation.transition(ele, {
- styles: {
- transform: 'translate(0,550)',
- transformOrigin: 'center center'
- },
- duration: 250,
- timingFunction: 'ease',
- delay: 0
- },() => {
- this.isShow = false;
- });
-
- },
-
- handleClick(event) {
- event.stopPropagation();
- }
- }
- }
- </script>
- <style lang="scss">
- .address-picker-mask {
- position: fixed;
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- z-index: 999988;
- }
- .address-picker-container {
- position: fixed;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 999999;
- height: 640rpx;
- background-color: #FFFFFF;
- }
- .show-address-picker-mask {
- transition-property: opacity;
- transition-duration: 0.2s;
- transition-timing-function: ease;
- }
- .hide-address-picker-mask {
- transition-property: opacity;
- transition-duration: 0.2s;
- transition-timing-function: ease;
- }
- .show-address-picker {
- /* #ifndef APP-PLUS-NVUE */
- transition-property: transform;
- transition-duration: 0.2s;
- transition-timing-function: ease;
- /* #endif */
- /* #ifdef APP-PLUS-NVUE */
- transform: 'translate(0,550)',
- /* #endif */
- }
- .hide-address-picker {
- /* #ifndef APP-PLUS-NVUE */
- transition-property: transform;
- transition-duration: 0.2s;
- transition-timing-function: ease;
- /* #endif */
- /* #ifdef APP-PLUS-NVUE */
- transform: 'translate(0,550)',
- /* #endif */
- }
-
- // 内容
- .address-picker-box{
- width: 750rpx;
- height: 500rpx;
- padding: 0 20rpx;
- /* #ifdef H5 */
- box-sizing: border-box;
- /* #endif */
- background-color: #FFF;
- }
- .address-picker-item{
- height: 100rpx;
- }
- .address-picker-item-text{
- color: #444;
- font-size: 32rpx;
- }
-
- // 按钮
- .address-picker-button{
- height: 100rpx;
- margin-bottom: 20rpx;
- box-shadow: 0 1rpx 1rpx #e4e4e4;
- background-color: #FFFFFF;
- }
- .address-picker-button-text{
- padding: 10rpx 25rpx;
- margin: 0 30rpx;
- }
-
- .row{
- /* #ifndef APP-PLUS-NVUE */
- display: flex;
- /* #endif */
- flex-direction: row;
-
- }
-
- .center{
- /* #ifndef APP-PLUS-NVUE */
- display: flex;
- /* #endif */
- justify-content: center;
- align-items: center;
- }
- .between-center{
- justify-content: space-between;
- align-items: center;
- }
- </style>
|