regular_invite.js 5.4 KB

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