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.

395 lines
11 KiB

3 years ago
<template>
<view :class="{page: isDetail}">
3 years ago
<uni-card v-if="customerId" :is-shadow="false" :border="false" is-full>
<view class="info">
3 years ago
<view class="name">{{ form.customerName }}</view>
<view class="text">客户类型{{ customerType }}</view>
3 years ago
<view class="text">产品到期时间{{ form.expireDate || '' }}</view>
</view>
</uni-card>
<view class="form-list">
<view class="line">
<view class="l-title">基本信息</view>
3 years ago
</view>
<view class="line req">
<view class="name">客户名称</view>
<view :class="['ph', {val: form.customerName}]" @click="schoolVisible = true">{{ form.customerName || '请选择学校' }}</view>
</view>
<view class="line">
<view class="name">省份</view>
<view class="val">{{ form.provinceName }}</view>
</view>
<view class="line">
<view class="name">城市</view>
<view class="val">{{ form.cityName }}</view>
</view>
<view class="line req">
<view class="name">行业类型</view>
<view v-if="isDetail" class="val">{{ form.industryClassName }}</view>
<uni-data-picker v-else class="picker-input" placeholder="请选择行业类型" popup-title="请选择行业类型" preload :clear-icon="false" :localdata="industryClassList" :map="{text: 'industryClassName', value: 'industryClassId'}" v-model="form.industryClassId" @change="industryClassChange"></uni-data-picker>
</view>
<view class="line req">
<view class="name">行业</view>
<view v-if="isDetail" class="val">{{ form.industryName }}</view>
<uni-data-picker v-else class="picker-input" placeholder="请选择行业" popup-title="请选择行业" preload :clear-icon="false" :localdata="industryList" :map="{text: 'industryName', value: 'industryId'}" v-model="form.industryId" :readonly="form.industryClassId ? false : true"></uni-data-picker>
</view>
<view class="line req">
<view class="name">联系人姓名</view>
<view v-if="isDetail" class="val">{{ form.name }}</view>
<input v-else type="text" v-model="form.name">
</view>
<view class="line">
<view class="name">手机</view>
<view v-if="isDetail" class="val">{{ form.phone }}</view>
<input v-else type="text" v-model="form.phone">
</view>
<view class="line req">
<view class="name">账号</view>
<view v-if="isDetail" class="val">{{ form.account }}</view>
<input v-else type="text" placeholder="请以院校首字母+admin的格式来设置" v-model="form.account">
</view>
<view class="line">
<view class="name">职务</view>
<view v-if="isDetail" class="val">{{ form.position }}</view>
<input v-else type="text" v-model="form.position">
</view>
<view class="line">
<view class="name">邮箱</view>
<view v-if="isDetail" class="val">{{ form.email }}</view>
<input v-else type="text" v-model="form.email">
</view>
<view class="line">
<view class="name">产品到期时间</view>
<view class="val">{{ form.expireDate }}</view>
</view>
<view class="line">
<view class="name">客户类型</view>
<view class="val">{{ customerType }}</view>
</view>
</view>
<view class="action" v-if="isDetail">
3 years ago
<view class="item" @click="toPage(`../clientDetail/clientDetail?customerId=${customerId}`)">
<uni-icons class="icon" custom-prefix="iconfont" type="icon-edit" size="20" color="#959595"></uni-icons>
<view class="text">编辑</view>
</view>
3 years ago
<view class="item" @click="toPage(`../ordered/ordered?customerId=${customerId}`)">
<uni-icons class="icon" custom-prefix="iconfont" type="icon-product" size="20" color="#959595"></uni-icons>
<view class="text">已订阅产品</view>
</view>
<view class="item" @click="toPage('../orders/orders')">
<uni-icons class="icon" custom-prefix="iconfont" type="icon-dingdan" size="20" color="#959595"></uni-icons>
<view class="text">订单</view>
</view>
</view>
3 years ago
<view class="mask" v-show="schoolVisible" @click="closeSchool"></view>
<view class="school-popup" v-show="schoolVisible">
<view class="top">请选择学校</view>
<uni-icons class="close" type="closeempty" size="20" @click="closeSchool"></uni-icons>
<uni-search-bar class="search" radius="5" placeholder="请输入学校名称" v-model="keyword" clearButton="auto" cancelButton="none" />
<view class="list">
<view class="item" v-for="item in schoolList" @click="schoolChange(item)">{{ item.schoolName }}</view>
</view>
</view>
3 years ago
</view>
</template>
<script>
3 years ago
import { queryCustomerDetails, querySchool, queryIndustryClass, queryIndustry, queryCustomerIsExists, addCustomer, updateCustomer } from '@/apis/modules/client.js'
3 years ago
export default {
data() {
return {
3 years ago
isDetail: false,
customerId: '',
// 客户类型
customerTypeList: [{
name: '正式',
3 years ago
value: 1
3 years ago
},
{
name: '试用',
3 years ago
value: 2
3 years ago
},
{
name: '到期',
value: 3
3 years ago
}],
3 years ago
nameRepeat: false,
3 years ago
schoolVisible: false,
keyword: '',
searchTimer: null,
3 years ago
schoolList: [],
3 years ago
schoolListAll: [],
3 years ago
industryClassList: [],
industryList: [],
form: {
3 years ago
countries: '中国',
3 years ago
customerId: '',
customerName: '',
industryClassId: '',
industryId: '',
provinceId: '',
3 years ago
provinceName: '',
3 years ago
account: '',
name: '',
phone: '',
position: '',
cityId: '',
3 years ago
cityName: '',
3 years ago
customerType: '',
expireDate: '',
email: '',
schoolId: ''
},
3 years ago
// 校验规则
rules: {
schoolId: {
rules: [{
required: true,
errorMessage: '请选择客户'
}]
},
industryClassId: {
rules: [{
required: true,
errorMessage: '请选择行业类型'
}]
},
industryId: {
rules: [{
required: true,
errorMessage: '请选择行业'
}]
},
name: {
rules: [{
required: true,
errorMessage: '联系人姓名不能为空'
}]
},
account: {
rules: [{
required: true,
errorMessage: '账号不能为空'
}]
},
},
3 years ago
customerType: '',
3 years ago
}
},
3 years ago
watch: {
keyword () {
clearTimeout(this.searchTimer)
this.searchTimer = setTimeout(() => {
this.filterSchool()
}, 500)
}
},
3 years ago
onLoad(option) {
this.customerId = option.customerId
this.isDetail = !!option.show
3 years ago
3 years ago
option.customerId && this.getInfo()
// 非详情才需要查询学校和行业
if (!this.isDetail) {
this.getSchool()
this.getIndustryClass()
}
// 设置标题
uni.setNavigationBarTitle({
title: option.customerId ?
(option.show ?
'客户详情' :
'编辑客户') :
'新增客户'
})
3 years ago
},
methods: {
3 years ago
// 获取详情
getInfo() {
queryCustomerDetails({
customerId: this.customerId
}).then(({ result }) => {
const { customer } = result
this.form = customer
this.$refs.nameInput.val = customer.name
this.$refs.phoneInput.val = customer.phone
this.$refs.accountInput.val = customer.account
this.$refs.positionInput.val = customer.position
this.$refs.emailInput.val = customer.email
3 years ago
this.customerType = this.customerTypeList.find(e => e.value === customer.customerType).name
}).catch(e => {})
},
// 获取学校列表
getSchool() {
querySchool({
schoolName: '',
provinceId: '',
cityId: ''
}).then(({ list }) => {
3 years ago
this.schoolListAll = list
3 years ago
this.schoolList = list
}).catch(res => {})
},
3 years ago
// 学校模糊匹配
filterSchool() {
const { keyword } = this
this.schoolList = keyword ?
this.schoolListAll.filter(e => e.schoolName.includes(keyword)) :
this.schoolListAll
},
// 关闭学校弹框
closeSchool() {
this.schoolVisible = false
this.keyword = ''
},
3 years ago
// 客户名称选择回调
3 years ago
schoolChange(school) {
3 years ago
const { form } = this
const { schoolId } = form
3 years ago
form.schoolId = school.schoolId
3 years ago
form.customerName = school.schoolName
form.provinceId = school.provinceId
form.provinceName = school.provinceName
form.cityId = school.cityId
form.cityName = school.cityName
3 years ago
this.closeSchool()
// 客户名称判重
3 years ago
queryCustomerIsExists({
schoolId
}).then(res => {
this.nameRepeat = false
}).catch(res => {
this.nameRepeat = true
})
},
3 years ago
// 获取行业类
getIndustryClass() {
queryIndustryClass().then(({ list }) => {
this.industryClassList = list
}).catch(res => {})
},
// 行业分类选择回调
industryClassChange() {
this.getIndustry()
},
// 获取行业
getIndustry() {
queryIndustry({
industryClassId: this.form.industryClassId
}).then(({ list }) => {
this.industryList = list
}).catch(res => {})
3 years ago
},
3 years ago
// 跳转
toPage(path) {
this.$util.to(path)
3 years ago
},
// 提交
3 years ago
submit() {
const refs = this.$refs
const { form } = this
3 years ago
// 有大量数据的情况下,input输入用v-model会有bug,所以给每个input加ref来手动取值赋值
form.name = refs.nameInput.val
form.account = refs.accountInput.val
form.position = refs.positionInput.val
form.phone = refs.phoneInput.val
form.email = refs.emailInput.val
this.$nextTick(() => {
this.$refs.form.validate().then(res => {
if (this.nameRepeat) return this.$util.errMsg('客户已存在!')
if (this.customerId) {
updateCustomer(form).then(res => {
this.$util.sucMsg('编辑成功')
setTimeout(() => {
this.$util.to('../clients/clients')
}, 1500)
}).catch(res => {})
} else {
addCustomer(form).then(res => {
this.$util.sucMsg('添加成功')
setTimeout(() => {
uni.navigateBack()
}, 1500)
}).catch(res => {})
}
}).catch(err => {})
})
3 years ago
},
3 years ago
}
}
</script>
<style scoped lang="scss">
.page {
padding-bottom: 55px;
}
.info {
.name {
margin-bottom: 5px;
font-size: 16px;
color: #333;
}
}
.action {
3 years ago
z-index: 2;
position: fixed;
bottom: 0;
display: flex;
justify-content: space-around;
width: 100%;
padding: 5px 10px;
background-color: #fff;
border-top: 1px solid #f3f3f3;
.item {
text-align: center;
}
.text {
font-size: 10px;
color: #959595;
}
}
3 years ago
.mask {
z-index: 9;
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
background-color: rgba(0, 0, 0, .5);
}
.school-popup {
z-index: 10;
position: fixed;
bottom: 0%;
width: 100%;
height: 90vh;
background-color: #fff;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
.top {
text-align: center;
line-height: 50px;
font-size: 14px;
color: #333;
border-bottom: 1px solid #f1f1f1;
}
.close {
position: absolute;
top: 15px;
right: 15px;
}
.list {
max-height: calc(90vh - 103px);
padding: 0 15px;
overflow: auto;
.item {
line-height: 34px;
font-size: 12px;
}
}
}
3 years ago
</style>