Răsfoiți Sursa

默认登录&收货地址

panhui 5 ani în urmă
părinte
comite
a8efc1e761

+ 2 - 1
.prettierrc.js

@@ -15,5 +15,6 @@ module.exports = {
                 parser: 'vue'
             }
         }
-    ]
+    ],
+    endOfLine: 'auto'
 };

+ 114 - 114
project.config.json

@@ -1,114 +1,114 @@
 {
-    "description": "项目配置文件",
-    "packOptions": {
-        "ignore": []
-    },
-    "setting": {
-        "urlCheck": false,
-        "es6": true,
-        "enhance": false,
-        "postcss": true,
-        "preloadBackgroundData": false,
-        "minified": true,
-        "newFeature": true,
-        "coverView": true,
-        "autoAudits": false,
-        "showShadowRootInWxmlPanel": true,
-        "scopeDataCheck": false,
-        "checkInvalidKey": true,
-        "checkSiteMap": true,
-        "uploadWithSourceMap": true,
-        "babelSetting": {
-            "ignore": [],
-            "disablePlugins": [],
-            "outputPath": ""
-        }
-    },
-    "compileType": "miniprogram",
-    "libVersion": "2.11.0",
-    "appid": "wx31f7e5e3081d6927",
-    "projectname": "%E6%8D%B7%E9%80%94JETOUR",
-    "cloudfunctionTemplateRoot": "",
-    "watchOptions": {
-        "ignore": []
-    },
-    "debugOptions": {
-        "hidedInDevtools": []
-    },
-    "scripts": {},
-    "simulatorType": "wechat",
-    "simulatorPluginLibVersion": {},
-    "condition": {
-        "search": {
-            "current": -1,
-            "list": []
-        },
-        "conversation": {
-            "current": -1,
-            "list": []
-        },
-        "plugin": {
-            "current": -1,
-            "list": []
-        },
-        "game": {
-            "list": []
-        },
-        "gamePlugin": {
-            "current": -1,
-            "list": []
-        },
-        "miniprogram": {
-            "current": -1,
-            "list": [
-                {
-                    "id": -1,
-                    "name": "我的",
-                    "pathName": "pages/my",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "购车",
-                    "pathName": "pages/car",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "途享",
-                    "pathName": "pages/tuxiang",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "注册",
-                    "pathName": "pages/register",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "登录",
-                    "pathName": "pages/login",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "试驾",
-                    "pathName": "pages/testDrive",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "选择城市",
-                    "pathName": "pages/cityChoose",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "经销商",
-                    "pathName": "pages/dealer",
-                    "scene": null
-                },
+	"description": "项目配置文件",
+	"packOptions": {
+		"ignore": []
+	},
+	"setting": {
+		"urlCheck": false,
+		"es6": true,
+		"enhance": false,
+		"postcss": true,
+		"preloadBackgroundData": false,
+		"minified": true,
+		"newFeature": true,
+		"coverView": true,
+		"autoAudits": false,
+		"showShadowRootInWxmlPanel": true,
+		"scopeDataCheck": false,
+		"checkInvalidKey": true,
+		"checkSiteMap": true,
+		"uploadWithSourceMap": true,
+		"babelSetting": {
+			"ignore": [],
+			"disablePlugins": [],
+			"outputPath": ""
+		}
+	},
+	"compileType": "miniprogram",
+	"libVersion": "2.11.0",
+	"appid": "wx31f7e5e3081d6927",
+	"projectname": "%E6%8D%B7%E9%80%94JETOUR",
+	"cloudfunctionTemplateRoot": "",
+	"watchOptions": {
+		"ignore": []
+	},
+	"debugOptions": {
+		"hidedInDevtools": []
+	},
+	"scripts": {},
+	"simulatorType": "wechat",
+	"simulatorPluginLibVersion": {},
+	"condition": {
+		"search": {
+			"current": -1,
+			"list": []
+		},
+		"conversation": {
+			"current": -1,
+			"list": []
+		},
+		"plugin": {
+			"current": -1,
+			"list": []
+		},
+		"game": {
+			"list": []
+		},
+		"gamePlugin": {
+			"current": -1,
+			"list": []
+		},
+		"miniprogram": {
+			"current": -1,
+			"list": [
+				{
+					"id": -1,
+					"name": "我的",
+					"pathName": "pages/my",
+					"scene": null
+				},
+				{
+					"id": -1,
+					"name": "购车",
+					"pathName": "pages/car",
+					"scene": null
+				},
+				{
+					"id": -1,
+					"name": "途享",
+					"pathName": "pages/tuxiang",
+					"scene": null
+				},
+				{
+					"id": -1,
+					"name": "注册",
+					"pathName": "pages/register",
+					"scene": null
+				},
+				{
+					"id": -1,
+					"name": "登录",
+					"pathName": "pages/login",
+					"scene": null
+				},
+				{
+					"id": -1,
+					"name": "试驾",
+					"pathName": "pages/testDrive",
+					"scene": null
+				},
+				{
+					"id": -1,
+					"name": "选择城市",
+					"pathName": "pages/cityChoose",
+					"scene": null
+				},
+				{
+					"id": -1,
+					"name": "经销商",
+					"pathName": "pages/dealer",
+					"scene": null
+				},
 				{
 					"id": -1,
 					"name": "商品详情",
@@ -140,7 +140,7 @@
 					"pathName": "pages/video",
 					"scene": null
 				}
-            ]
-        }
-    }
-}
+			]
+		}
+	}
+}

+ 22 - 0
src/App.vue

@@ -33,6 +33,28 @@ export default {
                 })
                     .then(res => {
                         this.$http.setToken(res.data.token);
+                        if (!res.link) {
+                            wx.getSetting({
+                                success: res => {
+                                    if (res.authSetting['scope.userInfo']) {
+                                        wx.getUserInfo({
+                                            success: e => {
+                                                this.$http
+                                                    .post('/applets/dealuserinfo', {
+                                                        ...e,
+                                                        userInfo: JSON.stringify(e.userInfo)
+                                                    })
+                                                    .then(res => {
+                                                        this.$store.commit('setLoginInfo', res.data);
+                                                        this.$store.dispatch('getUserInfo');
+                                                    });
+                                            }
+                                        });
+                                    }
+                                }
+                            });
+                        }
+
                         this.$store.commit('setLoginInfo', res.data);
                     })
                     .catch(e => {

+ 3 - 1
src/main.js

@@ -4,6 +4,7 @@ import VHtmlPlugin from '@megalo/vhtml-plugin';
 import Vuex from 'vuex';
 import http from './plugins/http';
 import Dialog from './vant/dialog/dialog';
+import ToastEvent from './mixins/ToastEvent';
 Vue.prototype.$colors = {
     prim: '#149A9A'
 };
@@ -32,7 +33,7 @@ Vue.mixin({
         }
     }
 });
-
+Vue.mixin(ToastEvent);
 const app = new Vue(App);
 
 app.$mount();
@@ -54,6 +55,7 @@ export default {
             'pages/calculator',
             'pages/submit',
             'pages/addressEdit',
+            'pages/addressList',
             'pages/video'
         ],
         tabBar: {

+ 24 - 0
src/mixins/ToastEvent.js

@@ -0,0 +1,24 @@
+export default {
+    methods: {
+        showToastError(title, icon = 'none', duration = 1500) {
+            wx.showToast({
+                icon: icon,
+                title: title,
+                mask: true,
+                duration: duration
+            });
+        },
+        navigateBack(timeOut = 0, delta = 1) {
+            setTimeout(function() {
+                wx.navigateBack({
+                    delta: delta
+                });
+            }, timeOut);
+        },
+        goNext(url) {
+            wx.navigateTo({
+                url: url
+            });
+        }
+    }
+};

+ 255 - 75
src/pages/addressEdit.vue

@@ -1,50 +1,89 @@
 <config>
 {
     "navigationBarTitleText": "填写个人信息",
-    "disableScroll": true
+    "disableScroll": true,
+		"backgroundColor":"#F8FAFF",
+		"usingComponents": {
+    		"van-popup": "../vant/popup/index"
+  	}
 }
 </config>
 <template>
     <div>
-        <div class="group">
-            <div class="field">
-                <div class="label">姓名</div>
-                <input class="value" placeholder-class="placeholder" placeholder="请输入姓名" />
+        <van-cell-group>
+            <van-field
+                :value="form.name"
+                @input="form.name = $event.detail"
+                label="姓名"
+                placeholder="请输入收货人名"
+                input-align="right"
+            />
+            <van-field
+                :value="form.mobile"
+                type="tel"
+                label="联系方式"
+                placeholder="请输入收货人手机号码"
+                input-align="right"
+                @input="form.mobile = $event.detail"
+            />
+            <van-field
+                :value="form.address"
+                @input="form.address = $event.detail"
+                readonly
+                label="所在地区"
+                icon="arrow"
+                placeholder="请选择"
+                input-align="right"
+                @click="showPicker = true"
+            />
+            <van-field
+                :value="form.detailAddress"
+                @input="form.detailAddress = $event.detail"
+                label="详细地址"
+                placeholder="请输入详细地址"
+                input-align="right"
+            />
+            <van-field
+                :value="form.phone"
+                @input="form.phone = $event.detail"
+                label="固定电话"
+                type="digit"
+                placeholder="请输入固定电话"
+                input-align="right"
+            />
+            <van-field
+                :value="form.zipCode"
+                @input="form.zipCode = $event.detail"
+                label="邮编"
+                type="digit"
+                placeholder="请输入邮编"
+                input-align="right"
+            />
+
+            <van-cell class="check">
+                <van-checkbox
+                    :value="form.isDefault == '1'"
+                    :checked-color="$colors.prim"
+                    @input="form.isDefault = $event.detail ? '1' : '0'"
+                    >设置为默认购车人</van-checkbox
+                >
+            </van-cell>
+            <div class="btn-wrapper">
+                <van-button block :color="$colors.prim" @click="onSubmit">保存</van-button>
             </div>
-            <div class="field">
-                <div class="label">联系方式</div>
-                <input class="value" placeholder-class="placeholder" placeholder="请输入收货人手机号码" type="number" />
-            </div>
-            <div class="field">
-                <div class="label">所在地区</div>
-                <div class="value placeholder">
-                    请选择城市
-                </div>
-                <img src="../static/imgs/icon_arrow_right.png" class="arrow" />
-            </div>
-            <div class="field">
-                <div class="label">详细地址</div>
-                <input class="value" placeholder-class="placeholder" placeholder="请选择详细地址" />
-            </div>
-            <div class="field">
-                <div class="label">固定电话</div>
-                <input class="value" placeholder-class="placeholder" placeholder="请输入固定电话" type="number" />
-            </div>
-            <div class="field" style="border: none;">
-                <div class="label">邮编</div>
-                <input class="value" placeholder-class="placeholder" placeholder="请输入邮编" type="number" />
-            </div>
-            <div class="cb-wrapper" @click="checked = !checked">
-                <img
-                    class="cb"
-                    :src="checked ? require('../static/imgs/cb_check.png') : require('../static/imgs/cb.png')"
-                />
-                <div>设置为默认购车人</div>
-            </div>
-        </div>
-        <div class="btn-wrapper">
-            <van-button block :color="$colors.prim">保存</van-button>
-        </div>
+        </van-cell-group>
+
+        <van-popup :show="showPicker" position="bottom">
+            <van-picker
+                show-toolbar
+                value-key="name"
+                :columns="columns"
+                @cancel="showPicker = false"
+                @confirm="onConfirm"
+                @change="onChange"
+            />
+        </van-popup>
+
         <van-dialog id="van-dialog" />
     </div>
 </template>
@@ -53,49 +92,192 @@ import Dialog from '../vant/dialog/dialog';
 export default {
     data() {
         return {
-            checked: false
+            form: {
+                name: '',
+                mobile: '',
+                address: '',
+                provinceId: '',
+                cityId: '',
+                countryId: '',
+                detailAddress: '',
+                phone: '',
+                zipCode: '',
+                isDefault: ''
+            },
+            provincesList: [],
+            cityList: [],
+            districtList: [],
+            showPicker: false
         };
     },
+    computed: {
+        columns() {
+            return [
+                {
+                    values: [...this.provincesList],
+                    defaultIndex: this.getIndex(this.form.provinceId, this.provincesList)
+                },
+                {
+                    values: [...this.cityList],
+                    defaultIndex: this.getIndex(this.form.cityId, this.cityList)
+                },
+                {
+                    values: [...this.districtList],
+                    defaultIndex: this.getIndex(this.form.countryId, this.districtList)
+                }
+            ];
+        }
+    },
     onShow() {
-        Dialog.alert({
-            message: '收获地址请填写真实购车人姓名和手机号,否则会影响权益领取!',
-            showCancelButton: true,
-            className: 'custom-class-name'
-        }).then(() => {
-            // on close
+        this.getFormInfo().then(() => {
+            this.getProvince();
         });
+    },
+    methods: {
+        getFormInfo() {
+            if (this.$mp.query.id) {
+                return this.$http
+                    .get('/applets/querycustomeraddressbyid', {
+                        id: this.$mp.query.id
+                    })
+                    .then(res => {
+                        res.data.mobile = res.data.originMobile;
+                        res.data.phone = res.data.originPhone;
+
+                        this.form = { ...res.data };
+                    });
+            } else {
+                Dialog.alert({
+                    message: '收获地址请填写真实购车人姓名和手机号,否则会影响权益领取!',
+                    showCancelButton: true,
+                    className: 'custom-class-name'
+                }).then(() => {
+                    // on close
+                });
+                return Promise.resolve();
+            }
+        },
+        getProvince() {
+            this.$http.get('/applets/queryallprovinces').then(res => {
+                this.provincesList = res.data;
+                this.cityList = [];
+                this.getCityList(this.form.provinceId || 0, this.form.provinceId ? 'id' : 'index');
+            });
+        },
+        getCityList(key, type = 'index') {
+            this.$http
+                .get('/applets/querycitybyprovinceid', {
+                    provinceId: type === 'id' ? key : this.provincesList[key || 0].id
+                })
+                .then(res => {
+                    this.cityList = res.data;
+                    this.districtList = [];
+                    this.getdistrictList();
+                });
+        },
+        getdistrictList(key, type = 'index') {
+            this.$http
+                .get('/applets/querydistrictbycityid', {
+                    cityId: type === 'id' ? key : this.cityList[key || 0].id
+                })
+                .then(res => {
+                    this.districtList = res.data;
+                });
+        },
+        onConfirm(e) {
+            const values = e.target.value;
+            this.form.provinceId = values[0].id;
+            this.form.cityId = values[1].id;
+            this.form.countryId = values[2].id;
+            this.form.address = values
+                .map(item => {
+                    return item.name;
+                })
+                .join(' ');
+            this.showPicker = false;
+        },
+        getIndex(id, list) {
+            let index = 0;
+            if (id) {
+                index = list.findIndex(item => {
+                    return item.id === id;
+                });
+            }
+
+            return index === -1 ? 0 : index;
+        },
+        onChange(e) {
+            const values = e.target.value;
+            if (values[0].id === values[1].provinceId && values[1].id !== values[2].cityId) {
+                this.getdistrictList(values[1].id, 'id');
+            } else if (values[0].id !== values[1].provinceId) {
+                this.getCityList(values[0].id, 'id');
+            }
+        },
+        onSubmit() {
+            if (!this.form.name) {
+                this.showToastError('请填写收货人');
+                return;
+            }
+            if (!this.form.mobile || !/1\d{10}/.test(this.form.mobile)) {
+                this.showToastError('请正确填写联系方式');
+                return;
+            }
+            if (!this.form.provinceId || !this.form.cityId || !this.form.countryId || !this.form.address) {
+                this.showToastError('请选择地址信息');
+                return;
+            }
+            if (!this.form.detailAddress) {
+                this.showToastError('请填写详细地址');
+                return;
+            }
+            if (!!this.form.phone && !/^[0-9]+$/.test(this.form.phone)) {
+                this.showToastError('请正确填写固定电话');
+                return;
+            }
+            if (!!this.form.zipCode && !/^[1-9][0-9]{5}$/.test(this.form.zipCode)) {
+                this.showToastError('请正确填写邮编');
+                return;
+            }
+
+            this.$http
+                .post(
+                    this.form.id ? '/applets/updateaddress' : '/applets/addaddress',
+                    {
+                        ...this.form
+                    },
+                    {
+                        header: {
+                            'Content-Type': 'application/json'
+                        }
+                    }
+                )
+                .then(res => {
+                    //1:成功 -1:已达上限
+                    if (res.data === -1) {
+                        this.showToastError('你的地址已达上限,无法新增');
+                        return;
+                    }
+                    if (res.data === 1) {
+                        this.showToastError(this.form.id ? '修改成功' : '新增成功', 'success');
+                        this.navigateBack(500);
+                        return;
+                    }
+                    this.showToastError(this.form.id ? '修改失败' : '新增失败');
+                });
+        }
     }
 };
 </script>
 <style lang="less">
 page {
-    background: @bg;
-}
-.group {
-    background: white;
-    border-top: 1px solid #dde6ef;
-    border-bottom: 1px solid #dde6ef;
+    background: @bg2;
 }
-.field {
-    .flex();
-    margin: 0 15px;
-    border-bottom: 1px solid #dde6ef;
-    height: 40px;
-    .label {
-        font-size: 14px;
-        color: @text1;
-        margin-left: 9px;
-    }
-    .value {
-        font-size: 16px;
-        color: @text1;
-        flex-grow: 1;
-        text-align: right;
-        margin-right: 10px;
-    }
-    .arrow {
-        width: 8px;
-        height: 13px;
+
+.check {
+    .van-checkbox {
+        font-size: 12px;
+        color: #666;
     }
 }
 .cb-wrapper {
@@ -111,9 +293,7 @@ page {
         margin-right: 6px;
     }
 }
-.placeholder {
-    color: #b7b7b7 !important;
-}
+
 .btn-wrapper {
     position: fixed;
     bottom: 0;

+ 183 - 0
src/pages/addressList.vue

@@ -0,0 +1,183 @@
+<config>
+{
+'navigationBarTitleText': '收货地址管理',
+}
+</config>
+
+<template>
+    <div class="address-content">
+        <van-empty description="无数据" v-if="addresses.length === 0" />
+
+        <div v-for="item in addresses" :key="item.id">
+            <div class="address">
+                <div class="address-top">
+                    <div class="text1">
+                        <span>{{ item.name }} </span><span>{{ item.mobile }}</span>
+                    </div>
+                    <div class="text2">{{ item.address }}{{ item.detailAddress }}</div>
+                </div>
+                <div class="btnList">
+                    <van-checkbox
+                        class="checkbox"
+                        readonly
+                        v-if="item.isDefault"
+                        :value="true"
+                        :checked-color="$colors.prim"
+                    >
+                        默认购车人
+                    </van-checkbox>
+
+                    <van-button size="small" icon="edit" @click="addressEdit(item.id)">编辑</van-button>
+                    <van-button size="small" icon="delete" @click="del(item.id)">删除</van-button>
+                </div>
+            </div>
+        </div>
+
+        <div class="btn-wrapper">
+            <van-button class="bottomBtn" block :color="$colors.prim" @click="addressEdit(0)"
+                >添加购车人(收货地址)</van-button
+            >
+        </div>
+        <van-dialog id="van-dialog" />
+    </div>
+</template>
+<script>
+import Dialog from '../vant/dialog/dialog';
+export default {
+    data() {
+        return {
+            addresses: []
+        };
+    },
+    onShow() {
+        this.getList();
+    },
+    methods: {
+        getList() {
+            this.$http.get('/applets/querycustomeraddress').then(res => {
+                this.addresses = res.data;
+            });
+        },
+        addressEdit(id) {
+            wx.navigateTo({
+                url: '/pages/addressEdit' + (id ? `?id=${id}` : '')
+            });
+        },
+        del(id) {
+            Dialog.confirm({
+                title: '您确认要删除这个地址?',
+                // message: '您确认要删除这个地址?',
+                className: 'custom-class-name',
+                cancelButtonText: '再想想'
+            })
+                .then(() => {
+                    this.$http
+                        .get('/applets/deletecustomeraddress', {
+                            addressId: id
+                        })
+                        .then(res => {
+                            if (res.data === 1) {
+                                this.getList();
+                                this.showToastError('删除成功', 'success');
+                            } else {
+                                this.showToastError('删除失败');
+                            }
+                        });
+                })
+                .catch(() => {});
+        }
+    }
+};
+</script>
+<style lang="less" scoped>
+.bottomBtn {
+    position: fixed;
+    bottom: 0;
+    left: 0;
+    right: 0;
+}
+
+.address {
+    margin: 0 15px;
+    border: 1px solid #ececec;
+    border-radius: 5px;
+    box-shadow: 0 0 10px 2px #ececec;
+}
+
+.address-top {
+    padding: 18px 10px 22px;
+    .text1 {
+        span {
+            font-size: 15px;
+            font-weight: bold;
+            color: #343434;
+            line-height: 18px;
+        }
+        span + span {
+            margin-left: 15px;
+        }
+    }
+
+    .text2 {
+        font-size: 12px;
+        font-weight: bold;
+        color: #666666;
+        line-height: 18px;
+        margin-top: 16px;
+    }
+}
+
+.address-content {
+    padding: 15px 0;
+}
+
+.btnList {
+    display: flex;
+    align-items: center;
+    padding: 15px;
+    position: relative;
+    &::before {
+        content: '';
+        position: absolute;
+        top: 0px;
+        right: 5px;
+        left: 5px;
+        height: 1px;
+        background-color: #dedede;
+    }
+
+    .checkbox {
+        flex-grow: 1;
+    }
+}
+</style>
+
+<style lang="less">
+.btnList {
+    .van-checkbox {
+        font-size: 12px;
+        line-height: 18px;
+        .van-checkbox__label {
+            color: #109a9a;
+            font-weight: bold;
+        }
+    }
+
+    .van-button {
+        border-width: 0px;
+    }
+}
+.bottomBtn {
+    .van-button {
+        height: 55px;
+        line-height: 55px;
+        font-size: 14px;
+    }
+}
+
+.dialog-index--custom-class-name {
+    .dialog-index--van-dialog__confirm {
+        color: @prim !important;
+    }
+}
+</style>

+ 21 - 5
src/pages/my.vue

@@ -19,19 +19,28 @@
         </div>
         <div class="cell">
             <div class="title">COUPE订单</div>
-            <div class="desc"></div>
+            <div class="desc">
+                <img src="../static/imgs/user1.png" class="icon" mode="widthFix" />
+            </div>
         </div>
         <div class="cell">
             <div class="title">其他订单</div>
-            <div class="desc"></div>
+            <div class="desc">
+                <img src="../static/imgs/user2.png" class="icon" mode="widthFix" />
+            </div>
         </div>
-        <div class="cell">
+        <div class="cell" @click="goNext('/pages/addressList')">
             <div class="title">收货地址管理</div>
-            <div class="desc"></div>
+            <div class="desc">
+                <img src="../static/imgs/user3.png" class="icon" mode="widthFix" />
+            </div>
         </div>
         <div class="cell" @click="call">
             <div class="title">联系我们</div>
-            <div class="desc">400-086-8888</div>
+            <div class="desc">
+                <span>400-086-8888</span>
+                <img src="../static/imgs/user4.png" class="icon" mode="widthFix" />
+            </div>
         </div>
     </div>
 </template>
@@ -102,6 +111,13 @@ button {
     .desc {
         font-size: 14px;
         color: @text3;
+        display: flex;
+        align-items: center;
     }
 }
+
+.icon {
+    width: 25px;
+    margin-left: 5px;
+}
 </style>

BIN
src/static/imgs/user1.png


BIN
src/static/imgs/user2.png


BIN
src/static/imgs/user3.png


BIN
src/static/imgs/user4.png


+ 1 - 0
src/styles/common.less

@@ -11,6 +11,7 @@
 @border3: #ebeef5;
 @border4: #f2f6fc;
 @bg: #f2f4f5;
+@bg2:#F8FAFF;
 .flex() {
     display: flex;
     align-items: center;