integral.js 28 KB

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