ufutx_love_mp/src/components/selectCity.wpy
2024-08-16 09:14:13 +08:00

233 lines
6.2 KiB
Plaintext

<template>
<picker mode="multiSelector" style="width:{{width}};height:{{height}};" @change="MultiPickerChange" @columnchange="MultiPickerColumnChange" value="{{multiIndex}}" range="{{objectArray}}">
<slot></slot>
</picker>
</template>
<script>
import wepy from '@wepy/core'
import base from '../mixins/base.js'
import https from '../mixins/https'
import {service} from '../config.js'
wepy.component({
mixins: [base, https],
options: {
multipleSlots: true // 在组件定义时的选项中启用多slot支持
},
data: {
region: [],
objectArray: [[], [], []],
provinces: [],
nationId: 0,
provinceId: 0,
cityId: 0
},
props: {
itemIndex: {
type: Number,
default: 0,
twoWay: true
},
selfTextareaShow: {
type: String,
default: ''
},
width: {
type: String,
default: ''
},
height: {
type: String,
default: ''
},
AddressValue: {
type: Array,
default: []
},
multiIndex: {
type: Array,
default: []
}
},
created() {
let vm = this
vm.$nextTick(() => {
vm.GetAddress()
})
},
onShow() {
},
watch: {},
methods: {
GetAddress() {
let vm = this
let url = ``
console.log(vm.selfTextareaShow, vm.multiIndex, '88888888888888888')
if (vm.selfTextareaShow) {
url = `${service.host}/addresses`
} else {
url = `${service.host}/addresses/v2`
}
vm.$get({url: url}).then(({code, data}) => {
vm.provinces = data
console.log(vm.provinces, 'vm.provinces')
if (vm.AddressValue.length > 0) {
vm.provinces.forEach((item, index) => {
vm.objectArray[0].push(item.name)
if (item.name == vm.AddressValue[0]) {
vm.multiIndex[0] = index
}
})
vm.provinces[vm.multiIndex[0]].son.forEach((item, index) => {
vm.objectArray[1].push(item.name)
if (item.name == vm.AddressValue[1]) {
vm.multiIndex[1] = index
}
})
vm.provinces[vm.multiIndex[0]].son[vm.multiIndex[1]].son.forEach((item, index) => {
vm.objectArray[2].push(item.name)
if (item.name == vm.AddressValue[2]) {
vm.multiIndex[2] = index
}
})
} else {
for (let item of vm.provinces) {
vm.objectArray[0].push(item.name)
}
for (let item of vm.provinces[vm.provinceId].son) {
vm.objectArray[1].push(item.name)
}
for (let item of vm.provinces[vm.cityId].son[vm.selfTextareaShow ? 0 : 18].son) {
vm.objectArray[2].push(item.name)
}
}
console.log(vm.provinces, 'provinces')
this.$emit('provinces', vm.provinces)
})
},
MultiPickerChange(e) { // 地址确定
console.log(this.itemIndex)
console.log(e, 'e-----')
this.multiIndex = e.$wx.detail.value
console.log(this.provinces, this.multiIndex, 'gggg')
console.log(this.provinces[this.multiIndex[0]], '=1')
console.log(this.provinces[this.multiIndex[0]].son[this.multiIndex[1]], '=2')
console.log(this.provinces[this.multiIndex[0]].son[this.multiIndex[1]].son[this.multiIndex[2]], '=3')
this.region = [this.provinces[this.multiIndex[0]].name, this.provinces[this.multiIndex[0]].son[this.multiIndex[1]].name, this.provinces[this.multiIndex[0]].son[this.multiIndex[1]].son[this.multiIndex[2]].name]
this.$emit('multiCity', this.multiIndex)
this.$emit('selectCity', this.region, this.itemIndex)
},
MultiPickerColumnChange(e) { // 省
console.log(e, '---')
let that = this,
province = [],
city = []
switch (e.$wx.detail.column) {
case 0:
that.nationId = e.$wx.detail.value
for (let item of that.provinces[that.nationId].son) {
province.push(item.name)
}
for (let item of that.provinces[that.nationId].son[0].son) {
city.push(item.name)
}
that.objectArray = [that.objectArray[0], province, city]
that.multiIndex = [e.$wx.detail.value, 0, 0]
break
case 1:
that.provinceId = e.$wx.detail.value
for (let item of that.provinces[that.nationId].son[that.provinceId].son) {
city.push(item.name)
}
that.objectArray = [that.objectArray[0], that.objectArray[1], city]
that.multiIndex = [that.multiIndex[0], e.$wx.detail.value, 0]
break
case 2:
that.multiIndex = [that.multiIndex[0], that.multiIndex[1], e.$wx.detail.value]
break
}
}
}
})
</script>
<style lang="less" scoped>
.loading-box{
width: 100vw;height: 100vh;
background-image: url("http://images.ufutx.com/201901/14/ed1b2da08b3581efdc7372b26f1ba40b.png");
background-size: cover;
background-repeat: no-repeat;
position: fixed;
top: 0;
left: 0;
z-index: 1000;
.loading-image{
width: 500rpx;height: 500rpx;
margin: auto;
margin-top: 30vh;
z-index: -1;
}
.loading-item{
width: 100%;height: 400rpx;
position: relative;
position: absolute;
overflow: inherit;
left: 0 ;
top: 30vh;
.image{
width: 220rpx;
position: absolute;
left: 0;
top: 0;
animation: opacity 1200ms ease-in;
animation-fill-mode: forwards;
}
}
}
cover-image,cover-view {
overflow: visible !important;
}
.animate{
-webkit-animation: move2 2s linear infinite;
}
.loading-icon {
width: 240rpx;
}
@-webkit-keyframes move2{
0%{-webkit-transform:rotate(0deg);}
50%{-webkit-transform:rotate(-180deg);}
100%{-webkit-transform:rotate(-360deg);}
}
.hide{
animation: opacity2 800ms ease-in;
animation-fill-mode: forwards;
}
@keyframes opacity{
0%{opacity: 0}
50%{opacity:.5;}
100%{opacity:1;}
}
@keyframes opacity2{
0%{opacity:1}
50%{opacity:.8;}
100%{opacity:0;}
}
@-webkit-keyframes move2{
0%{-webkit-transform:rotate(0deg);}
50%{-webkit-transform:rotate(-180deg);}
100%{-webkit-transform:rotate(-360deg);}
}
</style>