123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- <template>
- <view class="addAddress">
- <view class="form">
- <view class="head">
- <span>地址信息</span>
- <view class="checked_box" @click="goExhibits">
- <!-- <view class="checked" v-if="item.type == 0"></view> -->
- <view class="select" v-if="type == 0">
- <image src="../../static/identify/round.png" mode=""></image>
- </view>
- <view class="select" v-else>
- <image src="../../static/identify/select.png" mode=""></image>
- </view>
- 默认地址
- </view>
- </view>
- <view class="item">
- <view class="title">
- 姓名
- </view>
- <view class="inp">
- <input class="weui-input" name="input" v-model="form.userName" placeholder="输入您的姓名" />
- </view>
- </view>
- <view class="item">
- <view class="title">
- 手机号
- </view>
- <view class="inp">
- <input class="weui-input" placeholder="手机号" v-model="form.phone" />
- </view>
- </view>
- <view class="item">
- <view class="title">
- 所在地区
- </view>
- <view class="inp" @click="getAddress" v-if="form.address !== ''">
- <!-- <input class="weui-input" name="input" v-model="form.userName" placeholder="姓名(必填)" /> -->
- {{form.address}}{{form.name}}
- </view>
- <view class="inp street" @click="getAddress" v-else>
- 省、市、区、街道
- </view>
- </view>
- <view class="item">
- <view class="title">
- 详细地址
- </view>
- <view class="inp">
- <input class="weui-input" name="input" v-model="form.atlasAdd" placeholder="列:1号楼一层101室" />
- </view>
- </view>
- </view>
- <view class="addbtn">
- <button type="primary" @click="save">{{btnName}}</button>
- </view>
- </view>
- </template>
- <script>
- import {
- addUpdate,
- addDetails,
- updateAdd,
- addList,
- defaultAdd
- } from '../../api/index'
- export default {
- data() {
- return {
- btnName: '保存',
- type: 0,
- form: {
- userName: '',
- phone: '',
- atlasAdd: '',
- openid: '',
- type: 0,
- latitude: '',
- longitude: '',
- name: '',
- address: '',
- },
- pos_name: '',
- latitude: '',
- longitude: '',
- requestBody: {},
- err: '',
- saveAddress: {
- latitude: '',
- longitude: '',
- name: '',
- address: '',
- },
- }
- },
- methods: { //设为默认地址
- goExhibits() {
- // this.checkedIndex = index
- var id = {
- id: this.id,
- openid: uni.getStorageSync('wx_copenid'),
- }
- defaultAdd(id).then(res => {
- if (res.data.code == 200) {
- this.getList()
- uni.showToast({
- title: '设置默认地址成功!',
- icon: 'none'
- })
- }
- })
- },
- getAddress() {
- uni.chooseLocation({
- success: res => {
- this.form.name = res.name;
- this.form.latitude = res.latitude;
- this.form.longitude = res.longitude;
- this.form.address = res.address
- }
- });
- },
- save() {
- this.form.openid = uni.getStorageSync('wx_copenid')
- // this.form.address = JSON.stringify(this.saveAddress)
- if (this.form.userName === '') {
- uni.showToast({
- title: '请输入姓名',
- icon: 'none'
- })
- return
- }
- if (!/^1[3456789]\d{9}$/.test(this.form.phone)) {
- uni.showToast({
- title: '请输入正确的手机号',
- icon: 'none'
- });
- return;
- }
- if (this.form.address == '') {
- uni.showToast({
- title: '请选择地址',
- icon: 'none'
- });
- return;
- }
- if (this.btnName == '修改地址') {
- // this.form.type =
- updateAdd(this.form).then(res => {
- if (res.data.code == 200) {
- uni.showToast({
- title: '修改成功',
- })
- setTimeout(function() {
- uni.navigateBack()
- }, 500)
- }
- })
- } else {
- this.form.type = this.type
- // this.requestBody = this.form
- addUpdate(this.form).then(res => {
- // console.log(res,"添加成功之后的数据")
- if (res.data.code == 200) {
- uni.showToast({
- title: '添加成功',
- })
- setTimeout(function() {
- uni.navigateBack()
- }, 500)
- } else {
- this.err = res.msg
- }
- })
- }
- }
- // onChooseLocation() {
- // uni.navigateTo({
- // url: './select_position'
- // })
- // },
- },
- mounted() {},
- onShow() {
- uni.getLocation({
- type: 'wgs84',
- success: function(res) {}
- });
- },
- onLoad(options) {
- this.type = options.type
- if (options.id) {
- addDetails({
- id: options.id
- }).then(res => {
- this.form = res.data.data,
- // this.saveAddress = JSON.parse(res.data.data.address),
- // this.address = JSON.parse(res.data.data.address),
- this.btnName = '修改地址',
- console.log(this.saveAddress)
- })
- } else {}
- },
- }
- </script>
- <style lang="scss" scoped>
- .addAddress {
- background-color: #f8f8f8;
- height: 100vh;
- padding: 40rpx 32rpx;
- box-sizing: border-box;
- }
- .head {
- width: 100%;
- display: flex;
- justify-content: space-between;
- margin-bottom: 20px;
- .checked_box {
- width: 128rpx;
- display: flex;
- align-items: center;
- font-size: 24rpx;
- .select {
- display: flex;
- align-items: center;
- image {
- width: 24rpx;
- height: 24rpx;
- margin-right: 8rpx;
- }
- }
- }
- }
- .form {
- background: #FFFFFF;
- box-shadow: 0px 4rpx 12rpx 0px rgba(88, 209, 187, 0.05);
- border-radius: 20rpx 20rpx 20rpx 20rpx;
- padding: 32rpx 24rpx;
- .item {
- width: 100%;
- display: flex;
- align-items: center;
- font-size: 26rpx;
- margin-bottom: 20rpx;
- .title {
- width: 104rpx;
- color: #333333;
- margin-right: 20rpx;
- }
- .inp {
- flex: 1;
- height: 64rpx;
- border-radius: 8rpx 8rpx 8rpx 8rpx;
- border: 2rpx solid #EEEEEE;
- padding-left: 24rpx;
- }
- .street {
- font-size: 26rpx;
- color: #999999;
- line-height: 64rpx;
- }
- }
- }
- .addbtn {
- position: fixed;
- bottom: 30px;
- width: 100%;
- // background-color: #fff;
- // border-top: 1px solid #ccc;
- padding-top: 15px;
- padding-bottom: 10px;
- button {
- margin: 0 50px;
- background: linear-gradient(90deg, #1AD7CE 0%, #21C9C1 100%);
- border-radius: 106rpx;
- }
- }
- ::v-deep.weui-input {
- height: 100%;
- font-size: 26rpx;
- }
- </style>
|