邃芒智像相册
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

402 rivejä
9.1 KiB

  1. const app = getApp()
  2. const updateManager = wx.getUpdateManager()
  3. import request from '../../utils/request'
  4. import { timestampToTime } from '../../utils/util'
  5. import Dialog from '@vant/weapp/dialog/dialog';
  6. Page({
  7. data: {
  8. isLogin: false,
  9. itemList: [],
  10. showPrivacy: false,
  11. currentIndex: 1,
  12. avatarUrl: "../../asset/icon/logo-5.png",
  13. timer: null,
  14. scrollTop: 0.01
  15. },
  16. onLoad(option) {
  17. wx.hideHomeButton()
  18. // 携带机器识别码进入
  19. if (option.machineQrcodeId) {
  20. this.setData({
  21. machineQrcodeId: option.machineQrcodeId
  22. })
  23. }
  24. // 更新提示
  25. updateManager.onUpdateReady(function () {
  26. wx.showModal({
  27. title: '更新提示',
  28. content: '新版本已经准备好,是否重启应用?',
  29. success: function (res) {
  30. if (res.confirm) {
  31. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  32. updateManager.applyUpdate()
  33. }
  34. }
  35. })
  36. })
  37. // 直接进入页面,token回调返回时
  38. app.tokenCallBack = res => {
  39. this.setData({
  40. isLogin: res
  41. })
  42. wx.showLoading({
  43. title: '加载中',
  44. })
  45. this.getImageList(10, this.data.currentIndex)
  46. }
  47. },
  48. onShow() {
  49. const isLogin = wx.getStorageSync('token')
  50. const isPay = wx.getStorageSync('isPay')
  51. console.log(isLogin, 'isLogin');
  52. this.setData({
  53. isLogin,
  54. currentIndex: 1
  55. })
  56. if (isLogin) {
  57. request.setHead(isLogin)
  58. wx.showLoading({
  59. title: '加载中',
  60. })
  61. this.getImageList(10, this.data.currentIndex)
  62. if (this.data.machineQrcodeId && !isPay) {
  63. this.getPayInfo(this.data.machineQrcodeId)
  64. }
  65. }
  66. },
  67. /** 获取手机号授权 */
  68. doGetUserPhone(encryptedData, iv, sessionKey, appId) {
  69. request.post({
  70. url: '/api/user/getUserPhone',
  71. data: {
  72. encryptedData,
  73. iv,
  74. sessionKey,
  75. appId
  76. }
  77. }).then(res => {
  78. console.log(res, 'getUserPhone');
  79. wx.showToast({
  80. title: '申请成功!',
  81. icon: 'success'
  82. })
  83. this.checkUserInfo()
  84. }).catch(err => {
  85. console.log(err, 'err');
  86. })
  87. },
  88. // 删除作品
  89. showMore(e) {
  90. const that = this
  91. const id = e.currentTarget.dataset.id
  92. Dialog.confirm({
  93. title: '删除作品',
  94. message: '确定要删除这个作品吗?',
  95. })
  96. .then(() => {
  97. that.doDeleta(id)
  98. })
  99. .catch(() => {
  100. });
  101. },
  102. doDeleta(id) {
  103. const that = this
  104. const data = {
  105. id
  106. }
  107. request.post({
  108. url: `/api/digitalAvatarPhoto/delete`,
  109. data
  110. }).then(res => {
  111. console.log(res, 'res');
  112. wx.showToast({
  113. title: '删除成功!',
  114. icon: "success"
  115. })
  116. that.getImageList(10, 1)
  117. that.setData({
  118. scrollTop: 0.01,
  119. currentIndex: 1
  120. })
  121. }).catch(err => {
  122. console.log(err, 'err');
  123. wx.showToast({
  124. title: '删除失败!',
  125. icon: "error"
  126. })
  127. })
  128. },
  129. goLogin() {
  130. wx.redirectTo({
  131. url: '/pages/login/login',
  132. })
  133. },
  134. // 查看作品详情
  135. goCheckImage(e) {
  136. console.log(e, 'e');
  137. const id = e.currentTarget.dataset.id
  138. wx.navigateTo({
  139. url: `/pages/checkImg/checkImg?id=${id}`,
  140. })
  141. },
  142. /** 获取作品列表 */
  143. getImageList(pageSize, pageNum) {
  144. const that = this
  145. request.get({
  146. url: `/api/digitalAvatarPhoto/list?pageSize=${pageSize}&pageNum=${pageNum}`
  147. }).then(res => {
  148. console.log(res, 'getImageList');
  149. const list = res.data.list
  150. list.forEach(item => {
  151. item.createDate = timestampToTime(item.createDate, 'YYYY-MM-DD hh:mm:ss')
  152. })
  153. if (pageNum == 1) {
  154. this.setData({
  155. itemList: list
  156. })
  157. } else {
  158. const tempList = that.data.itemList
  159. list.forEach(item => {
  160. tempList.push(item)
  161. })
  162. this.setData({
  163. itemList: tempList
  164. })
  165. }
  166. if (!res.data.endRow) {
  167. wx.showToast({
  168. title: '已加载全部写真',
  169. icon: "success"
  170. })
  171. }
  172. wx.hideLoading()
  173. }).catch(err => {
  174. console.log(err, 'err');
  175. wx.hideLoading()
  176. })
  177. },
  178. // 下来加载更多
  179. loadMoreData() {
  180. const currentIndex = this.data.currentIndex + 1
  181. this.setData({
  182. currentIndex
  183. })
  184. wx.showLoading({
  185. title: '加载中',
  186. })
  187. this.getImageList(10, currentIndex)
  188. },
  189. // 获取支付信息
  190. getPayInfo(machineQrcodeId) {
  191. const that = this
  192. const openId = wx.getStorageSync('openId')
  193. const data = {
  194. payVendor: 1,
  195. productId: 1,
  196. machineQrcodeId,
  197. openId
  198. }
  199. request.post({
  200. url: '/api/productOrder/pay_screen',
  201. data
  202. }).then(res => {
  203. console.log(res, 'res');
  204. const data = {
  205. timeStamp: res.data.timeStamp,
  206. nonceStr: res.data.nonceStr,
  207. package: res.data.package,
  208. signType: res.data.signType,
  209. paySign: res.data.paySign,
  210. payOrderId: res.data.payOrderId
  211. }
  212. that.doPay(data)
  213. }).catch(err => {
  214. console.log(err, 'err');
  215. wx.showToast({
  216. title: '订单信息获取失败,请重新扫码',
  217. icon: "none"
  218. })
  219. })
  220. },
  221. // 拉起收银台
  222. doPay(data) {
  223. const that = this
  224. // 进入此阶段,无论支付是否成功,不再拉起收银台
  225. wx.setStorageSync('isPay', true)
  226. wx.requestPayment({
  227. timeStamp: data.timeStamp,
  228. nonceStr: data.nonceStr,
  229. package: data.package,
  230. signType: data.signType ? data.signType : "MD5",
  231. paySign: data.paySign,
  232. success: res => {
  233. wx.showLoading({
  234. title: '订单处理中',
  235. })
  236. // 检查支付状态
  237. that.setData({
  238. timer: setInterval(() => {
  239. that.checkPayStatus(data.payOrderId, true)
  240. }, 1000)
  241. })
  242. },
  243. fail: res => {
  244. console.log(res, 'Fail!!!!');
  245. wx.showLoading({
  246. title: '订单处理中',
  247. })
  248. // 检查支付状态
  249. that.setData({
  250. timer: setInterval(() => {
  251. that.checkPayStatus(data.payOrderId, false)
  252. }, 1000)
  253. })
  254. // wx.showToast({
  255. // title: '支付失败,请重新扫码支付',
  256. // icon: 'none'
  257. // })
  258. },
  259. complete: res => { }
  260. });
  261. },
  262. checkPayStatus(id, isSuccess) {
  263. const that = this
  264. request.get({
  265. url: `/api/productOrder/findStatus?orderNumber=${id}`
  266. }).then(res => {
  267. console.log(res, 'res');
  268. const timer = that.data.timer
  269. if (res.data.orderStatus == 3) {
  270. clearInterval(timer)
  271. wx.showToast({
  272. title: '支付成功!',
  273. icon: "success"
  274. })
  275. that.startSub()
  276. wx.hideLoading()
  277. } else if ((res.data.orderStatus == 1 && !isSuccess) || res.data.orderStatus == 4) {
  278. clearInterval(timer)
  279. wx.showToast({
  280. title: '支付取消!',
  281. icon: "error"
  282. })
  283. wx.hideLoading()
  284. }
  285. }).catch(err => {
  286. console.log(err, 'err');
  287. })
  288. },
  289. startSub() {
  290. const that = this
  291. request.get({
  292. url: `/api/templateMsg/list?projectType=6&plat=1`
  293. }).then(res => {
  294. console.log(res, 'res');
  295. const id = res.data[0].templateId
  296. wx.showModal({
  297. title: '订阅消息',
  298. content: '作品生成完毕后将会通知您',
  299. confirmColor: "",
  300. confirmText: "好的",
  301. showCancel: false,
  302. complete: (res) => {
  303. if (res.cancel) {
  304. }
  305. if (res.confirm) {
  306. that.subscribe(id)
  307. }
  308. }
  309. })
  310. }).catch(err => {
  311. console.log(err, 'err');
  312. })
  313. },
  314. subscribe(templateId) {
  315. const arr = [templateId]
  316. wx.requestSubscribeMessage({
  317. //此处填写刚才申请模板的模板ID
  318. tmplIds: arr,
  319. success(res) {
  320. console.log(res);
  321. let failFlag = true;
  322. arr.forEach((item) => {
  323. if (res[item] == "accept") {
  324. wx.showToast({
  325. title: "订阅成功",
  326. icon: "success",
  327. });
  328. failFlag = false;
  329. }
  330. });
  331. if (failFlag) {
  332. wx.showModal({
  333. title: "提示",
  334. content:
  335. "订阅失败 ,您可以在 \n 小程序设置->通知管理 \n 中重新启用订阅功能",
  336. confirmText: "确定",
  337. showCancel: false,
  338. });
  339. }
  340. },
  341. fail(err) {
  342. console.log("订阅消息失败", err);
  343. wx.showToast({
  344. title: "订阅失败",
  345. icon: "none",
  346. });
  347. },
  348. });
  349. },
  350. onShareAppMessage() {
  351. const promise = new Promise(resolve => {
  352. setTimeout(() => {
  353. resolve({
  354. title: '智像小相册'
  355. })
  356. }, 500)
  357. })
  358. return {
  359. title: '智像小相册',
  360. promise
  361. }
  362. },
  363. onShareTimeline() {
  364. const promise = new Promise(resolve => {
  365. setTimeout(() => {
  366. resolve({
  367. title: '智像小相册'
  368. })
  369. }, 500)
  370. })
  371. return {
  372. title: '智像小相册',
  373. promise
  374. }
  375. }
  376. })