regular_invite.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. if (e.detail == 0) {
  126. this.setData({
  127. showAddBut: false
  128. })
  129. } else {
  130. this.setData({
  131. showAddBut: true
  132. })
  133. }
  134. break;
  135. default:
  136. form[e.currentTarget.dataset.type] = e.detail
  137. break;
  138. }
  139. this.matchComplete();
  140. },
  141. // 判断用户是否填写完整
  142. matchComplete() {
  143. let form = this.data.form;
  144. let isDisabled = form.startTime && form.endTime && form.reason && form.phoneList && form.phoneList.length > 0 ? false : true;
  145. this.setData({
  146. isDisabled: isDisabled
  147. })
  148. },
  149. // 立即邀请
  150. gotoInvited() {
  151. const that = this;
  152. return new Promise((reslove, reject) => {
  153. that.data.form.userWhitelistId = app.data.adminInfo.userWhitelistId
  154. userWhiteInviteUserVisitor(that.data.form).then(res => {
  155. if (res.code != 200) {
  156. wx.showModal({
  157. title: '提示',
  158. content: res.msg,
  159. showCancel: false,
  160. success() {}
  161. })
  162. reject();
  163. return;
  164. }
  165. if (!that.data.showAddBut) {
  166. that.data.flag = 1;
  167. reslove({
  168. title: '您收到一个来自' + app.data.userInfo.username + '邀请函',
  169. path: '/pages/visitor_make/visitor_make?userVisitorDetailId=' + res.data[0].userVisitorListDetailId,
  170. imageUrl: '../../static/comment/invitation.jpg',
  171. })
  172. } else {
  173. wx.showModal({
  174. title: '提示',
  175. content: '您已成功邀请用户,短信将在几分钟内发送至用户手机~',
  176. showCancel: false,
  177. success() {
  178. wx.navigateBack({
  179. delta: 1,
  180. })
  181. }
  182. })
  183. }
  184. })
  185. })
  186. },
  187. //判断是否分享完回来的(无法判断是否真的分享-2018 年腾讯已取消分享取消回调)
  188. judgeContinueShare() {
  189. if (this.data.flag == 1) {
  190. this.data.flag = null;
  191. wx.showModal({
  192. content: '分享邀请函成功,是否继续邀请?',
  193. confirmText: "继续邀请",
  194. complete: (res) => {
  195. if (res.cancel) {
  196. wx.navigateBack({
  197. delta: 1,
  198. })
  199. }
  200. if (res.confirm) {
  201. this.setData({
  202. "form.phoneList": [],
  203. closeNum: true
  204. });
  205. this.matchComplete()
  206. }
  207. }
  208. })
  209. }
  210. },
  211. /**
  212. * 生命周期函数--监听页面加载
  213. */
  214. onLoad: function (options) {
  215. this.setData({
  216. 'form.reason': "业务洽谈"
  217. })
  218. this.userWhiteGetSnList()
  219. },
  220. /**
  221. * 生命周期函数--监听页面初次渲染完成
  222. */
  223. onReady: function () {
  224. },
  225. /**
  226. * 生命周期函数--监听页面显示
  227. */
  228. onShow: function () {
  229. this.judgeContinueShare()
  230. this.setData({
  231. language: app.data.language,
  232. })
  233. },
  234. /**
  235. * 生命周期函数--监听页面隐藏
  236. */
  237. onHide: function () {
  238. },
  239. /**
  240. * 生命周期函数--监听页面卸载
  241. */
  242. onUnload: function () {
  243. },
  244. /**
  245. * 页面相关事件处理函数--监听用户下拉动作
  246. */
  247. onPullDownRefresh: function () {
  248. },
  249. /**
  250. * 页面上拉触底事件的处理函数
  251. */
  252. onReachBottom: function () {
  253. },
  254. /**
  255. * 用户点击右上角分享
  256. */
  257. onShareAppMessage: function () {
  258. let userInfo = app.data.userInfo
  259. let promise = this.gotoInvited()
  260. return {
  261. title: '您收到一个来自' + userInfo.username + '邀请函',
  262. path: '/pages/visitor_make/visitor_make?userVisitorDetailId=null',
  263. imageUrl: '../../static/comment/invitation.jpg',
  264. promise
  265. }
  266. }
  267. })