hls_crm/pages/index/groupCompany/subsidiary/newSubsidiary/newSubsidiary.vue

1008 lines
24 KiB
Vue

<template>
<view class="create_customer">
<view class="fllow_form" >
<input type="text" class="nameinput" v-model="name" placeholder="输入客户名称"
placeholder-style="color:#999;font-size:32rpx;"
/>
<view class="form_right theme">
<image id="img" style="margin:0 15rpx 0 0;;" :src="BASE_IMG_URL+'chachong.png'" mode="scaleToFill"></image>
<view @click="checkName" style="color: #008EFF;font-size: 26rpx;">查重</view>
</view>
</view>
<!-- 基础信息 -->
<view class="info_head">基础信息</view>
<view class="fllow_form">
<view style="color: #999;font-size:32rpx;">上级公司</view>
<picker @change="changeParent" :disabled="parentDisabled" :value="parentIndex" :range="plist">
<view class="form_right">
<view :class="parentName ? 'valueActive' : '' ">{{parentName ? parentName : '点击选择'}}</view>
<view class="iconfont icon-arrows_right"></view>
</view>
</picker>
</view>
<view class="fllow_form" style="color: #999;font-size: 32rpx;">
<view><text>*</text>地址定位</view>
<view class="form_right" @click="detailAddClick">
<view class="location" :class="address_dingwei ? 'valueActive' : '' ">{{address_dingwei ? address_dingwei : '点击选择'}}</view>
<view class="iconfont icon-arrows_right"></view>
</view>
</view>
<view class="fllow_form" style="color: #999;font-size: 32rpx;">
<view><text>*</text>详细地址</view>
<view class="form_right">
<input type="text" :class="address_detail ? 'valueActive' : '' " v-model="address_detail" placeholder-style="font-size:30rpx;color: #999;" placeholder="填写详细地址" />
</view>
</view>
<form-item1 v-for="(item,index) in listForm" :key="index" :objInfo="item" @changeData="changeData"></form-item1>
<!-- 首联系人 -->
<view class="linktab">
<view class="info_head">首联系人</view>
<view class="link_right">
<view class="linkbtn" :class="countryType == 1 ? 'linkbtnactive' : '' " @click="changeCountry(1)">国内</view>
<view class="linkbtn" :class="countryType == 2 ? 'linkbtnactive' : ''" @click="changeCountry(2)">国外</view>
</view>
</view>
<view>
<form-item1 v-for="(item,index) in firstContactForm" :key="index" :objInfo="item" @changeData="changeContactData"></form-item1>
</view>
<view class="info_head">跟进任务</view>
<view class="fllow_form">
<view><text>*</text>跟进类型</view>
<picker @change="changeFollow" :value="followIndex" :range="followList">
<view class="form_right">
<view>{{follow_type ? follow_type : '点击选择'}}</view>
<view class="iconfont icon-arrows_right"></view>
</view>
</picker>
</view>
<view class="fllow_form">
<view><text>*</text>下次跟进时间</view>
<!-- #ifdef MP-WEIXIN -->
<picker @change="changeTime" mode="multiSelector" :range="dateTimeArray" :value="dateTime">
<view class="form_right">
<view>{{next_time ? next_time : '点击选择'}}</view>
<view class="iconfont icon-arrows_right"></view>
</view>
</picker>
<!-- #endif -->
<!-- #ifdef MP-ALIPAY -->
<picker @change="changeAlipayTime" mode="date">
<view class="form_right">
<view>{{next_time ? next_time : '点击选择'}}</view>
<view class="iconfont icon-arrows_right"></view>
</view>
</picker>
<!-- #endif -->
</view>
<view class="fllow_form">
<view>上传附件</view>
<view class="form_right" @click="uploadClick">
<view>选择附件</view>
<view class="iconfont icon-arrows_right"></view>
</view>
</view>
<view class="imglist" v-if="imgList.length != 0">
<view class="imgbox" v-for="(item,imgindex) in imgList" :key="index">
<image :src="BASE_IMG_URL+'close.png'" class="delimg" @click="delImg(imgindex)" mode="scaleToFill"></image>
<image :src="item.url" class="selfimg" @click="openCommonImg(imgList,imgindex)" mode="scaleToFill"></image>
</view>
</view>
<view class="fllow_file_li" v-if="fileList.length != 0">
<view class="fil_li" v-for="(item,fileindex) in fileList" :key="fileindex">
<image :src="BASE_IMG_URL+'fujian.png'" class="fileimg" mode="scaleToFill"></image>
<view class="filename" @click="openCommonFile(item)">{{item.name}}</view>
<image :src="BASE_IMG_URL+'close.png'" class="closeimg" @click="delFile(fileindex)" mode="scaleToFill"></image>
</view>
</view>
<view class="fllow_area">
<view class="area_head"><text>*</text>跟进内容</view>
<textarea :value="content" @input="changeContent" placeholder="勤跟进,多签单" placeholder-style="color:#999" />
</view>
<view class="affiliation">
<view class="aff_head">提醒谁看</view>
<view class="aff_con">
<view class="aff_item affbox" v-for="(item,index) in remindPeople" :key="index">
<image :src="BASE_IMG_URL+'close.png'" class="delremind" v-if="item.isDel" @click="delRemind(index)" mode="scaleToFill"></image>
<image :src="item.img ? item.img : BASE_IMG_URL+'headImg.png'" mode="scaleToFill"></image>
<view>{{item.name}}</view>
</view>
<view class="aff_last" @click="moreClick">
<image :src="BASE_IMG_URL+'morebtn.png'" mode="scaleToFill"></image>
</view>
</view>
</view>
<view id="btn" class="btn_g bg-blue button-hover round" @click="$noMultipleClicks(subSave)">
保存
</view>
<u-action-sheet
:list="uploadActions"
v-model="uploadShow"
@click="uploadType"
></u-action-sheet>
</view>
</template>
<script>
import { dateTimePicker, getMonthDay } from '@/util/dateTimePicker.js'
import { netSetForm, netStaffDefaultReviewer, uploadUrl } from '@/api/index.js'
import formItem from '@/components/form/formitem.vue'
import { checkPhone } from '@/util/util.js'
import {pageJumps} from "../../../../../pagesA/crm/createCustomer/createCust_page_jumps.js";
import { netAddkehu, netSelect, netPrevCustomer, netCheckName} from '@/api/kehu.js'
import { BASE_IMG_URL } from '@/util/api.js'
export default {
mixins:[pageJumps],
components:{
formItem
},
data() {
return {
BASE_IMG_URL:BASE_IMG_URL,
noClick:true, //防止 重复点击
name:'', //客户名称
subname:'', //助记名称
industry:'', //客户行业
level:'', //客户星级
source:'', //客户来源
follow:'', //跟进状态
address_dingwei:'', //地址定位
address_detail:'', //详细地址
lng:'', //经度
lat:'', //纬度
parent_id:'', //上级公司
parentList:[],
plist:[],
parentIndex:null,
parentName:'',
//跟进任务
is_event:true, //是否创建跟进任务
event_start_time:'', //跟进时间
event_title:'', //跟进内容
remindtype:'', //任务提醒
remindList:['准时提醒','5分钟前','15分钟前','30分钟前','一个小时前','两个小时前','一天前','两天前','一周前'], //提醒
remindIndex:null,
location:'', //所在地区
//联系人
is_contacts:true, //是否创建联系人
is_record:1,
//跟进状态
followList:[],
follow_type:null,
followIndex:null,
//下次跟进时间
next_time:'',
//上传附件
uploadShow:false,
uploadActions: [{
id: 1,
text: '拍照',
color: '#008EFF'
},
{
id: 2,
text: '从相册中选择',
color: '#008EFF'
}
],
imgList:[], //图片列表
fileList:[], //文件列表
//跟进内容
content:'',
DefaultRemind:[], //默认需要提醒的人
remindPeople: [], //提醒谁看
sourceList:[], //客户来源
sourceIndex:null,
listForm:[], //附加信息
firstContactForm:[], //首联系人
dateTimeArray:[],
dateArr:[],
dateTime:[],
countryType:1, //1国内 2国外
}
},
onLoad(options) {
this.parent_id = options.id
//获取 下拉选择项
this.getSelectlist()
//上级
this.getPrevCoustomer()
this.listForm = []
this.firstContactForm = []
//获取附加信息 form
this.getForm()
//获取 首联系人 form
this.getFirstContactform()
//初始化 时间
this.initTime()
},
onShow() {
this.remindPeople = []
//获取 默认需要提醒的人
this.getDefaultRemind()
},
onUnload() {
uni.removeStorageSync('remindlist')
},
methods: {
// 选择成员
moreClick() {
uni.navigateTo({
url: '/pagesA/crm/selectMember/selectMember'
})
},
//获取 需要默认提醒的人
getDefaultRemind() {
netStaffDefaultReviewer({type:'record'}).then(res=>{
res = res.data
res.forEach((ele,index) => {
ele.isDel = false
})
this.DefaultRemind = res
this.remindPeople = this.$deWeight([...res,...uni.getStorageSync('remindlist')])
})
},
//删除 提醒人
delRemind(index) {
this.remindPeople.splice(index, 1)
uni.setStorageSync('remindlist', this.remindPeople)
},
getForm() {
netSetForm({type:'customer'}).then(res=>{
res = res.data.data
res.forEach((item,index)=>{
if(item.id == 'name'){
res.splice(index,1)
}
item.value = item.value?item.value:''
})
this.listForm = res
})
},
changeData(name,value,obj) {
let arr = this.listForm
arr.forEach((ele,index) => {
if(ele.id == obj.id){
ele.value = value
this.$set(this.listForm,index,ele)
}
})
},
//首联系人 form表单
getFirstContactform() {
netSetForm({type:'contacts'}).then(res=>{
res = res.data.data
res.forEach(ele=>{
ele.value = ele.value?ele.value:''
})
this.firstContactForm = res
this.changeCountry(this.countryType)
})
},
changeCountry(type) {
this.countryType = type
let arr = this.firstContactForm
if(type == 1) {
//国内
arr.forEach((ele,index)=>{
if(ele.id == 'mobile'){
ele.config.required = true
}
if(ele.id == 'email'){
ele.config.required = false
}
})
}else{
//国外
arr.forEach((ele,index)=>{
if(ele.id == 'mobile'){
ele.config.required = true
}
if(ele.id == 'email'){
ele.config.required = true
}
})
}
this.firstContactForm = arr
},
changeContactData(name,value,obj) {
let arr = this.firstContactForm
arr.forEach((ele,index) => {
if(ele.id == obj.id){
ele.value = value
this.$set(this.firstContactForm,index,ele)
}
})
},
getPrevCoustomer() {
netPrevCustomer().then(res=>{
this.parentList = res.data
this.handleData(res.data)
if(this.parent_id){
//设置默认 上级公司
this.handleParent()
this.parentDisabled = true
}else{
this.parentDisabled = false
}
})
},
handleData(data) {
let arr = []
data.forEach(ele=>{
arr.push(ele.name)
})
this.plist = arr
},
handleParent() {
let id = this.parent_id
this.parentList.forEach((ele,index)=>{
if(ele.id == id){
this.parentIndex = index
this.parentName = ele.name
}
})
},
//获取 select
getSelectlist() {
netSelect().then(res=>{
this.followList = res.data['跟进类型']
this.sourceList = res.data['客户来源']
})
},
//改变 跟进 类型
changeFollow(e) {
this.followIndex = e.detail.value
this.follow_type = this.followList[e.detail.value]
},
//下次跟进时间
changeTime(e) {
let arr = e.detail.value
let str = this.handleTime(arr)
this.next_time = str
},
changeAlipayTime(e) {
this.next_time = e.detail.value
},
handleTime(arr) {
let year = this.dateArr[0][arr[0]]
let month = this.dateArr[1][arr[1]]
let day = this.dateArr[2][arr[2]]
let hour = this.dateArr[3][arr[3]]
let minu = this.dateArr[4][arr[4]]
let str = year + '-' + month + '-' + day + ' ' + hour + ':' + minu
return str
},
// 上传附件
uploadClick() {
this.uploadShow = true
},
onCancel() {
this.uploadShow = false
},
uploadType(index) {
if (index == 0) {
//拍照
uni.chooseImage({
sourceType: ['camera'],
sizeType:['compressed'],
success: (res) => {
let file = res.tempFilePaths
file.forEach(ele=>{
this.uploadFile(ele, 1)
})
}
})
} else if (index == 1) {
//相册 选择
uni.chooseImage({
sourceType: ['album'],
sizeType:['compressed'],
success: (res) => {
let file = res.tempFilePaths
file.forEach(ele=>{
this.uploadFile(ele, 1)
})
}
})
} else {
//选择文件
wx.chooseMessageFile({
count: 1,
type: 'file',
success: (res) => {
console.log(res)
let file = res.tempFiles[0]
this.uploadFile(file, 2)
},
fail: (err) => {
console.log(err)
}
})
}
},
//type 上传图片1 或 文件2
uploadFile(file, type) {
uni.uploadFile({
url: uploadUrl,
name: 'file',
header: {
'token': uni.getStorageSync('token'),
},
// #ifdef MP-ALIPAY
fileType:'image',
// #endif
filePath: type == 1 ? file : file.path,
success: (res) => {
let data = JSON.parse(res.data)
this.uploadShow = false
if(data.code == 1) {
if (type == 1) {
let obj = {
id:data.data.id,
file_path:data.data.url
}
this.imgList.push(obj)
} else {
let fileobj = {
id:data.data.id,
file_path:data.data.url
}
file = Object.assign({}, file, fileobj)
this.fileList.push(file)
}
}else{
uni.showToast({
title:'上传失败',
icon:'none'
})
}
},
fail: (err) => {
console.log(err)
}
})
},
//删除 图片
delImg(index) {
this.imgList.splice(index, 1)
},
//删除 文件
delFile(index) {
this.fileList.splice(index, 1)
},
//跟进内容
changeContent(e) {
this.content = e.detail.value
},
//姓名查重
checkName() {
let name = this.name
if(!name){
uni.showToast({
title: '请填写客户姓名',
icon:'none',
duration: 2000
})
return
}
netCheckName({name}).then(res=>{
uni.showToast({
title: res.msg,
icon:'none',
duration: 2000
})
})
},
//改变上级
changeParent(e) {
this.parentIndex = e.detail.value
this.parentName = this.parentList[e.detail.value].name
this.parent_id = this.parentList[e.detail.value].id
},
//是否创建 跟进任务
changeSwitch() {
this.is_event = !this.is_event
},
initTime() {
let date = new Date();
let endYear = date.getFullYear();
// 获取完整的年月日 时分秒,以及默认显示的数组
let obj = dateTimePicker(this.startYear, endYear);
// 精确到分的处理,将数组的秒去掉
let lastArray = obj.dateTimeArray.pop();
let lastTime = obj.dateTime.pop();
let lastDate = obj.dateArray.pop()
this.dateTimeArray=obj.dateTimeArray
this.dateArr = obj.dateArray
this.dateTime=obj.dateTime
},
//跟进时间
changeFollowTime(e) {
let arr = e.detail.value
if(arr.includes(-1)){
uni.showToast({
title:'请选择正确的时间',
icon:'none'
})
return
}
let str = this.handleTime(arr)
this.event_start_time = str
},
handleTime(arr) {
let year = this.dateArr[0][arr[0]]
let month = this.dateArr[1][arr[1]]
let day = this.dateArr[2][arr[2]]
let hour = this.dateArr[3][arr[3]]
let minu = this.dateArr[4][arr[4]]
let str = year+'-'+month+'-'+day+' '+ hour+':'+minu
return str
},
//任务提醒
changeRemind(e) {
this.remindIndex = e.detail.value
this.remindtype = this.remindList[e.detail.value]
},
// 详细地址
detailAddClick() {
uni.chooseLocation({
success: res => {
this.lat = res.latitude
this.lng = res.longitude
this.address_detail = res.name
this.address_dingwei = res.address
},
fail: err => {
if(err.errMsg == 'chooseLocation:fail auth deny'){
uni.showToast({
title:'请允许使用位置信息',
icon:'none'
})
}
}
})
},
//完成
subSave() {
let {
name, //客户名称
location, //所在地区
address_dingwei,
address_detail, //详细地址
lng, //经度
lat, //纬度
parent_id, //上级公司
is_event, //是否创建跟进任务
event_start_time, //跟进时间
event_title, //跟进内容
remindtype, //任务提醒
//联系人
is_contacts, //是否创建联系人
is_record, //是否创建 跟进记录
follow_type,
next_time,
imgList,
fileList,
content,
remindPeople
} = this
if(!name) {
uni.showToast({
title: '请填写客户名称',
icon:'none',
duration: 2000
})
return
}
if(!lng || !lat) {
uni.showToast({
title: '请选择所在位置',
icon:'none',
duration: 2000
})
return
}
let params = {
is_contacts: is_contacts ? 1 : 0,
is_record
}
// 附加信息
let arr = []
let customer = {}
this.listForm.forEach(ele=>{
arr.push({
name:ele.id,
required: ele.config.required,
msg: ele.config.placeholder,
value:ele.value
})
})
for(let i = 0; i < arr.length ; i++) {
if(arr[i].required && !arr[i].value){
uni.showToast({
title: arr[i].msg,
icon:'none'
})
return
}
if(arr[i].name == 'mobile' && !checkPhone(arr[i].value)){
uni.showToast({
title: '请填写正确的手机号',
icon:'none'
})
return
}
if(arr[i].name == 'telephone' && !checkPhone(arr[i].value)){
uni.showToast({
title: '请填写正确的手机号',
icon:'none'
})
return
}
if((arr[i].name == 'mobile' || arr[i].name == 'telephone') && arr[i].value && !checkPhone(arr[i].value)){
uni.showToast({
title: '请填写正确的手机号',
icon:'none'
})
return
}
customer[arr[i].name] = arr[i].value
}
customer = Object.assign({},customer,{name,address_detail,lng,lat,address:address_dingwei,parent_id})
//首联系人信息
let contacts = {}
let concatsArr = []
this.firstContactForm.forEach(ele=>{
concatsArr.push({
name:ele.id,
required: ele.config.required,
msg: ele.config.placeholder,
value:ele.value
})
})
for(let i = 0; i < concatsArr.length ; i++) {
if(concatsArr[i].required && !concatsArr[i].value && is_contacts){
uni.showToast({
title: concatsArr[i].msg,
icon:'none'
})
return
}
if(concatsArr[i].name == 'mobile' && !checkPhone(concatsArr[i].value)){
uni.showToast({
title: '请填写正确的手机号',
icon:'none'
})
return
}
if(concatsArr[i].name == 'telephone' && !checkPhone(concatsArr[i].value)){
uni.showToast({
title: '请填写正确的手机号',
icon:'none'
})
return
}
contacts[concatsArr[i].name] = concatsArr[i].value
}
//跟进记录
if (!follow_type) {
uni.showToast({
title: '请选择跟进类型',
icon: 'none',
duration: 2000
})
return
}
if (!next_time) {
uni.showToast({
title: '请选择跟进时间',
icon: 'none',
duration: 2000
})
return
}
if (!content) {
uni.showToast({
title: '请填写跟进内容',
icon: 'none',
duration: 2000
})
return
}
let files = '' //上传附件
let arrfile = []
imgList.forEach(ele => {
arrfile.push(ele.id)
})
fileList.forEach(ele => {
arrfile.push(ele.id)
})
files = arrfile.join(',')
let remindsid = '' //提醒谁看
let remarr = []
remindPeople.forEach(ele => {
remarr.push(ele.id)
})
remindsid = remarr.join(',')
let record = {
files,
follow_type,
next_time,
content,
reminds_id: remindsid,
}
params.record = record
params.customer = customer
params.contacts = contacts
netAddkehu(params).then(res=>{
uni.showToast({
title: res.msg,
icon:'none',
duration: 2000
})
setTimeout(()=>{
uni.navigateBack({
delta:1
})
},2000)
})
}
}
}
</script>
<style lang="scss" scoped>
#img{
float: left;
margin-right: 15rpx;
}
.linktab{
padding:0rpx 24rpx 20rpx 0;
display: flex;
justify-content: space-between;
align-items: center;
.link_right{
display: flex;
justify-content: flex-end;
align-items: center;
margin-top: 15rpx;
.linkbtn{
margin-right:15rpx;
width:120rpx;
height:60rpx;
border-radius: 45rpx;
font-size:24rpx;
color:#666;
text-align: center;
line-height: 58rpx;
border:1rpx solid #DDDDDD;
}
.linkbtnactive{
background:$uni-text-color;
border:1rpx solid $uni-text-color;
color:#fff;
}
}
}
.valueActive{
color:#333;
}
.affiliation {
background-color: #fff;
margin-bottom: 20rpx;
padding-bottom: 40rpx;
.aff_head {
font-size: 32rpx;
color: #999;
height: 100rpx;
line-height: 100rpx;
padding-left: 50rpx;
}
.aff_con {
display: flex;
text-align: center;
flex-wrap: wrap;
.aff_item {
width: 100rpx;
margin-right: 15rpx;
margin-bottom:15rpx;
image {
margin-bottom: 15rpx;
width: 60rpx;
height: 60rpx;
border-radius: 50%;
}
}
.affbox {
position: relative;
.delremind {
width: 32rpx;
height: 32rpx;
border-radius: 50%;
position: absolute;
right: -16rpx;
top: -16rpx;
background: rgba(0, 0, 0, 0.5);
z-index: 2;
}
}
.aff_last {
image {
margin-bottom: 15rpx;
width: 48rpx;
height: 48rpx;
}
}
}
}
.imglist {
padding: 24rpx 34rpx;
background: #fff;
border-bottom: 1rpx solid #EAEAEA;
display: flex;
justify-content: flex-start;
align-items: center;
flex-wrap: wrap;
.imgbox {
width: 160rpx;
height: 160rpx;
margin-right: 14rpx;
position: relative;
margin-bottom: 24rpx;
border: 1rpx solid #EAEAEA;
.delimg {
width: 32rpx;
height: 32rpx;
border-radius: 50%;
position: absolute;
right: -16rpx;
top: -16rpx;
background: rgba(0, 0, 0, 0.5);
z-index: 2;
}
.selfimg {
width: 160rpx;
height: 160rpx;
}
}
}
.fllow_file_li {
padding: 24rpx 34rpx;
background: #fff;
border-bottom: 1rpx solid #EAEAEA;
.fil_li {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 14rpx;
.fileimg {
width: 20rpx;
height: 20rpx;
}
.filename {
font-size: 24rpx;
color: #999999;
}
.closeimg {
width: 32rpx;
height: 32rpx;
}
}
}
.create_customer {
font-size: 28rpx;
.info_head {
height: 80rpx;
line-height: 80rpx;
font-size: 30rpx;
color: #999;
padding-left: 50rpx;
}
.mar_top {
margin-top: 30rpx;
}
.fllow_form {
display: flex;
justify-content: space-between;
background-color: #fff;
border-bottom: 1rpx solid #EAEAEA;
padding: 30rpx 40rpx 30rpx 50rpx;
font-size: 32rpx ;
color: #999;
.nameinput{
width:500rpx;
}
.form_right {
display: flex;
color: #999;
text-align: right;
.location{
width:300rpx;
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
}
image {
width: 40rpx;
height: 40rpx;
margin: 28rpx 5rpx 0 0;
}
}
.theme {
color: #5ca9fe;
}
text {
color: #f00;
margin-left: 10rpx;
}
.form_input {
input {
width:300rpx;
text-align: right;
height: 100rpx;
line-height: 100rpx;
text-align: right;
margin-right: 10rpx;
}
}
}
.fllow_area {
background-color: #fff;
padding: 0 30rpx 0 50rpx;
margin-bottom: 30rpx;
.area_head {
height: 100rpx;
line-height: 100rpx;
color: #999;
font-size: 32rpx;
text {
color: #f00;
}
}
textarea {
margin: 0 auto;
width: 95%;
height: 300rpx;
}
}
}
#btn{
width: 500rpx;
height: 88rpx;
background: $uni-text-color;
border-radius: 29rpx;
font-size: 34rpx;
color: #fff;
line-height: 88rpx;
}
</style>