integral.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. // pages/integral/integral.js
  2. import Integralinfo from '../../api/integralinfo'
  3. import {getMobileCache, getPhoneNumberNew as getPhoneNumberSync} from '../../utils/user'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. lock: false,
  10. noResult: false,
  11. noMore: false,
  12. bannerList: [],
  13. couponList: [],
  14. channelid: '',
  15. shopid: '',
  16. storeid: '',
  17. bodyHidden: true,
  18. bgStatus: false,
  19. scorePhone: false,
  20. animationData: {},
  21. integralIngo:{},
  22. loading: false,
  23. setPhone: '',
  24. current: '',
  25. integralNum: 0,
  26. phone: '********',
  27. // phone: '15888282621',
  28. mobile: '********',
  29. paymentStatus: false,
  30. paymentBgStatus: false,
  31. activeNum: 0,
  32. listTrue: [],
  33. listStatus: false,
  34. total: 0,
  35. row: {},
  36. codeName: '60s后重新获取',
  37. codeTime: '',
  38. active1obj: {
  39. orderId: '',
  40. order_no: '',
  41. step: ''
  42. },
  43. active1code: '',
  44. active2code: '',
  45. tgid: '',
  46. scene: '',
  47. noClick: true,
  48. showToastObj: {
  49. icon: '',
  50. title: '',
  51. status: false
  52. },
  53. isIphoneX:false,
  54. },
  55. /**
  56. * 生命周期函数--监听页面加载
  57. */
  58. onLoad: function (options) {
  59. var reg = /^(\d{3})\d{4}(\d{4})$/;
  60. this.setData({
  61. isLogin: getMobileCache() != '',
  62. phone: getMobileCache() == ''?'********':getMobileCache().replace(reg, "$1****$2"),
  63. setPhone: getMobileCache(),
  64. mobile: getMobileCache(),
  65. channelid: options.channelid === undefined ? '' : options.channelid,
  66. shopid: options.shopid === undefined ? '' : options.shopid,
  67. storeid: options.storeid === undefined ? '' : options.storeid,
  68. tgid: options.tgid === undefined ? '' : options.tgid,
  69. })
  70. },
  71. /**
  72. * 生命周期函数--监听页面初次渲染完成
  73. */
  74. onReady: function () {
  75. },
  76. /**
  77. * 生命周期函数--监听页面显示
  78. */
  79. onShow: function () {
  80. let _self = this;
  81. this.setData({
  82. isIphoneX:_self.isIphone()
  83. })
  84. this.getBannerList()
  85. // 获取优惠券列表
  86. this.getCouponList()
  87. if(getMobileCache() != ''){
  88. Integralinfo.getBalance({
  89. mobile: getMobileCache(),
  90. callbackUrl: '../integral/integral.wxml',
  91. fingerprint: '',
  92. sessionid: '',
  93. shopid: this.data.shopid,
  94. type: 'wx',
  95. }).then(arr => {
  96. if (arr.code === '0000') {
  97. var reg = /^(\d{3})\d{4}(\d{4})$/;
  98. this.setData({
  99. isLogin: getMobileCache() != '',
  100. phone: getMobileCache() == ''?'********':getMobileCache().replace(reg, "$1****$2"),
  101. setPhone: getMobileCache(),
  102. mobile: getMobileCache(),
  103. integralNum: arr.data,
  104. })
  105. }
  106. }).catch(error=>{
  107. console.log(error);
  108. if (error.data.code === '2000') {
  109. this.scoreClick()
  110. }
  111. })
  112. }
  113. },
  114. /**
  115. * 判断是否是iphone
  116. */
  117. isIphone() {
  118. let isIphone = false
  119. wx.getSystemInfo({
  120. success: function(res) {
  121. if (res.model.indexOf('iPhone') >= 0) {
  122. isIphone = true;
  123. }
  124. }
  125. })
  126. return isIphone
  127. },
  128. /**
  129. * 生命周期函数--监听页面隐藏
  130. */
  131. onHide: function () {
  132. },
  133. /**
  134. * 生命周期函数--监听页面卸载
  135. */
  136. onUnload: function () {
  137. },
  138. /**
  139. * 页面相关事件处理函数--监听用户下拉动作
  140. */
  141. onPullDownRefresh: function () {
  142. },
  143. /**
  144. * 页面上拉触底事件的处理函数
  145. */
  146. onReachBottom: function () {
  147. },
  148. /**
  149. * 用户点击右上角分享
  150. */
  151. onShareAppMessage: function () {
  152. },
  153. getBannerList: function() {
  154. Integralinfo.getBannerList({
  155. channelid: this.data.channelid,
  156. shopid: this.data.shopid,
  157. storeid: this.data.storeid
  158. }).then(res => {
  159. console.log(res.data)
  160. this.setData({
  161. bannerList: res.data
  162. })
  163. }).catch(err => {
  164. console.log(err)
  165. })
  166. },
  167. getCouponList: function() {
  168. Integralinfo.getList({
  169. channelid: this.data.channelid,
  170. shopid: this.data.shopid,
  171. storeid: this.data.storeid
  172. }).then(res => {
  173. this.couponListView(res.data)
  174. this.data.lock = false
  175. }).catch(_ => {
  176. console.log(_)
  177. this.data.lock = false
  178. })
  179. },
  180. couponListView: function(data) {
  181. if (!Array.isArray(data) || data.length == 0) {
  182. console.log("优惠券列表数据为空");
  183. }
  184. data.forEach((v) => {
  185. v.quantity = 0
  186. v.integral = v.price * v.ratio
  187. })
  188. if (this.data.mobile != '********') {
  189. let num = this.data.integralNum > 20000 ? 19999 : this.data.integralNum
  190. const arr = []
  191. this.setData({
  192. total: 0,
  193. })
  194. for (let i = 0; i < data.length; i++) {
  195. data[i].quantity = parseInt(num / data[i].integral)
  196. if (data[i].quantity > 0) {
  197. num -= (data[i].quantity * data[i].price) * data[i].ratio
  198. this.data.total += (data[i].quantity * data[i].price) * data[i].ratio
  199. this.setData({
  200. total:this.data.total
  201. })
  202. arr.push(data[i])
  203. data.splice(i, 1)
  204. i--
  205. }
  206. }
  207. this.setData({
  208. couponList: [...arr, ...data]
  209. })
  210. } else {
  211. this.setData({
  212. couponList: data
  213. })
  214. }
  215. console.log(this.data.total)
  216. },
  217. // 点击标识点触发
  218. detailsClick(row) {
  219. this.hideModal();
  220. this.row = row.currentTarget.dataset.info
  221. console.log(this.row)
  222. if (this.row.detail_type === 0) {
  223. this.row.detailArr = this.row.detail.split('\n')
  224. } else {
  225. this.row.detailArr = row.detail
  226. }
  227. this.setData({
  228. integralIngo: this.row,
  229. })
  230. console.log(this.data.integralIngo)
  231. setTimeout(() => {
  232. this.showDodal();
  233. }, 100)
  234. },
  235. showDodal() {
  236. var that = this;
  237. // 显示遮罩层
  238. var animation = wx.createAnimation({
  239. duration: 150,
  240. timingFunction: "linear",
  241. delay: 0
  242. })
  243. this.setData({
  244. bgStatus: true,
  245. bodyHidden: false
  246. })
  247. that.animation = animation
  248. animation.translateY(-500).step()
  249. that.setData({
  250. animationData: animation.export()
  251. })
  252. },
  253. //隐藏对话框
  254. hideModal() {
  255. var that = this;
  256. console.log(that.data)
  257. // 隐藏遮罩层
  258. var animation = wx.createAnimation({
  259. duration: 150,
  260. timingFunction: "linear",
  261. delay: 0
  262. })
  263. this.setData({
  264. bodyHidden: true,
  265. bgStatus: false,
  266. scorePhone: false,
  267. })
  268. that.animation = animation
  269. animation.translateY(0).step()
  270. that.setData({
  271. animationData: animation.export()
  272. })
  273. },
  274. // //隐藏对话框
  275. // paymenHideModal() {
  276. // var that = this;
  277. // console.log(that.data)
  278. // this.setData({
  279. // bodyHidden: true,
  280. // paymentBgStatus: false,
  281. // paymentStatus: false,
  282. // })
  283. // },
  284. /**授权手机号 */
  285. getPhoneNumber(e) {
  286. let that = this;
  287. getPhoneNumberSync(e, async () => {
  288. console.log(e)
  289. if (getMobileCache() == '') {
  290. wx.showToast({
  291. icon:'error',
  292. title:'先查询移动积分'
  293. })
  294. setTimeout(()=>{
  295. that.data.setPhone = ''
  296. that.scoreClick()
  297. wx.hideLoading()
  298. },500)
  299. } else {
  300. var reg = /^(\d{3})\d{4}(\d{4})$/;
  301. this.setData({
  302. isLogin: true,
  303. setPhone: getMobileCache(),
  304. mobile: getMobileCache(),
  305. phone: getMobileCache().replace(reg, "$1****$2")
  306. })
  307. // console.log(this.data.setPhone)
  308. // console.log(this.data.mobile)
  309. // console.log(this.data.phone)
  310. this.getphoneClick()
  311. }
  312. })
  313. },
  314. // 查询积分
  315. scoreClick() {
  316. this.setData({
  317. bgStatus: true,
  318. scorePhone: true,
  319. })
  320. },
  321. // 查询积分
  322. getphoneClick() {
  323. console.log(getMobileCache())
  324. if (!(/^1[3456789]\d{9}$/.test(getMobileCache()))) {
  325. wx.showToast({
  326. title: '填写正确手机号',
  327. icon: 'error',
  328. duration: 2000
  329. });
  330. } else if (getMobileCache() != '') {
  331. // wx.showLoading({
  332. // title: '加载中'
  333. // });
  334. Integralinfo.getBalance({
  335. mobile: getMobileCache(),
  336. callbackUrl: '../integral/integral.wxml',
  337. fingerprint: '',
  338. sessionid: '',
  339. shopid: this.data.shopid,
  340. type: 'wx',
  341. }).then(arr => {
  342. console.log(arr)
  343. wx.hideLoading();
  344. if (arr.code === '0000') {
  345. var reg = /^(\d{3})\d{4}(\d{4})$/;
  346. this.setData({
  347. integralNum: arr.data,
  348. setPhone: getMobileCache(),
  349. phone: getMobileCache().replace(reg, "$1****$2"),
  350. })
  351. // this.data.integralNum = arr.data
  352. // var reg = /^(\d{3})\d{4}(\d{4})$/;
  353. // this.data.mobile = this.data.setPhone
  354. // this.data.setPhone = this.data.setPhone.replace(reg, "$1****$2");
  355. let response = {
  356. points: arr.data,
  357. outTokenId: this.data.setPhone + '_out'
  358. }
  359. // App.globalData.AppShow = response
  360. this.hideModal()
  361. this.getCouponList()
  362. wx.pageScrollTo({
  363. scrollTop: 0
  364. });
  365. let dateNum = Math.round(new Date().getTime() / 1000).toString()
  366. if (wx.getStorageSync('orderDetails') != '' && this.data.mobile === JSON.parse(wx
  367. .getStorageSync('orderDetails')).mobile) {
  368. if (dateNum - JSON.parse(wx.getStorageSync('orderDetails')).date <= 120) {
  369. const data = JSON.parse(wx.getStorageSync('orderDetails'))
  370. if (dateNum - data.date < 60) {
  371. let time = dateNum - data.date
  372. this.data.codeName = 60 - time + 's后重新获取'
  373. this.codeSetInterval(60 - time)
  374. } else {
  375. this.data.codeName = '重新获取验证码'
  376. }
  377. this.setData({
  378. paymentStatus: true,
  379. paymentBgStatus: true,
  380. active1code: '',
  381. active2code: '',
  382. active1obj: data,
  383. })
  384. if (data.step === 1) {
  385. this.setData({
  386. activeNum: 1,
  387. })
  388. } else if (data.step === 2) {
  389. this.setData({
  390. activeNum: 0,
  391. })
  392. }
  393. }
  394. }
  395. }
  396. }).catch(error => {
  397. console.log(error)
  398. let arr = error.data
  399. console.log(arr)
  400. if(arr.code ==='2000'){
  401. this.setData({
  402. scorePhone: false,
  403. loading: true,
  404. bgStatus: true
  405. })
  406. setTimeout(() => {
  407. // #ifdef H5
  408. // window.location.href = arr.message;
  409. // #endif
  410. // #ifdef MP-WEIXIN
  411. const version = wx.getSystemInfoSync().SDKVersion
  412. if (this.compareVersion(version, '2.20.1') >= 0) {
  413. wx.openEmbeddedMiniProgram({
  414. appId: arr.data.appId,
  415. path: arr.data.path,
  416. extraData: arr.data.extraData,
  417. success(res) {
  418. // 打开成功
  419. },
  420. fail() {}
  421. })
  422. } else {
  423. // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
  424. wx.navigateToMiniProgram({
  425. appId: arr.data.appId,
  426. path: arr.data.path,
  427. extraData: arr.data.extraData,
  428. success(res) {
  429. // 打开成功
  430. },
  431. fail() {
  432. }
  433. })
  434. }
  435. // #endif
  436. this.hideModal()
  437. this.setData({
  438. loading: false
  439. })
  440. }, 4000)
  441. }
  442. })
  443. }
  444. },
  445. // 商品数量减少按钮
  446. reduceClick(e) {
  447. console.log(e.currentTarget.dataset.index)
  448. let index = e.currentTarget.dataset.index
  449. this.data.couponList[index].quantity--
  450. this.data.total -= parseInt(this.data.couponList[index].integral)
  451. this.setData({
  452. total: this.data.total,
  453. couponList: this.data.couponList
  454. })
  455. },
  456. // 商品数量添加按钮
  457. addClick(e) {
  458. let index = e.currentTarget.dataset.index
  459. if (this.data.phone !== '********') {
  460. if (this.data.total + parseInt(this.data.couponList[index].integral) > 20000) {
  461. wx.showToast({
  462. title: '单笔限额两万分',
  463. icon: 'error',
  464. duration: 2000
  465. });
  466. } else if ((this.data.integralNum - this.data.total) >= this.data.couponList[index].integral) {
  467. this.data.couponList[index].quantity++
  468. this.data.total += parseInt(this.data.couponList[index].integral)
  469. this.setData({
  470. total: this.data.total,
  471. couponList:this.data.couponList
  472. })
  473. } else {
  474. wx.showToast({
  475. title: '积分不足',
  476. icon: 'error',
  477. duration: 2000
  478. });
  479. }
  480. } else {
  481. wx.showToast({
  482. title: '先查询移动积分',
  483. icon: 'error',
  484. duration: 1000
  485. });
  486. setTimeout(() => {
  487. this.scoreClick()
  488. }, 1000)
  489. }
  490. },
  491. /** 刷新 */
  492. shuaxinClick() {
  493. Integralinfo.getBalance({
  494. mobile: getMobileCache(),
  495. callbackUrl: '../integral/integral.wxml',
  496. fingerprint: '',
  497. sessionid: '',
  498. shopid: this.data.shopid,
  499. type: 'wx',
  500. }).then(arr => {
  501. if (arr.code === '0000') {
  502. wx.hideLoading();
  503. wx.showToast({
  504. title: '查询成功!',
  505. icon: 'success',
  506. duration: 1000
  507. });
  508. var reg = /^(\d{3})\d{4}(\d{4})$/;
  509. this.setData({
  510. integralNum: arr.data,
  511. setPhone: getMobileCache(),
  512. phone: getMobileCache().replace(reg, "$1****$2"),
  513. })
  514. }
  515. }).catch(error=>{
  516. console.log(222222)
  517. console.log(error)
  518. })
  519. },
  520. // 支付按钮
  521. paymentClick() {
  522. console.log(this.data.mobile)
  523. if (this.data.mobile === '********') {
  524. setTimeout(() => {
  525. this.scoreClick()
  526. }, 1000)
  527. wx.showToast({
  528. title: '先查询移动积分',
  529. icon: 'error',
  530. duration: 1000
  531. });
  532. } else if (this.data.total === 0) {
  533. wx.showToast({
  534. title: '请选择商品数量',
  535. icon: 'error',
  536. duration: 2000
  537. });
  538. } else {
  539. const data = []
  540. this.data.couponList.forEach(v => {
  541. if (v.quantity > 0) {
  542. data.push({
  543. couponid: v.id,
  544. num: v.quantity,
  545. })
  546. }
  547. })
  548. // let fingerprint = ''
  549. // let sessionid = ''
  550. // // #ifndef MP-WEIXIN
  551. // fingerprint = window.fmOpt
  552. // sessionid = window.sessionId
  553. // // #endif
  554. Integralinfo.getOrder({
  555. fingerprint:'',
  556. list: data,
  557. mobile: getMobileCache(),
  558. tgid: this.data.tgid,
  559. sessionid:'',
  560. shopid: this.data.shopid
  561. }).then(res => {
  562. if (res.code === '0000') {
  563. this.codeSetInterval(60)
  564. this.setData({
  565. codeName: '60s后重新获取',
  566. paymentStatus: true,
  567. paymentBgStatus: true,
  568. active1code: '',
  569. active2code: '',
  570. active1obj:{
  571. orderId: res.data.orderId,
  572. order_no: res.data.order_no,
  573. step: res.data.step,
  574. date: Math.round(new Date().getTime() / 1000).toString(),
  575. mobile: getMobileCache()
  576. },
  577. })
  578. wx.setStorageSync('orderDetails', JSON.stringify(this.data.active1obj))
  579. if (res.data.step === 1) {
  580. this.setData({
  581. activeNum: 1,
  582. })
  583. } else if (res.data.step === 2) {
  584. this.setData({
  585. activeNum: 0,
  586. })
  587. }
  588. console.log(res.data.step,this.data.activeNum)
  589. // this.getPaySend()
  590. } else {
  591. console.log(res.message)
  592. console.log(this.data.integralNum,this.data.mobile,JSON.stringify(data))
  593. // log.error(`${res.data.message}`)
  594. // log.error(`${this.data.integralNum},${this.data.mobile},${JSON.stringify(data)}`)
  595. wx.showToast({
  596. icon: 'none',
  597. title: res.message
  598. })
  599. }
  600. }).catch(error=>{
  601. console.log('zhifu')
  602. console.log(error)
  603. wx.showToast({
  604. icon: 'none',
  605. title: '请一分钟后再选择'
  606. })
  607. })
  608. }
  609. },
  610. // 步骤按钮
  611. nextCodeClick() {
  612. console.log(this.data.activeNum,this.data.active2code)
  613. if (this.data.activeNum === 1 && this.data.active2code !== '') {
  614. // wx.showLoading({
  615. // title: '兑换中'
  616. // });
  617. // let fingerprint = ''
  618. // let sessionid = ''
  619. // // #ifndef MP-WEIXIN
  620. // fingerprint = window.fmOpt
  621. // sessionid = window.sessionId
  622. // #endif
  623. Integralinfo.getPayOnce({
  624. fingerprint: '',
  625. mobile: getMobileCache(),
  626. optCode: this.data.active2code,
  627. order_no: this.data.active1obj.order_no,
  628. orderId: this.data.active1obj.orderId,
  629. sessionid: '',
  630. shopid: this.data.shopid
  631. }).then(res => {
  632. if (res.code === '0000') {
  633. const obj = {
  634. mobile: this.data.mobile,
  635. channelid: this.data.channelid,
  636. shopid: this.data.shopid,
  637. storeid: this.data.storeid
  638. }
  639. this.data.integralNum -= this.data.total
  640. this.setData({
  641. integralNum: this.data.integralNum,
  642. total: 0,
  643. listStatus: false,
  644. listTrue: [],
  645. })
  646. this.data.couponList.forEach((v)=>{
  647. v.quantity = 0
  648. })
  649. this.setData({
  650. couponList: this.data.couponList,
  651. paymentStatus: false,
  652. paymentBgStatus: false,
  653. })
  654. wx.setStorageSync('orderDetails', null)
  655. wx.hideLoading();
  656. wx.navigateTo({
  657. url: '../integral/success?row=' + JSON.stringify(obj)
  658. })
  659. } else {
  660. wx.hideLoading();
  661. wx.showToast({
  662. icon: 'none',
  663. title: res.message
  664. })
  665. }
  666. }).catch(error => {
  667. let res = error.data;
  668. wx.showToast({
  669. icon: 'none',
  670. title: res.message
  671. })
  672. });
  673. } else if (this.data.activeNum === 0 && this.data.active1code !== '') {
  674. Integralinfo.getExchange({
  675. fingerprint: '',
  676. mobile: getMobileCache(),
  677. optCode: this.data.active1code,
  678. orderId: this.data.active1obj.orderId,
  679. order_no: this.data.active1obj.order_no,
  680. sessionid: '',
  681. shopid: this.data.shopid
  682. }).then(res => {
  683. if (res.code === '0000') {
  684. clearInterval(this.data.codeTime)
  685. this.setData({
  686. active2code: '',
  687. activeNum: this.activeNum++,
  688. codeName: '60s后重新获取',
  689. })
  690. this.codeSetInterval(60)
  691. } else {
  692. wx.showToast({
  693. icon: 'none',
  694. title: res.message
  695. })
  696. }
  697. }).catch(error => {
  698. let res = error.data;
  699. wx.showToast({
  700. icon: 'none',
  701. title: res.message
  702. })
  703. })
  704. } else {
  705. wx.showToast({
  706. icon: 'error',
  707. title: '请填写验证码'
  708. })
  709. }
  710. },
  711. // 短信定时器
  712. codeSetInterval(num) {
  713. console.log(num)
  714. let time = num
  715. this.data.codeTime = setInterval(() => {
  716. if (time <= 1) {
  717. this.setData({
  718. codeName: '重新获取验证码',
  719. })
  720. clearInterval(this.data.codeTime)
  721. } else {
  722. time--
  723. this.setData({
  724. codeName:`${time}s后重新获取`
  725. })
  726. }
  727. }, 1000)
  728. },
  729. getPaySend(){
  730. if (this.data.activeNum === 1) {
  731. console.log('发送短信')
  732. Integralinfo.getPaySend({
  733. order_no: this.data.active1obj.order_no,
  734. mobile: getMobileCache(),
  735. shopid: this.data.shopid,
  736. }).then(res => {
  737. if (res.code === '0000') {
  738. this.setData({
  739. codeName: '60s后重新获取',
  740. })
  741. this.codeSetInterval(60)
  742. } else {
  743. wx.showToast({
  744. icon: 'none',
  745. title: res.message
  746. })
  747. }
  748. }).catch(error=>{
  749. console.log('duanxin')
  750. console.log(error)
  751. })
  752. }
  753. },
  754. // 重新获取短信
  755. getCodeClick() {
  756. console.log(this.data.activeNum,this.data.codeName,this.data.active1obj.step)
  757. if ((this.data.activeNum === 1 && this.data.codeName === '重新获取验证码') && this.data.active1obj.step === 1) {
  758. Integralinfo.getSendCmccSms({
  759. orderId: this.data.active1obj.orderId,
  760. mobile: getMobileCache(),
  761. shopid: this.data.shopid
  762. }).then(res => {
  763. if (res.code === '0000') {
  764. this.setData({
  765. codeName: '60s后重新获取',
  766. })
  767. this.codeSetInterval(60)
  768. const obj = this.data.active1obj
  769. obj.date = Math.round(new Date().getTime() / 1000).toString()
  770. wx.setStorageSync('orderDetails', JSON.stringify(obj))
  771. } else {
  772. wx.showToast({
  773. icon: 'none',
  774. title: res.message
  775. })
  776. }
  777. }).catch(error=>{
  778. console.log('chongxin')
  779. console.log(error)
  780. });
  781. } else {
  782. if (this.data.activeNum === 0 && this.data.codeName === '重新获取验证码') {
  783. Integralinfo.getSendCmccSms({
  784. orderId: this.data.active1obj.orderId,
  785. mobile: getMobileCache(),
  786. shopid: this.data.shopid
  787. }).then(res => {
  788. if (res.code === '0000') {
  789. this.codeName = '60s后重新获取'
  790. this.codeSetInterval(60)
  791. } else {
  792. wx.showToast({
  793. icon: 'none',
  794. title: res.message
  795. })
  796. }
  797. }).catch(error=>{
  798. console.log('chongxin')
  799. console.log(error)
  800. });
  801. } else if (this.data.activeNum === 1 && this.data.codeName === '重新获取验证码') {
  802. console.log('短信')
  803. Integralinfo.getPaySend({
  804. order_no: this.data.active1obj.order_no,
  805. mobile: getMobileCache(),
  806. shopid: this.data.shopid,
  807. }).then(res => {
  808. if (res.code === '0000') {
  809. this.setData({
  810. codeName: '60s后重新获取',
  811. })
  812. this.codeSetInterval(60)
  813. } else {
  814. wx.showToast({
  815. icon: 'none',
  816. title: res.message
  817. })
  818. }
  819. }).catch(error=>{
  820. console.log('chongxin')
  821. console.log(error)
  822. });
  823. }
  824. }
  825. },
  826. toExchange(){
  827. const obj = {
  828. mobile: getMobileCache(),
  829. channelid: this.data.channelid,
  830. shopid: this.data.shopid,
  831. storeid: this.data.storeid
  832. }
  833. wx.navigateTo({
  834. url: '../integral/exchange?obj=' + JSON.stringify(obj)
  835. })
  836. },
  837. compareVersion(v1, v2) {
  838. v1 = v1.split('.')
  839. v2 = v2.split('.')
  840. const len = Math.max(v1.length, v2.length)
  841. while (v1.length < len) {
  842. v1.push('0')
  843. }
  844. while (v2.length < len) {
  845. v2.push('0')
  846. }
  847. for (let i = 0; i < len; i++) {
  848. const num1 = parseInt(v1[i])
  849. const num2 = parseInt(v2[i])
  850. if (num1 > num2) {
  851. return 1
  852. } else if (num1 < num2) {
  853. return -1
  854. }
  855. }
  856. return 0
  857. },
  858. })