leave-info-dialog.js 19 KB

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