course-baojia.vue 16 KB

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