regular_invite.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. // pages/regular_invite/regular_invite.js
  2. import international from '../../international/appointment_scence/index'
  3. const {
  4. userWhiteInviteUserVisitor,
  5. userWhiteGetSnList,
  6. } = require('../../utils/api/api')
  7. const app = getApp()
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. //国际化语言包
  14. international: international,
  15. //中英文配置
  16. language: null,
  17. // 人员类型列表
  18. personTypeList: [{
  19. id: 0,
  20. name_ch: '访客',
  21. name_en: 'visit',
  22. },
  23. {
  24. id: 1,
  25. name_ch: '同事',
  26. name_en: 'friend',
  27. },
  28. {
  29. id: 2,
  30. name_ch: '亲属',
  31. name_en: 'family',
  32. },
  33. ],
  34. //邀请方式
  35. isRealNameList: [{
  36. id: 0,
  37. name_ch: '微信',
  38. name_en: 'WeChat',
  39. },
  40. {
  41. id: 1,
  42. name_ch: '短信',
  43. name_en: 'SMS',
  44. },
  45. ],
  46. // 拜访事由列表
  47. reasonList: [{
  48. name: '业务洽谈'
  49. },
  50. {
  51. name: '会议邀请'
  52. },
  53. {
  54. name: '施工安装'
  55. },
  56. {
  57. name: '探亲访友'
  58. },
  59. {
  60. name: '工作检查'
  61. },
  62. {
  63. name: '面试邀请'
  64. },
  65. {
  66. name: '快递外卖'
  67. },
  68. {
  69. name: '家政保洁'
  70. }],
  71. // 通道权限列表--设备列表
  72. machineList: [],
  73. //是否打开设备列表勾选弹窗
  74. chooseSN: false,
  75. //选中的设备数量
  76. snListLength: null,
  77. //是否显示新增手机号按钮
  78. showAddBut: true,
  79. //是否清除已填写的手机号
  80. closeNum: false,
  81. //是否禁用邀请按钮
  82. isDisabled: true,
  83. //提交的表单
  84. form: {},
  85. },
  86. // 常客获取楼宇的设备列表(sn和name)
  87. userWhiteGetSnList() {
  88. let adminInfo = app.data.adminInfo
  89. userWhiteGetSnList({
  90. adminId: adminInfo.buildingAdminId,
  91. companyId: adminInfo.companyAdminId,
  92. }).then(res => {
  93. this.setData({
  94. machineList: res.data
  95. })
  96. })
  97. },
  98. // 打开通道权限弹出框
  99. showSN() {
  100. this.setData({
  101. chooseSN: true
  102. })
  103. },
  104. //获取填写的值
  105. getValue(e) {
  106. var {
  107. form
  108. } = this.data;
  109. switch (e.currentTarget.dataset.type) {
  110. case 'snList':
  111. this.setData({
  112. 'form.snList': e.detail,
  113. snListLength: e.detail.length
  114. })
  115. break;
  116. case 'reason':
  117. this.setData({
  118. 'form.reason': e.detail.name
  119. })
  120. break;
  121. case 'invitationWay':
  122. this.setData({
  123. 'form.invitationWay': e.detail
  124. })
  125. this.setData({
  126. showAddBut: e.detail == 0?false:true,
  127. 'form.phoneList': [],
  128. closeNum: true
  129. })
  130. break;
  131. default:
  132. form[e.currentTarget.dataset.type] = e.detail
  133. break;
  134. }
  135. this.matchComplete();
  136. },
  137. // 判断用户是否填写完整
  138. matchComplete() {
  139. let form = this.data.form;
  140. let isDisabled = form.startTime && form.endTime && form.reason && form.phoneList && form.phoneList.length > 0 ? false : true;
  141. this.setData({
  142. isDisabled: isDisabled
  143. })
  144. },
  145. // 立即邀请
  146. gotoInvited() {
  147. const that = this;
  148. return new Promise((reslove, reject) => {
  149. that.data.form.userWhitelistId = app.data.adminInfo.userWhitelistId
  150. userWhiteInviteUserVisitor(that.data.form).then(res => {
  151. if (res.code != 200) {
  152. wx.showModal({
  153. title: '提示',
  154. content: res.msg,
  155. showCancel: false,
  156. success() {}
  157. })
  158. reject();
  159. return;
  160. }
  161. if (!that.data.showAddBut) {
  162. that.data.flag = 1;
  163. reslove({
  164. title: '您收到一个来自' + app.data.userInfo.username + '邀请函',
  165. path: '/pages/visitor_make/visitor_make?userVisitorDetailId=' + res.data[0].userVisitorListDetailId,
  166. imageUrl: '../../static/comment/invitation.jpg',
  167. })
  168. } else {
  169. wx.showModal({
  170. title: '提示',
  171. content: '您已成功邀请用户,短信将在几分钟内发送至用户手机~',
  172. showCancel: false,
  173. success() {
  174. wx.navigateBack({
  175. delta: 1,
  176. })
  177. }
  178. })
  179. }
  180. })
  181. })
  182. },
  183. //判断是否分享完回来的(无法判断是否真的分享-2018 年腾讯已取消分享取消回调)
  184. judgeContinueShare() {
  185. if (this.data.flag == 1) {
  186. this.data.flag = null;
  187. wx.showModal({
  188. content: '分享邀请函成功,是否继续邀请?',
  189. confirmText: "继续邀请",
  190. complete: (res) => {
  191. if (res.cancel) {
  192. wx.navigateBack({
  193. delta: 1,
  194. })
  195. }
  196. if (res.confirm) {
  197. this.setData({
  198. "form.phoneList": [],
  199. closeNum: true
  200. });
  201. this.matchComplete()
  202. }
  203. }
  204. })
  205. }
  206. },
  207. /**
  208. * 生命周期函数--监听页面加载
  209. */
  210. onLoad: function (options) {
  211. this.setData({
  212. 'form.reason': "业务洽谈"
  213. })
  214. this.userWhiteGetSnList()
  215. },
  216. /**
  217. * 生命周期函数--监听页面初次渲染完成
  218. */
  219. onReady: function () {
  220. },
  221. /**
  222. * 生命周期函数--监听页面显示
  223. */
  224. onShow: function () {
  225. this.judgeContinueShare()
  226. this.setData({
  227. language: app.data.language,
  228. })
  229. },
  230. /**
  231. * 生命周期函数--监听页面隐藏
  232. */
  233. onHide: function () {
  234. },
  235. /**
  236. * 生命周期函数--监听页面卸载
  237. */
  238. onUnload: function () {
  239. },
  240. /**
  241. * 页面相关事件处理函数--监听用户下拉动作
  242. */
  243. onPullDownRefresh: function () {
  244. },
  245. /**
  246. * 页面上拉触底事件的处理函数
  247. */
  248. onReachBottom: function () {
  249. },
  250. /**
  251. * 用户点击右上角分享
  252. */
  253. onShareAppMessage: function () {
  254. let userInfo = app.data.userInfo
  255. let promise = this.gotoInvited()
  256. return {
  257. title: '您收到一个来自' + userInfo.username + '邀请函',
  258. path: '/pages/visitor_make/visitor_make?userVisitorDetailId=null',
  259. imageUrl: '../../static/comment/invitation.jpg',
  260. promise
  261. }
  262. }
  263. })