初始化代码

This commit is contained in:
2025-12-22 17:13:05 +08:00
parent ed0de08e3a
commit 1f7e9d401b
2947 changed files with 526137 additions and 0 deletions

View File

@@ -0,0 +1,278 @@
<template>
<view class="mine-address-edit" v-if="isLoad">
<view class="fill-base f-title">
<view class="flex-between pd-lg b-1px-b">
<view>联系人</view>
<input v-model="subForm.user_name" type="text" class="flex-1 f-paragraph text-right"
placeholder-class="c-placeholder" :placeholder="rule[0].errorMsg" />
</view>
<view class="flex-between pd-lg b-1px-b">
<view>手机号</view>
<input v-model="subForm.mobile" type="number" class="flex-1 f-paragraph text-right"
placeholder-class="c-placeholder" :placeholder="rule[1].errorMsg" />
<button open-type="getPhoneNumber" @getphonenumber="toAuthPhone" class="clear-btn"
:style="{color:primaryColor,marginLeft:'15rpx',fontSize:'28rpx'}">授权</button>
</view>
<view class="flex-between pd-lg b-1px-b">
<view class="flex-1">选择地区</view>
<view @tap.stop="toChooseLocation" class="flex-y-center f-paragraph max-500 text-right">
<view class="flex-1 text-right"
:class="[{'c-placeholder':!subForm.address},{'c-title':subForm.address}]">
{{subForm.address || `点击右边图标设置`}}
</view><i class="iconfont icon-dingwei-fill ml-sm" :style="{color: primaryColor}"></i>
</view>
</view>
<view class="pd-lg f-title">
<view>详细地址</view>
<textarea class="pt-lg textarea-item f-paragraph" v-model="subForm.address_info" maxlength="100"
placeholder-class="c-placeholder" :placeholder="rule[3].errorMsg"></textarea>
</view>
</view>
<view class="fill-base mt-md pt-sm pb-sm pl-lg pr-lg f-paragraph">
<view class="flex-between">
<view class="f-paragraph">设为默认地址</view>
<view @tap.stop="toSetItem" class="flex-1 text-right">
<i class="iconfont icon-switch ml-sm" :class="[{'icon-switch-on':subForm.status==1}]"
:style="{color: subForm.status==1 ? primaryColor : '#999'}"></i>
</view>
</view>
</view>
<view class="f-caption c-title mt-md pl-lg"> 设置后下单时优先展示该地址</view>
<view class="space-max-footer"></view>
<fix-bottom-button @cancel="$refs.del_item.open()" @confirm="confirmSubmit"
:text="subForm.id?[{text: '删除',type: 'cancel'}, {text: '保存',type: 'confirm'}]:[{text: '提交',type: 'confirm'}]"
bgColor="#fff"></fix-bottom-button>
<common-popup @confirm="confirmDel" ref="del_item" type="DEL_ITEM" :info="popupInfo"></common-popup>
</view>
</template>
<script>
import {
mapState,
mapActions,
mapMutations
} from "vuex"
export default {
components: {},
data() {
return {
isLoad: false,
options: {},
subForm: {
id: 0,
user_name: '',
mobile: '',
address: '',
address_info: '',
province:'',
lng: '',
lat: '',
status: 0
},
rule: [{
name: "user_name",
checkType: "isNotNull",
errorMsg: "请输入联系人姓名",
regType: 2
}, {
name: "mobile",
checkType: "isMobile",
errorMsg: "请输入手机号"
},
{
name: "address",
checkType: "isNotNull",
errorMsg: "设置地区"
},
{
name: "address_info",
checkType: "isNotNull",
errorMsg: "请输入街道、楼牌号等",
regType: 2
},
],
lockTap: false,
popupInfo: {}
}
},
computed: mapState({
primaryColor: state => state.config.configInfo.primaryColor,
subColor: state => state.config.configInfo.subColor,
userInfo: state => state.user.userInfo,
}),
onLoad(options) {
this.options = options
this.initIndex()
},
methods: {
...mapActions(['getAuthPhone']),
...mapMutations(['updateOrderItem']),
async initIndex() {
let {
id = 0
} = this.options
uni.setNavigationBarTitle({
title: id ? `编辑地址` : `新增地址`
})
if (!id) {
this.isLoad = true
this.subForm.mobile = this.userInfo.phone
return
}
this.$util.showLoading()
let data = await this.$api.mine.addressInfo({
id
})
for (let key in this.subForm) {
this.subForm[key] = data[key]
}
this.isLoad = true
this.$util.hideAll()
},
// 授权手机号
async toAuthPhone(e) {
let phone = await this.getAuthPhone({
e,
})
if (!phone) return
this.$nextTick(() => {
this.subForm.mobile = phone
})
},
// 选择地区
async toChooseLocation(e) {
await this.$util.checkAuth({
type: 'userLocation'
})
let [, {
address = '',
longitude,
latitude
} = {}] = await uni.chooseLocation();
if (!address) return
let reg = /.+?(省|市|自治区|自治州|区)/g
this.subForm.province = address.match(reg)[0]
this.subForm.address = address
this.subForm.lng = longitude
this.subForm.lat = latitude
},
toSetItem() {
this.subForm.status = this.subForm.status == 1 ? 0 : 1
},
// 确认:删除
async confirmDel() {
let {
id
} = this.subForm
let {
check_id
} = this.$util.getPage(-1)
if (this.lockTap) return
this.lockTap = true
this.$util.showLoading()
try {
await this.$api.mine.addressDel({
id
})
this.lockTap = false
this.$util.hideAll()
this.$util.showToast({
title: `删除成功`
})
this.$refs.del_item.close()
if (id == check_id) {
this.updateOrderItem({
key: 'haveOperItem',
val: true
})
}
setTimeout(() => {
this.$util.back()
this.$util.goUrl({
url: 1,
openType: `navigateBack`
})
}, 1000)
} catch (e) {
setTimeout(() => {
this.lockTap = false
this.$util.hideAll()
}, 2000)
}
},
//表单验证
validate(param) {
let validate = new this.$util.Validate();
this.rule.map(item => {
let {
name,
} = item
validate.add(param[name], item);
})
let message = validate.start();
return message;
},
// 新增/编辑
async confirmSubmit() {
let param = this.$util.deepCopy(this.subForm)
let msg = this.validate(param);
if (msg) {
this.$util.showToast({
title: msg
});
return;
}
if (this.lockTap) return
this.lockTap = true
this.$util.showLoading()
try {
let methodModel = param.id ? `addressUpdate` : `addressAdd`
await this.$api.mine[methodModel](param)
this.$util.hideAll()
this.$util.showToast({
title: `保存成功`,
});
this.lockTap = false;
setTimeout(() => {
this.$util.back()
this.$util.goUrl({
url: 1,
openType: `navigateBack`
})
}, 1000)
} catch (e) {
setTimeout(() => {
this.lockTap = false
this.$util.hideAll()
}, 2000)
}
}
}
}
</script>
<style lang="scss">
.mine-address-edit {
.icon-dingwei-fill {
font-size: 40rpx;
}
.icon-switch,
.icon-switch-on {
font-size: 80rpx;
}
.textarea-item {
width: 690rpx;
height: 200rpx;
overflow-y: auto;
}
}
</style>

View File

@@ -0,0 +1,279 @@
<template>
<view class="mine-address-list">
<view @tap.stop="toUpdateItem(index)" class="list-item fill-base mt-md" v-for="(item,index) in list.data"
:key="index">
<view class="flex-warp pd-lg b-1px-b">
<view class="address-icon flex-center c-base radius" :style="{background:primaryColor}"><i
class="iconfont icon-dingwei-fill"></i></view>
<view class="address-info flex-1 ml-md">
<view class="flex-y-baseline username c-title text-bold">{{item.user_name}}
<view class="ml-md f-desc c-paragraph">{{item.mobile}}</view>
</view>
<view class="f-desc c-title">{{`${item.address} ${item.address_info}`}}</view>
</view>
</view>
<view class="oper-info pl-lg pr-lg f-paragraph c-paragraph flex-between">
<view class="flex-y-center"
:style="{color:options.check && item.id == check_id || !options.check && item.status==1 ?primaryColor:''}">
<i class="iconfont icon-xuanze mr-sm"
:class="[{'icon-xuanze-fill':options.check && item.id == check_id || !options.check && item.status==1}]"
:style="{color:options.check && item.id == check_id || !options.check && item.status==1?primaryColor:''}"></i>
<block v-if="options.check">{{item.id == check_id ?'当前选择地址':'点击选择'}}</block>
<block v-else>{{item.status ==1?'默认地址':'设为默认'}}</block>
</view>
<view class="flex-center">
<view @tap.stop="goDetail(index)" class="pl-lg pr-lg">编辑</view>
<view @tap.stop="toDel(index)" class="pl-lg">删除</view>
</view>
</view>
</view>
<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading" v-if="loading">
</load-more>
<abnor title="暂未设置地址信息" :tip="[{ text: '点击下方按钮添加', color: 0 }]"
v-if="!loading&&list.data.length<=0&&list.current_page==1">
</abnor>
<view class="space-max-footer"></view>
<fix-bottom-button @confirm="$util.goUrl({url:`/mine/pages/address/edit`})"
:text="[{text:'新增地址',type:'confirm'}]"></fix-bottom-button>
<common-popup @confirm="confirmDel" ref="del_item" type="DEL_ITEM" :info="popupInfo"></common-popup>
</view>
</template>
<script>
import {
mapState,
mapMutations
} from "vuex"
export default {
components: {},
data() {
return {
options: {},
check_id: 0,
param: {
page: 1,
},
list: {
data: []
},
loading: true,
lockTap: false,
popupInfo: {}
}
},
computed: mapState({
primaryColor: state => state.config.configInfo.primaryColor,
subColor: state => state.config.configInfo.subColor,
userInfo: state => state.user.userInfo,
haveOperItem: state => state.order.haveOperItem,
}),
onLoad(options) {
let {
check = 0
} = options
// check 1土地/认养/商城下单选择地址2认养配送选择地址3土地配送选择地址
options.check = check
if (check) {
let {
id = 0
} = check == 1 ? this.$util.getPage(-1).orderInfo.address : this.$util.getPage(-1).address_info
this.check_id = id
}
this.options = options
this.updateOrderItem({
key: 'haveOperItem',
val: false
})
this.initIndex()
},
onUnload() {
let {
check = 0,
} = this.options
let {
haveOperItem
} = this
if (check && haveOperItem) {
if (check == 1) {
this.$util.getPage(-1).orderInfo.address = {}
} else {
this.$util.getPage(-1).address_info = {}
}
this.$util.back()
}
},
onPullDownRefresh() {
// #ifndef APP-PLUS
uni.showNavigationBarLoading()
// #endif
this.initRefresh()
uni.stopPullDownRefresh()
},
onReachBottom() {
if (this.list.current_page >= this.list.last_page || this.loading) return
this.param.page = this.param.page + 1
this.loading = true
this.getList()
},
methods: {
...mapMutations(['updateOrderItem']),
initIndex() {
this.getList()
},
initRefresh() {
this.param.page = 1
this.initIndex()
},
async getList() {
let {
list: oldList,
param,
check_id = 0
} = this
let {
check = 0
} = this.options
let newList = await this.$api.mine.addressList(param);
if (this.param.page == 1) {
this.list = newList
let arr = newList.data.filter(item => {
return item.id == check_id
})
if (check && arr.length > 0) {
if (check == 1) {
this.$util.getPage(-1).orderInfo.address = arr[0]
this.$util.back()
} else {
this.$util.getPage(-1).address_info = arr[0]
if (check == 3) {
this.$util.getPage(-1).detail.address_info = arr[0]
}
}
}
} else {
newList.data = oldList.data.concat(newList.data)
this.list = newList
}
this.loading = false
this.$util.hideAll()
},
async toUpdateItem(index) {
let {
check = 0
} = this.options
let item = this.list.data[index]
// check 1下单选择地址2发起配送选择地址
if (check) {
if (check == 1) {
this.$util.getPage(-1).orderInfo.address = item
this.$util.back()
} else {
this.$util.getPage(-1).address_info = item
}
this.$util.goUrl({
url: 1,
openType: `navigateBack`
})
} else {
let {
id,
status
} = item
await this.$api.mine.addressUpdate({
id,
status: status == 0 ? 1 : 0
})
this.initRefresh()
}
},
// 弹窗:删除
async toDel(index) {
let {
id,
} = this.list.data[index]
this.popupInfo = {
id,
name: '',
image: '',
index,
}
this.$refs.del_item.open()
},
async confirmDel() {
let {
id,
index,
} = this.popupInfo
let {
check_id
} = this
if (this.lockTap) return
this.lockTap = true
this.$util.showLoading()
try {
await this.$api.mine.addressDel({
id
})
this.lockTap = false
this.$util.hideAll()
this.$util.showToast({
title: `删除成功`
})
this.list.data.splice(index, 1)
this.$refs.del_item.close()
if (id == check_id) {
this.updateOrderItem({
key: 'haveOperItem',
val: true
})
}
} catch (e) {
setTimeout(() => {
this.lockTap = false
this.$util.hideAll()
}, 2000)
}
},
goDetail(index) {
let {
id
} = this.list.data[index]
let url = `/mine/pages/address/edit?id=${id}`
this.$util.goUrl({
url
})
},
}
}
</script>
<style lang="scss">
.mine-address-list {
.address-icon {
width: 64rpx;
height: 64rpx;
.iconfont {
font-size: 38rpx;
}
}
.address-info {
max-width: 606rpx;
}
.username {
font-size: 30rpx;
}
.oper-info {
height: 80rpx;
}
}
</style>