course-baojia.vue 16 KB

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