certificate.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import Card from "../../model/card";
  2. import {getEventParam, showLoading} from "../../utils/utils";
  3. import {logicStatus} from "../../model/enum";
  4. import Api from "../../model/api";
  5. Page({
  6. data: {
  7. info: null,
  8. template: {
  9. drawWidth: 350,
  10. drawHeight: 484,
  11. },
  12. image: '',
  13. isGraduated: false,
  14. eInfo: {},
  15. isPCDeviceUnkonw: false,
  16. },
  17. async onLoad(options) {
  18. const {detail} = options;
  19. let app = getApp();
  20. let isPCDeviceUnkonw = app.globalData.isPCDeviceUnkonw;
  21. let eInfo = JSON.parse(detail);
  22. this.setData({
  23. eInfo, isPCDeviceUnkonw
  24. });
  25. showLoading();
  26. const res = await Api.getStudentNum(eInfo.eduStuId);
  27. if (res && res.data.graduateType) {
  28. const template = await Api.getTemplate({
  29. stuId: eInfo.eduStuId
  30. });
  31. if (template) {
  32. this.setData({
  33. template: template.data,
  34. });
  35. }
  36. this.setData({
  37. isGraduated: true,
  38. info: new Card().palette(this.data.template),
  39. });
  40. if (eInfo.graduateType != res.data.graduateType) {
  41. const eventChannel = this.getOpenerEventChannel()
  42. eventChannel.emit('get');
  43. }
  44. }
  45. wx.hideLoading();
  46. },
  47. async produce(e) {
  48. let eInfo = this.data.eInfo;
  49. const res = await Api.produceGradu(eInfo.eduStuId, eInfo.teamId,
  50. eInfo.isOnline ? logicStatus.YES : logicStatus.NO, true);
  51. const template = await Api.getTemplate({
  52. stuId: eInfo.eduStuId
  53. });
  54. if (template) {
  55. this.setData({
  56. template: template.data
  57. });
  58. }
  59. const eventChannel = this.getOpenerEventChannel();
  60. eventChannel.emit('get');
  61. this.setData({
  62. isGraduated: true,
  63. info: new Card().palette(this.data.template),
  64. });
  65. },
  66. async save(e) {
  67. if (this.data.image && typeof this.data.image === 'string') {
  68. showLoading('保存中...')
  69. try {
  70. await wx.saveImageToPhotosAlbum({
  71. filePath: this.data.image,
  72. })
  73. } catch (e) {
  74. console.log(e)
  75. if (e.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
  76. wx.showModal({
  77. title: "提示",
  78. content: "请点击右上角进入设置勾选相册后方可保存到相册",
  79. showCancel: false
  80. })
  81. }
  82. }
  83. wx.hideLoading()
  84. }
  85. },
  86. onImgOK(e) {
  87. this.imagePath = getEventParam(e, "path");
  88. this.setData({
  89. image: this.imagePath
  90. })
  91. },
  92. })