addAddress.vue 12.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
<template>
	<!-- 编辑/添加地址 -->
	<view class="container flex-center flex-column">
    <global-loading />
    <!-- #ifdef MP-WEIXIN -->

    <!-- #endif -->
		<view class="addressBack-box">
			<view class="consignee-box bor-line-F7F7F7">
				<input v-model="addressData.username" class="fs28"  placeholder-class="consignee" placeholder="收货人" />
			</view>
			<view class="iphoneNum-box bor-line-F7F7F7">
				<input type="number" v-model="addressData.phone" class="fs28" placeholder-class="iphoneNum" placeholder="手机号码" />
			</view>
			<view @click="locationClick" class="location-box bor-line-F7F7F7 flex-row-plus flex-sp-between flex-items">
				<view class="fs28 location">所在地</view>
				<view class="locationBox">
<!--					<city-select v-model="locationShowFalg" @city-change="cityChange"></city-select>-->
          <u-picker-cere mode="region" v-model="locationShowFalg" @confirm="cityChange" :default-region='addressData.defaultRegion' title="所在地"></u-picker-cere>
					<text v-model="addressData.ssqText">{{addressData.ssqText}}</text>
					<image class="arrow mar-left-20" src="https://zhgw-uat.028wlkj.com/cdwlMall/zsfwzxt/file/static/images/greyArrow.png"></image>
				</view>
			</view>
			<view class="detailAddress-box">
				<input class="fs28" v-model="addressData.address" placeholder-class="detailAddress" placeholder="详细地址:如道路、门牌号、小区、楼栋号、单元等" />
			</view>
		</view>
		<view class="addressTagBack-box">
			<view @click="addressTagClick" class="addressTag-box bor-line-F7F7F7 flex-row-plus flex-sp-between flex-items">
				<view class="fs28 addressTag">地址标签</view>
				<view class="flex-items">
					<text v-model="tag">{{tag}}</text>
					<image class="arrow mar-left-20" src="https://zhgw-uat.028wlkj.com/cdwlMall/zsfwzxt/file/static/images/greyArrow.png"></image>
				</view>
			</view>
			<view class="defaultState-box flex-row-plus flex-sp-between flex-items">
				<view class="fs28 defaultState">设为默认地址</view>
				<u-switch v-model="ifDefault" active-color="#C5AA7B" inactive-color="#eee"></u-switch>
			</view>
		</view>
		<view class="deleteAddress-box" @click="delAddress" v-if="type == 2">
			<text class="font-color-C5AA7B">删除收货地址</text>
		</view>
		<view class="saveAddress-box">
			<view class="saveAddress" v-if="type == 1 || type == 3" @click="addAddressClick">保存</view>
			<view class="saveAddress" v-else @click="saveAddressClick">保存</view>
		</view>
		<!-- 所在地弹窗 -->
		<!-- <u-select v-model="locationShowFalg" safe-area-inset-bottom="true" mode="mutil-column-auto" :list="locationList" @confirm="locationConfirm" title="所在地"></u-select> -->
		<!-- 所在地弹窗 -->
<!--		<u-select v-model="addressTagShowFalg" mode="single-column" :list="addressTagList" @confirm="addressTagconfirm" title="地址标签"></u-select>-->
    <u-picker-cere mode="selector" v-model="addressTagShowFalg" :range="addressTagList" range-key="label" @confirm="addressTagconfirm" title="地址标签" :default-selector="[addressTagIndex]"></u-picker-cere>
	</view>
</template>

<script>
// import citySelect from './u-city-select.vue';
const NET = require('../../utils/request')
const API = require('../../config/api')
	export default {
    // components: {
		// 	citySelect
		// },
		data() {
			return {
				show: false,
				type: 1, // 1.添加新地址 2.编辑收货地址
				locationShowFalg:false,
				locationList: [],
				locationName:'',
				provinceName:'',
				cityName:'',
				districtName:'',
				addressTagList: [
					{
						value: '1',
						label: '家'
					},
					{
						value: '2',
						label: '公司'
					},
					{
						value: '3',
						label: '学校'
					}
				],
				addressTagShowFalg:false,
				areaList:[],
				username:'',
				phone:'',
				ssqText:'',
				address:'',
				tag:'',
				ifDefault: 0,
				province:'',
				city:'',
				area:'',
				id:'',
				ordertype:0,
				editAddress:{},
        addressTagIndex: 0,
        // defaultRegion: [],
        addressData: {
          username: '',
          phone: '',
          ssqText: '',
          address: '',
          defaultRegion: [],
          city:'',
          province:'',
        }
			}
		},
		onLoad(options) {
			this.type = options.type
			console.log(this.type,'this.type')
			if(options.ordertype == 1){
				this.ordertype = 1
			}
			let receiveId = options.receiveId
      this.id = receiveId
			if(this.type == 2){
        // uni.showLoading({
        //   mask: true,
        //   title: '请稍后...',
        // })
        NET.request(API.receiveGetInfo,{receiveId:receiveId},"GET").then(res => {
          this.editAddress = res.data
          this.addressData.username = this.editAddress.receiveName
          this.addressData.phone = this.editAddress.receivePhone
          this.addressData.ssqText = this.editAddress.receiveAdress
          this.addressData.address = this.editAddress.address
          this.tag = this.editAddress.label
          for(let i=0;i<this.addressTagList.length;i++){
            if(this.addressTagList[i].label === this.tag){
              this.addressTagIndex = i
            }
          }
          this.ifDefault = this.editAddress.ifDefault
          this.addressData.defaultRegion = this.addressData.ssqText.split("-")
          this.addressData.province = this.addressData.defaultRegion[0]
          this.addressData.city = this.addressData.defaultRegion[1]
          this.addressData.area = this.addressData.defaultRegion[2]
          this.addressData.id = this.editAddress.receiveId
          uni.hideLoading()
        }).catch(res => {

        })
			}
      if (this.type == 3) {
        let obj = JSON.parse(options.wxAddressData)
        this.addressData = obj
        // this.username = obj.username
        // this.phone = obj.phone
        // this.ssqText =  obj.ssqText
        // this.defaultRegion = obj.defaultRegion
        // this.address = obj.address
        // this.province = obj.provinceName
        // this.city = obj.cityName
      }
			if(this.editAddress != ''){
				uni.removeStorageSync('editAddress')
			}
		},
		methods: {
			cityChange(e) {
				this.addressData.ssqText = e.province.label + '-' + e.city.label + '-' + e.area.label;
				this.addressData.province = e.province.label
				this.addressData.city = e.city.label
				this.addressData.area = e.area.label
			},
			locationClick(){
				this.locationShowFalg = true
			},
			locationConfirm(e) {
				this.provinceName = e[0].label
				this.cityName = e[1].label
				this.districtName = e[2].label
				this.locationDot = '·'
			},
			addressTagClick(){
				this.addressTagShowFalg = true
			},
			addressTagconfirm(index){
				this.tag = this.addressTagList[index].label
			},
			//编辑地址
			saveAddressClick(){
				let phoneCodeVerification = /^[1][3-9][0-9]{9}$/;
				if(this.addressData.username==''){
					uni.showToast({
					    title: '请输入收货人!',
					    duration: 2000,
						icon:'none'
					});
				}else if(this.addressData.phone ==''){
					uni.showToast({
					    title: '请输入手机号!',
					    duration: 2000,
						icon:'none'
					});
				}else if(!phoneCodeVerification.test(this.addressData.phone)){
					uni.showToast({
						title: '请输入正确的手机号!',
						duration: 2000,
						icon:'none'
					});
				}else if(this.addressData.province==''||this.addressData.city==''){
					uni.showToast({
					    title: '所在地不能为空!',
					    duration: 2000,
						icon:'none'
					});
				}else if(this.addressData.address==''){
					uni.showToast({
					    title: '请输入详细地址!',
					    duration: 2000,
						icon:'none'
					});
				}else{
					NET.request(API.AddresUpdate,{
						receiveId: this.id,
						receiveName: this.addressData.username,
						receivePhone: this.addressData.phone,
						receiveAdress: this.addressData.ssqText,
						address:this.addressData.address,
						label:this.tag,
            ifDefault:this.ifDefault ? 1 : 0
					},'POST').then(res => {
						uni.navigateBack({
							delta: 1
						});
						uni.removeStorageSync('editAddress');
					}).catch(res => {

					})
				}

			},
			//新增地址
			addAddressClick(){
				let phoneCodeVerification = /^[1][3-9][0-9]{9}$/;
				if(this.addressData.username==''){
					uni.showToast({
					    title: '请输入收货人!',
					    duration: 2000,
						icon:'none'
					});
				}else if(this.addressData.phone==''){
					uni.showToast({
					    title: '请输入手机号!',
					    duration: 2000,
						icon:'none'
					});
				}else if(!phoneCodeVerification.test(this.addressData.phone)){
				 	uni.showToast({
				 	    title: '请输入正确的手机号!',
				 	    duration: 2000,
				 		icon:'none'
				 	});
				 }else if(this.addressData.province==''||this.addressData.city==''){
					uni.showToast({
					    title: '所在地不能为空!',
					    duration: 2000,
						icon:'none'
					});
				}else if(this.addressData.address==''){
					uni.showToast({
					    title: '请输入详细地址!',
					    duration: 2000,
						icon:'none'
					});
				}else{
					NET.request(API.AddresAdd,
					{
						receiveName: this.addressData.username,
						receivePhone: this.addressData.phone,
						receiveAdress: this.addressData.ssqText,
						address:this.addressData.address,
						label:this.tag,
            ifDefault: this.ifDefault ? 1 : 0
					},'POST').then(res => {
						if(this.ordertype == 1){
							uni.setStorageSync('receiveItem', res.data)
							uni.navigateBack({
								delta: 2
							});
						}else{
							uni.navigateBack({
								delta: 1
							});
						}
					}).catch(res => {

					})
				}
			},
      // addAddressWx() {
      //   let self = this
      //   uni.chooseAddress({
      //     success(res){
      //       self.username = res.userName
      //       self.phone = res.telNumber
      //       self.ssqText =  `${res.provinceName}-${res.cityName}-${res.countyName}`
      //       self.defaultRegion = self.ssqText.split("-")
      //       self.address = res.detailInfo
      //       self.province = res.provinceName
      //       self.city = res.cityName
      //     }
      //   })
      // },
			//删除地址
			delAddress(){
				uni.showModal({
          title: '温馨提示',
          content: '是否删除此地址?',
          confirmText:'确定',
          cancelText:'取消',
          success: (res)=> {
            if (res.confirm) {
              this.subm()
            } else if (res.cancel) {
            }
          }
        })
			},
			subm(){
				NET.request(API.AddresDelete,{
					receiveId: this.id
				},'POST').then(res => {
					if(res.code === "200"){
						uni.navigateBack({
							delta: 1
						});
					}
				}).catch(res => {

				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #F7F7F7;
	}
	.container{
		.addressBack-box{
			background-color: #FFFFFF;
			padding: 30upx 30upx;
			.consignee-box{
				padding-bottom: 36upx;
				width: 690upx;
				margin-top: 20upx;
				.consignee{
					color: #999999;
					font-size: 28upx;
				}
			}
			.iphoneNum-box{
				padding-bottom: 36upx;
				width: 690upx;
				margin-top: 36upx;
				.iphoneNum{
					color: #999999;
					font-size: 28upx;
				}
			}
			.location-box{
				padding-bottom: 36upx;
				width: 690upx;
				margin-top: 36upx;
				.location{
					color: #999999;
					font-size: 28upx;
				}
        .locationBox {
          display: flex;
          align-items: center;
        }
			}
			.detailAddress-box{
				padding-bottom: 36upx;
				width: 690upx;
				margin-top: 36upx;
				input{
					width: 100%;
				}
				.detailAddress{
					color: #999999;
					font-size: 28upx;
				}
			}
		}
		.addressTagBack-box{
			background-color: #FFFFFF;
			padding: 30upx 30upx;
			margin-top: 20upx;
			.addressTag-box{
				padding-bottom: 36upx;
				width: 690upx;
				.addressTag{
					color: #999999;
					font-size: 28upx;
				}
			}
			.defaultState-box{
				padding-bottom: 10upx;
				width: 690upx;
				margin-top: 36upx;
				.defaultState{
					color: #999999;
					font-size: 28upx;
				}
			}
		}
		.arrow{
			width: 62upx;
			height: 62upx;
		}
		.saveAddress-box{
			position: fixed;
			bottom: 50upx;
			left: 30upx;
			.saveAddress{
				width: 690upx;
				height: 100upx;
				text-align: center;
				line-height: 100upx;
				background: #333333;
        color: #FFEBC4;
			}
		}
    .wxAddress {
      height: 80rpx;
      text-align: center;
      line-height: 80rpx;
      color: #999999;
      .wxBtnBox {
        width: 100rpx;
        height: 80rpx;
        image {
          width: 80rpx;
          height: 80rpx;
        }
      }
    }
	}
	.deleteAddress-box{
		background-color: #FFFFFF;
		padding: 30upx 30upx;
		margin-top: 20upx;
	}
	.content{
		font-size: 35rpx;
		width: 500rpx;
		.btn{
			margin-bottom: 20rpx;
			 width: 200rpx;
			 background-image: linear-gradient( 135deg, #FFA100 10%, #FF7911 100%);
		}
	}
</style>
<style scoped>
.addressBack-box /deep/ .u-tab-item{
  color: #C5AA7B !important;
  font-weight: 400 !important;
}
.addressBack-box /deep/ .u-tab-bar {
  background-color: #C5AA7B !important;
}
</style>