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

331 lines
7.4 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. this.setData({
  52. isLogin,
  53. currentIndex: 1
  54. })
  55. if (isLogin) {
  56. wx.showLoading({
  57. title: '加载中',
  58. })
  59. this.getImageList(10, this.data.currentIndex)
  60. if (this.data.machineQrcodeId && !isPay) {
  61. this.getPayInfo(this.data.machineQrcodeId)
  62. }
  63. }
  64. },
  65. /** 获取手机号授权 */
  66. doGetUserPhone(encryptedData, iv, sessionKey, appId) {
  67. request.post({
  68. url: '/api/user/getUserPhone',
  69. data: {
  70. encryptedData,
  71. iv,
  72. sessionKey,
  73. appId
  74. }
  75. }).then(res => {
  76. console.log(res, 'getUserPhone');
  77. wx.showToast({
  78. title: '申请成功!',
  79. icon: 'success'
  80. })
  81. this.checkUserInfo()
  82. }).catch(err => {
  83. console.log(err, 'err');
  84. })
  85. },
  86. // 删除作品
  87. showMore(e) {
  88. const that = this
  89. const id = e.currentTarget.dataset.id
  90. Dialog.confirm({
  91. title: '删除作品',
  92. message: '确定要删除这个作品吗?',
  93. })
  94. .then(() => {
  95. that.doDeleta(id)
  96. })
  97. .catch(() => {
  98. });
  99. },
  100. doDeleta(id) {
  101. const that = this
  102. const data = {
  103. id
  104. }
  105. request.post({
  106. url: `/api/digitalAvatarPhoto/delete`,
  107. data
  108. }).then(res => {
  109. console.log(res, 'res');
  110. wx.showToast({
  111. title: '删除成功!',
  112. icon: "success"
  113. })
  114. that.getImageList(10, 1)
  115. that.setData({
  116. scrollTop: 0.01,
  117. currentIndex: 1
  118. })
  119. }).catch(err => {
  120. console.log(err, 'err');
  121. wx.showToast({
  122. title: '删除失败!',
  123. icon: "error"
  124. })
  125. })
  126. },
  127. goLogin() {
  128. wx.redirectTo({
  129. url: '/pages/login/login',
  130. })
  131. },
  132. // 查看作品详情
  133. goCheckImage(e) {
  134. console.log(e, 'e');
  135. const id = e.currentTarget.dataset.id
  136. wx.navigateTo({
  137. url: `/pages/checkImg/checkImg?id=${id}`,
  138. })
  139. },
  140. /** 获取作品列表 */
  141. getImageList(pageSize, pageNum) {
  142. const that = this
  143. request.get({
  144. url: `/api/digitalAvatarPhoto/list?pageSize=${pageSize}&pageNum=${pageNum}`
  145. }).then(res => {
  146. console.log(res, 'getImageList');
  147. const list = res.data.list
  148. list.forEach(item => {
  149. item.createDate = timestampToTime(item.createDate, 'YYYY-MM-DD hh:mm:ss')
  150. })
  151. if (pageNum == 1) {
  152. this.setData({
  153. itemList: list
  154. })
  155. } else {
  156. const tempList = that.data.itemList
  157. list.forEach(item => {
  158. tempList.push(item)
  159. })
  160. this.setData({
  161. itemList: tempList
  162. })
  163. }
  164. if (!res.data.endRow) {
  165. wx.showToast({
  166. title: '已加载全部写真',
  167. icon: "success"
  168. })
  169. }
  170. wx.hideLoading()
  171. }).catch(err => {
  172. console.log(err, 'err');
  173. wx.hideLoading()
  174. })
  175. },
  176. // 下来加载更多
  177. loadMoreData() {
  178. const currentIndex = this.data.currentIndex + 1
  179. this.setData({
  180. currentIndex
  181. })
  182. wx.showLoading({
  183. title: '加载中',
  184. })
  185. this.getImageList(10, currentIndex)
  186. },
  187. // 获取支付信息
  188. getPayInfo(machineQrcodeId) {
  189. const that = this
  190. const openId = wx.getStorageSync('openId')
  191. const data = {
  192. payVendor: 1,
  193. productId: 1,
  194. machineQrcodeId,
  195. openId
  196. }
  197. request.post({
  198. url: '/api/productOrder/pay_screen',
  199. data
  200. }).then(res => {
  201. console.log(res, 'res');
  202. const data = {
  203. timeStamp: res.data.timeStamp,
  204. nonceStr: res.data.nonceStr,
  205. package: res.data.package,
  206. signType: res.data.signType,
  207. paySign: res.data.paySign,
  208. payOrderId: res.data.payOrderId
  209. }
  210. that.doPay(data)
  211. }).catch(err => {
  212. console.log(err, 'err');
  213. wx.showToast({
  214. title: '订单信息获取失败,请重新扫码',
  215. icon: "none"
  216. })
  217. })
  218. },
  219. // 拉起收银台
  220. doPay(data) {
  221. const that = this
  222. // 进入此阶段,无论支付是否成功,不再拉起收银台
  223. wx.setStorageSync('isPay', true)
  224. wx.requestPayment({
  225. timeStamp: data.timeStamp,
  226. nonceStr: data.nonceStr,
  227. package: data.package,
  228. signType: data.signType ? data.signType : "MD5",
  229. paySign: data.paySign,
  230. success: res => {
  231. wx.showLoading({
  232. title: '订单处理中',
  233. })
  234. // 检查支付状态
  235. that.setData({
  236. timer: setInterval(() => {
  237. that.checkPayStatus(data.payOrderId, true)
  238. }, 1000)
  239. })
  240. },
  241. fail: res => {
  242. console.log(res, 'Fail!!!!');
  243. wx.showLoading({
  244. title: '订单处理中',
  245. })
  246. // 检查支付状态
  247. that.setData({
  248. timer: setInterval(() => {
  249. that.checkPayStatus(data.payOrderId, false)
  250. }, 1000)
  251. })
  252. // wx.showToast({
  253. // title: '支付失败,请重新扫码支付',
  254. // icon: 'none'
  255. // })
  256. },
  257. complete: res => { }
  258. });
  259. },
  260. checkPayStatus(id, isSuccess) {
  261. const that = this
  262. request.get({
  263. url: `/api/productOrder/findStatus?orderNumber=${id}`
  264. }).then(res => {
  265. console.log(res, 'res');
  266. const timer = that.data.timer
  267. if (res.data.orderStatus == 3) {
  268. clearInterval(timer)
  269. wx.showToast({
  270. title: '支付成功!',
  271. icon: "success"
  272. })
  273. wx.hideLoading()
  274. } else if ((res.data.orderStatus == 1 && !isSuccess) || res.data.orderStatus == 4) {
  275. clearInterval(timer)
  276. wx.showToast({
  277. title: '支付取消!',
  278. icon: "error"
  279. })
  280. wx.hideLoading()
  281. }
  282. }).catch(err => {
  283. console.log(err, 'err');
  284. })
  285. },
  286. onShareAppMessage() {
  287. const promise = new Promise(resolve => {
  288. setTimeout(() => {
  289. resolve({
  290. title: '智像小相册'
  291. })
  292. }, 500)
  293. })
  294. return {
  295. title: '智像小相册',
  296. promise
  297. }
  298. },
  299. onShareTimeline() {
  300. const promise = new Promise(resolve => {
  301. setTimeout(() => {
  302. resolve({
  303. title: '智像小相册'
  304. })
  305. }, 500)
  306. })
  307. return {
  308. title: '智像小相册',
  309. promise
  310. }
  311. }
  312. })