integral.js 28 KB

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