收货地址

msb_beta
ch 4 years ago
parent 8b68af9ad7
commit 019197fc61

@ -2,23 +2,23 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-17 16:38:39 * @Date: 2022-03-17 16:38:39
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-04-06 09:59:52 * @LastEditTime: 2022-04-07 09:58:19
* @Description: file content * @Description: file content
*/ */
import {ToAsyncAwait, MsbRequest} from '@/common/utils'; import {ToAsyncAwait, MsbRequestTk} from '@/common/utils';
const BASE_URL = '/uc' const BASE_URL = '/uc';
/**
* 获取当前登录用户信息
*/
export const ApiGetCurrentUser = () =>
ToAsyncAwait(MsbRequestTk.get(`${BASE_URL}/user/current`));
const ApiGetCurrentUser = () => /**
ToAsyncAwait(MsbRequest.get(`${BASE_URL}/user/current`)); * 修改用户信息
* @param {*} data
const ApiPutUser = (data) => */
ToAsyncAwait(MsbRequest.put(`${BASE_URL}/user/`, data)) export const ApiPutUser = (data) =>
export { ToAsyncAwait(MsbRequestTk.put(`${BASE_URL}/user/`, data));
// 获取当前登录用户信息
ApiGetCurrentUser,
// 修改用户信息
ApiPutUser
}

@ -0,0 +1,31 @@
/*
* @Author: ch
* @Date: 2022-04-06 17:29:13
* @LastEditors: ch
* @LastEditTime: 2022-04-07 09:58:34
* @Description: file content
*/
import {ToAsyncAwait, MsbRequestTk} from '@/common/utils';
const BASE_URL = '/mall/base';
/**
* 获取收货地址
*/
export const ApiGetAddress = () =>
ToAsyncAwait(MsbRequestTk.get(`${BASE_URL}/receiveAddress`));
/**
* 新增收货地址
*/
export const ApiPostAddress = (data) =>
ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/receiveAddress`, data));
/**
* 修改
*/
export const ApiPutAddress = (data) =>
ToAsyncAwait(MsbRequestTk.put(`${BASE_URL}/receiveAddress`, data));
/**
* 删除
*/
export const ApiDeleteAddress = (data) =>
ToAsyncAwait(MsbRequestTk.delete(`${BASE_URL}/receiveAddress?idList=${data.idList}`));

@ -2,11 +2,11 @@
* @Author: ch * @Author: ch
* @Date: 2022-04-06 10:14:03 * @Date: 2022-04-06 10:14:03
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-04-06 15:49:07 * @LastEditTime: 2022-04-07 09:58:43
* @Description: file content * @Description: file content
*/ */
import {ToAsyncAwait, MsbRequest} from '@/common/utils'; import {ToAsyncAwait, MsbRequestTk} from '@/common/utils';
const BASE_URL = '/mall/product'; const BASE_URL = '/mall/product';
@ -15,24 +15,24 @@ const BASE_URL = '/mall/product';
* @param {id,number} data * @param {id,number} data
*/ */
export const ApiPutCartNum = (data) => export const ApiPutCartNum = (data) =>
ToAsyncAwait(MsbRequest.put(`${BASE_URL}/shoppingCart/number`, data)); ToAsyncAwait(MsbRequestTk.put(`${BASE_URL}/shoppingCart/number`, data));
/** /**
* 往购物车中添加商品 * 往购物车中添加商品
* @param {prodcutId, productSkuId, number} data * @param {prodcutId, productSkuId, number} data
*/ */
export const ApiPutAddCart = (data) => export const ApiPutAddCart = (data) =>
ToAsyncAwait(MsbRequest.put(`${BASE_URL}/shoppingCart/increase`, data)); ToAsyncAwait(MsbRequestTk.put(`${BASE_URL}/shoppingCart/increase`, data));
/** /**
* 删除购物车中的商品 * 删除购物车中的商品
* @param {idList} data * @param {idList} data
*/ */
export const ApiDeleteCartGoods = (data) => export const ApiDeleteCartGoods = (data) =>
ToAsyncAwait(MsbRequest.delete(`${BASE_URL}/shoppingCart?idList=${data.idList}`, data)); ToAsyncAwait(MsbRequestTk.delete(`${BASE_URL}/shoppingCart?idList=${data.idList}`, data));
/** /**
* 获取购物车列表 * 获取购物车列表
*/ */
export const ApiGetCartList = () => export const ApiGetCartList = () =>
ToAsyncAwait(MsbRequest.get(`${BASE_URL}/shoppingCart`)); ToAsyncAwait(MsbRequestTk.get(`${BASE_URL}/shoppingCart`));

@ -2,10 +2,10 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-29 17:38:17 * @Date: 2022-03-29 17:38:17
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-04-06 10:01:40 * @LastEditTime: 2022-04-07 09:58:52
* @Description: file content * @Description: file content
*/ */
import {ToAsyncAwait, MsbRequest} from '@/common/utils'; import {ToAsyncAwait, MsbRequestTk} from '@/common/utils';
const BASE_URL = '/mall/trade'; const BASE_URL = '/mall/trade';
@ -14,39 +14,39 @@ const BASE_URL = '/mall/trade';
* @param {*} params * @param {*} params
*/ */
export const ApiGetOrderList = (params) => export const ApiGetOrderList = (params) =>
ToAsyncAwait(MsbRequest.get(`${BASE_URL}/app/tradeOrder/page`, params)); ToAsyncAwait(MsbRequestTk.get(`${BASE_URL}/app/tradeOrder/page`, params));
/** /**
* 获取预订单 * 获取预订单
* @param {*} data * @param {*} data
*/ */
export const ApiGetBeforeOrder = (data) => export const ApiGetBeforeOrder = (data) =>
ToAsyncAwait(MsbRequest.get(`${BASE_URL}/app/tradeOrder/buyAdvanceOrder`, data)); ToAsyncAwait(MsbRequestTk.get(`${BASE_URL}/app/tradeOrder/buyAdvanceOrder`, data));
/** /**
* 订单详情 * 订单详情
* @param {*} id * @param {*} id
*/ */
export const ApiGetOrderDetail = (id) => export const ApiGetOrderDetail = (id) =>
ToAsyncAwait(MsbRequest.get(`${BASE_URL}/app/tradeOrder/${id}`)); ToAsyncAwait(MsbRequestTk.get(`${BASE_URL}/app/tradeOrder/${id}`));
/** /**
* 提交订单 * 提交订单
* @param {*} data * @param {*} data
*/ */
export const ApiPostSubmitOrder = (data) => export const ApiPostSubmitOrder = (data) =>
ToAsyncAwait(MsbRequest.post(`${BASE_URL}/app/tradeOrder/submitOrder`, data)); ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/app/tradeOrder/submitOrder`, data));
/** /**
* 取消订单 * 取消订单
* @param {*} data * @param {*} data
*/ */
export const ApiPutCancelOrder = (data) => export const ApiPutCancelOrder = (data) =>
ToAsyncAwait(MsbRequest.post(`${BASE_URL}/app/tradeOrder/cancel`, data)); ToAsyncAwait(MsbRequestTkTk.post(`${BASE_URL}/app/tradeOrder/cancel`, data));
/** /**
* 获取支付参数 * 获取支付参数
* @param {*} data * @param {*} data
*/ */
export const ApiPostWxPay = (data) => export const ApiPostWxPay = (data) =>
ToAsyncAwait(MsbRequest.post(`${BASE_URL}/pay/wxPay/app`, data)); ToAsyncAwait(MsbRequestTkTk.post(`${BASE_URL}/pay/wxPay/app`, data));

File diff suppressed because one or more lines are too long

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-17 16:36:59 * @Date: 2022-03-17 16:36:59
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-03-30 10:14:44 * @LastEditTime: 2022-04-07 10:10:16
* @Description: 针对uniapp request请求做了一次封装使用思维参考axios * @Description: 针对uniapp request请求做了一次封装使用思维参考axios
* *
* *
@ -61,6 +61,9 @@ class MsbUniRequest {
if(!option){ if(!option){
throw new Error('没有请求配置或是request拦截未做return'); throw new Error('没有请求配置或是request拦截未做return');
} }
if(option.constructor === Promise){
return option
}
return new Promise((resolve, reject)=>{ return new Promise((resolve, reject)=>{
uni.request(option).then(res => { uni.request(option).then(res => {
const response = res[1]; const response = res[1];

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-22 18:28:52 * @Date: 2022-03-22 18:28:52
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-03-30 16:58:03 * @LastEditTime: 2022-04-06 20:22:21
* @Description: file content * @Description: file content
*/ */
import Vue from 'vue' import Vue from 'vue'
@ -13,7 +13,8 @@ Vue.use(Vuex)
export default new Vuex.Store({ export default new Vuex.Store({
state : { state : {
token : uni.getStorageSync('tk') || '', token : uni.getStorageSync('tk') || '',
userInfo : JSON.parse(uni.getStorageSync('ui') || '{}') userInfo : JSON.parse(uni.getStorageSync('ui') || '{}'),
address : JSON.parse(uni.getStorageSync('ads') || '[]')
}, },
mutations:{ mutations:{
SET_TOKEN (state, token = ''){ SET_TOKEN (state, token = ''){
@ -23,9 +24,15 @@ export default new Vuex.Store({
SET_USER_INFO (state, userInfo = {}){ SET_USER_INFO (state, userInfo = {}){
state.userInfo = userInfo; state.userInfo = userInfo;
uni.setStorageSync('ui', JSON.stringify(userInfo)); uni.setStorageSync('ui', JSON.stringify(userInfo));
},
SET_ADDRESS (state, address = []){
state.address = address;
uni.setStorageSync('ads', JSON.stringify(address));
} }
}, },
getters:{ actions:{
UPDATE_ADDRESS(){
}
} }
}) })

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-17 17:42:32 * @Date: 2022-03-17 17:42:32
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-04-02 09:58:14 * @LastEditTime: 2022-04-07 10:26:32
* @Description: 项目接口请求统一处理器返回一个需要token和不需要token的请求封装方法 * @Description: 项目接口请求统一处理器返回一个需要token和不需要token的请求封装方法
*/ */
@ -39,13 +39,32 @@ MsbRequest.baseUrl = BASE_URL[ENV];
MsbRequest.use('request', (option) => { MsbRequest.use('request', (option) => {
$store.state.token && (option.header = {...option.header, Authorization:$store.state.token});
return option; return option;
}) })
MsbRequest.use('success', successIntercept); MsbRequest.use('success', successIntercept);
MsbRequest.use('error', errorIntercept); MsbRequest.use('error', errorIntercept);
// 不需要token的接口封装
const MsbRequestTk = new MsbUniRequest();
MsbRequestTk.baseUrl = BASE_URL[ENV];
MsbRequestTk.use('request', (option) => {
const token = $store.state.token
if(!token){
uni.redirectTo({url:'/login'});
return Promise.reject({message:'请您先登录'});
}else{
option.header = {...option.header, Authorization:$store.state.token}
return option;
}
})
MsbRequestTk.use('success', successIntercept);
MsbRequestTk.use('error', errorIntercept);
export { export {
MsbRequest MsbRequest,
MsbRequestTk
} }

@ -2,91 +2,95 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-29 16:05:06 * @Date: 2022-03-29 16:05:06
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-03-29 16:20:03 * @LastEditTime: 2022-04-06 21:34:20
* @Description: file content * @Description: file content
--> -->
<template> <template>
<view> <view>
<UiCell title="所在区域" @click="show = true"> <UiCell title="所在区域" @click="show = true">
<template slot="value"> <template slot="value">
<input class="cityInput" disabled value="我的" placeholder="请选择省市区" /> <input class="cityInput" disabled :value="valueText" placeholder="请选择省市区" />
</template> </template>
</UiCell> </UiCell>
<u-picker <u-picker
:show="show" :show="show"
keyName="label" keyName="name"
:columns="data" :columns="columnsData"
:defaultIndex="defaultIndex"
@cancel="show = false" @cancel="show = false"
@change="changeRegion" @change="changeCity"
@confirm="onConfirm" @confirm="confirm"
/> />
</view> </view>
</template> </template>
<script> <script>
import UiCell from "./UiCell"; import UiCell from "./UiCell";
import Province from '@/common/dicts/area';
const DefaultCityColumn = Province[0].children;
const DefaultAreaColumn = DefaultCityColumn[0].children;
export default { export default {
components: { UiCell }, components: { UiCell },
props: ["value"], props: {
value : {
type : Array,
default : []
}
},
data() { data() {
return { return {
show: false, show: false,
data: [ columnsData : [],
[ defaultIndex : []
{
label: "北京",
id: 11000000,
children: [
{
label: "东城",
id: 11100000,
},
{
label: "西城",
id: 11200000,
},
],
},
{
label: "湖南",
id: 43000000,
children: [
{
label: "长沙",
id: 11100000,
},
{
label: "邵阳",
id: 11200000,
},
],
},
],
[
{
label: "东城",
id: 11100000,
},
{
label: "西城",
id: 11200000,
},
],
],
}; };
}, },
computed:{ computed:{
valueText(){ valueText(){
// this.va return this.value.map(i => i.name).join('/');
}, },
}, },
watch:{
value(val){
this.setColumAndDefalut(val);
}
},
mounted(){
console.log(Province.find(i => i.name == '重庆市'));
this.setColumAndDefalut(this.value);
},
methods: { methods: {
changeCity(val) { /**
this.data = [this.options[0],val.value[0].children] * 设置列数据和默认选中值
*/
setColumAndDefalut(val){
if(val.length){
//
const provinceIndex = Province.findIndex(item => val[0].code === item.code) || 0;
//
const city = Province[provinceIndex].children;
const cityIndex = city.findIndex(item => val[1].code === item.code) || 0;
//
const area = city[cityIndex].children;
const areaIndex = area.findIndex(item => val[2].code === item.code) || 0;
this.columnsData = [Province, city, area];
this.defaultIndex = [provinceIndex, cityIndex, areaIndex]
}else{
this.columnsData = [Province, DefaultCityColumn, DefaultAreaColumn];
}
},
changeCity(val, b, c) {
const city = val.value[0].children;
const area = val.value[1].children;
this.columnsData = [Province, city, area]
}, },
confirm(value) { confirm(value) {
this.$emit('input', value) this.show = false;
this.$emit('change', value) this.$emit('input', value.value)
this.$emit('change', value.value)
}, },
}, },
}; };

@ -81,6 +81,9 @@
"/mall/trade/" : { "/mall/trade/" : {
"target": "http://192.168.10.20:8090/" "target": "http://192.168.10.20:8090/"
}, },
"/mall/base/" : {
"target": "http://192.168.10.20:8090/"
},
"/pay/" : { "/pay/" : {
"target": "http://192.168.10.20:8090/" "target": "http://192.168.10.20:8090/"
}, },

@ -1,188 +0,0 @@
<!--
* @Author: ch
* @Date: 2022-03-22 14:12:18
* @LastEditors: ch
* @LastEditTime: 2022-03-22 16:31:24
* @Description: file content
-->
<template>
<view class="container">
<!-- 标题 -->
<view class="page-title">收货地址</view>
<!-- 表单组件 -->
<view class="form-wrapper">
<u-form :model="form" ref="uForm" label-width="140rpx">
<u-form-item label="姓名" prop="name">
<u-input v-model="form.name" placeholder="请输入收货人姓名" />
</u-form-item>
<u-form-item label="电话" prop="phone">
<u-input v-model="form.phone" placeholder="请输入收货人手机号" />
</u-form-item>
<u-form-item label="地区" prop="region">
<select-region v-model="form.region" />
</u-form-item>
<u-form-item label="详细地址" prop="detail" :border-bottom="false">
<u-input v-model="form.detail" placeholder="街道门牌、楼层等信息" />
</u-form-item>
</u-form>
</view>
<!-- 操作按钮 -->
<view class="footer">
<view class="btn-wrapper">
<view class="btn-item btn-item-main" :class="{ disabled }" @click="handleSubmit()"></view>
</view>
</view>
</view>
</template>
<script>
import SelectRegion from '@/components/SelectRegion.vue'
import { isPhone } from '@/common/utils/utils'
// import * as AddressApi from '@/api/address'
//
const form = {
name: '',
phone: '',
region: [],
detail: ''
}
//
const rules = {
name: [{
required: true,
message: '请输入姓名',
trigger: ['blur', 'change']
}],
phone: [{
required: true,
message: '请输入手机号',
trigger: ['blur', 'change']
}, {
//
validator: (rule, value, callback) => {
// truefalse
return isPhone(value)
},
message: '手机号码不正确',
// blurchange
trigger: ['blur'],
}],
region: [{
required: true,
message: '请选择省市区',
trigger: ['blur', 'change'],
type: 'array'
}],
detail: [{
required: true,
message: '请输入详细地址',
trigger: ['blur', 'change']
}],
}
export default {
components: {
SelectRegion
},
data() {
return {
form,
rules,
//
disabled: false
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {},
// onReadyonLoad
onReady() {
this.$refs.uForm.setRules(this.rules)
},
methods: {
//
handleSubmit() {
const app = this
if (app.disabled) {
return false
}
app.$refs.uForm.validate(valid => {
if (valid) {
app.disabled = true
AddressApi.add(app.form)
.then(result => {
app.$toast(result.message)
uni.navigateBack()
})
.finally(() => app.disabled = false)
}
})
}
}
}
</script>
<style>
page {
background: #f7f8fa;
}
</style>
<style lang="scss" scoped>
.page-title {
width: 94%;
margin: 0 auto;
padding-top: 40rpx;
font-size: 28rpx;
color: rgba(69, 90, 100, 0.6);
}
.form-wrapper {
margin: 20rpx auto 20rpx auto;
padding: 0 40rpx;
width: 94%;
box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
border-radius: 16rpx;
background: #fff;
}
/* 底部操作栏 */
.footer {
margin-top: 60rpx;
.btn-wrapper {
height: 100%;
display: flex;
align-items: center;
padding: 0 20rpx;
}
.btn-item {
flex: 1;
font-size: 28rpx;
height: 100rpx;
line-height: 100rpx;
text-align: center;
color: #fff;
border-radius: 50rpx;
}
.btn-item-main {
background: linear-gradient(to right, #f9211c, #ff6335);
//
&.disabled {
background: #ff9779;
}
}
}
</style>

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-22 14:12:18 * @Date: 2022-03-22 14:12:18
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-03-29 16:27:03 * @LastEditTime: 2022-04-06 21:19:21
* @Description: file content * @Description: file content
--> -->
<template> <template>
@ -10,28 +10,27 @@
<view class="form"> <view class="form">
<UiCell class="form--item" title="收货人" :rightIcon="false"> <UiCell class="form--item" title="收货人" :rightIcon="false">
<template slot="value"> <template slot="value">
<input class="form--itemInput" placeholder="请输入收货人姓名"/> <input class="form--itemInput" v-model="address.name" placeholder="请输入收货人姓名"/>
</template> </template>
</UiCell> </UiCell>
<UiCell class="form--item" title="手机号码" :rightIcon="false"> <UiCell class="form--item" title="手机号码" :rightIcon="false">
<template slot="value"> <template slot="value">
<input class="form--itemInput" placeholder="请输入收货手机号码"/> <input class="form--itemInput" v-model="address.phone" placeholder="请输入收货手机号码"/>
</template> </template>
</UiCell> </UiCell>
<BsSelectCity class="form--item form--city"></BsSelectCity> <BsSelectCity class="form--item form--city" v-model="city"></BsSelectCity>
<UiCell class="form--item form--item__last" title="详细地址" :rightIcon="false"> <UiCell class="form--item form--item__last" title="详细地址" :rightIcon="false">
<template slot="value"> <template slot="value">
<input class="form--itemInput" placeholder="请输入详细地址"/> <input class="form--itemInput" v-model="address.detailAddress" placeholder="请输入详细地址"/>
</template> </template>
</UiCell> </UiCell>
</view> </view>
<UiCell class="form--item form--item__last" title="设为默认地址" > <UiCell class="form--item form--item__last" title="设为默认地址" >
<template slot="right-icon"> <template slot="right-icon">
<u-switch space="2" :value="true" activeColor="#FF875B" inactiveColor="#F3F3F3" /> <u-switch space="2" v-model="address.isDefault" activeColor="#FF875B" inactiveColor="#F3F3F3" />
</template> </template>
</UiCell> </UiCell>
<UiButton class="saveBtn" type="solid" size="max">保存</UiButton> <UiButton class="saveBtn" type="solid" size="max" @click="save"></UiButton>
</view> </view>
</template> </template>
@ -39,8 +38,58 @@
import BsSelectCity from '../../../components/BsSelectCity.vue'; import BsSelectCity from '../../../components/BsSelectCity.vue';
import UiButton from '../../../components/UiButton.vue'; import UiButton from '../../../components/UiButton.vue';
import UiCell from '../../../components/UiCell.vue'; import UiCell from '../../../components/UiCell.vue';
import {IsPhone} from '@/common/utils';
import {ApiPutAddress} from '@/common/api/base';
export default { export default {
components: { UiCell, UiButton, BsSelectCity } components: { UiCell, UiButton, BsSelectCity },
data (){
return {
address : {},
city : []
}
},
onShow(){
this.address.isDefault = this.$Route.query.first === 'true' ? true : false
},
methods: {
async save(){
const $toast = uni.$u.toast;
if(!this.address.name){
$toast('请填写收货人姓名');
return false;
}
if(!this.address.phone || !IsPhone(this.address.phone)){
$toast('请填写正确的手机号');
return false;
}
if(!this.city.length){
$toast('请选择地区');
return false;
}
if(!this.address.detailAddress){
$toast('请填写详细地址');
return false;
}
const areaCode = this.city[2].code;
const area = this.city[2].name;
const city = this.city[1].name;
const cityCode = this.city[1].code;
const provinceCode = this.city[0].code;
const province = this.city[0].name;
const {error} = await ApiPutAddress({
...this.address,
province,provinceCode,areaCode,area,city,cityCode
});
if(error){
$toast(error.message);
return false;
}
$toast('保存成功');
this.$Router.back();
}
}
}; };
</script> </script>

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-22 14:12:18 * @Date: 2022-03-22 14:12:18
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-03-29 16:24:26 * @LastEditTime: 2022-04-07 09:30:07
* @Description: file content * @Description: file content
--> -->
<template> <template>
@ -10,31 +10,28 @@
<view class="form"> <view class="form">
<UiCell class="form--item" title="收货人" :rightIcon="false"> <UiCell class="form--item" title="收货人" :rightIcon="false">
<template slot="value"> <template slot="value">
<input class="form--itemInput" placeholder="请输入收货人姓名"/> <input class="form--itemInput" v-model="address.name" placeholder="请输入收货人姓名"/>
</template> </template>
</UiCell> </UiCell>
<UiCell class="form--item" title="手机号码" :rightIcon="false"> <UiCell class="form--item" title="手机号码" :rightIcon="false">
<template slot="value"> <template slot="value">
<input class="form--itemInput" placeholder="请输入收货手机号码"/> <input class="form--itemInput" v-model="address.phone" placeholder="请输入收货手机号码"/>
</template> </template>
</UiCell> </UiCell>
<BsSelectCity class="form--item form--city"></BsSelectCity> <BsSelectCity class="form--item form--city" v-model="city"></BsSelectCity>
<UiCell class="form--item form--item__last" title="详细地址" :rightIcon="false"> <UiCell class="form--item form--item__last" title="详细地址" :rightIcon="false">
<template slot="value"> <template slot="value">
<input class="form--itemInput" placeholder="请输入详细地址"/> <input class="form--itemInput" v-model="address.detailAddress" placeholder="请输入详细地址"/>
</template> </template>
</UiCell> </UiCell>
</view> </view>
<view class="form"> <UiCell class="form--item form--item__last" title="设为默认地址" >
<UiCell class="form--item" title="设为默认地址" > <template slot="right-icon">
<template slot="right-icon"> <u-switch space="2" v-model="address.isDefault" activeColor="#FF875B" inactiveColor="#F3F3F3" />
<u-switch space="2" :value="true" activeColor="#FF875B" inactiveColor="#F3F3F3" /> </template>
</template> </UiCell>
</UiCell> <UiCell class="form--item form--item__last del-address" @click="delAddress" title="删除收货地址" :rightIcon="false"></UiCell>
<UiCell class="form--item form--item__last delAddress" title="删除收货地址" :rightIcon="false"></UiCell> <UiButton class="saveBtn" type="solid" size="max" @click="save"></UiButton>
</view>
<UiButton class="saveBtn" type="solid" size="max">保存</UiButton>
</view> </view>
</template> </template>
@ -42,8 +39,79 @@
import BsSelectCity from '../../../components/BsSelectCity.vue'; import BsSelectCity from '../../../components/BsSelectCity.vue';
import UiButton from '../../../components/UiButton.vue'; import UiButton from '../../../components/UiButton.vue';
import UiCell from '../../../components/UiCell.vue'; import UiCell from '../../../components/UiCell.vue';
import {IsPhone} from '@/common/utils';
import {ApiPutAddress, ApiDeleteAddress} from '@/common/api/base';
export default { export default {
components: { UiCell, UiButton, BsSelectCity } components: { UiCell, UiButton, BsSelectCity },
data (){
return {
address : {},
city : []
}
},
onShow(){
this.address = this.$store.state.address.find(i => i.id == this.$Route.query.id);
this.city = [
{code : this.address.provinceCode, name : this.address.province},
{code : this.address.cityCode, name : this.address.city},
{code : this.address.areaCode, name : this.address.area},
]
},
methods: {
async save(){
const $toast = uni.$u.toast;
if(!this.address.name){
$toast('请填写收货人姓名');
return false;
}
if(!this.address.phone || !IsPhone(this.address.phone)){
$toast('请填写正确的手机号');
return false;
}
if(!this.city.length){
$toast('请选择地区');
return false;
}
if(!this.address.detailAddress){
$toast('请填写详细地址');
return false;
}
const areaCode = this.city[2].code;
const area = this.city[2].name;
const city = this.city[1].name;
const cityCode = this.city[1].code;
const provinceCode = this.city[0].code;
const province = this.city[0].name;
const {error} = await ApiPutAddress({
...this.address,
province,provinceCode,areaCode,area,city,cityCode
});
if(error){
$toast(error.message);
return false;
}
$toast('保存成功');
this.$Router.back();
},
async delAddress(){
uni.showModal({
title: '友情提示',
content: '您确定要删除该地址吗?',
showCancel: true,
success:async ()=> {
const {error} = await ApiDeleteAddress({idList : this.$Route.query.id});
if(error){
uni.$u.toast(error.message);
return false;
}
this.$Router.back();
}
})
}
}
}; };
</script> </script>
@ -75,7 +143,7 @@ page {
left: 30rpx; left: 30rpx;
} }
/deep/ { /deep/ {
.delAddress .uiCell--title{ .del-address .uiCell--title{
color: #FF875B; color: #FF875B;
} }
.form--city .uiCell{ .form--city .uiCell{

@ -2,41 +2,47 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-22 13:54:15 * @Date: 2022-03-22 13:54:15
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-03-30 14:54:44 * @LastEditTime: 2022-04-06 20:22:31
* @Description: file content * @Description: file content
--> -->
<template> <template>
<view class="container"> <view class="container">
<view class="address"> <view class="address">
<BsEmpty tips="暂无收货地址呢~"></BsEmpty>
<view class="addressItem" v-for="item in 2" :key="item" <u-loadmore v-if="isLoading" status="loading" />
:class="{'addressItem__last' : item === 2,'addressItem__default':item == 1}"> <BsEmpty tips="暂无收货地址呢~" v-if="!isLoading && !addresList.length"></BsEmpty>
<view class="addressItem" v-for="(item, index) in addresList" :key="item.id"
:class="{'addressItem__last' : index === addresList.length - 1,'addressItem__default':item.isDefault}">
<view> <view>
<view class="addressItem--city">湖南省长沙市岳麓区</view> <view class="addressItem--city">{{item.province}}{{item.city}}{{item.area}}</view>
<view class="addressItem--detail">西上海大厦芯城科技园8栋13楼</view> <view class="addressItem--detail">{{item.detailAddress}}</view>
<view> <view>
<text class="addressItem--name">马老师</text> <text class="addressItem--name">{{item.name}}</text>
<text>189****0000</text> <text>{{item.phone}}</text>
</view> </view>
</view> </view>
<image class="addressItem--edit" src="@/static/account/edit.png" <image class="addressItem--edit" src="@/static/account/edit.png"
@click="$Router.push('/addressEdit')" /> @click="$Router.push(`/addressEdit?id=${item.id}`)" />
</view> </view>
</view> </view>
<UiButton class="addAddress" type="solid" size="max" @click="$Router.push('/addressCreate')"></UiButton> <UiButton class="addAddress" type="solid" size="max" @click="$Router.push(`/addressCreate?first=${!addresList.length}`)"></UiButton>
</view> </view>
</template> </template>
<script> <script>
import BsEmpty from "@/components/BsEmpty"; import BsEmpty from "@/components/BsEmpty";
import UiButton from '../../../components/UiButton.vue'; import UiButton from '../../../components/UiButton.vue';
import {ApiGetAddress} from '@/common/api/base';
export default { export default {
components: { BsEmpty, UiButton }, components: { BsEmpty, UiButton },
data() { data() {
return {}; return {
addresList : [],
isLoading : true
};
}, },
/** /**
@ -47,9 +53,23 @@ export default {
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() {}, onShow() {
this.getAddressList();
},
methods: {}, methods: {
async getAddressList(){
this.isLoading = true;
const {error, result} = await ApiGetAddress();
this.isLoading = false;
if(error){
uni.$u.toast(error.message);
return false;
}
this.addresList = result;
this.$store.commit('SET_ADDRESS', result);
}
},
}; };
</script> </script>
@ -103,6 +123,9 @@ page{
position: fixed; position: fixed;
bottom: 89rpx; bottom: 89rpx;
left: 30rpx; left: 30rpx;
display: flex;
align-items: center;
justify-content: center;
&::before{ &::before{
display: inline-block; display: inline-block;
content: "+"; content: "+";

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-22 15:09:06 * @Date: 2022-03-22 15:09:06
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-03-30 18:43:33 * @LastEditTime: 2022-04-06 17:38:07
* @Description: file content * @Description: file content
--> -->
<template> <template>
@ -10,7 +10,7 @@
<UiCell class="userInfo cell" :title="userInfo.nickname" @click="$Router.push('/setUserInfo')"> <UiCell class="userInfo cell" :title="userInfo.nickname" @click="$Router.push('/setUserInfo')">
<image slot="icon" class="userInfo--head" src="@/static/account/tx.png" ></image> <image slot="icon" class="userInfo--head" src="@/static/account/tx.png" ></image>
</UiCell> </UiCell>
<UiCell class="cell" title="我的收货地址"></UiCell> <UiCell class="cell" title="我的收货地址" @click="$Router.push('/addressList')"></UiCell>
<UiCell class="cell" title="关于我们" ></UiCell> <UiCell class="cell" title="关于我们" ></UiCell>
<UiCell class="cell cell--last" title="版本号" value="1.0.0" valueClass="cell--value" :rightIcon="false"></UiCell> <UiCell class="cell cell--last" title="版本号" value="1.0.0" valueClass="cell--value" :rightIcon="false"></UiCell>
<view class="logout" @click="logout">退</view> <view class="logout" @click="logout">退</view>

@ -2,13 +2,13 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-22 15:36:46 * @Date: 2022-03-22 15:36:46
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-03-29 14:00:56 * @LastEditTime: 2022-04-07 10:33:33
* @Description: file content * @Description: file content
--> -->
<template> <template>
<view class="container"> <view class="container">
<view class="header"> <view class="header">
<image class="arrow" src="@/static/search/arrow.png" @click="$Router.back()"/> <image class="arrow" src="@/static/search/arrow.png" @click="goBack"/>
</view> </view>
<view class="logo">马士兵严选</view> <view class="logo">马士兵严选</view>
<u--form class="login"> <u--form class="login">
@ -46,6 +46,7 @@ export default {
} }
}, },
mounted(){ mounted(){
this.$store.state.token && this.goBack();
}, },
methods : { methods : {
codeChange(text) { codeChange(text) {
@ -83,7 +84,7 @@ export default {
} }
if(!this.checked){ if(!this.checked){
uni.$u.toast('请勾选同意《用户协议》和《隐私协议》'); uni.$u.toast('请勾选同意《用户协议》和《隐私协议》');
return false return false;
} }
const {error, result} = await ApiPostLogin({ const {error, result} = await ApiPostLogin({
phone : this.phone, phone : this.phone,
@ -95,6 +96,9 @@ export default {
return false; return false;
} }
this.$store.commit('SET_TOKEN',result.token); this.$store.commit('SET_TOKEN',result.token);
this.goBack();
},
goBack(){
const pagesLength = getCurrentPages().length; const pagesLength = getCurrentPages().length;
pagesLength > 1 ? this.$Router.back() : this.$Router.replace('/'); pagesLength > 1 ? this.$Router.back() : this.$Router.replace('/');
} }

Loading…
Cancel
Save