123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941 |
- // pages/integral/integral.js
- import Integralinfo from '../../api/integralinfo'
- import {getMobileCache, getPhoneNumberNew as getPhoneNumberSync} from '../../utils/user'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- lock: false,
- noResult: false,
- noMore: false,
- bannerList: [],
- couponList: [],
- channelid: '',
- shopid: '',
- storeid: '',
- bodyHidden: true,
- bgStatus: false,
- scorePhone: false,
- animationData: {},
- integralIngo:{},
- loading: false,
- setPhone: '',
- current: '',
- integralNum: 0,
- isQuery: false,
- phone: '********',
- // phone: '15888282621',
- mobile: '********',
- paymentStatus: false,
- paymentBgStatus: false,
- activeNum: 0,
- listTrue: [],
- listStatus: false,
- total: 0,
- row: {},
- codeName: '60s后重新获取',
- codeTime: '',
- active1obj: {
- orderId: '',
- order_no: '',
- step: ''
- },
- active1code: '',
- active2code: '',
- tgid: '',
- scene: '',
- noClick: true,
- showToastObj: {
- icon: '',
- title: '',
- status: false
- },
- isIphoneX:false,
- codeNum: '',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var reg = /^(\d{3})\d{4}(\d{4})$/;
- this.setData({
- isLogin: getMobileCache() != '',
- phone: getMobileCache() == ''?'********':getMobileCache().replace(reg, "$1****$2"),
- setPhone: getMobileCache(),
- mobile: getMobileCache(),
- channelid: options.channelid === undefined ? '' : options.channelid,
- shopid: options.shopid === undefined ? '' : options.shopid,
- storeid: options.storeid === undefined ? '' : options.storeid,
- tgid: options.tgid === undefined ? '' : options.tgid,
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- let _self = this;
- this.setData({
- isIphoneX:_self.isIphone()
- })
- this.getBannerList()
- // 获取优惠券列表
- this.getCouponList()
- if(getMobileCache() != ''){
- // this.findIntegral()
- this.getphoneClick()
- }
- },
- /** 积分查询 */
- findIntegral: function(){
- Integralinfo.getBalance({
- mobile: getMobileCache(),
- callbackUrl: '../integral/integral.wxml',
- fingerprint: '',
- sessionid: '',
- shopid: this.data.shopid,
- type: 'wx',
- }).then(arr => {
- if (arr.code === '0000') {
- var reg = /^(\d{3})\d{4}(\d{4})$/;
- this.setData({
- isLogin: getMobileCache() != '',
- phone: getMobileCache() == ''?'********':getMobileCache().replace(reg, "$1****$2"),
- setPhone: getMobileCache(),
- mobile: getMobileCache(),
- integralNum: arr.data,
- isQuery:true,
- codeNum: arr.code,
- })
- this.getCouponList()
-
- }
- }).catch(error=>{
- console.log(error);
- if (error.data.code === '2000') {
- this.setData({
- codeNum: error.data.code,
- })
- this.scoreClick()
- }
- })
- },
- /**
- * 判断是否是iphone
- */
- isIphone() {
- let isIphone = false
- wx.getSystemInfo({
- success: function(res) {
- if (res.model.indexOf('iPhone') >= 0) {
- isIphone = true;
- }
- }
- })
- return isIphone
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- getBannerList: function() {
- Integralinfo.getBannerList({
- channelid: this.data.channelid,
- shopid: this.data.shopid,
- storeid: this.data.storeid
- }).then(res => {
- console.log(res.data)
- this.setData({
- bannerList: res.data
- })
- }).catch(err => {
- console.log(err)
- })
- },
- getCouponList: function() {
- Integralinfo.getList({
- channelid: this.data.channelid,
- shopid: this.data.shopid,
- storeid: this.data.storeid
- }).then(res => {
- this.couponListView(res.data)
- this.data.lock = false
- }).catch(_ => {
- console.log(_)
- this.data.lock = false
- })
- },
- couponListView: function(data) {
- if (!Array.isArray(data) || data.length == 0) {
- console.log("优惠券列表数据为空");
- }
- data.forEach((v) => {
- v.quantity = 0
- v.integral = v.price * v.ratio
- })
- if (this.data.mobile != '********') {
- let num = this.data.integralNum > 20000 ? 19999 : this.data.integralNum
- const arr = []
- this.setData({
- total: 0,
- })
- for (let i = 0; i < data.length; i++) {
- data[i].quantity = parseInt(num / data[i].integral)
- if (data[i].quantity > 0) {
- num -= (data[i].quantity * data[i].price) * data[i].ratio
- this.data.total += (data[i].quantity * data[i].price) * data[i].ratio
- this.setData({
- total:this.data.total
- })
- arr.push(data[i])
- data.splice(i, 1)
- i--
- }
- }
- this.setData({
- couponList: [...arr, ...data]
- })
- } else {
- this.setData({
- couponList: data
- })
- }
- console.log(this.data.total)
- },
- // 点击标识点触发
- detailsClick(row) {
- this.hideModal();
- this.row = row.currentTarget.dataset.info
- console.log(this.row)
- if (this.row.detail_type === 0) {
- this.row.detailArr = this.row.detail.split('\n')
- } else {
- this.row.detailArr = row.detail
- }
- this.setData({
- integralIngo: this.row,
- })
- console.log(this.data.integralIngo)
- setTimeout(() => {
- this.showDodal();
- }, 100)
- },
- showDodal() {
- var that = this;
- // 显示遮罩层
- var animation = wx.createAnimation({
- duration: 150,
- timingFunction: "linear",
- delay: 0
- })
- this.setData({
- bgStatus: true,
- bodyHidden: false
- })
-
- that.animation = animation
- animation.translateY(-500).step()
- that.setData({
- animationData: animation.export()
- })
- },
- //隐藏对话框
- hideModal() {
- var that = this;
- console.log(that.data)
- // 隐藏遮罩层
- var animation = wx.createAnimation({
- duration: 150,
- timingFunction: "linear",
- delay: 0
- })
- this.setData({
- bodyHidden: true,
- bgStatus: false,
- scorePhone: false,
- })
-
- that.animation = animation
- animation.translateY(0).step()
- that.setData({
- animationData: animation.export()
- })
- },
- // //隐藏对话框
- // paymenHideModal() {
- // var that = this;
- // console.log(that.data)
- // this.setData({
- // bodyHidden: true,
- // paymentBgStatus: false,
- // paymentStatus: false,
- // })
-
- // },
- /**授权手机号 */
- getPhoneNumber(e) {
- let that = this;
- getPhoneNumberSync(e, async () => {
- console.log(e)
- if (getMobileCache() == '') {
- wx.showToast({
- icon:'error',
- title:'先查询移动积分'
- })
- setTimeout(()=>{
- that.data.setPhone = ''
- that.scoreClick()
- // wx.hideLoading()
- },500)
- } else {
- var reg = /^(\d{3})\d{4}(\d{4})$/;
- this.setData({
- isLogin: true,
- setPhone: getMobileCache(),
- mobile: getMobileCache(),
- phone: getMobileCache().replace(reg, "$1****$2")
- })
- // console.log(this.data.setPhone)
- // console.log(this.data.mobile)
- // console.log(this.data.phone)
- this.getphoneClick()
- }
-
- })
- },
- // 查询积分
- scoreClick() {
- this.setData({
- bgStatus: true,
- scorePhone: true,
- })
- },
- // 查询积分
- getphoneClick() {
- console.log(getMobileCache())
- if (!(/^1[3456789]\d{9}$/.test(getMobileCache()))) {
- wx.showToast({
- title: '填写正确手机号',
- icon: 'error',
- duration: 2000
- });
- } else if (getMobileCache() != '') {
- // wx.showLoading({
- // title: '加载中'
- // });
- Integralinfo.getBalance({
- mobile: getMobileCache(),
- callbackUrl: '../integral/integral.wxml',
- fingerprint: '',
- sessionid: '',
- shopid: this.data.shopid,
- type: 'wx',
- }).then(arr => {
- console.log(arr)
- // wx.hideLoading();
- if (arr.code === '0000') {
- var reg = /^(\d{3})\d{4}(\d{4})$/;
- this.setData({
- integralNum: arr.data,
- isQuery:true,
- setPhone: getMobileCache(),
- phone: getMobileCache().replace(reg, "$1****$2"),
- codeNum: arr.code,
- })
- // this.data.integralNum = arr.data
- // var reg = /^(\d{3})\d{4}(\d{4})$/;
- // this.data.mobile = this.data.setPhone
- // this.data.setPhone = this.data.setPhone.replace(reg, "$1****$2");
- let response = {
- points: arr.data,
- outTokenId: this.data.setPhone + '_out'
- }
- // App.globalData.AppShow = response
- this.hideModal()
- this.getCouponList()
- wx.pageScrollTo({
- scrollTop: 0
- });
- let dateNum = Math.round(new Date().getTime() / 1000).toString();
- const data = JSON.parse(wx.getStorageSync('orderDetails'))
- if (wx.getStorageSync('orderDetails') != '' && this.data.mobile == data.mobile) {
- console.log(dateNum - data.date)
- if (dateNum - data.date <= 120) {
- let codeName = "重新获取验证码"
- if (dateNum - data.date < 60) {
- let time = dateNum - data.date
- codeName = 60 - time + 's后重新获取'
- this.codeSetInterval(60 - time)
- }
- this.setData({
- paymentStatus: true,
- paymentBgStatus: true,
- active1code: '',
- active2code: '',
- active1obj: data,
- codeName:codeName
- })
-
- if (data.step === 1) {
- this.setData({
- activeNum: 1,
- })
- } else if (data.step === 2) {
- this.setData({
- activeNum: 0,
- })
- }
- }else{
- wx.setStorageSync('orderDetails', null)
- }
- }
- }
- }).catch(error => {
- console.log(error)
- let arr = error.data
- console.log(arr)
- if(arr.code ==='2000'){
- this.setData({
- scorePhone: false,
- loading: true,
- bgStatus: true,
- codeNum: arr.code,
- })
-
- setTimeout(() => {
- // #ifdef H5
- // window.location.href = arr.message;
- // #endif
- // #ifdef MP-WEIXIN
- const version = wx.getSystemInfoSync().SDKVersion
- if (this.compareVersion(version, '2.20.1') >= 0) {
- wx.openEmbeddedMiniProgram({
- appId: arr.data.appId,
- path: arr.data.path,
- extraData: arr.data.extraData,
- success(res) {
- // 打开成功
- },
- fail() {}
- })
- } else {
- // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
- wx.navigateToMiniProgram({
- appId: arr.data.appId,
- path: arr.data.path,
- extraData: arr.data.extraData,
- success(res) {
- // 打开成功
- },
- fail() {
- }
- })
- }
- // #endif
- this.hideModal()
- this.setData({
- loading: false
- })
- }, 4000)
- }
- })
- }
- },
- // 商品数量减少按钮
- reduceClick(e) {
- console.log(e.currentTarget.dataset.index)
- let index = e.currentTarget.dataset.index
- this.data.couponList[index].quantity--
- this.data.total -= parseInt(this.data.couponList[index].integral)
- this.setData({
- total: this.data.total,
- couponList: this.data.couponList
- })
- },
- // 商品数量添加按钮
- addClick(e) {
- let index = e.currentTarget.dataset.index
- this.findIntegral()
- if (this.data.phone !== '********' && this.data.codeNum === '0000') {
- if (this.data.total + parseInt(this.data.couponList[index].integral) > 20000) {
- wx.showToast({
- title: '单笔限额两万分',
- icon: 'error',
- duration: 2000
- });
- } else if ((this.data.integralNum - this.data.total) >= this.data.couponList[index].integral) {
- this.data.couponList[index].quantity++
- this.data.total += parseInt(this.data.couponList[index].integral)
- this.setData({
- total: this.data.total,
- couponList:this.data.couponList
- })
- } else {
- wx.showToast({
- title: '积分不足',
- icon: 'error',
- duration: 2000
- });
- }
- } else {
- // wx.showToast({
- // title: '先查询移动积分',
- // icon: 'error',
- // duration: 1000
- // });
- // setTimeout(() => {
- // this.scoreClick()
- // }, 1000)
- this.scoreClick()
- }
- },
- /** 刷新 */
- shuaxinClick() {
- Integralinfo.getBalance({
- mobile: getMobileCache(),
- callbackUrl: '../integral/integral.wxml',
- fingerprint: '',
- sessionid: '',
- shopid: this.data.shopid,
- type: 'wx',
- }).then(arr => {
- if (arr.code === '0000') {
- // wx.hideLoading();
- wx.showToast({
- title: '查询成功!',
- icon: 'success',
- duration: 1000
- });
-
- var reg = /^(\d{3})\d{4}(\d{4})$/;
- this.setData({
- integralNum: arr.data,
- isQuery:true,
- setPhone: getMobileCache(),
- phone: getMobileCache().replace(reg, "$1****$2"),
- })
-
- }
- }).catch(error=>{
- console.log(222222)
- console.log(error)
- })
- },
- // 支付按钮
- paymentClick() {
- console.log(this.data.mobile)
- if (this.data.mobile === '********') {
- setTimeout(() => {
- this.scoreClick()
- }, 1000)
- wx.showToast({
- title: '先查询移动积分',
- icon: 'error',
- duration: 1000
- });
- } else if (this.data.total === 0) {
- wx.showToast({
- title: '请选择商品数量',
- icon: 'error',
- duration: 2000
- });
- } else {
- const data = []
- this.data.couponList.forEach(v => {
- if (v.quantity > 0) {
- data.push({
- couponid: v.id,
- num: v.quantity,
- })
- }
- })
- // let fingerprint = ''
- // let sessionid = ''
- // // #ifndef MP-WEIXIN
- // fingerprint = window.fmOpt
- // sessionid = window.sessionId
- // // #endif
- Integralinfo.getOrder({
- fingerprint:'',
- list: data,
- mobile: getMobileCache(),
- tgid: this.data.tgid,
- sessionid:'',
- shopid: this.data.shopid
- }).then(res => {
- if (res.code === '0000') {
- this.codeSetInterval(60)
- this.setData({
- codeName: '60s后重新获取',
- paymentStatus: true,
- paymentBgStatus: true,
- active1code: '',
- active2code: '',
- active1obj:{
- orderId: res.data.orderId,
- order_no: res.data.order_no,
- step: res.data.step,
- date: Math.round(new Date().getTime() / 1000).toString(),
- mobile: getMobileCache()
- },
-
- })
- wx.setStorageSync('orderDetails', JSON.stringify(this.data.active1obj))
- if (res.data.step === 1) {
- this.setData({
- activeNum: 1,
- })
- } else if (res.data.step === 2) {
- this.setData({
- activeNum: 0,
- })
- }
- console.log(res.data.step,this.data.activeNum)
- // this.getPaySend()
- } else {
- console.log(res.message)
- console.log(this.data.integralNum,this.data.mobile,JSON.stringify(data))
- // log.error(`${res.data.message}`)
- // log.error(`${this.data.integralNum},${this.data.mobile},${JSON.stringify(data)}`)
-
- wx.showToast({
- icon: 'none',
- title: res.message
- })
- }
- }).catch(error=>{
- console.log('zhifu')
- console.log(error.data.message)
- wx.showToast({
- icon: 'none',
- title: error.data.message
- })
- })
- }
- },
- // 步骤按钮
- nextCodeClick() {
- console.log(this.data.activeNum,this.data.active2code)
- if (this.data.activeNum === 1 && this.data.active2code !== '') {
- // wx.showLoading({
- // title: '兑换中'
- // });
- // let fingerprint = ''
- // let sessionid = ''
- // // #ifndef MP-WEIXIN
- // fingerprint = window.fmOpt
- // sessionid = window.sessionId
- // #endif
- Integralinfo.getPayOnce({
- fingerprint: '',
- mobile: getMobileCache(),
- optCode: this.data.active2code,
- order_no: this.data.active1obj.order_no,
- orderId: this.data.active1obj.orderId,
- sessionid: '',
- shopid: this.data.shopid
- }).then(res => {
- if (res.code === '0000') {
- const obj = {
- mobile: this.data.mobile,
- channelid: this.data.channelid,
- shopid: this.data.shopid,
- storeid: this.data.storeid
- }
- this.data.integralNum -= this.data.total
- this.setData({
- integralNum: this.data.integralNum,
- isQuery:true,
- total: 0,
- listStatus: false,
- listTrue: [],
- })
- this.data.couponList.forEach((v)=>{
- v.quantity = 0
- })
- this.setData({
- couponList: this.data.couponList,
- paymentStatus: false,
- paymentBgStatus: false,
- })
- wx.setStorageSync('orderDetails', null)
- // wx.hideLoading();
- wx.navigateTo({
- url: '../integral/success?row=' + JSON.stringify(obj)
- })
- } else {
- // wx.hideLoading();
- wx.showToast({
- icon: 'none',
- title: res.message
- })
- }
- }).catch(error => {
- let res = error.data;
- wx.showToast({
- icon: 'none',
- title: res.message
- })
- });
- } else if (this.data.activeNum === 0 && this.data.active1code !== '') {
- Integralinfo.getExchange({
- fingerprint: '',
- mobile: getMobileCache(),
- optCode: this.data.active1code,
- orderId: this.data.active1obj.orderId,
- order_no: this.data.active1obj.order_no,
- sessionid: '',
- shopid: this.data.shopid
- }).then(res => {
- if (res.code === '0000') {
- clearInterval(this.data.codeTime)
- this.setData({
- active2code: '',
- activeNum: this.activeNum++,
- codeName: '60s后重新获取',
- })
- this.codeSetInterval(60)
- } else {
- wx.showToast({
- icon: 'none',
- title: res.message
- })
- }
- }).catch(error => {
- let res = error.data;
- wx.showToast({
- icon: 'none',
- title: res.message
- })
-
- })
- } else {
- wx.showToast({
- icon: 'error',
- title: '请填写验证码'
- })
- }
- },
- // 短信定时器
- codeSetInterval(num) {
- console.log(num)
- let time = num
- this.data.codeTime = setInterval(() => {
- if (time <= 1) {
- this.setData({
- codeName: '重新获取验证码',
- })
- clearInterval(this.data.codeTime)
- } else {
- time--
- this.setData({
- codeName:`${time}s后重新获取`
- })
- }
- }, 1000)
- },
- getPaySend(){
- if (this.data.activeNum === 1) {
- console.log('发送短信')
- Integralinfo.getPaySend({
- order_no: this.data.active1obj.order_no,
- mobile: getMobileCache(),
- shopid: this.data.shopid,
- }).then(res => {
- if (res.code === '0000') {
- this.setData({
- codeName: '60s后重新获取',
- })
- this.codeSetInterval(60)
- } else {
- wx.showToast({
- icon: 'none',
- title: res.message
- })
- }
- }).catch(error=>{
- console.log('duanxin')
- console.log(error)
- })
- }
- },
- // 重新获取短信
- getCodeClick() {
- console.log(this.data.activeNum,this.data.codeName,this.data.active1obj.step)
- if ((this.data.activeNum === 1 && this.data.codeName === '重新获取验证码') && this.data.active1obj.step === 1) {
- Integralinfo.getSendCmccSms({
- orderId: this.data.active1obj.orderId,
- mobile: getMobileCache(),
- shopid: this.data.shopid
- }).then(res => {
- if (res.code === '0000') {
- this.setData({
- codeName: '60s后重新获取',
- })
- this.codeSetInterval(60)
- const obj = this.data.active1obj
- obj.date = Math.round(new Date().getTime() / 1000).toString()
- wx.setStorageSync('orderDetails', JSON.stringify(obj))
- } else {
- wx.showToast({
- icon: 'none',
- title: res.message
- })
- }
- }).catch(error=>{
- console.log('chongxin')
- console.log(error)
- wx.showToast({
- icon: 'none',
- title: error.data.message
- })
- });
- } else {
- if (this.data.activeNum === 0 && this.data.codeName === '重新获取验证码') {
- Integralinfo.getSendCmccSms({
- orderId: this.data.active1obj.orderId,
- mobile: getMobileCache(),
- shopid: this.data.shopid
- }).then(res => {
- if (res.code === '0000') {
- this.codeName = '60s后重新获取'
- this.codeSetInterval(60)
- } else {
- wx.showToast({
- icon: 'none',
- title: res.message
- })
- }
- }).catch(error=>{
- console.log('chongxin')
- console.log(error)
- });
- } else if (this.data.activeNum === 1 && this.data.codeName === '重新获取验证码') {
- console.log('短信')
- Integralinfo.getPaySend({
- order_no: this.data.active1obj.order_no,
- mobile: getMobileCache(),
- shopid: this.data.shopid,
- }).then(res => {
- if (res.code === '0000') {
- this.setData({
- codeName: '60s后重新获取',
- })
- this.codeSetInterval(60)
- } else {
- wx.showToast({
- icon: 'none',
- title: res.message
- })
- }
- }).catch(error=>{
- console.log('chongxin')
- console.log(error)
- });
- }
- }
- },
- toExchange(){
- const obj = {
- mobile: getMobileCache(),
- channelid: this.data.channelid,
- shopid: this.data.shopid,
- storeid: this.data.storeid
- }
- wx.navigateTo({
- url: '../integral/exchange?obj=' + JSON.stringify(obj)
- })
- },
- compareVersion(v1, v2) {
- v1 = v1.split('.')
- v2 = v2.split('.')
- const len = Math.max(v1.length, v2.length)
- while (v1.length < len) {
- v1.push('0')
- }
- while (v2.length < len) {
- v2.push('0')
- }
- for (let i = 0; i < len; i++) {
- const num1 = parseInt(v1[i])
- const num2 = parseInt(v2[i])
- if (num1 > num2) {
- return 1
- } else if (num1 < num2) {
- return -1
- }
- }
- return 0
- },
-
- })
|