emis-sapp/pages/address/edit.vue

204 lines
6.2 KiB
Vue
Raw Normal View History

2023-12-05 14:16:45 +00:00
<template>
2024-06-03 08:45:36 +00:00
<tpx-page>
<tpx-layout>
<template v-slot:body>
<view class="com-jianju pos-rlt pb-30" style="padding-top: 2rpx;">
<view class="blcok-white radius-20">
<u-textarea v-model="ansValue" border="none" height="110" placeholder="粘贴或输入地址,点击“智能识别”自动拆分姓名、电话和地址" custom-style="border:0;padding: 0;"></u-textarea>
<u-row justify="end">
<view class="mt-10">
<u-button @click="handleAnsText()" type="primary" size="mini" shape="circle" custom-style="width: 130rpx;font-size: 24rpx;padding:0;">智能识别</u-button>
</view>
</u-row>
</view>
<view class="blcok-white radius-20">
<view class="">
2024-12-06 09:35:49 +00:00
<view style="margin-top: 10rpx;" class="mt-10 lbRequiredDot">
2024-08-02 08:09:52 +00:00
<tpx-input v-model:value="submitParam.name" placeholder="真实姓名"></tpx-input>
2024-12-06 09:35:49 +00:00
</view>
<view class="mt-30 lbRequiredDot">
<tpx-input v-model:value="submitParam.phone" placeholder="电话"></tpx-input>
2024-08-02 08:09:52 +00:00
</view>
<view class="mt-40 pos-rlt lbRequiredDot">
2024-06-03 08:45:36 +00:00
<tpx-input :value="getAddressDetail(submitParam, false)" placeholder="所在地区"></tpx-input>
<view @click="handleDialogClick(addressModal)" class="pos-abt-all"></view>
</view>
2024-12-06 09:35:49 +00:00
<view class="mt-30 pos-rlt">
2024-08-02 08:09:52 +00:00
<view class="lbRequiredDot mt-30" style="position: absolute;"></view>
2024-06-03 08:45:36 +00:00
<tpx-textarea v-model:value="submitParam.address" placeholder="详细地址(例如**街道**号**)"></tpx-textarea>
</view>
<view class="mt-30">
<tpx-input v-model:value="submitParam.postCode" placeholder="邮编"></tpx-input>
</view>
<view class="mt-30">
<tpx-input v-model:value="submitParam.email" placeholder="邮箱(选填"></tpx-input>
</view>
2024-12-06 09:35:49 +00:00
<view class="mt-30 lbRequiredDot">
<tpx-input v-model:value="submitParam.company" placeholder="公司名称"></tpx-input>
2024-06-03 08:45:36 +00:00
</view>
2023-12-05 18:05:39 +00:00
</view>
2024-06-03 08:45:36 +00:00
</view>
2023-12-05 16:35:57 +00:00
2024-06-03 08:45:36 +00:00
<view class="mt-30 pl-30 pr-30">
<u-row justify="between">
<view>
<u-checkbox-group v-model="submitParam.blDefaultFlag" placement="column">
<u-checkbox
:name="true"
shape="circle"
size="30" label="默认地址" active-color="#B12D29"
label-size="28"
>
</u-checkbox>
</u-checkbox-group>
</view>
<view @click="handleReset">
<u-text text="清空" size="28" color="#0E0708"></u-text>
</view>
</u-row>
2023-12-05 16:35:57 +00:00
</view>
</view>
2024-06-03 08:45:36 +00:00
</template>
<template v-slot:footer>
<view class="blcok-white-noradius">
<u-button @click="handleSubmit()" type="primary" size="large" shape="circle"
custom-style="height:80rpx;font-size: 30rpx;"
>确定</u-button>
2023-12-05 18:05:39 +00:00
</view>
2024-06-03 08:45:36 +00:00
</template>
</tpx-layout>
<buns-address-sheet v-model:show="addressModal.show" v-model:value="addressModal.values" @onSure="handleAddressChoose"></buns-address-sheet>
</tpx-page>
2023-12-05 14:16:45 +00:00
</template>
2023-12-05 18:05:39 +00:00
2023-12-05 14:16:45 +00:00
<script>
2024-06-03 08:45:36 +00:00
import { getAddressModels } from "./model"
import * as apiService from "@/common/api"
import { addressNameCodeMap } from "@/common/enum"
2024-06-11 01:16:31 +00:00
import { pageEventNames } from "@/common/enum"
2024-06-03 08:45:36 +00:00
import { getAddressDetail, setAddresModalParam } from "@/common/util"
2024-06-20 14:27:46 +00:00
import { checkParams } from "@/common/validate"
2024-06-03 08:45:36 +00:00
2023-12-05 14:16:45 +00:00
export default {
props: {
},
2023-12-05 16:35:57 +00:00
computed: {
2023-12-05 18:05:39 +00:00
2023-12-05 16:35:57 +00:00
},
2023-12-05 14:16:45 +00:00
data() {
return {
2024-06-03 08:45:36 +00:00
queryOption: {
2024-06-11 01:16:31 +00:00
id: undefined,
addressType: undefined, // 1寄件 2收件
listQuery: {}
2024-06-03 08:45:36 +00:00
},
addressModal: {
show: false,
values: {
regIds: [],
regNames: []
}
},
ansValue: '',
2023-12-05 18:05:39 +00:00
submitParam: {
2024-06-03 08:45:36 +00:00
...getAddressModels(),
2024-06-20 14:27:46 +00:00
},
submitValidConfig: {
name: { required: true, requiredMsg: '姓名不能为空' },
phone: { required: true, requiredMsg: '手机号不能为空' },
country: { required: true, requiredMsg: '国家不能为空' },
province: { required: true, requiredMsg: '省份不能为空' },
2024-12-06 09:35:49 +00:00
address: { required: true, requiredMsg: '详细地址不能为空' },
company: { required: true, requiredMsg: '公司名称不能为空' },
2024-06-20 14:27:46 +00:00
},
2023-12-05 14:16:45 +00:00
}
},
onShareAppMessage() {
return {
2023-12-05 16:35:57 +00:00
// title: '',
2023-12-05 14:16:45 +00:00
// path: 'TODO'
}
},
2024-06-03 08:45:36 +00:00
onLoad(queryOption) {
this.queryOption = queryOption
2023-12-05 16:35:57 +00:00
this.initData();
},
onUnload() {
2023-12-05 18:05:39 +00:00
2023-12-05 16:35:57 +00:00
},
2023-12-05 14:16:45 +00:00
methods: {
2024-06-03 08:45:36 +00:00
getAddressDetail,
async initData() {
if(this.queryOption.id) {
let res = await apiService.getAddressById({ id: this.queryOption.id, _loading: true })
if(res.data.blDefaultFlag) {
res.data.blDefaultFlag = [true]
}
// 回显 国家-省市区组件数据
this.addressModal.values = setAddresModalParam(res.data);
this.submitParam = res.data
}
2023-12-05 16:35:57 +00:00
},
2024-06-03 08:45:36 +00:00
async handleAnsText(){
let res = await apiService.parseAddress({ content: this.ansValue, _loading: true })
let data = res.data || {}
this.addressModal.values = setAddresModalParam(data);
Object.assign(this.submitParam, data)
2023-12-05 16:35:57 +00:00
},
2024-12-06 09:35:49 +00:00
handleAddressChoose(data) {
addressNameCodeMap.map((nameCodeMap, index)=> {
this.submitParam[nameCodeMap.codeKey] = data.regIds[index]
this.submitParam[nameCodeMap.nameKey] = data.regNames[index]
2024-06-03 08:45:36 +00:00
})
},
handleReset(){
this.submitParam = getAddressModels()
this.addressModal.values = {
regIds: [],
regNames: [],
}
2023-12-05 16:35:57 +00:00
},
2024-06-03 08:45:36 +00:00
async handleSubmit() {
let params = { ...this.submitParam }
2024-06-20 14:27:46 +00:00
await checkParams(params, this.submitValidConfig)
2024-06-03 08:45:36 +00:00
let curServiceHand = apiService.addAddress
if(this.queryOption.id) {
curServiceHand = apiService.editAddress
2024-06-11 01:16:31 +00:00
} else {
params.addressType = this.queryOption.addressType
2024-06-03 08:45:36 +00:00
}
params.blDefaultFlag = Number(!!(params.blDefaultFlag && params.blDefaultFlag.length > 0));
await curServiceHand({ ...params, _loading: true })
this.showToast("操作成功")
2024-06-11 01:16:31 +00:00
uni.$emit(pageEventNames.addressSaveSuccess, {
data: params
})
2024-06-03 08:45:36 +00:00
this.goBack()
2023-12-05 16:35:57 +00:00
},
2024-06-03 08:45:36 +00:00
handleDialogClick(curModal) {
curModal.show = true
}
2023-12-05 14:16:45 +00:00
}
}
</script>
<style lang="scss">
@import '@/common/uni-nvue.scss';
2023-12-05 18:05:39 +00:00
2023-12-05 16:35:57 +00:00
page {
background-color: #F6F6F6;
height: 100% !important;
2023-12-05 14:16:45 +00:00
}
2023-12-05 16:35:57 +00:00
</style>
<style scoped lang="scss">
</style>