integral.js 28 KB

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