邃芒智像相册
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.

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