integral.js 28 KB

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