integral.js 27 KB

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