index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. const _my = require("../../__antmove/api/index.js")(my);
  2. const wx = _my;
  3. // components/detailsCard/index.js
  4. import international from "../../international/appointment_scence/index";
  5. import { getVisitorQrcodeId } from "../../utils/api/api";
  6. import QRCode from "../../utils/util/weapp-qrcode";
  7. Component({
  8. options: {
  9. observers: true,
  10. lifetimes: true
  11. },
  12. /**
  13. * 组件的属性列表
  14. */
  15. properties: {
  16. // 标题
  17. title: {
  18. type: String,
  19. value: "认证信息"
  20. },
  21. //单子状态
  22. status: {
  23. type: Number,
  24. value: null
  25. },
  26. //内容
  27. msg: {
  28. type: Array,
  29. value: []
  30. },
  31. // //二维码内容
  32. // qrCodeUrl: {
  33. // type: String,
  34. // value: ''
  35. // },
  36. // 语言
  37. language: {
  38. type: String,
  39. value: "ch"
  40. },
  41. userInfo: {
  42. type: Object,
  43. value: {}
  44. },
  45. regularList: {
  46. type: Object,
  47. value: null
  48. },
  49. isRegular: {
  50. type: Boolean,
  51. value: true
  52. },
  53. type: {
  54. type: String
  55. }
  56. },
  57. /**
  58. * 组件的初始数据
  59. */
  60. data: {
  61. international: international,
  62. //国际化语言包
  63. imageUrl: "",
  64. dateTime: null,
  65. qrCode: null,
  66. qrCodeType: null,
  67. //1已失效2未到时间3允许通行
  68. timer: null
  69. },
  70. /**
  71. * 组件的方法列表
  72. */
  73. methods: {
  74. //图片预览
  75. preview(e) {
  76. let url = e.currentTarget.dataset.src;
  77. wx.previewImage({
  78. current: url,
  79. // 当前显示图片的http链接
  80. urls: [url] // 需要预览的图片http链接列表
  81. });
  82. },
  83. // 获取访客qrcodeId
  84. getVisitorQrcodeId() {
  85. let id = this.data.regularList.userId;
  86. getVisitorQrcodeId({
  87. userId: id
  88. }).then(res => {
  89. this.setData({
  90. dateTime: new Date().getTime()
  91. });
  92. if(res.data && res.data.qrcodeId) {
  93. this.creatQrCode(res.data.qrcodeId);
  94. }
  95. });
  96. },
  97. // 创建二维码
  98. creatQrCode(id) {
  99. let that = this;
  100. new QRCode("myQrcode", {
  101. text: `HHFKJ?userId=${id}&timestamp=${this.data.dateTime}`,
  102. width: 176,
  103. //canvas 画布的宽
  104. height: 176,
  105. //canvas 画布的高
  106. padding: 0,
  107. // 生成二维码四周自动留边宽度,不传入默认为0
  108. correctLevel: QRCode.CorrectLevel.L,
  109. // 二维码可辨识度
  110. callback: res => {
  111. //工具回调数据
  112. // 接下来就可以直接调用微信小程序的api保存到本地或者将这张二维码直接画在海报上面去,看各自需求
  113. // wx.hideLoading()
  114. //将图片路劲放入data中,显示在wxml的image标签上
  115. that.setData({
  116. qrCode: res.path
  117. });
  118. }
  119. });
  120. },
  121. // 更新访客码
  122. updateQrCode() {
  123. // 访客申请记录页面
  124. if (!this.data.regularList) {
  125. return;
  126. }
  127. var newDate = new Date();
  128. var startTime = new Date(this.data.regularList.startTime);
  129. var endTime = new Date(this.data.regularList.endTime);
  130. let type;
  131. if (newDate > endTime) {
  132. type = 1;
  133. } else if (newDate < startTime) {
  134. type = 2;
  135. } else {
  136. type = 3;
  137. this.getVisitorQrcodeId();
  138. }
  139. this.setData({
  140. qrCodeType: type
  141. });
  142. },
  143. antmoveAction: function () {
  144. //执行时动态赋值,请勿删除
  145. }
  146. },
  147. observers: {
  148. status: function (status) {
  149. var {
  150. imageUrl
  151. } = this.data;
  152. switch (status) {
  153. case 0:
  154. imageUrl = "wait";
  155. break;
  156. case 1:
  157. imageUrl = "reject";
  158. break;
  159. case 2:
  160. imageUrl = "pass";
  161. break;
  162. case 3:
  163. imageUrl = "entrance";
  164. break;
  165. default:
  166. break;
  167. }
  168. this.setData({
  169. imageUrl
  170. });
  171. },
  172. regularList: function (n) {
  173. this.updateQrCode();
  174. }
  175. },
  176. lifetimes: {
  177. created: function () {
  178. // 在组件实例刚刚被创建时执行,该节点不能使用this.setData({}),
  179. },
  180. ready: function () {
  181. // 在组件实例进入页面节点树时执行,该节点可以开始使用this,setData({})
  182. },
  183. attached: function () {
  184. // console.log(this.properties.regularList)
  185. // 在组件实例进入页面节点树时执行,该节点可以开始使用
  186. this.updateQrCode();
  187. this.data.timer = setInterval(() => {
  188. this.updateQrCode();
  189. }, 1000 * 30);
  190. },
  191. detached: function () {
  192. // 移除
  193. clearInterval(this.data.timer);
  194. this.data.timer = null;
  195. }
  196. }
  197. });