// 模板字符串 var temp = `
基本信息
@@codeText@@
公司信息
温馨提示:请提供准确的信息,我们将为您推荐更准确、更个性化的商机和服务
您可以通过剑鱼标讯提供的全国招投标数据自助导出功能,指定关键词、发布时间、地区或行业等筛选条件,以Excel表格的形式打包下载,精准获取所需数据。
` var jobJson = [ '总裁', '总经理', '总监', '经理', '主管', '职员' ] var branchJson = [ '市场', '产品', '销售', '渠道', '其他' ] var jobData = jobJson.map(function (item) { return { value: item, label: item } }) // 防抖 function debounce(fn, delay) { var timer return function () { var context = this var args = arguments clearTimeout(timer) timer = setTimeout(function () { fn.apply(context, args) }, delay) } } // 部门数据处理 var branchData = branchJson.map(function(item) { return { value: item, label: item } }) var vm = new Vue({ el: '#vue-collect-user-info', delimiters: ['@@', '@@'], props: ['type'], template: temp, data: function () { var validName = function(rule,value,callback) { if(value === '') { return callback(new Error('姓名为必填项')); } else { if (value.length < 2) { return callback(new Error('姓名填写不正确')); } callback(); } } var validPhone = function(rule,value,callback) { var status = /^1[3-9]\d{9}$/.test(value) if(value === '') { return callback(new Error('手机号为必填项')); } else if (!status) { return callback(new Error('手机号填写不正确')); } else { callback(); } } var validCode = function(rule,value,callback) { var status = /\d{6}/.test(value) if(value === '') { return callback(new Error('短信验证码为必填项')); } else if (!status) { return callback(new Error('验证码格式不正确')); } else { setTimeout(function() { if (!vm.codeStatus) { return callback(new Error('短信验证码不正确')); } else { callback(); } }, 500) } } var validEmail = function(rule,value,callback) { var status = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(value) if (value === '') { return callback(new Error('邮箱为必填项')); } else { if (!status) { return callback(new Error('邮箱填写不正确')); } else { callback(); } } } var validCompany = function(rule,value,callback) { if (value === '') { return callback(new Error('公司名称为必填项')); } else { if (value.length < 2) { return callback(new Error('公司名称至少输入2个字')); } else { callback(); } } } var validComType = function(rule,value,callback) { if (value.length === 0) { return callback(new Error('公司类型为必填项')); } else { callback(); } } var validJob = function(rule,value,callback) { if(value === '') { return callback(new Error('职位为必填项')); return callback(); } else { if (value === '其他' && vm.form.otherJob === '') { return callback(); } else { callback(); } } } var validBranch = function(rule,value,callback) { if(value === '') { return callback(new Error('请选择部门')); } else { callback(); } } return { dialogTitle: '为给您匹配精准的推荐信息,请完善个人信息', jobData: jobData, // 职位数据 branchData: branchData, form: { oldPhone: '', // 带出来的手机号,用于判断是否需要短信验证码 name: '', // 姓名 phone: '', // 手机号 mail: '', // 邮箱 code: '', // 短信验证码 companyName: '', // 公司名称 companyType: [], // 公司类型 job: '', // 职位值 otherJob: '', //自定义职位 branch: '' }, codeText: '获取验证码', sendCodeBtn: false, countdown: 0, codeStatus: true, rules: { name: [ { required: true, validator: validName, trigger: 'blur' } ], phone: [ { required: true, validator: validPhone, trigger: 'blur' } ], mail: [ { required: true, validator: validEmail, trigger: 'blur' } ], code: [ { required: true, validator: validCode, message: '', trigger: 'blur' } ], companyName: [ { required: true, validator: validCompany, trigger: 'blur' } ], companyType: [ { required: true, validator: validComType, trigger: 'blur' } ], job: [ { required: true, validator: validJob, trigger: 'blur' } ], branch: [ { required: true, trigger: 'blur', validator: validBranch, message: '' } ], }, showSearchResult: false, companyList: [], showForm: false, // 显示表单填写弹框 showSuccess: false, // 显示提交成功弹框 showExport: false, isForce: false, // 是否强制 source: '', // 来源模块 interest: '', // 感兴趣内容 moduleShow: { name: true, phone: true, mail: true, code: false, companyName: true, companyType: true, job: true, branch: false } } }, computed: { showOtherJob: function() { return this.form.job == '其他' }, showCode: function () { return (this.form.phone !== this.form.oldPhone && this.form.phone.length === 11) || !this.form.oldPhone }, defaultSource: function() { // 默认提交成功不显示广告图和邮箱文案 如果是结构化数据则显示 var noEmailSource = ['structedData', 'pc_data_custom_export'] return noEmailSource.indexOf(this.source) === -1 }, showBranch: function () { // 切换到总裁或总经理之后 把之前选择的部门清空 if (this.form.job.indexOf('总裁') > -1 || this.form.job.indexOf('总经理') > -1) { this.form.branch = '' } var zc = this.form.job.indexOf('总裁') > -1 var zjl = this.form.job.indexOf('总经理') > -1 return !(zc || zjl) && this.form.job } }, mounted() { var that = this; $(document).on('click', function (e) { let dom = $('.company-name')[0]; if (dom) { // 如果点击的区域不在自定义dom范围 if (!dom.contains((e.target))) { that.showSearchResult = false } } }) $(window).on('resize', this.changeTop) }, beforeDestroy() { $(document).off('click') }, methods: { getModules: function () { var source = this.source switch (source) { case 'pc_supermarket_Noresults_customization': case 'pc_market_ApplicationScenario': case 'pc_supermarket_details_customization': case 'pc_supermarket_details_buy': { this.hideModule(['mail']) break; } default: this.hideModule() break; } }, hideModule: function (keys) { if (!keys) return var hideType = keys for (var k in this.moduleShow) { if (hideType.indexOf(k) !== -1) { this.moduleShow[k] = false } } }, changeTop: function () { this.$nextTick(function () { var dialogDom = $('#collectUserInfoDialog .dialog-container') var diffHeight = window.innerHeight - dialogDom.height() - 240 if (diffHeight < 0) { dialogDom.css('margin-top', diffHeight.toString() + 'px') } }) }, nameFocus:function(){ this.$refs['ruleForm'].clearValidate(['name']); }, phoneFocus:function(){ this.$refs['ruleForm'].clearValidate(['phone']); }, mailFocus:function(){ this.$refs['ruleForm'].clearValidate(['mail']); }, codeFocus: function() { this.$refs['ruleForm'].clearValidate(['code']); }, // 公司名称获取焦点时 companyFocus: function() { this.$refs['ruleForm'].clearValidate(['companyName']); this.getResult(this.form.companyName) }, otherFocus:function() { this.$refs['ruleForm'].clearValidate(['job','otherJob']); }, // 发送验证码 sendCode: function() { var status = /^1[3-9]\d{9}$/.test(this.form.phone) var _this = this if (!status) return $.ajax({ type:'POST', url:'/salesLeads/sendMsg', data: { phoneNum: _this.form.phone }, success:function (res) { if (res.data && res.data.success) { _this.sendCodeBtn = true _this.countdown = 60 _this.codeText = '重新获取' + _this.countdown + 's' var timeInt = setInterval(function() { _this.countdown-- _this.codeText = '重新获取' + _this.countdown + 's' if (_this.countdown <= 0) { _this.sendCodeBtn = false _this.codeText = '获取验证码' window.clearInterval(timeInt) } }, 1000) } else { _this.$message.error('短信验证码发送失败'); } } }) }, // 校验验证码 checkCode: function(val) { var _this = this if (val.length !== 6) return $.ajax({ type:'POST', url:'/salesLeads/checkCode', data: { code: _this.form.code, phoneNum: _this.form.phone }, success:function (res) { if (res.data && res.data.flag) { _this.$message.success('验证成功') _this.codeStatus = true } else { _this.codeStatus = false } } }) }, // 日志统计 logAjax: function(source) { $.ajax({ type:'POST', url:'/front/portraitClassify?source=' + source, success:function (res) { console.log(res) } }) }, // 是否留资 isNeedSubmit: function(source, callback, interest) { if (!loginflag) { openLoginDig() return } this.source = source this.interest = interest this.logAjax(source) var _this = this $.ajax({ type:'GET', url:'/salesLeads/retainedCapital', data: { source: source }, success:function (res) { // 判断当前信息否在其他页面留资 如果全部留资 直接弹窗提交成功 var checkKeys = ['name', 'phone', 'company', 'mail', 'branch', 'position', 'companyType'] var result = checkRequiredKeys(checkKeys, res.info) res.info.interest = interest if (result) { callback && callback() _this.formAjax(_this.source, res.info) } else if (res.data) { _this.isForce = res.data.fource if (res.data.retainedCapital) { _this.showForm = true // 当前头部背景图 _this.isSelfHeader() _this.changeTop() if (res.info) { echoRequiredValues(_this.form, res.info, ['name', 'phone', 'mail', 'branch']) // 原有赋值回显逻辑 _this.form.oldPhone = res.info.phone ? res.info.phone : '' _this.form.companyName = res.info.company ? res.info.company : '' _this.form.companyType = res.info.companyType ? res.info.companyType.split(',') : [] if (res.info.position) { if (jobJson.indexOf(res.info.position) == -1) { // _this.form.job = '其他' // _this.form.otherJob = res.data.position.replace('其他/', '') _this.form.job = '' _this.form.otherJob = '' } else { _this.form.job = res.info.position } } else { _this.form.job = '' } } } else { callback && callback() } } } }) }, // 自定义弹窗头部 isSelfHeader: function(){ var imgUrl = '/common-module/pc-dialog/image/structed-title.png' var custom_export = this.source.indexOf('custom_export') > -1 var custom_data = this.source.indexOf('custom_data') > -1 var api_interface = this.source.indexOf('api_interface') > -1 // 数据超市source var marketNoResult = this.source.indexOf('pc_supermarket_Noresults_customization') > -1 // 数据超市列表无数据-申请定制 var marketApplicationScenario = this.source.indexOf('pc_market_ApplicationScenario') > -1 // 数据市场落地页-大数据服务应用场景-立即咨询 var marketBuy = this.source.indexOf('pc_supermarket_details_buy') > -1 // 数据超市详情页-申请购买 var marketDetailCustom = this.source.indexOf('pc_supermarket_details_customization') > -1 // 数据超市详情页-申请定制 if (custom_export || custom_data || marketNoResult || marketDetailCustom) { imgUrl = '/common-module/pc-dialog/image/leave-title-custom.png' } else if (api_interface) { imgUrl = '/common-module/pc-dialog/image/leave-title-api.png' } else if (marketApplicationScenario) { imgUrl = '/common-module/pc-dialog/image/data-supermarket-contact.png' } else if (marketBuy) { imgUrl = '/common-module/pc-dialog/image/data-supermarket-buy.png' } this.getModules() this.$nextTick(function(){ $('#collectUserInfoDialog .dialog-header').css('background-image', 'url(' + imgUrl + ')') }) }, // 表单提交事件 submitForm: function(formName) { var _this = this this.$refs[formName].validate(function (valid) { if (valid) { _this.formAjax(_this.source) } else { console.log('error submit!!'); return false; } }); }, // 表单提交请求 formAjax: function(source, info) { var params = { source: source, name: this.form.name, phone: this.form.phone, mail: this.form.mail, company: this.form.companyName, // 公司名称 companyType: this.form.companyType.join(','), position: this.form.job == '其他' ? this.form.job + '/' + this.form.otherJob : this.form.job, code: this.form.code, agree: true, // 原来留资模块的同意协议字段,,,默认传一个true 方便后端处理 branch: this.form.branch.indexOf('总裁') > -1 || this.form.branch.indexOf('总经理') > -1 || !this.form.job ? '' : this.form.branch, // interest: this.interest } if (info) { params = info params.source = source params.interest = info.interest // 感兴趣内容 } var _this = this $.ajax({ type:'POST', url: '/salesLeads/collectInfo', contentType: "application/json;charset=utf-8", data: JSON.stringify(params), success:function (res) { if (res.data) { _this.showForm = false _this.showSuccess = true } else { _this.$message.error(res.error_msg); } } }) }, // 手机号输入框input事件 inputPhone: function(val) { this.form.phone = val.replace(/[^\d]/g,'') }, // 企业名称联想 getResult:function(name) { // 名称为空或长度小于2不发请求 if (!name || name.length < 2) return var _this = this $.ajax({ type:'POST', url:'/jypay/user/company/association', data: { name: name, companyCount:10 }, heads : { 'content-type': 'application/x-www-form-urlencoded' }, success:function (res) { console.log(res) if (res.data && res.data.length > 0) { var result = [] res.data.map(function(item){ item = _this.brightKeyword(item) result.push(item) return result }) _this.companyList = result _this.showSearchResult = true } } }) }, searchCompany: debounce(function(val){ if(val === '') { this.showSearchResult = false} this.getResult(val) }, 600), // 选择联想出来的公司名称 selectCompany: function(item) { this.form.companyName = item.replace(/<.*?>/ig, '') this.showSearchResult = false }, // 关键词高亮 brightKeyword: function (val) { var name = this.form.companyName if (val.indexOf(name) !== -1) { return val.replace(name, `${name}`) } else { return val } }, // 暂不提供 cancelForm: function() { this.form.name = '' this.form.phone = '' this.form.mail = '' this.form.companyName = '' this.form.job = '' this.form.otherJob = '' this.form.code = '' var needExportSource = ['structedData', 'pc_data_custom_export', 'pc_data_custom_data'] if (needExportSource.indexOf(this.source) > -1) { this.showForm = false this.showExport = true } else { this.showForm = false } this.showSearchResult=false }, // 数据导出 dataExport: function() { location.href = "/front/dataExport/toSieve" } } })