123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- <template>
- <view class="area_container">
- <view class="area_container_title">
- <view></view>
- <view class="area_container_title_name">选择地区</view>
- <view class="area_container_title_close" @click.stop="close"><text class="iconfont" ></text></view>
- </view>
- <view class="area_container_content">
- <view class="selectList_con">
- <view class="selectList_con_item" v-for="(item, index) in selectList" :key="index">
- <text>{{ item.name }}</text>
- <text class="iconfont" @click="delSelectItem(item, index)"></text>
- </view>
- </view>
- <view class="selectList_tap">
- <view class="selectList_tap_item" v-for="(item, index) in tapList" :key="index" @click="selectTapItem(item, index)" :class="{ selectTap: selectTap == item.id }">
- {{ item.name }}
- </view>
- <view class="selectList_tap_item" @click="selectTapLastItem(-1)" v-if="isShowLastItem" :class="{ selectTap: selectTap == -1 }">请选择</view>
- </view>
- <view class="selectList_area">
- <scroll-view scroll-y="true" class="scroll" :scroll-top="scrollTop" @scroll="scroll">
- <view v-for="(item, index) in areaList" :key="index" class="selectList_area_item">
- <view class="selectList_area_item_name" @click="selectArea(item)">{{ item.name }}</view>
- <view @click="handlyAddSelect(item)"><text class="iconfont"></text></view>
- </view>
- </scroll-view>
- </view>
- <view class="handle"><view class="handle_button" @click="handleGetSelectArea">确定</view></view>
- </view>
- </view>
- </template>
- <script>
-
- import { getCityV2 } from '@/api/api.js';
- import { serialize, Toast } from '../../../libs/uniApi.js';
- export default {
- props:{
- allReadySelect: {
- type: Array,
- default:() => {
- return []
- }
- }
- },
- data() {
- return {
- selectList: [],
- selectTap: -1,
- selectTapIndex: -1,
- tapList: [],
- isShowLastItem: true,
- areaList: [],
- old: { scrollTop: 0 },
- scrollTop: 0
- };
- },
- watch: {
- allReadySelect: {
- handler(val) {
- this.selectList = this.allReadySelect;
- },
- deep: true
- }
- },
- created() {
- this.loadAddress(0);
- this.selectList = this.allReadySelect;
- },
- methods: {
- loadAddress(address_id) {
- return getCityV2(address_id).then(res => {
- this.areaList = res.data;
- });
- },
-
- async selectArea(item) {
-
- if (this.selectTapIndex > -1) {
- this.tapList.splice(this.selectTapIndex, 999);
- this.loadAddress(item.id);
- this.tapList.push(item);
- this.isShowLastItem = true;
- this.selectTap = -1;
- this.selectTapIndex = -1;
- this.goTop();
- return;
- }
-
- if (item.snum) {
- this.loadAddress(item.id);
- this.tapList.push(item);
- this.isShowLastItem = true;
- this.selectTap = -1;
- this.goTop();
- return;
- }
-
- if (!item.snum) {
- return;
- if (this.isShowLastItem) {
- this.tapList.push(item);
- } else {
- this.tapList.splice(this.tapList.length - 1, 1, item);
- }
- this.isShowLastItem = false;
- this.goTop();
- return;
- }
-
- },
-
- async selectTapItem(item, index) {
- this.selectTap = item.id;
- this.selectTapIndex = index;
- await this.loadAddress(item.parent_id);
- },
-
- selectTapLastItem(val) {
- this.selectTap = -1;
- if (!this.tapList.length) {
- this.loadAddress(0);
- return;
- }
- this.loadAddress(this.tapList[this.tapList.length - 1].id);
- },
-
- handlyAddSelect(item) {
- if (this.selectList.some(val => val.id == item.id)) {
- Toast('已经选择过了')
- return
- }
- if (this.selectTapIndex > -1) {
- this.tapList.splice(this.selectTapIndex, 999);
- }
- if (!item.parent_id) {
- this.selectList.push(item);
- return;
- }
- let str = '';
- str =
- serialize(this.tapList)
- .map(val => val.name)
- .join('/') +
- '/' +
- item.name;
- this.selectList.push({ ...item, name: str });
- },
-
- delSelectItem(item, index) {
- console.log(1);
- this.selectList.splice(index, 1);
- },
-
- handleGetSelectArea() {
- this.$emit('handleGetSelectArea', this.selectList);
- },
- close() {
- this.$emit('close');
- },
-
- unique(arr) {
- var obj = {};
- return arr.filter(ele => {
- if (!obj[ele]) {
- obj[ele] = true;
- return true;
- }
- });
- },
- scroll : function(e) {
- this.old.scrollTop = e.detail.scrollTop
- },
- goTop: function(e) {
- this.scrollTop = this.old.scrollTop
- this.$nextTick(() => {
- this.scrollTop = 0
- });
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .area_container {
- background: #fff;
- border-radius: 16px 16px 0px 0px;
- &_title {
- display: flex;
- justify-content: space-between;
- padding: 36rpx 30rpx 46rpx 0;
- > view {
- flex: 1;
- }
- &_name {
- text-align: center;
- font-weight: bold;
- font-size: 32rpx;
- }
- &_close {
- text-align: right;
- }
- }
- &_content {
- padding: 0 30rpx;
- .selectList_con {
- display: flex;
- flex-wrap: wrap;
- margin-bottom: 50rpx;
- &_item {
- padding: 3rpx 10rpx;
- background: #fff6f5;
- color: #e93323;
- margin-right: 20rpx;
- margin-bottom: 20rpx;
- display: flex;
- align-items: center;
- font-size: 22rpx;
- > span:nth-child(1) {
- display: inline-block;
- margin-right: 14rpx;
- white-space: nowrap;
- }
- .iconfont {
- font-size: 20rpx;
- margin-left: 6rpx;
- }
- }
- }
- .selectList_tap {
- border-bottom: 1px solid #eeeeee;
- display: flex;
- &_item {
- font-size: 28rpx;
- margin-right: 60rpx;
- white-space: nowrap;
- }
- .selectTap {
- color: #e93323;
- border-bottom: 3rpx solid #e93323;
- padding-bottom: 21rpx;
- }
- }
- .selectList_area {
- .scroll {
- height: 597rpx;
- }
- .selectList_area_item {
- padding: 40rpx 0;
- display: flex;
- justify-content: space-between;
- font-size: 28rpx;
- .iconfont {
- color: #e93323;
- font-size: 40rpx;
- }
- .selectList_area_item_name {
- flex: 0.7;
- }
- }
- }
- .handle {
- height: 126rpx;
- &_button {
- width: 690rpx;
- height: 86rpx;
- background: #e93323;
- border-radius: 43rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 32rpx;
- color: #fff;
- }
- }
- }
- }
- </style>
|