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

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