|
@@ -9,30 +9,33 @@
|
|
|
<uni-forms-item label="联系电话" name="phone">
|
|
|
<uni-easyinput type="number" v-model="form.phone" placeholder="请输入联系电话" />
|
|
|
</uni-forms-item>
|
|
|
- <uni-forms-item label="地图选点">
|
|
|
+ <uni-forms-item label="地图选点" v-if="is_wx==true">
|
|
|
<button type="default" size="mini" class="toLoacl" @click="toLocaltion()">地图选点</button>
|
|
|
</uni-forms-item>
|
|
|
- <uni-forms-item label="所在省份">
|
|
|
+ <uni-forms-item label="所在省份" name="province">
|
|
|
<picker class="picker" mode="selector" :range="provinceList" @change="proChange" range-key="value">
|
|
|
<view>{{form.province||'请选择所在省份'}}</view>
|
|
|
</picker>
|
|
|
</uni-forms-item>
|
|
|
- <uni-forms-item label="所在市">
|
|
|
+ <uni-forms-item label="所在市" name="city">
|
|
|
<picker class="picker" mode="selector" :range="cityList" @change="cityChange" range-key="value">
|
|
|
<view>{{form.city||'请选择所在市'}}</view>
|
|
|
</picker>
|
|
|
</uni-forms-item>
|
|
|
- <uni-forms-item label="所在区">
|
|
|
+ <uni-forms-item label="所在区" name="area">
|
|
|
<picker class="picker" mode="selector" :range="areaList" @change="areaChange" range-key="value">
|
|
|
<view>{{form.area||'请选择所在区'}}</view>
|
|
|
</picker>
|
|
|
</uni-forms-item>
|
|
|
<uni-forms-item label="详细地址" name="address">
|
|
|
- <uni-easyinput type="textarea" v-model="form.address" placeholder="请输入所在小区/大厦/学校" />
|
|
|
+ <uni-easyinput type="textarea" v-model="form.address" placeholder="请输入详细地址" />
|
|
|
+ </uni-forms-item>
|
|
|
+ <uni-forms-item label="是否默认" name="is_default">
|
|
|
+ <switch color="#FB1438" :checked="form.is_default=='1'?true:false" @change="defaChange" />
|
|
|
</uni-forms-item>
|
|
|
</uni-forms>
|
|
|
<view class="btn">
|
|
|
- <button type="primary" @click="onSubmit('form')" size="small">提交保存</button>
|
|
|
+ <button type="primary" size="mini" @click="onSubmit('form')">提交保存</button>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
@@ -40,38 +43,51 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
- const chooseLocation = requirePlugin('chooseLocation');
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
+ is_wx: true,
|
|
|
+ user: {},
|
|
|
id: '',
|
|
|
form: {},
|
|
|
rules: {
|
|
|
- // name: {
|
|
|
- // rules: [{
|
|
|
- // required: true,
|
|
|
- // errorMessage: '请输入收货人',
|
|
|
- // }]
|
|
|
- // },
|
|
|
- // phone: {
|
|
|
- // rules: [{
|
|
|
- // required: true,
|
|
|
- // errorMessage: '请输入联系电话',
|
|
|
- // tel: true
|
|
|
- // }]
|
|
|
- // },
|
|
|
- // deptname: {
|
|
|
- // rules: [{
|
|
|
- // required: true,
|
|
|
- // errorMessage: '请输入机构名称'
|
|
|
- // }]
|
|
|
- // },
|
|
|
- // address: {
|
|
|
- // rules: [{
|
|
|
- // required: true,
|
|
|
- // errorMessage: '请输入详细地址'
|
|
|
- // }]
|
|
|
- // },
|
|
|
+ name: {
|
|
|
+ rules: [{
|
|
|
+ required: true,
|
|
|
+ errorMessage: '请输入收货人',
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ phone: {
|
|
|
+ rules: [{
|
|
|
+ required: true,
|
|
|
+ errorMessage: '请输入联系电话',
|
|
|
+ tel: true
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ province: {
|
|
|
+ rules: [{
|
|
|
+ required: true,
|
|
|
+ errorMessage: '请选择所在省'
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ city: {
|
|
|
+ rules: [{
|
|
|
+ required: true,
|
|
|
+ errorMessage: '请选择所在市'
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ area: {
|
|
|
+ rules: [{
|
|
|
+ required: false,
|
|
|
+ errorMessage: '请选择所在区'
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ address: {
|
|
|
+ rules: [{
|
|
|
+ required: true,
|
|
|
+ errorMessage: '请输入详细地址'
|
|
|
+ }]
|
|
|
+ },
|
|
|
},
|
|
|
provinceList: [ //所在省份
|
|
|
{
|
|
@@ -121,26 +137,46 @@
|
|
|
onLoad: function(e) {
|
|
|
const that = this;
|
|
|
that.$set(that, `id`, e && e.id || '');
|
|
|
- that.search()
|
|
|
+ that.watchLogin();
|
|
|
},
|
|
|
onShow: function() {
|
|
|
const that = this;
|
|
|
- that.searchLocal()
|
|
|
+ that.searchplatform();
|
|
|
+ that.searchLocal();
|
|
|
},
|
|
|
onUnload: function() {
|
|
|
+ const chooseLocation = requirePlugin('chooseLocation');
|
|
|
chooseLocation.setLocation(null);
|
|
|
},
|
|
|
methods: {
|
|
|
- // 查询详细信息
|
|
|
- async search() {
|
|
|
+ // 监听用户是否登录
|
|
|
+ watchLogin() {
|
|
|
const that = this;
|
|
|
- if (that.id) {
|
|
|
- let res = await that.$api(`/address/${that.id}`, 'GET')
|
|
|
- if (res.errcode == '0') {
|
|
|
- console.log(res.data);
|
|
|
- that.$set(that, `form`, res.data)
|
|
|
+ uni.getStorage({
|
|
|
+ key: 'token',
|
|
|
+ success: async function(res) {
|
|
|
+ let user = that.$jwt(res.data);
|
|
|
+ if (user) {
|
|
|
+ that.$set(that, `user`, user);
|
|
|
+ if (that.id) {
|
|
|
+ let arr = await that.$api(`/address/${that.id}`, 'GET')
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ that.$set(that, `form`, arr.data)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ that.$set(that, `form`, {
|
|
|
+ name: user.name || '',
|
|
|
+ phone: user.phone || ''
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: function(err) {
|
|
|
+ uni.reLaunch({
|
|
|
+ url: '/pages/login/index'
|
|
|
+ })
|
|
|
}
|
|
|
- }
|
|
|
+ })
|
|
|
},
|
|
|
// 定位
|
|
|
toLocaltion() {
|
|
@@ -152,8 +188,15 @@
|
|
|
});
|
|
|
},
|
|
|
searchLocal() {
|
|
|
+ const that = this;
|
|
|
+ const chooseLocation = requirePlugin('chooseLocation');
|
|
|
const location = chooseLocation.getLocation();
|
|
|
- console.log(location);
|
|
|
+ if (location) {
|
|
|
+ that.$set(that.form, `province`, location.province || '');
|
|
|
+ that.$set(that.form, `city`, location.city || '');
|
|
|
+ that.$set(that.form, `area`, location.district || '');
|
|
|
+ that.$set(that.form, `address`, location.address || '');
|
|
|
+ }
|
|
|
},
|
|
|
// 选择省份
|
|
|
proChange(e) {
|
|
@@ -179,15 +222,52 @@
|
|
|
that.$set(that.form, `city`, data.value)
|
|
|
}
|
|
|
},
|
|
|
+ // 是否默认
|
|
|
+ defaChange(e) {
|
|
|
+ const that = this;
|
|
|
+ let value = e.detail.value == true ? '1' : '0';
|
|
|
+ that.$set(that.form, `is_default`, value)
|
|
|
+ },
|
|
|
// 提交保存
|
|
|
- onSubmit() {
|
|
|
+ onSubmit(ref) {
|
|
|
const that = this;
|
|
|
- let data = that.form;
|
|
|
- data = {
|
|
|
- ...data,
|
|
|
- check: that.check
|
|
|
- }
|
|
|
+ let id = that.id;
|
|
|
+ let user = that.user;
|
|
|
+ that.$refs[ref].validate().then(async params => {
|
|
|
+ params.customer = user.id;
|
|
|
+ let res;
|
|
|
+ if (id) res = await that.$api(`/address/${id}`, 'POST', params)
|
|
|
+ else res = await that.$api(`/address`, 'POST', params);
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ uni.showToast({
|
|
|
+ title: '维护信息成功',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ uni.navigateBack({
|
|
|
+ delta: 1
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: res.errmsg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
+ // 查询平台
|
|
|
+ searchplatform() {
|
|
|
+ const that = this;
|
|
|
+ uni.getStorage({
|
|
|
+ key: 'system',
|
|
|
+ success: function(res) {
|
|
|
+ if (res.data.uniPlatform == 'mp-weixin') {
|
|
|
+ that.$set(that, `is_wx`, true)
|
|
|
+ } else {
|
|
|
+ that.$set(that, `is_wx`, false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
@@ -211,25 +291,16 @@
|
|
|
border-radius: 5px;
|
|
|
padding: 2vw;
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // .uni-forms-item {
|
|
|
- // margin-bottom: 6vw !important;
|
|
|
- // display: flex;
|
|
|
- // flex-direction: row;
|
|
|
- // }
|
|
|
|
|
|
- // .local {
|
|
|
- // .uni-data-tree {
|
|
|
- // width: 60vw;
|
|
|
- // }
|
|
|
+ .btn {
|
|
|
+ text-align: center;
|
|
|
|
|
|
- // }
|
|
|
-
|
|
|
- // .localicon {
|
|
|
- // position: absolute;
|
|
|
- // right: 0;
|
|
|
- // top: 5px;
|
|
|
- // }
|
|
|
-</style>
|
|
|
+ button {
|
|
|
+ width: 30%;
|
|
|
+ font-size: 14px;
|
|
|
+ background-color: var(--f35BColor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+</style>
|