|
| 1 | +<template> |
| 2 | + <div class="rating_page"> |
| 3 | + <head-top head-title="新增地址" go-back='true'></head-top> |
| 4 | + <section class="adddetail"> |
| 5 | + <form action="" v-on:submit.prevent> |
| 6 | + <section class="ui-padding-block"> |
| 7 | + <div class="input-new"> |
| 8 | + <input type="text" placeholder="请填写你的姓名" :class="{verifies:verify}" v-model="message" @input="inputThing"> |
| 9 | + <p v-if="verify">请填写您的姓名</p> |
| 10 | + </div> |
| 11 | + <router-link to='/profile/info/address/add/addDetail' class="add-detail"> |
| 12 | + <div class="input-new"> |
| 13 | + <input type="text" placeholder="小区/写字楼/学校等" readonly="readonly" v-model="addAddress" /> |
| 14 | + </div> |
| 15 | + </router-link> |
| 16 | + <div class="input-new"> |
| 17 | + <input type="text" placeholder="请填写详细送餐地址" :class="{verifies:verifythree}" @input="inputThingthree" v-model="mesthree"/> |
| 18 | + <p v-if="verifythree">{{sendaddress}}</p> |
| 19 | + </div> |
| 20 | + <div class="input-new"> |
| 21 | + <input type="text" placeholder="请填写能够联系到您的手机号" :class="{verifies:verifyfour}" v-model="telenum" @input="inputThingfour" /> |
| 22 | + <p v-if="verifyfour">{{telephone}}</p> |
| 23 | + </div> |
| 24 | + <div class="input-new"> |
| 25 | + <input type="text" placeholder="备用联系电话(选填)" v-model="standbytelenum" @input="inputThingfive" /> |
| 26 | + <p v-if="verifyfive">{{standbytele}}</p> |
| 27 | + </div> |
| 28 | + </section> |
| 29 | + <section class="addbutton"> |
| 30 | + <button :class="{butopacity:butpart}" @click.prevent="submitThing">新增地址</button> |
| 31 | + </section> |
| 32 | + </form> |
| 33 | + </section> |
| 34 | + <transition name="router-slid" mode="out-in"> |
| 35 | + <router-view></router-view> |
| 36 | + </transition> |
| 37 | + <alert-tip v-if="showAlert" @closeTip="showAlert = false" :alertText="alertText"></alert-tip> |
| 38 | + </div> |
| 39 | +</template> |
| 40 | + |
| 41 | +<script> |
| 42 | +import headTop from '@/components/header/head' |
| 43 | +import { getImgPath } from '@/components/common/mixin' |
| 44 | +import { mapState, mapMutations } from 'vuex' |
| 45 | +// import { postAddAddress } from '@/service/getData' |
| 46 | +import alertTip from '@/components/common/alertTip' |
| 47 | +
|
| 48 | +export default { |
| 49 | + data () { |
| 50 | + return { |
| 51 | + verify: false, // 姓名 |
| 52 | + verifytwo: false, // 备注 |
| 53 | + verifythree: false, // 地址 |
| 54 | + verifyfour: false, // 电话 |
| 55 | + verifyfive: false, // 备用电话 |
| 56 | + butpart: false, // 新增地址按钮的透明度 |
| 57 | + sendaddress: '', // 地址 |
| 58 | + message: '', // 信息 |
| 59 | + mesthree: '', // 送餐地址 |
| 60 | + telenum: '', // 手机号 |
| 61 | + telephone: '', // 手机号提示 |
| 62 | + standbytele: '', // 备用手机号提示 |
| 63 | + standbytelenum: '', // 备用手机号 |
| 64 | + addSearch: false, // 添加搜索地址 |
| 65 | + newAddress: {}, // 增加数组的元素 |
| 66 | + showAlert: false, // 弹出框 |
| 67 | + alertText: null // 弹出信息 |
| 68 | + } |
| 69 | + }, |
| 70 | + mixins: [getImgPath], |
| 71 | + components: { |
| 72 | + headTop, |
| 73 | + alertTip |
| 74 | + }, |
| 75 | + computed: { |
| 76 | + ...mapState([ |
| 77 | + 'userInfo', |
| 78 | + 'addAddress', |
| 79 | + 'removeAddress', |
| 80 | + 'newAddress', |
| 81 | + 'geohash' |
| 82 | + ]) |
| 83 | + }, |
| 84 | + methods: { |
| 85 | + ...mapMutations(['ADD_ADDRESS']), |
| 86 | + inputThing () { |
| 87 | + !this.message ? (this.verify = true) : (this.verify = false) |
| 88 | + this.bindThing() |
| 89 | + }, |
| 90 | + // 输入地址 |
| 91 | + inputThingthree () { |
| 92 | + this.verifythree = true |
| 93 | + if (this.mesthree.length === 0) { |
| 94 | + this.sendaddress = '请详细填写送餐地址' |
| 95 | + } else if (this.mesthree.length > 0 && this.mesthree.length <= 2) { |
| 96 | + this.sendaddress = '送餐地址太短了,不能辨识' |
| 97 | + } else { |
| 98 | + this.sendaddress = '' |
| 99 | + this.verifythree = false |
| 100 | + } |
| 101 | + this.bindThing() |
| 102 | + }, |
| 103 | + // 输入手机号 |
| 104 | + inputThingfour () { |
| 105 | + this.verifyfour = true |
| 106 | + if (/^[1][358][0-9]{9}$/.test(this.telenum)) { |
| 107 | + this.verifyfour = false |
| 108 | + } else if (this.telenum === '') { |
| 109 | + this.telephone = '手机号不能为空' |
| 110 | + } else { |
| 111 | + this.telephone = '请输入正确的手机号' |
| 112 | + } |
| 113 | + this.bindThing() |
| 114 | + }, |
| 115 | + // 输入备注手机号 |
| 116 | + inputThingfive () { |
| 117 | + this.verifyfive = true |
| 118 | + if ( |
| 119 | + /^[1][358][0-9]{9}$/.test(this.standbytelenum) || |
| 120 | + this.standbytelenum === '' |
| 121 | + ) { |
| 122 | + this.verifyfive = false |
| 123 | + } else { |
| 124 | + this.standbytele = '请输入正确的手机号' |
| 125 | + } |
| 126 | + this.bindThing() |
| 127 | + }, |
| 128 | + bindThing () { |
| 129 | + if (this.message && this.mesthree && !this.verifyfour) { |
| 130 | + this.butpart = true |
| 131 | + } else { |
| 132 | + this.butpart = false |
| 133 | + } |
| 134 | + }, |
| 135 | + // 保存地址 |
| 136 | + submitThing () { |
| 137 | + let data = { |
| 138 | + userId: this.userInfo.user_id, |
| 139 | + address: this.mesthree, |
| 140 | + address_detail: this.addAddress, |
| 141 | + geohash: this.geohash, |
| 142 | + name: this.message, |
| 143 | + phone: this.telenum, |
| 144 | + phone_bk: this.standbytelenum, |
| 145 | + poi_type: 0, |
| 146 | + sex: 1, |
| 147 | + tag: '公司', |
| 148 | + tag_type: 4 |
| 149 | + } |
| 150 | + this.$axios.post('/v1/users/' + this.userInfo.user_id + '/addresses', data).then((res) => { |
| 151 | + if (res.message) { |
| 152 | + this.showAlert = true |
| 153 | + this.alertText = res.message |
| 154 | + } else if (this.butpart) { |
| 155 | + // 保存的地址存入vuex |
| 156 | + this.ADD_ADDRESS({ |
| 157 | + name: this.message, |
| 158 | + address: this.mesthree, |
| 159 | + address_detail: this.addAddress, |
| 160 | + geohash: 'wtw37r7cxep4', |
| 161 | + phone: this.telenum, |
| 162 | + phone_bk: this.standbytelenum, |
| 163 | + poi: this.addAddress, |
| 164 | + poi_type: 0 |
| 165 | + }) |
| 166 | + this.$router.go(-1) |
| 167 | + } |
| 168 | + }) |
| 169 | + } |
| 170 | + } |
| 171 | +} |
| 172 | +</script> |
| 173 | +<style lang='scss'> |
| 174 | +@import "../../../../../style/add.scss"; |
| 175 | +</style> |
0 commit comments