leave-info-dialog.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. // 模板字符串
  2. var temp = `
  3. <div>
  4. <div class="user-data-dialog" id="collectUserInfoDialog" v-if="showForm">
  5. <div class="mask"></div>
  6. <div class="dialog-container">
  7. <div class="dialog-header"></div>
  8. <div class="dialog-content">
  9. <el-form class="user-form" :model="form" :rules="rules" ref="ruleForm">
  10. <!-- 基本信息 -->
  11. <div class="basic clearfix">
  12. <div class="form-title">基本信息</div>
  13. <div class="form-main clearfix">
  14. <div class="short-control fl">
  15. <el-form-item label="姓名 :" prop="name">
  16. <el-input v-model.trim="form.name" class="item-input" placeholder="请输入姓名" @focus="nameFocus" required>
  17. </el-input>
  18. </el-form-item>
  19. </div>
  20. <div class="short-control fr">
  21. <el-form-item label="邮箱 :" prop="mail">
  22. <el-input v-model.trim="form.mail" class="item-input" placeholder="请输入邮箱" @focus="mailFocus"></el-input>
  23. </el-form-item>
  24. </div>
  25. <div class="short-control fl">
  26. <el-form-item label="手机号 :" prop="phone">
  27. <el-input v-model.trim="form.phone" maxlength="11" @input="inputPhone" class="item-input" placeholder="请输入准确的手机号" @focus="phoneFocus"></el-input>
  28. </el-form-item>
  29. </div>
  30. <div class="short-control fr" v-if="showCode">
  31. <el-form-item label="验证码 :" prop="code">
  32. <el-input v-model.trim="form.code" maxlength="6" @change="checkCode" class="item-input code-input" placeholder="请输入手机验证码" @focus="codeFocus">
  33. <el-button slot="append" :disabled="sendCodeBtn" @click="sendCode">@@codeText@@</el-button>
  34. </el-input>
  35. </el-form-item>
  36. </div>
  37. </div>
  38. </div>
  39. <div class="company clearfix">
  40. <div class="form-title">公司信息</div>
  41. <div class="form-main">
  42. <div class="long-control" style="position: relative;">
  43. <el-form-item label="公司名称 :" prop="companyName">
  44. <el-input
  45. v-model.trim="form.companyName"
  46. data-long-input
  47. class="item-input company-name"
  48. @focus="companyFocus"
  49. @input="searchCompany"
  50. placeholder="请输入准确的公司名称">
  51. </el-input>
  52. </el-form-item>
  53. <div class="company-result" v-if="showSearchResult">
  54. <div class="company-list" v-for="item in companyList" :key="item" @click="selectCompany(item)" v-html="item"></div>
  55. </div>
  56. </div>
  57. <div class="long-control" >
  58. <el-form-item label="公司类型 :" class="company-type" prop="companyType">
  59. <el-checkbox-group v-model="form.companyType">
  60. <el-checkbox label="投标企业"></el-checkbox>
  61. <el-checkbox label="招标采购单位"></el-checkbox>
  62. <el-checkbox label="厂商"></el-checkbox>
  63. <el-checkbox label="招标代理机构"></el-checkbox>
  64. <el-checkbox label="经销商"></el-checkbox>
  65. <el-checkbox label="服务提供商"></el-checkbox>
  66. <el-checkbox label="其他"></el-checkbox>
  67. </el-checkbox-group>
  68. </el-form-item>
  69. </div>
  70. <div class="short-control fl">
  71. <el-form-item label="职位 :" prop="job">
  72. <el-select v-model="form.job" placeholder="请选择职位" class="item-input" clearable>
  73. <el-option v-for="item in jobData" :key="item.value" :label="item.label" :value="item.value">
  74. </el-option>
  75. </el-select>
  76. </el-form-item>
  77. </div>
  78. <div class="short-control fr" v-if="showBranch">
  79. <el-form-item label-width="0" label="" prop="branch" class="no-label">
  80. <el-select v-model="form.branch" placeholder="请选择部门" class="item-input" clearable>
  81. <el-option v-for="item in branchData" :key="item.value" :label="item.label" :value="item.value">
  82. </el-option>
  83. </el-select>
  84. </el-form-item>
  85. </div>
  86. </div>
  87. </div>
  88. <div class="warm-prompt">
  89. <span class="icon-warning"></span>
  90. <span class="warm-text">温馨提示:请提供准确的信息,我们将为您推荐更准确、更个性化的商机和服务</span>
  91. </div>
  92. <div class="dialog-footer">
  93. <el-button class="cancel-btn" @click="cancelForm">暂不提供</el-button>
  94. <el-button class="submit-btn" @click="submitForm('ruleForm')">提交</el-button>
  95. </div>
  96. </el-form>
  97. </div>
  98. </div>
  99. </div>
  100. <div id="success-dialog" style="display: none;" v-show="showSuccess">
  101. <div class="mask"></div>
  102. <div class="success-dialog-container">
  103. <div class="success-title">提交成功</div>
  104. <div class="success-content" v-if="defaultSource">我们的客户经理会在24小时内尽快与您联系。</div>
  105. <div class="success-content" v-else>我们稍后将以邮件的形式发送数据样例。</div>
  106. <div class="success-footer">
  107. <button type="button" class="custom-btn go-know" @click="showSuccess = false">我知道了</button>
  108. </div>
  109. <div class="dialog-adv" v-if="!defaultSource" @click="dataExport">
  110. <img src="/common-module/pc-dialog/image/data-export.png" />
  111. </div>
  112. </div>
  113. </div>
  114. <div id="export-dialog" v-show="showExport">
  115. <div class="mask"></div>
  116. <div class="export-dialog-container">
  117. <div class="export-title">
  118. <span class="export-close" @click="showExport = false"></span>
  119. </div>
  120. <div class="export-content">您可以通过剑鱼标讯提供的全国招投标数据自助导出功能,指定关键词、发布时间、地区或行业等筛选条件,以Excel表格的形式打包下载,精准获取所需数据。</div>
  121. <div class="export-footer">
  122. <button type="button" class="custom-btn go-know" @click="dataExport">数据自助导出</button>
  123. </div>
  124. </div>
  125. </div>
  126. </div>
  127. `
  128. var jobJson = [
  129. '总裁',
  130. '总经理',
  131. '总监',
  132. '经理',
  133. '主管',
  134. '职员'
  135. ]
  136. var branchJson = [
  137. '市场',
  138. '产品',
  139. '销售',
  140. '渠道',
  141. '其他'
  142. ]
  143. var jobData = jobJson.map(function (item) {
  144. return {
  145. value: item,
  146. label: item
  147. }
  148. })
  149. // 防抖
  150. function debounce(fn, delay) {
  151. var timer
  152. return function () {
  153. var context = this
  154. var args = arguments
  155. clearTimeout(timer)
  156. timer = setTimeout(function () {
  157. fn.apply(context, args)
  158. }, delay)
  159. }
  160. }
  161. // 部门数据处理
  162. var branchData = branchJson.map(function(item) {
  163. return {
  164. value: item,
  165. label: item
  166. }
  167. })
  168. var vm = new Vue({
  169. el: '#vue-collect-user-info',
  170. delimiters: ['@@', '@@'],
  171. props: ['type'],
  172. template: temp,
  173. data: function () {
  174. var validName = function(rule,value,callback) {
  175. if(value === '') {
  176. return callback(new Error('姓名为必填项'));
  177. } else {
  178. if (value.length < 2) {
  179. return callback(new Error('姓名填写不正确'));
  180. }
  181. callback();
  182. }
  183. }
  184. var validPhone = function(rule,value,callback) {
  185. var status = /^1[3-9]\d{9}$/.test(value)
  186. if(value === '') {
  187. return callback(new Error('手机号为必填项'));
  188. } else if (!status) {
  189. return callback(new Error('手机号填写不正确'));
  190. } else {
  191. callback();
  192. }
  193. }
  194. var validCode = function(rule,value,callback) {
  195. var status = /\d{6}/.test(value)
  196. if(value === '') {
  197. return callback(new Error('短信验证码为必填项'));
  198. } else if (!status) {
  199. return callback(new Error('验证码格式不正确'));
  200. } else {
  201. setTimeout(function() {
  202. if (!vm.codeStatus) {
  203. return callback(new Error('短信验证码不正确'));
  204. } else {
  205. callback();
  206. }
  207. }, 500)
  208. }
  209. }
  210. var validEmail = function(rule,value,callback) {
  211. var status = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(value)
  212. if (value === '') {
  213. return callback(new Error('邮箱为必填项'));
  214. } else {
  215. if (!status) {
  216. return callback(new Error('邮箱填写不正确'));
  217. } else {
  218. callback();
  219. }
  220. }
  221. }
  222. var validCompany = function(rule,value,callback) {
  223. if (value === '') {
  224. return callback(new Error('公司名称为必填项'));
  225. } else {
  226. if (value.length < 2) {
  227. return callback(new Error('公司名称至少输入2个字'));
  228. } else {
  229. callback();
  230. }
  231. }
  232. }
  233. var validComType = function(rule,value,callback) {
  234. if (value.length === 0) {
  235. return callback(new Error('公司类型为必填项'));
  236. } else {
  237. callback();
  238. }
  239. }
  240. var validJob = function(rule,value,callback) {
  241. if(value === '') {
  242. return callback(new Error('职位为必填项'));
  243. return callback();
  244. } else {
  245. if (value === '其他' && vm.form.otherJob === '') {
  246. return callback();
  247. } else {
  248. callback();
  249. }
  250. }
  251. }
  252. return {
  253. dialogTitle: '为给您匹配精准的推荐信息,请完善个人信息',
  254. jobData: jobData, // 职位数据
  255. branchData: branchData,
  256. form: {
  257. oldPhone: '', // 带出来的手机号,用于判断是否需要短信验证码
  258. name: '', // 姓名
  259. phone: '', // 手机号
  260. mail: '', // 邮箱
  261. code: '', // 短信验证码
  262. companyName: '', // 公司名称
  263. companyType: [], // 公司类型
  264. job: '', // 职位值
  265. otherJob: '', //自定义职位
  266. branch: ''
  267. },
  268. codeText: '获取验证码',
  269. sendCodeBtn: false,
  270. countdown: 0,
  271. codeStatus: true,
  272. rules: {
  273. name: [
  274. {
  275. required: true,
  276. validator: validName,
  277. trigger: 'blur'
  278. }
  279. ],
  280. phone: [
  281. {
  282. required: true,
  283. validator: validPhone,
  284. trigger: 'blur'
  285. }
  286. ],
  287. mail: [
  288. {
  289. required: true,
  290. validator: validEmail,
  291. trigger: 'blur'
  292. }
  293. ],
  294. code: [
  295. {
  296. required: true,
  297. validator: validCode,
  298. message: '',
  299. trigger: 'blur'
  300. }
  301. ],
  302. companyName: [
  303. {
  304. required: true,
  305. validator: validCompany,
  306. trigger: 'blur'
  307. }
  308. ],
  309. companyType: [
  310. {
  311. required: true,
  312. validator: validComType,
  313. trigger: 'blur'
  314. }
  315. ],
  316. job: [
  317. {
  318. required: true,
  319. validator: validJob,
  320. trigger: 'blur'
  321. }
  322. ],
  323. branch: [
  324. {
  325. required: true,
  326. trigger: 'blur',
  327. message: '请选择部门'
  328. }
  329. ],
  330. },
  331. showSearchResult: false,
  332. companyList: [],
  333. showForm: false, // 显示表单填写弹框
  334. showSuccess: false, // 显示提交成功弹框
  335. showExport: false,
  336. isForce: false, // 是否强制
  337. source: '' // 来源模块
  338. }
  339. },
  340. computed: {
  341. showOtherJob: function() {
  342. return this.form.job == '其他'
  343. },
  344. showCode: function () {
  345. return (this.form.phone !== this.form.oldPhone && this.form.phone.length === 11) || !this.form.oldPhone
  346. },
  347. defaultSource: function() {
  348. // 默认提交成功不显示广告图和邮箱文案 如果是结构化数据则显示
  349. var noEmailSource = ['structedData', 'pc_data_custom_export']
  350. return noEmailSource.indexOf(this.source) === -1
  351. },
  352. showBranch: function () {
  353. // 切换到总裁或总经理之后 把之前选择的部门清空
  354. if (this.form.job.indexOf('总裁') > -1 || this.form.job.indexOf('总经理') > -1) {
  355. this.form.branch = ''
  356. }
  357. var zc = this.form.job.indexOf('总裁') > -1
  358. var zjl = this.form.job.indexOf('总经理') > -1
  359. return !(zc || zjl) && this.form.job
  360. }
  361. },
  362. mounted() {
  363. var that = this;
  364. $(document).on('click', function (e) {
  365. let dom = $('.company-name')[0];
  366. if (dom) {
  367. // 如果点击的区域不在自定义dom范围
  368. if (!dom.contains((e.target))) {
  369. that.showSearchResult = false
  370. }
  371. }
  372. })
  373. $(window).on('resize', this.changeTop)
  374. },
  375. beforeDestroy() {
  376. $(document).off('click')
  377. },
  378. methods: {
  379. changeTop: function () {
  380. this.$nextTick(function () {
  381. var dialogDom = $('#collectUserInfoDialog .dialog-container')
  382. var diffHeight = window.innerHeight - dialogDom.height() - 240
  383. if (diffHeight < 0) {
  384. dialogDom.css('margin-top', diffHeight.toString() + 'px')
  385. }
  386. })
  387. },
  388. nameFocus:function(){
  389. this.$refs['ruleForm'].clearValidate(['name']);
  390. },
  391. phoneFocus:function(){
  392. this.$refs['ruleForm'].clearValidate(['phone']);
  393. },
  394. mailFocus:function(){
  395. this.$refs['ruleForm'].clearValidate(['mail']);
  396. },
  397. codeFocus: function() {
  398. this.$refs['ruleForm'].clearValidate(['code']);
  399. },
  400. // 公司名称获取焦点时
  401. companyFocus: function() {
  402. this.$refs['ruleForm'].clearValidate(['companyName']);
  403. this.getResult(this.form.companyName)
  404. },
  405. otherFocus:function() {
  406. this.$refs['ruleForm'].clearValidate(['job','otherJob']);
  407. },
  408. // 发送验证码
  409. sendCode: function() {
  410. var status = /^1[3-9]\d{9}$/.test(this.form.phone)
  411. var _this = this
  412. if (!status) return
  413. $.ajax({
  414. type:'POST',
  415. url:'/salesLeads/sendMsg',
  416. data: {
  417. phoneNum: _this.form.phone
  418. },
  419. success:function (res) {
  420. if (res.data && res.data.success) {
  421. _this.sendCodeBtn = true
  422. _this.countdown = 60
  423. _this.codeText = '重新获取' + _this.countdown + 's'
  424. var timeInt = setInterval(function() {
  425. _this.countdown--
  426. _this.codeText = '重新获取' + _this.countdown + 's'
  427. if (_this.countdown <= 0) {
  428. _this.sendCodeBtn = false
  429. _this.codeText = '获取验证码'
  430. window.clearInterval(timeInt)
  431. }
  432. }, 1000)
  433. } else {
  434. _this.$message.error('短信验证码发送失败');
  435. }
  436. }
  437. })
  438. },
  439. // 校验验证码
  440. checkCode: function(val) {
  441. var _this = this
  442. if (val.length !== 6) return
  443. $.ajax({
  444. type:'POST',
  445. url:'/salesLeads/checkCode',
  446. data: {
  447. code: _this.form.code,
  448. phoneNum: _this.form.phone
  449. },
  450. success:function (res) {
  451. if (res.data && res.data.flag) {
  452. _this.$message.success('验证成功')
  453. _this.codeStatus = true
  454. } else {
  455. _this.codeStatus = false
  456. }
  457. }
  458. })
  459. },
  460. // 日志统计
  461. logAjax: function(source) {
  462. $.ajax({
  463. type:'POST',
  464. url:'/front/portraitClassify?source=' + source,
  465. success:function (res) {
  466. console.log(res)
  467. }
  468. })
  469. },
  470. // 是否留资
  471. isNeedSubmit: function(source, callback, dom) {
  472. if (!loginflag) {
  473. openLoginDig()
  474. return
  475. }
  476. this.source = source
  477. this.logAjax(source)
  478. var _this = this
  479. $.ajax({
  480. type:'GET',
  481. url:'/salesLeads/retainedCapital',
  482. data: {
  483. source: source
  484. },
  485. success:function (res) {
  486. // 判断当前信息否在其他页面留资 如果全部留资 直接弹窗提交成功
  487. var checkKeys = ['name', 'phone', 'company', 'mail', 'branch', 'position', 'companyType']
  488. var result = checkRequiredKeys(checkKeys, res.info)
  489. if (result) {
  490. callback && callback()
  491. _this.formAjax(_this.source, res.info)
  492. } else if (res.data) {
  493. _this.isForce = res.data.fource
  494. if (res.data.retainedCapital) {
  495. _this.showForm = true
  496. // 当前头部背景图
  497. _this.isSelfHeader()
  498. _this.changeTop()
  499. if (res.info) {
  500. echoRequiredValues(_this.form, res.info, ['name', 'phone', 'mail', 'branch'])
  501. // 原有赋值回显逻辑
  502. _this.form.oldPhone = res.info.phone ? res.info.phone : ''
  503. _this.form.companyName = res.info.company ? res.info.company : ''
  504. _this.form.companyType = res.info.companyType ? res.info.companyType.split(',') : []
  505. if (res.info.position) {
  506. if (jobJson.indexOf(res.info.position) == -1) {
  507. // _this.form.job = '其他'
  508. // _this.form.otherJob = res.data.position.replace('其他/', '')
  509. _this.form.job = ''
  510. _this.form.otherJob = ''
  511. } else {
  512. _this.form.job = res.info.position
  513. }
  514. } else {
  515. _this.form.job = ''
  516. }
  517. }
  518. } else {
  519. callback && callback()
  520. }
  521. }
  522. }
  523. })
  524. },
  525. // 自定义弹窗头部
  526. isSelfHeader: function(){
  527. var imgUrl = '/common-module/pc-dialog/image/structed-title.png'
  528. if (this.source.indexOf('custom_export') > -1 || this.source.indexOf('custom_data') > -1) {
  529. imgUrl = '/common-module/pc-dialog/image/leave-title-custom.png'
  530. } else if (this.source.indexOf('api_interface') > -1) {
  531. imgUrl = '/common-module/pc-dialog/image/leave-title-api.png'
  532. }
  533. this.$nextTick(function(){
  534. $('#collectUserInfoDialog .dialog-header').css('background-image', 'url(' + imgUrl + ')')
  535. })
  536. },
  537. // 表单提交事件
  538. submitForm: function(formName) {
  539. var _this = this
  540. this.$refs[formName].validate(function (valid) {
  541. if (valid) {
  542. _this.formAjax(_this.source)
  543. } else {
  544. console.log('error submit!!');
  545. return false;
  546. }
  547. });
  548. },
  549. // 表单提交请求
  550. formAjax: function(source, info) {
  551. var params = {
  552. source: source,
  553. name: this.form.name,
  554. phone: this.form.phone,
  555. mail: this.form.mail,
  556. company: this.form.companyName, // 公司名称
  557. companyType: this.form.companyType.join(','),
  558. position: this.form.job == '其他' ? this.form.job + '/' + this.form.otherJob : this.form.job,
  559. code: this.form.code,
  560. agree: true, // 原来留资模块的同意协议字段,,,默认传一个true 方便后端处理
  561. branch: this.form.branch.indexOf('总裁') > -1 || this.form.branch.indexOf('总经理') > -1 || !this.form.job ? '' : this.form.branch
  562. }
  563. if (info) {
  564. params = info
  565. params.source = source
  566. }
  567. var _this = this
  568. $.ajax({
  569. type:'POST',
  570. url: '/salesLeads/collectInfo',
  571. contentType: "application/json;charset=utf-8",
  572. data: JSON.stringify(params),
  573. success:function (res) {
  574. if (res.data) {
  575. _this.showForm = false
  576. _this.showSuccess = true
  577. } else {
  578. _this.$message.error(res.error_msg);
  579. }
  580. }
  581. })
  582. },
  583. // 手机号输入框input事件
  584. inputPhone: function(val) {
  585. this.form.phone = val.replace(/[^\d]/g,'')
  586. },
  587. // 企业名称联想
  588. getResult:function(name) {
  589. // 名称为空或长度小于2不发请求
  590. if (!name || name.length < 2) return
  591. var _this = this
  592. $.ajax({
  593. type:'POST',
  594. url:'/jypay/user/company/association',
  595. data: {
  596. name: name,
  597. companyCount:10
  598. },
  599. heads : {
  600. 'content-type': 'application/x-www-form-urlencoded'
  601. },
  602. success:function (res) {
  603. console.log(res)
  604. if (res.data && res.data.length > 0) {
  605. var result = []
  606. res.data.map(function(item){
  607. item = _this.brightKeyword(item)
  608. result.push(item)
  609. return result
  610. })
  611. _this.companyList = result
  612. _this.showSearchResult = true
  613. }
  614. }
  615. })
  616. },
  617. searchCompany: debounce(function(val){
  618. if(val === '') { this.showSearchResult = false}
  619. this.getResult(val)
  620. }, 600),
  621. // 选择联想出来的公司名称
  622. selectCompany: function(item) {
  623. this.form.companyName = item.replace(/<.*?>/ig, '')
  624. this.showSearchResult = false
  625. },
  626. // 关键词高亮
  627. brightKeyword: function (val) {
  628. var name = this.form.companyName
  629. if (val.indexOf(name) !== -1) {
  630. return val.replace(name, `<span style='color:#2ABED1;'>${name}</span>`)
  631. } else {
  632. return val
  633. }
  634. },
  635. // 暂不提供
  636. cancelForm: function() {
  637. this.form.name = ''
  638. this.form.phone = ''
  639. this.form.mail = ''
  640. this.form.companyName = ''
  641. this.form.job = ''
  642. this.form.otherJob = ''
  643. this.form.code = ''
  644. var needExportSource = ['structedData', 'pc_data_custom_export', 'pc_data_custom_data']
  645. if (needExportSource.indexOf(this.source) > -1) {
  646. this.showForm = false
  647. this.showExport = true
  648. } else {
  649. this.showForm = false
  650. }
  651. this.showSearchResult=false
  652. },
  653. // 数据导出
  654. dataExport: function() {
  655. location.href = "/front/dataExport/toSieve"
  656. }
  657. }
  658. })