integral.js 28 KB

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