平板端快衣店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

391 lines
10 KiB

<!-- 新增供应商和客户 -->
<template>
<view>
<view class="formBox">
<uni-forms ref="form" :modelValue="formData" :rules="rules" labelWidth="85px">
<uni-forms-item label="姓名" name="consigneeName">
<uni-easyinput type="text" v-model="formData.consigneeName" placeholder="请输入人员姓名" />
<button @tap="getUserPhone">通讯录导入</button>
</uni-forms-item>
<uni-forms-item label="手机号码" name="consigneeMobile">
<uni-easyinput type="number" v-model="formData.consigneeMobile" placeholder="请输入手机号码" />
</uni-forms-item>
<uni-forms-item label="地址" name="address1">
<view class="input selectcity" @tap="openPicker">
<input placeholder="请选择省市区" disabled type="text" v-model="formData.address1"></input>
</view>
</uni-forms-item>
<uni-forms-item label="详细地址" name="address">
<uni-easyinput type="textarea" v-model="formData.address" />
</uni-forms-item>
</uni-forms>
<view class="tui-tabbar">
<view class="tui-btn-mr" v-if="type=='edit'" @tap.stop="del()">删除人员</view>
<view class="tui-btn-mr" @tap.stop="submit()">提交</view>
</view>
<cc-selectDity :show="show" @sureSelectArea="onsetCity" @hideShow="onhideShow"></cc-selectDity>
</view>
<u-modal :show="delShow" :title="'删除'" :content="'是否确认删除此用户?'" showCancelButton="true" @cancel="delShow = false"
@confirm="delItemModal"></u-modal>
</view>
</template>
<script>
import {
getArea
} from '@/utils/global.js'
import {
mapState
} from 'vuex';
export default {
data() {
return {
userInfo: '',
show: false,
delShow: false,
addressObj: {},
type: '',
popleType: '',
formData: {
consigneeMobile: '',
consigneeName: '',
address1: '',
address: '',
province: '',
city: '',
area: ''
},
// 单选数据源
sexs: [{
text: '男',
value: '男'
}, {
text: '女',
value: '女'
}],
rules: {
consigneeName: {
rules: [{
required: true,
errorMessage: '请输入姓名',
}]
},
consigneeMobile: {
rules: [{
required: true,
errorMessage: '请输入手机号',
}, {
minLength: 11,
maxLength: 11,
errorMessage: '手机号为11个字符',
}]
},
address1: {
rules: [{
required: true,
errorMessage: '请选择地址',
}]
},
address: {
rules: [{
required: true,
errorMessage: '请输入详细地址',
}]
},
},
};
},
computed: {
...mapState(['shopName', 'shopIndex'])
},
onReady() {
// 需要在onReady中设置规则
this.$refs.form.setRules(this.rules)
},
onLoad(option) {
this.popleType = option.popleType
this.type = option.type
let data = JSON.parse(option.data)
if (option.type = "edit") {
this.formData.address1 = data.province + data.city + data.area
this.formData.address = data.address
this.formData.area = data.area
this.formData.city = data.city
this.formData.province = data.province
this.formData.id = data.id
this.formData.consigneeMobile = data.consigneeMobile || data.phone
this.formData.consigneeName = data.consigneeName || data.name
}
},
methods: {
//获取手机通讯录
getUserPhone() {
console.log("aaaaa")
let that = this;
wx.chooseContact({
success: function(res) {
console.log(res)
that.formData.consigneeMobile = res.phoneNumber
that.formData.consigneeName = res.displayName
},
fail(res) {
console.log(res, '错误回调')
}
})
},
del() {
this.delShow = true;
},
delItemModal() {
this.delShow = false;
if (this.popleType == "khName") {
this.tui.request("/app/customer/delById", "post", {
id: this.formData.id,
}, false, true).then((res) => {
if (res.code == 200) {
uni.showToast({
title: "删除成功",
icon: 'none'
})
uni.navigateBack()
} else {
uni.showToast({
title: "删除失败",
icon: 'none'
})
}
})
} else {
this.tui.request("/app/supplier/delByIds", "post", {
ids: this.formData.id,
}, false, true).then((res) => {
if (res.code == 200) {
uni.showToast({
title: "删除成功",
icon: 'none'
})
uni.navigateBack()
} else {
uni.showToast({
title: "删除失败",
icon: 'none'
})
}
})
}
},
nameBlur() {
this.formData.username = this.formData.phone;
},
authVerification() {
uni.getSetting({
success: (res) => {
if (res.authSetting['scope.userLocation']) {
/* 用户授权成功时走这里 */
this.openPicker()
} else if (res.authSetting['scope.userLocation'] === undefined) {
/* 用户未授权时走这里 */
console.log('没有授权')
this.handleOpenSetting()
} else {
/* 用户拒绝了授权后走这里 */
console.log('拒绝了授权 false')
this.handleOpenSetting()
}
},
})
},
handleOpenSetting() {
wx.openSetting({
success: (res) => {
console.log('定位 openSetting', res)
if (res.authSetting["scope.userLocation"]) {
this.openPicker()
}
}
})
},
openPicker() {
let that = this;
uni.chooseLocation({
success: function(res) {
if (res.name != '') {
let aaa = getArea(res.address)
that.formData.province = aaa.province
that.formData.city = aaa.city
that.formData.area = aaa.country
that.formData.address = aaa.address + '-' + res.name
that.formData.address1 = aaa.province + aaa.city + aaa.country
} else {
that.tui.toast("微信地址选择器调用失败,请重新选择!")
}
},
fail: function(res) {
console.log(res)
}
});
},
// 触发提交表单
submit() {
let that = this;
this.$refs.form.validate().then(res => {
if (this.popleType == 'khName') {
if (that.type == 'edit') {
that.tui.request("/app/customer/edit", "post", {
name: this.formData.consigneeName,
phone: this.formData.consigneeMobile,
address: this.formData.address,
province: this.formData.province,
city: this.formData.city,
area: this.formData.area,
id: this.formData.id,
userName: this.formData.consigneeMobile
}, false, true).then((res) => {
if (res.code == 200) {
uni.showToast({
title: "添加成功",
icon: 'none'
})
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2];
prevPage.$vm.popleType = 'khName'
uni.navigateBack({
delta: 1
})
} else {
uni.showToast({
title: "添加失败",
icon: 'none'
})
}
})
} else {
that.tui.request("/app/customer/save", "post", {
name: this.formData.consigneeName,
phone: this.formData.consigneeMobile,
address: this.formData.address,
province: this.formData.province,
city: this.formData.city,
area: this.formData.area,
userName: this.formData.consigneeMobile
}, false, true).then((res) => {
if (res.code == 200) {
uni.showToast({
title: "添加成功",
icon: 'none'
})
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2];
prevPage.$vm.popleType = 'khName'
uni.navigateBack({
delta: 1
})
} else {
uni.showToast({
title: "添加失败",
icon: 'none'
})
}
})
}
} else {
if (that.type == 'edit') {
that.tui.request("/app/supplier/edit", "post", this.formData, false,
true).then((res) => {
if (res.code == 200) {
uni.showToast({
title: "修改成功",
icon: 'none'
})
uni.navigateBack()
} else {
uni.showToast({
title: "修改失败",
icon: 'none'
})
}
})
} else {
that.tui.request("/app/supplier/save", "post", this.formData, false,
true).then((res) => {
if (res.code == 200) {
uni.showToast({
title: "添加成功",
icon: 'none'
})
let pages =
getCurrentPages();
let prevPage = pages[pages.length - 2];
prevPage.$vm.popleType = 'gysName'
uni.navigateBack({
delta: 1
})
} else {
uni.showToast({
title: "添加失败",
icon: 'none'
})
}
})
}
}
}).catch(err => {})
}
}
}
</script>
<style lang="scss">
.cc_area_view {
z-index: 997 !important;
}
.formBox {
margin: 20rpx;
padding: 20rpx;
background-color: #fff;
}
.tui-tabbar {
width: 100%;
height: 98rpx;
background: #fff;
position: fixed;
left: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: flex-end;
font-size: 26rpx;
box-shadow: 0 0 1px rgba(0, 0, 0, .3);
padding-bottom: env(safe-area-inset-bottom);
z-index: 996;
padding: 0 20rpx;
.tui-btn-mr {
width: 130rpx;
height: 60rpx;
background: #088FEB;
color: #fff;
border-radius: 10px;
line-height: 60rpx;
text-align: center;
margin-right: 30rpx;
}
}
button{
height: 73rpx;
line-height: 73rpx;
width: 130rpx;
font-size: 22rpx;
padding: 0;
margin: 0;
background: #088FEB;
color: #fff;
border-radius: 0;
}
</style>