Init project

This commit is contained in:
lifizer
2023-09-20 21:49:33 +08:00
parent 85a5989c96
commit c9ceac9f37
710 changed files with 125705 additions and 0 deletions
+375
View File
@@ -0,0 +1,375 @@
<template>
<view class="addAddress absolute">
<view class="list">
<view class="item acea-row row-between-wrapper">
<view class="name">姓名</view>
<input type="text" placeholder="请输入姓名" v-model="userAddress.realName" required/>
</view>
<view class="item acea-row row-between-wrapper">
<view class="name">联系电话</view>
<input type="text" placeholder="请输入联系电话" v-model="userAddress.phone" required :maxlength="11"/>
</view>
<view class="item acea-row row-between-wrapper">
<view class="name">所在地区</view>
<view class="picker acea-row row-between-wrapper select-value form-control">
<view class="address">
<CitySelect
ref="cityselect"
:defaultValue="addressText"
@callback="result"
:items="district"
></CitySelect>
</view>
<view class="iconfont icon-dizhi font-color-red" @click="getCurAddress()"></view>
</view>
</view>
<view class="item acea-row row-between-wrapper" style="flex-wrap: nowrap;">
<view class="name">详细地址</view>
<input type="text" placeholder="请填写具体地址" v-model="userAddress.detail" required/>
<!-- <textarea v-model="userAddress.detail" placeholder="请填写具体地址" /> -->
</view>
</view>
<view class="default acea-row row-middle">
<view class="select-btn">
<view class="checkbox-wrapper">
<checkbox-group @change="ChangeIsDefault">
<label class="well-check">
<checkbox :checked="userAddress.isDefault ? true : false"></checkbox>
<text class="def">设置为默认地址</text>
</label>
</checkbox-group>
</view>
</view>
</view>
<view></view>
<view class="keepBnt bg-color-red" @tap="submit">立即保存</view>
<view class="wechatAddress" v-if="isWechat && !id" @click="getAddress">导入微信地址</view>
</view>
</template>
<script type="text/babel">
import CitySelect from "@/components/CitySelect";
import config from '@/utils/mapConfig';
import {getAddress, getCity, postAddress} from "@/api/user";
import attrs, {chs_extphone, required} from "@/utils/validate";
import {validatorDefaultCatch} from "@/utils/dialog";
// import { openAddress } from "@/libs/wechat";
import {isWeixin} from "@/utils";
export default {
name: "AddAddress",
components: {
CitySelect
},
computed: {},
data() {
return {
district: [],
id: 0,
userAddress: {isDefault: 0},
address: {},
isWechat: isWeixin(),
addressText: ""
};
},
mounted: function () {
let id = this.$yroute.query.id;
this.id = id;
if (this.id) {
uni.setNavigationBarTitle({
title: '编辑地址'
})
}
this.getUserAddress();
this.getCityList();
},
watch: {
// addressText(nextModel2) {
// console.log(nextModel2, 8585858585);
// }
//定位成功后回调
// province(newVal,oldVal){
// uni.hideLoading();
// //if(newVal!=oldVal){
// this.addressText =
// this.province + " " + this.city + " " + this.county;
// this.address.province = this.province;
// this.address.city = this.city;
// this.address.district = this.county;
// this.userAddress.detail = this.detailAddress;
// //}
// }
},
methods: {
getIndex(value, arr) {
var idx = -1;
for (var i = 0; i < arr.length; i++) {
if (arr[i].n == value) {
idx = i;
break;
}
}
return idx;
},
//获取当前定位地址
getCurAddress() {
var that = this;
//定位
uni.showLoading({
title: '定位中...'
});
//this.getLocation();
uni.getLocation({
type: 'wgs84',
success: function (res) {
let latitude = res.latitude;
let longitude = res.longitude;
console.log('latitude:' + latitude + 'longitude:' + longitude)
// #ifdef H5
Vue.jsonp(
'https://apis.map.qq.com/ws/geocoder/v1/?location=' + latitude + ',' + longitude + '&key=' + config.key,
{
//callbackName: 'QQmap',
output: 'jsonp',
}).then(json => {
// Success.
uni.hideLoading();
that.addressText =
json.result.ad_info.province + " " + json.result.ad_info.city + " " + json.result.ad_info.district;
that.address.province = json.result.ad_info.province;
that.address.city = json.result.ad_info.city;
that.address.district = json.result.ad_info.district;
that.$set(that.userAddress, 'detail', json.result.formatted_addresses.recommend);
//that.userAddress.detail = json.result.formatted_addresses.recommend;
// that.$refs.cityselect.adjustDefaultValue();
//设置city_id
var pIdx = that.getIndex(that.address.province, that.district);
if (pIdx > -1) {
var citys = that.district[pIdx].c;
var cIdx = that.getIndex(that.address.city, citys);
if (cIdx > -1) {
var city = citys[cIdx];
that.address.city_id = city.v;
console.log('city_id:' + city.v);
}
}
}).catch(err => {
// Failed.
console.log('地址解析失败:' + JSON.stringify(err));
uni.hideLoading();
})
// #endif
// #ifndef H5
uni.request({
url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=' + latitude + ',' + longitude + '&key=' + config.key,
success: function (res) {
// console.log('res:'+JSON.stringify(res.data));
uni.hideLoading();
that.addressText =
res.data.result.ad_info.province + " " + res.data.result.ad_info.city + " " + res.data.result.ad_info.district;
that.address.province = res.data.result.ad_info.province;
that.address.city = res.data.result.ad_info.city;
that.address.district = res.data.result.ad_info.district;
//that.userAddress.detail = res.data.result.formatted_addresses.recommend;
that.$set(that.userAddress, 'detail', res.data.result.formatted_addresses.recommend);
// that.$refs.cityselect.adjustDefaultValue();
//设置city_id
var pIdx = that.getIndex(that.address.province, that.district);
if (pIdx > -1) {
var citys = that.district[pIdx].c;
var cIdx = that.getIndex(that.address.city, citys);
if (cIdx > -1) {
var city = citys[cIdx];
that.address.city_id = city.v;
console.log('city_id:' + city.v);
}
}
},
fail: function (res) {
console.log('地址解析失败');
uni.hideLoading();
},
complete: function () {
}
});
// #endif
},
fail: function (res) {
uni.hideLoading();
// uni.showToast({
// title:'城市定位失败:'+JSON.stringify(res),
// icon:'none',
// duration:2000
// })
}
});
},
getCityList: function () {
let that = this;
getCity()
.then(res => {
that.district = res.data;
that.ready = true;
if (this.id) {
//设置city_id
var pIdx = that.getIndex(that.address.province, that.district);
if (pIdx > -1) {
var citys = that.district[pIdx].c;
var cIdx = that.getIndex(that.address.city, citys);
if (cIdx > -1) {
var city = citys[cIdx];
that.address.city_id = city.v;
console.log('city_id:' + city.v);
}
}
}
})
.catch(err => {
that.$dialog.error(err.msg);
});
},
getUserAddress: function () {
if (!this.id) return false;
let that = this;
getAddress(that.id).then(res => {
that.userAddress = res.data;
that.addressText =
res.data.province + " " + res.data.city + " " + res.data.district;
that.address.province = res.data.province;
that.address.city = res.data.city;
that.address.district = res.data.district;
if (that.district.length > 0) {
//设置city_id
var pIdx = that.getIndex(that.address.province, that.district);
if (pIdx > -1) {
var citys = that.district[pIdx].c;
var cIdx = that.getIndex(that.address.city, citys);
if (cIdx > -1) {
var city = citys[cIdx];
that.address.city_id = city.v;
console.log('city_id:' + city.v);
}
}
}
});
},
getAddress() {
},
async submit() {
let name = this.userAddress.realName,
phone = this.userAddress.phone,
addressText = this.addressText,
detail = this.userAddress.detail,
isDefault = this.userAddress.isDefault;
if (phone.length < 11) {
uni.showToast({
title: "请输入11位手机号码",
icon: "none"
})
return;
}
try {
await this.$validator({
name: [
required(required.message("姓名")),
attrs.range([2, 16], attrs.range.message("姓名"))
],
phone: [
required(required.message("联系电话")),
chs_extphone(chs_extphone.message())
//chs_phone(chs_phone.message())
],
addressText: [required("请选择地址")],
detail: [required(required.message("具体地址"))]
}).validate({name, phone, addressText, detail});
} catch (e) {
return validatorDefaultCatch(e);
}
try {
let that = this,
data = {
id: that.id,
real_name: name,
phone: phone,
address: this.address,
detail: detail,
is_default: isDefault ? true : false,
post_code: ""
};
postAddress(data).then(function () {
if (that.id) {
uni.showToast({
title: "修改成功",
icon: "none",
duration: 2000
});
} else {
uni.showToast({
title: "已取消绑定",
icon: "none",
duration: 2000
});
}
that.$yrouter.back();
});
} catch (err) {
uni.showToast({
title: err.msg || err.response.data.msg || err.response.data.message,
icon: "none",
duration: 2000
});
}
},
ChangeIsDefault: function () {
this.userAddress.isDefault = !this.userAddress.isDefault;
},
result(values) {
console.log(this);
console.log(values);
this.address = {
province: values.province.name || "",
city: values.city.name || "",
district: values.district.name || "",
city_id: values.city.id
};
this.addressText = `${this.address.province} ${this.address.city} ${this.address.district}`;
// this.addressText =
// this.address.province + this.address.city + this.address.district;
}
}
};
</script>
<style lang="less">
.address {
text {
width: 100%;
display: block;
}
}
</style>
@@ -0,0 +1,273 @@
<template>
<view
class="address-management"
:class="addressList.length < 1 && page > 1 ? 'on' : ''"
ref="container"
>
<view style="margin-bottom: 12rpx;" class="line" v-if="addressList.length > 0">
<image :src="webUrl+'/20230304135025917856.png'"/>
</view>
<view style="position: relative;" class="item" v-for="(item, addressListIndex) in addressList"
:key="addressListIndex" @click="tapAddress(item)">
<view v-if="item.isDefault||item.isDefault=='1' ? true : false" class=""
style="position: absolute;top: 0;right: 0;">
<image style="width: 72rpx;height: 36rpx;" :src="webUrl+'/20210807165228290910.png'" mode=""></image>
</view>
<view class="address">
<view class="consignee">
收货人:{{ item.realName }}
<text class="phone">{{ item.phone }}</text>
</view>
<view style="color: #8B8F99;">
收货地址:{{ item.province }}{{ item.city }}{{
item.district
}}{{ item.detail }}
</view>
</view>
<view v-if="!chooseMode" class="operation acea-row row-between-wrapper">
<view class="select-btn">
<view class="checkbox-wrapper">
<checkbox-group @change.stop="radioChange(item.id)">
<label class="well-check acea-row row-middle">
<checkbox style="transform: scale(0.55);"
:checked="item.isDefault||item.isDefault=='1' ? true : false"></checkbox>
<text class="default" style="margin-left: -10rpx;">设为默认</text>
</label>
</checkbox-group>
</view>
</view>
<view class="acea-row row-middle">
<view @click.stop="editAddress(addressListIndex)" style="color: #B3BCBF;">
<text class="iconfont icon-bianji" style="color: #B3BCBF;"></text>
<text>修改</text>
</view>
<view @click.stop="delAddress(addressListIndex)" style="color: #B3BCBF;">
<text class="iconfont icon-shanchu" style="color: #B3BCBF;"></text>
<text>删除</text>
</view>
</view>
</view>
</view>
<Loading :loaded="loadend" :loading="loading"></Loading>
<view class="noCommodity" v-if="addressList.length < 1 && page > 1">
<view class="noPictrue">
<image :src="webUrl+'/20210203154438492268.png'" class="image"/>
</view>
</view>
<view style="height:100rpx;"></view>
<view class="footer acea-row row-between-wrapper">
<view class="addressBnt bg-color-lightred" v-if="isWechat" @click="addAddress">
<text class="iconfont icon-tianjiadizhi"></text>
添加新地址
</view>
<view class="addressBnt on bg-color-lightred" v-else @click="addAddress">
<text class="iconfont icon-tianjiadizhi"></text>
添加新地址
</view>
<!--<view class="addressBnt wxbnt" v-if="isWechat" @click="getAddress">-->
<!--<text class="iconfont icon-weixin2"></text>导入微信地址-->
<!--</view>-->
</view>
</view>
</template>
<style scoped lang="less">
.address-management.on {
background-color: #fff;
height: 100vh;
}
</style>
<script type="text/babel">
import {getAddressDefaultSet, getAddressList, getAddressRemove} from "@/api/user";
import Loading from "@/components/Loading";
import {isWeixin} from "@/utils";
export default {
components: {
Loading
},
data() {
return {
webUrl: this.$VUE_APP_RESOURCES_URL,
page: 1,
limit: 20,
chooseMode: false,//是否选择地址模式
addressList: [],
loadTitle: "",
loading: false,
loadend: false,
isWechat: isWeixin()
};
},
mounted: function () {
this.AddressList();
},
onReachBottom() {
!this.loading && this.AddressList();
},
onLoad: function (e) {
//是否选择模式
if (this.$yroute.query.choosMode != undefined) {
this.chooseMode = true;
uni.setNavigationBarTitle({
title: '选择收货地址'
})
} else {
this.chooseMode = false;
}
},
onShow: function () {
this.refresh();
},
methods: {
tapAddress: function (item) {
if (this.chooseMode) {
//通知前一界面修改地址
uni.$emit('chooseAddress', item)
//关闭当前页面
this.$yrouter.back();
}
},
refresh: function () {
this.addressList = [];
this.page = 1;
this.loadend = false;
this.AddressList();
},
/**
* 获取地址列表
*
*/
AddressList: function () {
let that = this;
if (that.loading) return; //阻止下次请求(false可以进行请求);
if (that.loadend) return; //阻止结束当前请求(false可以进行请求);
that.loading = true;
getAddressList({page: that.page, limit: that.limit}).then(res => {
that.loading = false;
//apply();js将一个数组插入另一个数组;
that.addressList.push.apply(that.addressList, res.data);
that.loadend = res.data.length < that.limit; //判断所有数据是否加载完成;
that.page = that.page + 1;
});
},
/**
* 编辑地址
*/
editAddress: function (index) {
this.$yrouter.push({
path: "/pages/user/address/AddAddress/index",
query: {id: this.addressList[index].id}
});
},
/**
* 删除地址
*/
delAddress: function (index) {
let that = this;
let address = this.addressList[index];
let id = address.id;
uni.showModal({
title: '确认删除此收货地址?',
content: '',
showCancel: true,
cancelText: '取消',
confirmText: '确认',
success: res => {
if (res.confirm) {
getAddressRemove(id).then(function () {
uni.showToast({
title: "删除成功!",
icon: "success",
duration: 2000,
complete: () => {
that.addressList.splice(index, 1);
that.$set(that, "addressList", that.addressList);
}
});
});
}
},
fail: () => {
},
complete: () => {
}
});
},
/**
* 设置默认地址
*/
radioChange: function (id) {
getAddressDefaultSet(id).then(res => {
this.refresh();
uni.showToast({title: res.msg, icon: "none", duration: 2000});
});
},
/**
* 新增地址
*/
addAddress: function () {
this.$yrouter.push({
path: "/pages/user/address/AddAddress/index"
});
},
getAddress() {
// openAddress().then(userInfo => {
// uni.showLoading({ title: "加载中" });
// postAddress({
// real_name: userInfo.userName,
// phone: userInfo.telNumber,
// address: {
// province: userInfo.provinceName,
// city: userInfo.cityName,
// district: userInfo.countryName
// },
// detail: userInfo.detailInfo,
// post_code: userInfo.postalCode,
// wx_export: 1
// })
// .then(() => {
// this.page = 1;
// this.loading = false;
// this.loadend = false;
// this.addressList = [];
// this.AddressList();
// uni.hideLoading();
// uni.showToast({
// title: "添加成功",
// icon: 'success',
// duration: 2000
// });
// })
// .catch(err => {
// uni.hideLoading();
// uni.showToast({
// title: err.msg || err.response.data.msg|| err.response.data.message,
// icon: 'none',
// duration: 2000
// });
// });
// });
}
}
};
</script>
<style scoped lang="less">
.address-management .item {
box-shadow: 0px 6rpx 6rpx rgba(0, 0, 0, 0.1);
opacity: 1;
border-radius: 16rpx;
margin-left: 32rpx;
margin-right: 32rpx;
}
</style>