integral.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  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. this.scoreClick()
  502. }
  503. },
  504. /** 刷新 */
  505. shuaxinClick() {
  506. Integralinfo.getBalance({
  507. mobile: getMobileCache(),
  508. callbackUrl: '../integral/integral.wxml',
  509. fingerprint: '',
  510. sessionid: '',
  511. shopid: this.data.shopid,
  512. type: 'wx',
  513. }).then(arr => {
  514. if (arr.code === '0000') {
  515. // wx.hideLoading();
  516. wx.showToast({
  517. title: '查询成功!',
  518. icon: 'success',
  519. duration: 1000
  520. });
  521. var reg = /^(\d{3})\d{4}(\d{4})$/;
  522. this.setData({
  523. integralNum: arr.data,
  524. setPhone: getMobileCache(),
  525. phone: getMobileCache().replace(reg, "$1****$2"),
  526. })
  527. }
  528. }).catch(error=>{
  529. console.log(222222)
  530. console.log(error)
  531. })
  532. },
  533. // 支付按钮
  534. paymentClick() {
  535. console.log(this.data.mobile)
  536. if (this.data.mobile === '********') {
  537. setTimeout(() => {
  538. this.scoreClick()
  539. }, 1000)
  540. wx.showToast({
  541. title: '先查询移动积分',
  542. icon: 'error',
  543. duration: 1000
  544. });
  545. } else if (this.data.total === 0) {
  546. wx.showToast({
  547. title: '请选择商品数量',
  548. icon: 'error',
  549. duration: 2000
  550. });
  551. } else {
  552. const data = []
  553. this.data.couponList.forEach(v => {
  554. if (v.quantity > 0) {
  555. data.push({
  556. couponid: v.id,
  557. num: v.quantity,
  558. })
  559. }
  560. })
  561. // let fingerprint = ''
  562. // let sessionid = ''
  563. // // #ifndef MP-WEIXIN
  564. // fingerprint = window.fmOpt
  565. // sessionid = window.sessionId
  566. // // #endif
  567. Integralinfo.getOrder({
  568. fingerprint:'',
  569. list: data,
  570. mobile: getMobileCache(),
  571. tgid: this.data.tgid,
  572. sessionid:'',
  573. shopid: this.data.shopid
  574. }).then(res => {
  575. if (res.code === '0000') {
  576. this.codeSetInterval(60)
  577. this.setData({
  578. codeName: '60s后重新获取',
  579. paymentStatus: true,
  580. paymentBgStatus: true,
  581. active1code: '',
  582. active2code: '',
  583. active1obj:{
  584. orderId: res.data.orderId,
  585. order_no: res.data.order_no,
  586. step: res.data.step,
  587. date: Math.round(new Date().getTime() / 1000).toString(),
  588. mobile: getMobileCache()
  589. },
  590. })
  591. wx.setStorageSync('orderDetails', JSON.stringify(this.data.active1obj))
  592. if (res.data.step === 1) {
  593. this.setData({
  594. activeNum: 1,
  595. })
  596. } else if (res.data.step === 2) {
  597. this.setData({
  598. activeNum: 0,
  599. })
  600. }
  601. console.log(res.data.step,this.data.activeNum)
  602. // this.getPaySend()
  603. } else {
  604. console.log(res.message)
  605. console.log(this.data.integralNum,this.data.mobile,JSON.stringify(data))
  606. // log.error(`${res.data.message}`)
  607. // log.error(`${this.data.integralNum},${this.data.mobile},${JSON.stringify(data)}`)
  608. wx.showToast({
  609. icon: 'none',
  610. title: res.message
  611. })
  612. }
  613. }).catch(error=>{
  614. console.log('zhifu')
  615. console.log(error)
  616. wx.showToast({
  617. icon: 'none',
  618. title: '请一分钟后再选择'
  619. })
  620. })
  621. }
  622. },
  623. // 步骤按钮
  624. nextCodeClick() {
  625. console.log(this.data.activeNum,this.data.active2code)
  626. if (this.data.activeNum === 1 && this.data.active2code !== '') {
  627. // wx.showLoading({
  628. // title: '兑换中'
  629. // });
  630. // let fingerprint = ''
  631. // let sessionid = ''
  632. // // #ifndef MP-WEIXIN
  633. // fingerprint = window.fmOpt
  634. // sessionid = window.sessionId
  635. // #endif
  636. Integralinfo.getPayOnce({
  637. fingerprint: '',
  638. mobile: getMobileCache(),
  639. optCode: this.data.active2code,
  640. order_no: this.data.active1obj.order_no,
  641. orderId: this.data.active1obj.orderId,
  642. sessionid: '',
  643. shopid: this.data.shopid
  644. }).then(res => {
  645. if (res.code === '0000') {
  646. const obj = {
  647. mobile: this.data.mobile,
  648. channelid: this.data.channelid,
  649. shopid: this.data.shopid,
  650. storeid: this.data.storeid
  651. }
  652. this.data.integralNum -= this.data.total
  653. this.setData({
  654. integralNum: this.data.integralNum,
  655. total: 0,
  656. listStatus: false,
  657. listTrue: [],
  658. })
  659. this.data.couponList.forEach((v)=>{
  660. v.quantity = 0
  661. })
  662. this.setData({
  663. couponList: this.data.couponList,
  664. paymentStatus: false,
  665. paymentBgStatus: false,
  666. })
  667. wx.setStorageSync('orderDetails', null)
  668. // wx.hideLoading();
  669. wx.navigateTo({
  670. url: '../integral/success?row=' + JSON.stringify(obj)
  671. })
  672. } else {
  673. // wx.hideLoading();
  674. wx.showToast({
  675. icon: 'none',
  676. title: res.message
  677. })
  678. }
  679. }).catch(error => {
  680. let res = error.data;
  681. wx.showToast({
  682. icon: 'none',
  683. title: res.message
  684. })
  685. });
  686. } else if (this.data.activeNum === 0 && this.data.active1code !== '') {
  687. Integralinfo.getExchange({
  688. fingerprint: '',
  689. mobile: getMobileCache(),
  690. optCode: this.data.active1code,
  691. orderId: this.data.active1obj.orderId,
  692. order_no: this.data.active1obj.order_no,
  693. sessionid: '',
  694. shopid: this.data.shopid
  695. }).then(res => {
  696. if (res.code === '0000') {
  697. clearInterval(this.data.codeTime)
  698. this.setData({
  699. active2code: '',
  700. activeNum: this.activeNum++,
  701. codeName: '60s后重新获取',
  702. })
  703. this.codeSetInterval(60)
  704. } else {
  705. wx.showToast({
  706. icon: 'none',
  707. title: res.message
  708. })
  709. }
  710. }).catch(error => {
  711. let res = error.data;
  712. wx.showToast({
  713. icon: 'none',
  714. title: res.message
  715. })
  716. })
  717. } else {
  718. wx.showToast({
  719. icon: 'error',
  720. title: '请填写验证码'
  721. })
  722. }
  723. },
  724. // 短信定时器
  725. codeSetInterval(num) {
  726. console.log(num)
  727. let time = num
  728. this.data.codeTime = setInterval(() => {
  729. if (time <= 1) {
  730. this.setData({
  731. codeName: '重新获取验证码',
  732. })
  733. clearInterval(this.data.codeTime)
  734. } else {
  735. time--
  736. this.setData({
  737. codeName:`${time}s后重新获取`
  738. })
  739. }
  740. }, 1000)
  741. },
  742. getPaySend(){
  743. if (this.data.activeNum === 1) {
  744. console.log('发送短信')
  745. Integralinfo.getPaySend({
  746. order_no: this.data.active1obj.order_no,
  747. mobile: getMobileCache(),
  748. shopid: this.data.shopid,
  749. }).then(res => {
  750. if (res.code === '0000') {
  751. this.setData({
  752. codeName: '60s后重新获取',
  753. })
  754. this.codeSetInterval(60)
  755. } else {
  756. wx.showToast({
  757. icon: 'none',
  758. title: res.message
  759. })
  760. }
  761. }).catch(error=>{
  762. console.log('duanxin')
  763. console.log(error)
  764. })
  765. }
  766. },
  767. // 重新获取短信
  768. getCodeClick() {
  769. console.log(this.data.activeNum,this.data.codeName,this.data.active1obj.step)
  770. if ((this.data.activeNum === 1 && this.data.codeName === '重新获取验证码') && this.data.active1obj.step === 1) {
  771. Integralinfo.getSendCmccSms({
  772. orderId: this.data.active1obj.orderId,
  773. mobile: getMobileCache(),
  774. shopid: this.data.shopid
  775. }).then(res => {
  776. if (res.code === '0000') {
  777. this.setData({
  778. codeName: '60s后重新获取',
  779. })
  780. this.codeSetInterval(60)
  781. const obj = this.data.active1obj
  782. obj.date = Math.round(new Date().getTime() / 1000).toString()
  783. wx.setStorageSync('orderDetails', JSON.stringify(obj))
  784. } else {
  785. wx.showToast({
  786. icon: 'none',
  787. title: res.message
  788. })
  789. }
  790. }).catch(error=>{
  791. console.log('chongxin')
  792. console.log(error)
  793. });
  794. } else {
  795. if (this.data.activeNum === 0 && this.data.codeName === '重新获取验证码') {
  796. Integralinfo.getSendCmccSms({
  797. orderId: this.data.active1obj.orderId,
  798. mobile: getMobileCache(),
  799. shopid: this.data.shopid
  800. }).then(res => {
  801. if (res.code === '0000') {
  802. this.codeName = '60s后重新获取'
  803. this.codeSetInterval(60)
  804. } else {
  805. wx.showToast({
  806. icon: 'none',
  807. title: res.message
  808. })
  809. }
  810. }).catch(error=>{
  811. console.log('chongxin')
  812. console.log(error)
  813. });
  814. } else if (this.data.activeNum === 1 && this.data.codeName === '重新获取验证码') {
  815. console.log('短信')
  816. Integralinfo.getPaySend({
  817. order_no: this.data.active1obj.order_no,
  818. mobile: getMobileCache(),
  819. shopid: this.data.shopid,
  820. }).then(res => {
  821. if (res.code === '0000') {
  822. this.setData({
  823. codeName: '60s后重新获取',
  824. })
  825. this.codeSetInterval(60)
  826. } else {
  827. wx.showToast({
  828. icon: 'none',
  829. title: res.message
  830. })
  831. }
  832. }).catch(error=>{
  833. console.log('chongxin')
  834. console.log(error)
  835. });
  836. }
  837. }
  838. },
  839. toExchange(){
  840. const obj = {
  841. mobile: getMobileCache(),
  842. channelid: this.data.channelid,
  843. shopid: this.data.shopid,
  844. storeid: this.data.storeid
  845. }
  846. wx.navigateTo({
  847. url: '../integral/exchange?obj=' + JSON.stringify(obj)
  848. })
  849. },
  850. compareVersion(v1, v2) {
  851. v1 = v1.split('.')
  852. v2 = v2.split('.')
  853. const len = Math.max(v1.length, v2.length)
  854. while (v1.length < len) {
  855. v1.push('0')
  856. }
  857. while (v2.length < len) {
  858. v2.push('0')
  859. }
  860. for (let i = 0; i < len; i++) {
  861. const num1 = parseInt(v1[i])
  862. const num2 = parseInt(v2[i])
  863. if (num1 > num2) {
  864. return 1
  865. } else if (num1 < num2) {
  866. return -1
  867. }
  868. }
  869. return 0
  870. },
  871. })