regular_visit_details.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. const _my = require("../../__antmove/api/index.js")(my);
  2. const wx = _my;
  3. // pages/regular_visit_details/regular_visit_details.js
  4. const {
  5. userWhiteHandleVisitList,
  6. userWhiteGetSnList,
  7. visitoryDownFaceAgain
  8. } = require("../../utils/api/api");
  9. const app = getApp();
  10. import international from "../../international/appointment_scence/index";
  11. const {
  12. throttle
  13. } = require("../../utils/throttle/throttle");
  14. import QRCode from "../../utils/util/weapp-qrcode";
  15. import { userCreate } from '/utils/api/zfb_ioTVsp'
  16. import { iotVspInit, iotVspUniqueId } from '/utils/ioTVsp/index'
  17. Page({
  18. /**
  19. * 页面的初始数据
  20. */
  21. data: {
  22. international: international,
  23. language: app.data.language,
  24. regularList: null,
  25. //相关信息
  26. machineList: [],
  27. // 通道权限列表--设备列表
  28. chooseSN: false,
  29. snListLength: null,
  30. snList: null,
  31. isRegular: false,
  32. // 人员类型列表
  33. personTypeList: [{
  34. id: 0,
  35. name_ch: "访客",
  36. name_en: "visitors"
  37. }, {
  38. id: 1,
  39. name_ch: "同事",
  40. name_en: "colleagues"
  41. }, {
  42. id: 2,
  43. name_ch: "亲属",
  44. name_en: "relatives"
  45. }],
  46. personnelType: 0,
  47. remark: "",
  48. uniqueId: null,
  49. //备注
  50. reviewStatus: 2 //2同意1拒绝
  51. },
  52. // 常客获取楼宇的设备列表(sn和name)
  53. userWhiteGetSnList() {
  54. let adminInfo = app.data.adminInfo;
  55. if (adminInfo) {
  56. userWhiteGetSnList({
  57. adminId: adminInfo.adminId,
  58. companyId: adminInfo.companyAdminId
  59. }).then(res => {
  60. // res.data.
  61. this.setData({
  62. machineList: res.data
  63. });
  64. });
  65. }
  66. },
  67. //获取开始时间
  68. getValue(e) {
  69. var {
  70. form
  71. } = this.data;
  72. switch (e.currentTarget.dataset.type) {
  73. case "snList":
  74. // form.snList = e.detail
  75. this.setData({
  76. snList: e.detail,
  77. snListLength: e.detail.length,
  78. chooseSN: false
  79. });
  80. break;
  81. case "personnelType":
  82. this.setData({
  83. personnelType: e.detail
  84. });
  85. break;
  86. default:
  87. form[e.currentTarget.dataset.type] = e.detail;
  88. break;
  89. }
  90. },
  91. // 打开通道权限弹出框
  92. showSN() {
  93. this.setData({
  94. chooseSN: true
  95. });
  96. },
  97. // 选择通过/拒绝
  98. chooseFun(e) {
  99. this.setData({
  100. reviewStatus: e.currentTarget.dataset.type,
  101. remark: ""
  102. });
  103. },
  104. // 备注
  105. onInput(e) {
  106. this.setData({
  107. remark: e.detail
  108. });
  109. },
  110. handle(e) {
  111. let {
  112. snList,
  113. regularList,
  114. remark,
  115. reviewStatus,
  116. personnelType
  117. } = this.data;
  118. wx.requestSubscribeMessage({
  119. entityIds: ["9d4ddcd78f66444482ad66c5a262ffed"],
  120. success(res) {
  121. if(res.behavior === 'cancel') {
  122. return
  123. }
  124. if (snList || reviewStatus == 1) {
  125. let data = {
  126. snList: snList || [],
  127. reviewStatus,
  128. userVisitorListDetailId: regularList.userVisitorListDetailId,
  129. personnelType,
  130. remark
  131. };
  132. userWhiteHandleVisitList(data).then(res => {
  133. if (res.code == 200) {
  134. my.alert({
  135. title: "提醒",
  136. content: "操作成功!",
  137. success(res) {
  138. wx.navigateBack({
  139. delta: 1
  140. })
  141. }
  142. })
  143. } else {
  144. wx.showToast({
  145. title: res.msg,
  146. icon: "none"
  147. });
  148. }
  149. });
  150. } else {
  151. wx.showToast({
  152. title: "请选择通道权限!",
  153. icon: "none"
  154. });
  155. }
  156. }
  157. });
  158. },
  159. // 访客重新下发
  160. visitoryDownFaceAgain: throttle(function () {
  161. visitoryDownFaceAgain({
  162. userVisitorListDetailId: this.data.regularList.userVisitorListDetailId
  163. }).then(res => {
  164. if (res.code === 200) {
  165. wx.showToast({
  166. title: "下发成功!",
  167. icon: "none"
  168. });
  169. if(!this.data.isRegular && this.data.uniqueId) {
  170. iotVspUniqueId(app.data.userInfo.idNumber, app.data.userInfo.username, app.data.userInfo.phone, app.data.userInfo.avatar, this.data.uniqueId).then((res) => {})
  171. }
  172. } else {
  173. wx.showToast({
  174. title: res.msg,
  175. icon: "none"
  176. });
  177. }
  178. });
  179. }, 5000),
  180. // 生成二维码
  181. creatQrCode(id) {
  182. // wx.showLoading({
  183. // title: '加载中...',
  184. // })
  185. let that = this;
  186. new QRCode("myQrcode", {
  187. text: `HHFKJ?userId=$123&timestamp=${this.data.dateTime}`,
  188. width: 176,
  189. //canvas 画布的宽
  190. height: 176,
  191. //canvas 画布的高
  192. padding: 0,
  193. // 生成二维码四周自动留边宽度,不传入默认为0
  194. correctLevel: QRCode.CorrectLevel.L,
  195. // 二维码可辨识度
  196. callback: res => {
  197. //工具回调数据
  198. // 接下来就可以直接调用微信小程序的api保存到本地或者将这张二维码直接画在海报上面去,看各自需求
  199. // wx.hideLoading()
  200. //将图片路劲放入data中,显示在wxml的image标签上
  201. console.log(res);
  202. that.setData({
  203. qrCode: res.path
  204. });
  205. }
  206. });
  207. },
  208. // 获取人脸入库的流水号
  209. getUniqueId() {
  210. userCreate({
  211. certType: 'IDENTITY_CARD',
  212. certNo: app.data.userInfo.idNumber,
  213. certName: app.data.userInfo.username,
  214. phone: app.data.userInfo.phone,
  215. avatar: app.data.userInfo.avatar
  216. }).then((res) => {
  217. if(res.data && !res.data.uniqueId) {
  218. // uniqueId为空,表示已入库
  219. this.setData({
  220. uniqueId: null
  221. })
  222. } else {
  223. this.setData({
  224. uniqueId: res.data.uniqueId
  225. })
  226. }
  227. })
  228. },
  229. /**
  230. * 生命周期函数--监听页面加载
  231. */
  232. onLoad: function (options) {
  233. this.creatQrCode()
  234. if (options && options.isRegular) {
  235. this.setData({
  236. isRegular: true
  237. })
  238. } else {
  239. this.getUniqueId()
  240. }
  241. this.data.regularList = JSON.parse(options.list)
  242. this.userWhiteGetSnList();
  243. },
  244. /**
  245. * 生命周期函数--监听页面初次渲染完成
  246. */
  247. onReady: function () {
  248. let {
  249. regularList
  250. } = this.data;
  251. this.setData({
  252. regularList
  253. });
  254. if(!this.data.isRegular) {
  255. iotVspInit((res) => {
  256. my.navigateBack()
  257. if(res.success) {
  258. this.setData({
  259. uniqueId: null
  260. })
  261. }
  262. })
  263. }
  264. },
  265. /**
  266. * 生命周期函数--监听页面显示
  267. */
  268. onShow: function () {
  269. this.setData({
  270. language: app.data.language
  271. });
  272. },
  273. /**
  274. * 生命周期函数--监听页面隐藏
  275. */
  276. onHide: function () {},
  277. /**
  278. * 生命周期函数--监听页面卸载
  279. */
  280. onUnload: function () {},
  281. /**
  282. * 页面相关事件处理函数--监听用户下拉动作
  283. */
  284. onPullDownRefresh: function () {},
  285. /**
  286. * 页面上拉触底事件的处理函数
  287. */
  288. onReachBottom: function () {},
  289. /**
  290. * 用户点击右上角分享
  291. */
  292. onShareAppMessage: function () {},
  293. antmoveAction: function () {
  294. //执行时动态赋值,请勿删除
  295. }
  296. });