leave-info-dialog.js 20 KB

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