course-baojia.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <template>
  2. <div class="course-baojia">
  3. <!-- 第一行报价人数 -->
  4. <div class="baojia-counts">
  5. <i></i><span>已有 {{ sum }} 位客户成功报价</span>
  6. </div>
  7. <!-- 手机号 -->
  8. <div class="baojia-phone">
  9. <el-input class="phone-input" v-model="baojia.phone" placeholder="请输入手机号(必填)"></el-input>
  10. </div>
  11. <!-- 进度条 -->
  12. <div class="baojia-nc">
  13. <div id="baojiaId" class="nc-container"></div>
  14. </div>
  15. <!-- 验证码+按钮 -->
  16. <div class="baojia-btns-code">
  17. <el-input v-model="baojia.code" placeholder="请输入验证码"/>
  18. <el-button class="code-btn" :disabled="btnTextDisabled" @click="checkVerification">{{ btnText }}</el-button>
  19. </div>
  20. <!-- 称呼 -->
  21. <div class="baojia-custom-name">
  22. <el-input v-model="baojia.name" placeholder="请输入您的称呼(必填)"/>
  23. </div>
  24. <!-- 按钮 -->
  25. <div class="baojia-btn">
  26. <el-button type="primary" @click="handleBaojia">预约咨询顾客</el-button>
  27. </div>
  28. <!-- 底部滚动 -->
  29. <div class="baojia-bottom" v-if="userData.length">
  30. <div v-swiper:mySwiper="swiperOption" class="swiper-container">
  31. <div class="swiper-wrapper">
  32. <div class="swiper-slide div-row" v-for="(d,index) in userData" :key="index">
  33. <span class="icon-w1">
  34. <i></i>
  35. <span>{{ d.chenghu }}</span>
  36. </span>
  37. <span>{{ d.phone }}</span>
  38. <span>{{ d.timer }}</span>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </template>
  45. <script>
  46. export default {
  47. name: "course-baojia",
  48. props: {
  49. sum: {
  50. type: Number,
  51. default: 0
  52. },
  53. tag: {
  54. type: String,
  55. default: 'dhl'
  56. },
  57. userList: {
  58. type: Array,
  59. default: [],
  60. }
  61. },
  62. computed: {
  63. curTag() {
  64. const tag = {
  65. 'wkl': 1,
  66. 'dhl': 2,
  67. 'ppt': 3,
  68. }
  69. return tag[this.tag]
  70. },
  71. userData() {
  72. const userList = this.userList.filter(user => user.chenghu)
  73. return userList.map(user => {
  74. const chenghu = user.chenghu.length > 2 ? `${user.chenghu[0]}**` : `${user.chenghu[0]}*`;
  75. const ps = user.phone.split('');
  76. const phone = `${ps[0]}${ps[1]}${ps[2]}****${ps[7]}${ps[8]}${ps[9]}${ps[10]}`;
  77. return {chenghu, phone, timer: this.getTimeString(user['endSecond'])}
  78. })
  79. },
  80. },
  81. data() {
  82. return {
  83. baojia: {
  84. phone: '',
  85. code: '',
  86. name: ''
  87. },
  88. btnTextDisabled: false,
  89. btnText: '获取验证码',
  90. countdown: 60, // 60秒倒计时
  91. swiperOption: {},
  92. appKey: 'FFFF0N00000000007EC0',
  93. }
  94. },
  95. methods: {
  96. getTimeString(timer) {
  97. let m10 = 10 * 60 * 1000;
  98. let m30 = 30 * 60 * 1000;
  99. let h1 = 60 * 60 * 1000;
  100. let h6 = 6 * 60 * 60 * 1000;
  101. let d1 = 24 * 60 * 60 * 1000;
  102. let z1 = 7 * 24 * 60 * 60 * 1000;
  103. let M1 = 30 * 24 * 60 * 60 * 1000;
  104. if (timer > M1) {
  105. return `1个月前`
  106. }
  107. if (timer > z1) {
  108. return `1周前`
  109. }
  110. if (timer > d1) {
  111. return `1天前`
  112. }
  113. if (timer > h6) {
  114. return `6小时前`
  115. }
  116. if (timer > h1) {
  117. return `1小时前`
  118. }
  119. if (timer > m30) {
  120. return `30分钟前`
  121. }
  122. if (timer > m10) {
  123. return `10分中前`
  124. }
  125. return `刚刚`;
  126. },
  127. // 倒计时60秒
  128. setTime() {
  129. if (this.countdown === 0) {
  130. this.btnTextDisabled = false;
  131. this.btnText = '获取验证码';
  132. this.countdown = 60;
  133. } else if (this.countdown === -1) {
  134. this.btnTextDisabled = false;
  135. this.btnText = '获取验证码';
  136. this.countdown = 60;
  137. } else {
  138. this.btnTextDisabled = true;
  139. this.btnText = '重新发送(' + this.countdown + 's)';
  140. this.countdown--;
  141. this.countTimer = setTimeout(() => this.setTime(), 1000);
  142. }
  143. },
  144. /**
  145. * 串联加载指定的脚本
  146. * 串联加载[异步]逐个加载,每个加载完成后加载下一个
  147. * 全部加载完成后执行回调
  148. * @param array|string 指定的脚本们
  149. * @param function 成功后回调的函数
  150. * @return array 所有生成的脚本元素对象数组
  151. * 异步加载js后运行回调函数callback / scripts 为数组或字符串
  152. */
  153. seriesLoadScripts(scripts, callback) {
  154. if (typeof (scripts) != 'object') {
  155. var scripts = [scripts];
  156. }
  157. var HEAD = document.getElementsByTagName('head').item(0) || document.documentElement;
  158. var s = new Array(), last = scripts.length - 1, recursiveLoad = function (i) { //递归
  159. s[i] = document.createElement('script');
  160. s[i].setAttribute('type', 'text/javascript');
  161. s[i].onload = s[i].onreadystatechange = function () { //Attach handlers for all browsers
  162. if (!/*@cc_on!@*/0 || this.readyState == 'loaded' || this.readyState == 'complete') {
  163. this.onload = this.onreadystatechange = null;
  164. this.parentNode.removeChild(this);
  165. if (i != last) {
  166. recursiveLoad(i + 1);
  167. } else if (typeof (callback) == 'function') {
  168. callback();
  169. }
  170. }
  171. };
  172. s[i].setAttribute('src', scripts[i]);
  173. HEAD.appendChild(s[i]);
  174. };
  175. recursiveLoad(0);
  176. },
  177. // 滑块
  178. sliderFun() {
  179. const nc_token = [this.appKey, (new Date()).getTime(), Math.random()].join(':');
  180. const NC_Opt = {
  181. //声明滑动验证需要渲染的目标元素ID。
  182. renderTo: '#baojiaId',
  183. //应用类型标识。它和使用场景标识(scene字段)一起决定了滑动验证的业务场景与后端对应使用的策略模型。您可以在人机验证控制台的配置管理页签找到对应的appkey字段值,请务必正确填写。
  184. appkey: this.appKey,
  185. //使用场景标识。它和应用类型标识(appkey字段)一起决定了滑动验证的业务场景与后端对应使用的策略模型。您可以在人机验证控制台的配置管理页签找到对应的scene值,请务必正确填写。
  186. scene: 'nc_message',
  187. //滑动验证码的主键,请勿将该字段定义为固定值。确保每个用户每次打开页面时,其token值都是不同的。系统默认的格式为:”您的appkey”+”时间戳”+”随机数”。
  188. token: nc_token,
  189. //滑动条的宽度。
  190. customWidth: 300,
  191. //业务键字段,可为空。为便于线上问题的排查,建议您按照线上问题定位文档中推荐的方法配置该字段值。
  192. trans: {'key1': 'code0'},
  193. //通过Dom的ID属性自动填写trans业务键,可为空。建议您按照线上问题定位文档中推荐的方法配置该字段值。
  194. elementID: ['usernameID'],
  195. //是否自定义配置底层采集组件。如无特殊场景,请使用默认值(0),即不自定义配置底层采集组件。
  196. is_Opt: 0,
  197. //语言。PC端Web页面场景默认支持18国语言,详细配置方法请参见自定义文案与多语言文档。
  198. language: 'cn',
  199. //是否启用。一般情况,保持默认值(true)即可。
  200. isEnabled: true,
  201. //内部网络请求的超时时间。一般情况建议保持默认值(3000ms)。
  202. timeout: 3000,
  203. //允许服务器超时重复次数,默认5次。超过重复次数后将触发报错。
  204. times: 5,
  205. //用于自定义滑动验证各项请求的接口地址。一般情况,请勿配置该参数。
  206. apimap: {
  207. // 'analyze': '//a.com/nocaptcha/analyze.jsonp',
  208. // 'get_captcha': '//b.com/get_captcha/ver3',
  209. // 'get_captcha': '//pin3.aliyun.com/get_captcha/ver3'
  210. // 'get_img': '//c.com/get_img',
  211. // 'checkcode': '//d.com/captcha/checkcode.jsonp',
  212. // 'umid_Url': '//e.com/security/umscript/3.2.1/um.js',
  213. // 'uab_Url': '//aeu.alicdn.com/js/uac/909.js',
  214. // 'umid_serUrl': 'https://g.com/service/um.json'
  215. },
  216. //前端滑动验证通过时会触发该回调参数。您可以在该回调参数中将请求标识(token)、会话ID(sessionid)、签名串(sig)字段记录下来,随业务请求一同发送至您的服务端调用验签。
  217. callback: (data) => {
  218. this.sliderData = Object.assign({}, data, {
  219. appkey: NC_Opt.appkey,
  220. scene: NC_Opt.scene,
  221. });
  222. console.log(this.sliderData);
  223. },
  224. };
  225. let date11 = () => {
  226. let _date = new Date();
  227. let year = _date.getFullYear().toString();
  228. let month = _date.getMonth().toString();
  229. let day = _date.getDate().toString();
  230. let a = _date.getHours().toString();
  231. let b = _date.getMinutes().toString();
  232. let c = _date.getSeconds().toString();
  233. return year + month + day + a + b + c;
  234. };
  235. let c = date11();
  236. const scripts = [
  237. `https://g.alicdn.com/sd/ncpc/nc.js?t=${c}`,
  238. ];
  239. this.seriesLoadScripts(scripts, function () {
  240. var nc = new noCaptcha(NC_Opt);
  241. nc.upLang('cn', {
  242. _startTEXT: '请按住滑块,拖动到最右边',
  243. _yesTEXT: '验证通过',
  244. _error300: '哎呀,出错了,点击<a href="javascript:__nc.reset()">刷新</a>再来一次',
  245. _errorNetwork: '网络不给力,请<a href="javascript:__nc.reset()">点击刷新</a>',
  246. });
  247. });
  248. },
  249. // 验证码
  250. checkVerification() {
  251. if (this.sliderData.appkey === undefined) {
  252. this.$message.error('请先通过滑块校验');
  253. return;
  254. }
  255. this.$axios.$post(`/develop/exists`, {phone: this.baojia.phone}).then(res => {
  256. if (res.code === 0 && res.data) {
  257. let req = {
  258. 'appkey': this.sliderData.appkey,
  259. 'phone': this.baojia.phone,
  260. 'scene': this.sliderData.scene,
  261. 'sessionid': this.sliderData.csessionid,
  262. 'sig': this.sliderData.sig,
  263. 'token': this.sliderData.token,
  264. 'type': 0,
  265. }
  266. this.$axios.$post('/sendCode', req).then(res => {
  267. if (res.code === 0 && res.data) {
  268. this.setTime();
  269. } else {
  270. this.$message.error(res.msg || '手机号已存在');
  271. }
  272. })
  273. } else {
  274. this.$message.error(res.msg || '手机号已存在');
  275. return false;
  276. }
  277. })
  278. },
  279. // 申请报价
  280. handleBaojia() {
  281. const opt = {
  282. type: this.curTag,
  283. phone: this.baojia.phone,
  284. code: this.baojia.code,
  285. chenghu: this.baojia.name
  286. }
  287. if (!this.baojia.phone) {
  288. this.$message.error("请填写手机号");
  289. return;
  290. }
  291. if (!this.baojia.code) {
  292. this.$message.error("验证码不能为空");
  293. return;
  294. }
  295. if (!this.baojia.name) {
  296. this.$message.error("请输入您的称呼");
  297. return;
  298. }
  299. this.confirmTl(opt)
  300. },
  301. confirmTl(options){
  302. // 请求后台
  303. this.$axios.$post('/develop/add',options).then(res=>{
  304. if (res.code === 0 && res.data) {
  305. this.$message.success('申请成功');
  306. this.resetCode();
  307. } else {
  308. this.$message.error('申请失败');
  309. this.resetCode();
  310. }
  311. });
  312. },
  313. resetCode() {
  314. this.btnTextDisabled = false;
  315. this.btnText = '获取验证码';
  316. this.countdown = 60; // 60秒倒计时
  317. this.swiperOption = {};
  318. this.countTimer && clearTimeout(this.countTimer);
  319. }
  320. },
  321. mounted() {
  322. this.sliderFun();
  323. }
  324. }
  325. </script>
  326. <style lang="scss" scoped>
  327. .course-baojia {
  328. box-sizing: border-box;
  329. background: #ffffff;
  330. border-radius: 10px;
  331. box-shadow: -8px 0px 35px 8px rgba(196, 198, 200, 0.34);
  332. overflow: hidden;
  333. position: relative;
  334. width: 379px;
  335. height: 471px;
  336. padding: 34px 22px;
  337. .baojia-counts {
  338. display: flex;
  339. justify-content: flex-start;
  340. align-items: center;
  341. background-color: rgba(73, 172, 252, 0.08);
  342. border-radius: 6px;
  343. margin-bottom: 22px;
  344. width: 335px;
  345. height: 44px;
  346. > i {
  347. display: inline-block;
  348. background-image: url("~static/images/client/course/animation/fire.png");
  349. background-size: contain;
  350. background-repeat: no-repeat;
  351. margin: 0 5px 0 14px;
  352. width: 19px;
  353. height: 22px;
  354. }
  355. > span {
  356. font-size: 14px;
  357. font-weight: 400;
  358. text-align: left;
  359. color: #2779f7;
  360. }
  361. }
  362. .baojia-phone {
  363. margin-bottom: 17px;
  364. .phone-input {
  365. border: 1px solid #d3d3d3;
  366. border-radius: 6px;
  367. width: 335px;
  368. height: 50px;
  369. ::v-deep .el-input__inner {
  370. border: none;
  371. height: 50px;
  372. line-height: 50px;
  373. }
  374. }
  375. }
  376. .baojia-nc {
  377. background: #f7f7f7;
  378. margin-bottom: 22px;
  379. width: 335px;
  380. height: 30px;
  381. .nc-container {
  382. ::v-deep .nc_wrapper {
  383. // 此处id会随机生成 借用class + important 冲掉 id权重
  384. width: 100% !important;
  385. }
  386. }
  387. }
  388. .baojia-btns-code {
  389. display: flex;
  390. justify-content: space-between;
  391. align-items: center;
  392. margin-bottom: 20px;
  393. width: 100%;
  394. ::v-deep .el-input {
  395. border: 1px solid #d3d3d3;
  396. border-radius: 6px;
  397. width: 200px;
  398. height: 50px;
  399. }
  400. ::v-deep .el-input__inner {
  401. border: none;
  402. height: 50px;
  403. line-height: 50px;
  404. }
  405. .code-btn {
  406. background: linear-gradient(to right, #247bfa 0%, #4baffc 100%);
  407. border-radius: 6px;
  408. box-shadow: 0 0 0px 0 #257df9;
  409. border: none;
  410. width: 123px;
  411. height: 50px;
  412. margin-left: 10px;
  413. ::v-deep span {
  414. color: #fff;
  415. }
  416. }
  417. }
  418. .baojia-custom-name {
  419. border: 1px solid #d3d3d3;
  420. border-radius: 6px;
  421. margin-bottom: 20px;
  422. width: 335px;
  423. height: 50px;
  424. ::v-deep .el-input__inner {
  425. border: none;
  426. height: 50px;
  427. line-height: 50px;
  428. }
  429. }
  430. .baojia-btn {
  431. ::v-deep .el-button {
  432. background: linear-gradient(to right, #247bfa 0%, #4baffc 100%);
  433. border-radius: 6px;
  434. box-shadow: 0 0 0px 0 #257df9;
  435. width: 335px;
  436. height: 50px;
  437. span {
  438. font-size: 16px;
  439. font-weight: 400;
  440. text-align: left;
  441. color: #ffffff;
  442. }
  443. }
  444. }
  445. .baojia-bottom {
  446. background: rgba(39, 127, 250, 0.07);
  447. position: absolute;
  448. bottom: 0;
  449. left: 0;
  450. width: 379px;
  451. height: 36px;
  452. .icon-w1 {
  453. display: flex;
  454. align-items: center;
  455. justify-content: flex-start;
  456. i {
  457. background-image: url('~static/images/client/course/animation/yinling.png');
  458. display: inline-block;
  459. width: 13px;
  460. height: 14px;
  461. margin: 13px 15px 0 28px;
  462. }
  463. span {
  464. margin-top: 13px;
  465. }
  466. }
  467. .swiper-slide {
  468. display: flex;
  469. justify-content: space-between;
  470. align-items: center;
  471. > span {
  472. font-size: 14px;
  473. font-weight: 400;
  474. text-align: left;
  475. color: #2779f7;
  476. &:nth-child(2), &:nth-child(3) {
  477. margin-top: 13px;
  478. margin-right: 20px;
  479. }
  480. }
  481. }
  482. }
  483. @media (max-width: 768px){
  484. & {
  485. transform: scale(0.8);
  486. }
  487. }
  488. }
  489. </style>