|
- const app = getApp()
- const updateManager = wx.getUpdateManager()
- import request from '../../utils/request'
- import { timestampToTime } from '../../utils/util'
- import Dialog from '@vant/weapp/dialog/dialog';
-
- Page({
- data: {
- isLogin: false,
- itemList: [],
- showPrivacy: false,
- currentIndex: 1,
- avatarUrl: "../../asset/icon/logo-5.png",
- timer: null,
- scrollTop: 0.01
- },
-
- onLoad(option) {
- wx.hideHomeButton()
- // 携带机器识别码进入
- if (option.machineQrcodeId) {
- this.setData({
- machineQrcodeId: option.machineQrcodeId
- })
- }
-
- // 更新提示
- updateManager.onUpdateReady(function () {
- wx.showModal({
- title: '更新提示',
- content: '新版本已经准备好,是否重启应用?',
- success: function (res) {
- if (res.confirm) {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- updateManager.applyUpdate()
- }
- }
- })
- })
-
- // 直接进入页面,token回调返回时
- app.tokenCallBack = res => {
- this.setData({
- isLogin: res
- })
- wx.showLoading({
- title: '加载中',
- })
- this.getImageList(10, this.data.currentIndex)
-
- }
- },
-
- onShow() {
- const isLogin = wx.getStorageSync('token')
- const isPay = wx.getStorageSync('isPay')
-
- console.log(isLogin, 'isLogin');
- this.setData({
- isLogin,
- currentIndex: 1
- })
- if (isLogin) {
- request.setHead(isLogin)
- wx.showLoading({
- title: '加载中',
- })
- this.getImageList(10, this.data.currentIndex)
- if (this.data.machineQrcodeId && !isPay) {
-
- this.getPayInfo(this.data.machineQrcodeId)
- }
- }
- },
-
- /** 获取手机号授权 */
- doGetUserPhone(encryptedData, iv, sessionKey, appId) {
- request.post({
- url: '/api/user/getUserPhone',
- data: {
- encryptedData,
- iv,
- sessionKey,
- appId
- }
- }).then(res => {
- console.log(res, 'getUserPhone');
- wx.showToast({
- title: '申请成功!',
- icon: 'success'
- })
- this.checkUserInfo()
- }).catch(err => {
- console.log(err, 'err');
- })
- },
-
- // 删除作品
- showMore(e) {
- const that = this
- const id = e.currentTarget.dataset.id
- Dialog.confirm({
- title: '删除作品',
- message: '确定要删除这个作品吗?',
- })
- .then(() => {
- that.doDeleta(id)
- })
- .catch(() => {
- });
- },
-
- doDeleta(id) {
- const that = this
- const data = {
- id
- }
- request.post({
- url: `/api/digitalAvatarPhoto/delete`,
- data
- }).then(res => {
- console.log(res, 'res');
- wx.showToast({
- title: '删除成功!',
- icon: "success"
- })
- that.getImageList(10, 1)
- that.setData({
- scrollTop: 0.01,
- currentIndex: 1
- })
- }).catch(err => {
- console.log(err, 'err');
- wx.showToast({
- title: '删除失败!',
- icon: "error"
- })
- })
- },
-
- goLogin() {
- wx.redirectTo({
- url: '/pages/login/login',
- })
- },
-
- // 查看作品详情
- goCheckImage(e) {
- console.log(e, 'e');
- const id = e.currentTarget.dataset.id
- wx.navigateTo({
- url: `/pages/checkImg/checkImg?id=${id}`,
- })
- },
-
- /** 获取作品列表 */
- getImageList(pageSize, pageNum) {
- const that = this
- request.get({
- url: `/api/digitalAvatarPhoto/list?pageSize=${pageSize}&pageNum=${pageNum}`
- }).then(res => {
- console.log(res, 'getImageList');
- const list = res.data.list
- list.forEach(item => {
- item.createDate = timestampToTime(item.createDate, 'YYYY-MM-DD hh:mm:ss')
- })
- if (pageNum == 1) {
- this.setData({
- itemList: list
- })
- } else {
- const tempList = that.data.itemList
- list.forEach(item => {
- tempList.push(item)
- })
- this.setData({
- itemList: tempList
- })
- }
- if (!res.data.endRow) {
- wx.showToast({
- title: '已加载全部写真',
- icon: "success"
- })
- }
-
- wx.hideLoading()
- }).catch(err => {
- console.log(err, 'err');
- wx.hideLoading()
- })
- },
-
- // 下来加载更多
- loadMoreData() {
- const currentIndex = this.data.currentIndex + 1
- this.setData({
- currentIndex
- })
- wx.showLoading({
- title: '加载中',
- })
- this.getImageList(10, currentIndex)
- },
-
- // 获取支付信息
- getPayInfo(machineQrcodeId) {
- const that = this
- const openId = wx.getStorageSync('openId')
- const data = {
- payVendor: 1,
- productId: 1,
- machineQrcodeId,
- openId
- }
- request.post({
- url: '/api/productOrder/pay_screen',
- data
- }).then(res => {
- console.log(res, 'res');
- const data = {
- timeStamp: res.data.timeStamp,
- nonceStr: res.data.nonceStr,
- package: res.data.package,
- signType: res.data.signType,
- paySign: res.data.paySign,
- payOrderId: res.data.payOrderId
- }
- that.doPay(data)
- }).catch(err => {
- console.log(err, 'err');
- wx.showToast({
- title: '订单信息获取失败,请重新扫码',
- icon: "none"
- })
- })
- },
-
- // 拉起收银台
- doPay(data) {
- const that = this
- // 进入此阶段,无论支付是否成功,不再拉起收银台
- wx.setStorageSync('isPay', true)
- wx.requestPayment({
- timeStamp: data.timeStamp,
- nonceStr: data.nonceStr,
- package: data.package,
- signType: data.signType ? data.signType : "MD5",
- paySign: data.paySign,
- success: res => {
- wx.showLoading({
- title: '订单处理中',
- })
- // 检查支付状态
- that.setData({
- timer: setInterval(() => {
- that.checkPayStatus(data.payOrderId, true)
- }, 1000)
- })
- },
- fail: res => {
- console.log(res, 'Fail!!!!');
- wx.showLoading({
- title: '订单处理中',
- })
- // 检查支付状态
- that.setData({
- timer: setInterval(() => {
- that.checkPayStatus(data.payOrderId, false)
- }, 1000)
- })
- // wx.showToast({
- // title: '支付失败,请重新扫码支付',
- // icon: 'none'
- // })
- },
- complete: res => { }
- });
- },
-
- checkPayStatus(id, isSuccess) {
- const that = this
- request.get({
- url: `/api/productOrder/findStatus?orderNumber=${id}`
- }).then(res => {
- console.log(res, 'res');
- const timer = that.data.timer
- if (res.data.orderStatus == 3) {
- clearInterval(timer)
- wx.showToast({
- title: '支付成功!',
- icon: "success"
- })
- that.startSub()
- wx.hideLoading()
- } else if ((res.data.orderStatus == 1 && !isSuccess) || res.data.orderStatus == 4) {
- clearInterval(timer)
- wx.showToast({
- title: '支付取消!',
- icon: "error"
- })
- wx.hideLoading()
- }
- }).catch(err => {
- console.log(err, 'err');
- })
- },
-
- startSub() {
- const that = this
- request.get({
- url: `/api/templateMsg/list?projectType=6&plat=1`
- }).then(res => {
- console.log(res, 'res');
- const id = res.data[0].templateId
-
- wx.showModal({
- title: '订阅消息',
- content: '作品生成完毕后将会通知您',
- confirmColor: "",
- confirmText: "好的",
- showCancel: false,
- complete: (res) => {
- if (res.cancel) {
-
- }
-
- if (res.confirm) {
- that.subscribe(id)
- }
- }
- })
- }).catch(err => {
- console.log(err, 'err');
- })
- },
-
- subscribe(templateId) {
- const arr = [templateId]
- wx.requestSubscribeMessage({
- //此处填写刚才申请模板的模板ID
- tmplIds: arr,
- success(res) {
- console.log(res);
- let failFlag = true;
- arr.forEach((item) => {
- if (res[item] == "accept") {
- wx.showToast({
- title: "订阅成功",
- icon: "success",
- });
- failFlag = false;
- }
- });
- if (failFlag) {
- wx.showModal({
- title: "提示",
- content:
- "订阅失败 ,您可以在 \n 小程序设置->通知管理 \n 中重新启用订阅功能",
- confirmText: "确定",
- showCancel: false,
- });
- }
- },
- fail(err) {
- console.log("订阅消息失败", err);
- wx.showToast({
- title: "订阅失败",
- icon: "none",
- });
- },
- });
- },
-
- onShareAppMessage() {
- const promise = new Promise(resolve => {
- setTimeout(() => {
- resolve({
- title: '智像小相册'
- })
- }, 500)
- })
- return {
- title: '智像小相册',
- promise
- }
- },
- onShareTimeline() {
- const promise = new Promise(resolve => {
- setTimeout(() => {
- resolve({
- title: '智像小相册'
- })
- }, 500)
- })
- return {
- title: '智像小相册',
- promise
- }
- }
- })
|