visitor_make.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. const _my = require("../../__antmove/api/index.js")(my);
  2. const wx = _my;
  3. // pages/visitor_make/visitor_make.js
  4. import { getBuildingList, getUserWhiteByphoneAndAdminId, visitorySubmit, getVisitoryByUserVisitorListDetailId } from "../../utils/api/api";
  5. import { getContextByAdminId } from "../../utils/api/customField";
  6. import { getThreeCodeByAdminId } from "../../utils/api/three_yards";
  7. const {
  8. showToast
  9. } = require("../../utils/func/request");
  10. import international from "../../international/appointment_scence/index";
  11. import { iotVspInit, iotVspUniqueId } from '/utils/ioTVsp/index'
  12. const app = getApp();
  13. Page({
  14. /**
  15. * 页面的初始数据
  16. */
  17. data() {
  18. return {
  19. international: international,
  20. //国际化语言包
  21. language: app.data.language,
  22. isDisabled: false,
  23. chooseOne: true,
  24. //展示访客确认页面
  25. // swiper的index
  26. currentIndex: 0,
  27. // swiper滚动长度
  28. swiperDx: 0,
  29. // 步骤列表
  30. stepsList: [{
  31. name: "访客确认",
  32. name1: "Visitors confirm",
  33. complete: false
  34. }, {
  35. name: "拜访信息填写",
  36. name1: "Visit information",
  37. complete: false
  38. }],
  39. // 受访单位列表
  40. companyList: [],
  41. companyIndex: 0,
  42. // 拜访事由列表
  43. reasonList: [{
  44. name: "业务洽谈"
  45. }, {
  46. name: "会议邀请"
  47. }, {
  48. name: "施工安装"
  49. }, {
  50. name: "探亲访友"
  51. }, {
  52. name: "工作检查"
  53. }, {
  54. name: "面试邀请"
  55. }, {
  56. name: "快递外卖"
  57. }, {
  58. name: "家政保洁"
  59. }],
  60. reasonIndex: null,
  61. // 人员类型列表
  62. personTypeList: [{
  63. id: 0,
  64. name_ch: "访客",
  65. name_en: "visitors"
  66. }, {
  67. id: 1,
  68. name_ch: "同事",
  69. name_en: "colleagues"
  70. }, {
  71. id: 2,
  72. name_ch: "亲属",
  73. name_en: "relatives"
  74. }],
  75. personTypIndex: 0,
  76. // 提交表单
  77. form: {},
  78. userInfo: null,
  79. building_list: [],
  80. buildingIndex: 0,
  81. isAudit: false,
  82. //受邀禁用信息
  83. auditList: null,
  84. type: 1,
  85. //1->访客自主提交 2->访客受邀
  86. disableComplete: false,
  87. isShowApplet: false,
  88. //是否开启自定义字段
  89. threeCodeList: [],
  90. //是否开启三码
  91. startTime: null,
  92. endTime: null,
  93. //传入组件的预约开始时间
  94. hsHour: null, //核酸时长(单位小时)
  95. carNumberShow: false
  96. }
  97. },
  98. // 获取认证状态
  99. getCertificationState(e) {
  100. if (e.detail) {
  101. showToast("认证成功~");
  102. wx.setStorageSync("language", app.data.language);
  103. this.setData({
  104. isDisabled: true
  105. });
  106. this.updateSetting();
  107. } else {
  108. showToast("认证失败了,再试一次吧~");
  109. }
  110. },
  111. // 更新个人信息
  112. updateSetting() {
  113. let {
  114. form
  115. } = this.data;
  116. if (app.data.language == wx.getStorageSync("language")) {
  117. if (app.data.language == "en") {
  118. this.setData({
  119. userInfo: app.data.userInfo || app.data.temporary_userInfo,
  120. isDisabled: app.data.userInfo ? true : false
  121. });
  122. } else if (app.data.language === "ch") {
  123. this.setData({
  124. userInfo: app.data.userInfo,
  125. isDisabled: app.data.userInfo ? true : false
  126. });
  127. }
  128. if (app.data.userInfo) {
  129. form.userId = app.data.userInfo.userId;
  130. form.name = app.data.userInfo.username;
  131. form.phone = app.data.userInfo.phone;
  132. form.idNumber = app.data.userInfo.idNumber;
  133. this.matchCorrectPhone();
  134. this.matchStepComplete();
  135. }
  136. }
  137. if (app.data.extraMessage) {
  138. let extraMessage = app.data.extraMessage;
  139. this.setData({
  140. "form.company": extraMessage.company,
  141. "form.carno": extraMessage.carno
  142. });
  143. this.matchStepComplete();
  144. }
  145. },
  146. // 判断受邀人的手机号是否和当前用户手机号一致
  147. matchCorrectPhone() {
  148. if (app.data.userInfo && this.data.form.correctPhone && this.data.type === 2) {
  149. if (app.data.userInfo.phone != this.data.form.correctPhone) {
  150. this.setData({
  151. disableComplete: true
  152. });
  153. wx.showModal({
  154. title: "提示",
  155. content: "你暂无权限接受此邀请哦",
  156. showCancel: false
  157. });
  158. }
  159. }
  160. },
  161. // 获取是否可以展示信息
  162. getUpdateState(e) {
  163. if (e.detail) {
  164. this.updateSetting();
  165. }
  166. },
  167. // 获得swiper-item位置
  168. getSwiperPercent(e) {
  169. this.setData({
  170. swiperDx: e.detail.dx
  171. });
  172. },
  173. // 改变swiper
  174. changeSwiper(e) {
  175. if (e.detail.current < this.data.currentIndex || this.data.stepsList[e.detail.current].complete) {
  176. this.setData({
  177. currentIndex: e.detail.current
  178. });
  179. } else {
  180. this.setData({
  181. currentIndex: this.data.currentIndex
  182. });
  183. }
  184. },
  185. // 下一步
  186. next_step(e) {
  187. this.setData({
  188. currentIndex: 1
  189. });
  190. },
  191. // 上一步
  192. previous_step(e) {
  193. this.setData({
  194. currentIndex: 0
  195. });
  196. },
  197. carNumberShowChange(e) {
  198. this.setData({
  199. carNumberShow: e.detail
  200. })
  201. },
  202. //获取输入or选择的内容
  203. getValue(e) {
  204. var {
  205. form
  206. } = this.data;
  207. switch (e.currentTarget.dataset.type) {
  208. case "reason":
  209. this.setData({
  210. "form.reason": e.detail.name
  211. });
  212. // form.reason = e.detail.name
  213. break;
  214. case "company":
  215. this.setData({
  216. "form.company": e.detail
  217. });
  218. break;
  219. case "visiteeBuilding":
  220. var index = this.data.building_list.findIndex(item => {
  221. return item.adminId == e.detail.adminId;
  222. });
  223. this.setData({
  224. "form.visiteeBuilding": e.detail.username,
  225. "form.visiteeBuildingId": e.detail.adminId,
  226. companyList: this.data.building_list[index].userWhiteIntervieweeVOList,
  227. "form.visiteeCompany": this.data.building_list[index].userWhiteIntervieweeVOList[0].companyName,
  228. "form.userWhitelistId": this.data.building_list[index].userWhiteIntervieweeVOList[0].userWhitelistId,
  229. "form.visiteeXm": this.data.building_list[index].userWhiteIntervieweeVOList[0].name
  230. });
  231. this.getContextByAdminId(e.detail.adminId);
  232. this.getThreeCodeByAdminId(e.detail.adminId);
  233. break;
  234. case "visiteeCompany":
  235. this.setData({
  236. "form.visiteeXm": e.detail.name,
  237. "form.userWhitelistId": e.detail.userWhitelistId
  238. });
  239. break;
  240. case "visiteePhone":
  241. this.setData({
  242. "form.phone": e.detail
  243. });
  244. this.getUserWhiteByphoneAndAdminId();
  245. break;
  246. case "startTime":
  247. this.setData({
  248. startTime: e.detail
  249. });
  250. default:
  251. form[e.currentTarget.dataset.type] = e.detail;
  252. break;
  253. }
  254. this.matchStepComplete();
  255. },
  256. visiteePhoneFun(e) {
  257. if(!e.detail.value) {
  258. return
  259. }
  260. this.setData({
  261. "form.phone": e.detail.value
  262. });
  263. this.getUserWhiteByphoneAndAdminId();
  264. },
  265. //步骤条判断是否完成
  266. matchStepComplete() {
  267. let {
  268. stepsList,
  269. disableComplete,
  270. form,
  271. isFillFields,
  272. isthreeYards
  273. } = this.data;
  274. stepsList[0].complete = !disableComplete && form.userId && form.name && form.idNumber && form.phone && form.company ? true : false;
  275. stepsList[1].complete = !disableComplete && form.visiteePhone && form.reason && form.visiteeBuilding && isFillFields && isthreeYards ? true : false;
  276. this.setData({
  277. stepsList
  278. });
  279. },
  280. getUserWhiteByphoneAndAdminId(type) {
  281. wx.showLoading({
  282. title: "获取中..."
  283. });
  284. var {
  285. form
  286. } = this.data;
  287. let data = {
  288. // adminId: form.visiteeBuildingId, //楼宇id
  289. phone: form.phone
  290. };
  291. getUserWhiteByphoneAndAdminId(data).then(res => {
  292. wx.hideLoading();
  293. if (res.code === 200) {
  294. form.visiteePhone = form.phone;
  295. form.visiteeBuilding = res.data[this.data.buildingIndex].username;
  296. form.visiteeBuildingId = res.data[this.data.buildingIndex].adminId;
  297. form.visiteeCompany = res.data[this.data.buildingIndex].userWhiteIntervieweeVOList[this.data.companyIndex].companyName;
  298. form.userWhitelistId = res.data[this.data.buildingIndex].userWhiteIntervieweeVOList[this.data.companyIndex].userWhitelistId;
  299. form.visiteeXm = res.data[this.data.buildingIndex].userWhiteIntervieweeVOList[this.data.companyIndex].name;
  300. this.setData({
  301. form: form,
  302. companyList: res.data[this.data.buildingIndex].userWhiteIntervieweeVOList,
  303. companyIndex: 0,
  304. building_list: res.data,
  305. buildingIndex: 0
  306. });
  307. this.getContextByAdminId(res.data[this.data.buildingIndex].adminId);
  308. this.getThreeCodeByAdminId(res.data[this.data.buildingIndex].adminId);
  309. } else {
  310. showToast(res.msg);
  311. this.setData({
  312. companyList: null,
  313. companyIndex: 0,
  314. building_list: null,
  315. buildingIndex: 0,
  316. threeCodeList: [],
  317. hsHour: null,
  318. isShowApplet: false
  319. });
  320. }
  321. });
  322. },
  323. //提交申请
  324. submit() {
  325. const that = this;
  326. let {
  327. form,
  328. isthreeYards,
  329. isFillFields
  330. } = this.data;
  331. wx.requestSubscribeMessage({
  332. entityIds: ["95a6bdda7c7d49bfa4c0014f5e035601", "63ecddec46ef4424a13fcb966ecd1bc4"],
  333. success(res) {
  334. if(res.behavior === 'cancel') {
  335. return
  336. }
  337. form.addCustomList = isFillFields == true ? null : isFillFields;
  338. form.hs = isthreeYards.hs || null;
  339. form.hsPhoto = isthreeYards.hsPhoto || null;
  340. form.jkm = isthreeYards.jkm || null;
  341. form.jkmPhoto = isthreeYards.jkmPhoto || null;
  342. form.xc = isthreeYards.xc || null;
  343. form.xcPhoto = isthreeYards.xcPhoto || null;
  344. form.xcPhone = isthreeYards.xcPhone || null;
  345. visitorySubmit(that.data.form).then(res => {
  346. if (res.code === 200) {
  347. let extraMessage = {
  348. company: that.data.form.company,
  349. carno: that.data.form.carno,
  350. type: 2
  351. };
  352. app.data.extraMessage = extraMessage;
  353. wx.setStorageSync("extraMessage", extraMessage);
  354. my.alert({
  355. title: "提示",
  356. content: that.data.type === 1 ? "您的预约已提交,请耐心等待常客审核吧~" : "您已成功接受邀请啦~",
  357. success() {
  358. if (that.data.type === 1) {
  359. my.navigateBack()
  360. } else {
  361. iotVspUniqueId(app.data.userInfo.idNumber, app.data.userInfo.username, app.data.userInfo.phone, app.data.userInfo.avatar).then((res) => {
  362. if(res) {
  363. wx.switchTab({
  364. url: "/pages/resitor_scence/resitor_scence"
  365. })
  366. }
  367. })
  368. }
  369. }
  370. })
  371. } else {
  372. showToast(res.msg);
  373. }
  374. });
  375. }
  376. });
  377. },
  378. // 获取常客信息
  379. getVisitoryByUserVisitorListDetailId(id) {
  380. var {
  381. form
  382. } = this.data;
  383. getVisitoryByUserVisitorListDetailId({
  384. userVisitorListDetailId: id
  385. }).then(res => {
  386. form.userVisitorListDetailId = res.data.id;
  387. form.correctPhone = res.data.phone;
  388. form.visiteePhone = res.data.visiteePhone;
  389. form.visiteeBuilding = res.data.visiteeBuilding;
  390. form.visiteeBuildingId = res.data.visiteeBuildingId;
  391. form.visiteeCompany = res.data.visiteeCompany;
  392. form.visiteeXm = res.data.visiteeXm;
  393. form.userWhitelistId = res.data.userWhitelistId;
  394. form.startTime = res.data.startTime;
  395. form.endTime = res.data.endTime;
  396. form.reason = res.data.reason;
  397. // form.personnelType = res.data.personnelType;
  398. let building_list = [{
  399. adminId: res.data.visiteeBuildingId,
  400. username: res.data.visiteeBuilding
  401. }];
  402. this.reasonEcho(res.data.reason);
  403. let companyList = [{
  404. adminId: res.data.visiteeCompanyId,
  405. companyName: res.data.visiteeCompany
  406. }];
  407. this.setData({
  408. form,
  409. building_list: building_list,
  410. buildingIndex: 0,
  411. companyList: companyList,
  412. companyIndex: 0,
  413. isAudit: true,
  414. personTypIndex: res.data.personnelType
  415. });
  416. // this.getBuildingList({
  417. // adminId: res.data.visiteeBuildingId,
  418. // name: res.data.visiteeBuilding
  419. // });
  420. this.matchCorrectPhone();
  421. this.getContextByAdminId(res.data.visiteeBuildingId);
  422. this.getThreeCodeByAdminId(res.data.visiteeBuildingId);
  423. });
  424. },
  425. // 来访事由
  426. reasonEcho(name) {
  427. let reason = {
  428. name
  429. };
  430. let index = this.data.reasonList.map(item => {
  431. return JSON.stringify(item);
  432. }).indexOf(JSON.stringify(reason));
  433. if (index > -1) {
  434. this.setData({
  435. reasonIndex: index
  436. });
  437. }
  438. },
  439. // 更具楼宇id检查楼宇列表是否有符合条件的对象及获得其数组下标
  440. getBuildingList(buildingObj) {
  441. getBuildingList().then(res => {
  442. this.setData({
  443. building_list: res.data
  444. });
  445. if (!buildingObj) return;
  446. console.log(buildingObj);
  447. let index = res.data.map(item => {
  448. return JSON.stringify(item);
  449. }).indexOf(JSON.stringify(buildingObj));
  450. if (index > -1) {
  451. this.setData({
  452. buildingIndex: index,
  453. "form.visiteeBuildingId": buildingObj.adminId,
  454. "form.visiteeBuilding": buildingObj.name
  455. });
  456. this.matchStepComplete();
  457. }
  458. });
  459. },
  460. //获取是否有自定义字段
  461. getContextByAdminId(orgId) {
  462. wx.showLoading({
  463. title: "检查配置中.."
  464. });
  465. getContextByAdminId(orgId).then(res => {
  466. if (res.code == 200) {
  467. this.setData({
  468. isShowApplet: res.data,
  469. isFillFields: !res.data
  470. });
  471. this.matchStepComplete();
  472. } else {
  473. showToast(res.msg);
  474. }
  475. wx.hideLoading();
  476. });
  477. },
  478. // 判断自定义字段是否填写完成
  479. isFillFields(e) {
  480. this.data.isFillFields = e.detail;
  481. this.matchStepComplete();
  482. },
  483. // 查询三码信息
  484. getThreeCodeByAdminId(adminId) {
  485. wx.showLoading({
  486. title: "检查配置中.."
  487. });
  488. getThreeCodeByAdminId({
  489. adminId
  490. }).then(res => {
  491. wx.hideLoading();
  492. this.setData({
  493. threeCodeList: res.data.threeCodeList,
  494. hsHour: res.data.hsHour
  495. });
  496. if (res.data.threeCodeList.length == 0) {
  497. this.data.isthreeYards = true;
  498. this.matchStepComplete();
  499. }
  500. });
  501. },
  502. // 三码填写内容
  503. isthreeYards(e) {
  504. this.data.isthreeYards = e.detail;
  505. this.matchStepComplete();
  506. },
  507. /**
  508. * 生命周期函数--监听页面加载
  509. */
  510. onLoad: async function (options) {
  511. // options = {
  512. // userVisitorDetailId: 13499
  513. // }
  514. if(!options || !options.formMain) {
  515. let launchOptions = my.getLaunchOptionsSync()
  516. if(!launchOptions.query) {
  517. launchOptions = my.getEnterOptionsSync()
  518. }
  519. if (launchOptions.query && launchOptions.query.userVisitorDetailId) {
  520. this.getVisitoryByUserVisitorListDetailId(launchOptions.query.userVisitorDetailId);
  521. this.setData({
  522. type: 2
  523. });
  524. }
  525. }
  526. this.updateSetting();
  527. },
  528. /**
  529. * 生命周期函数--监听页面初次渲染完成
  530. */
  531. onReady: function () {
  532. if(this.data.type === 2) {
  533. iotVspInit((res) => {
  534. my.navigateBack()
  535. if(res.success) {
  536. wx.switchTab({
  537. url: "/pages/resitor_scence/resitor_scence"
  538. })
  539. }
  540. })
  541. }
  542. },
  543. /**
  544. * 生命周期函数--监听页面显示
  545. */
  546. onShow: function () {
  547. wx.hideBackHome()
  548. this.setData({
  549. language: app.data.language
  550. });
  551. },
  552. /**
  553. * 生命周期函数--监听页面隐藏
  554. */
  555. onHide: function () {},
  556. /**
  557. * 生命周期函数--监听页面卸载
  558. */
  559. onUnload: function () {},
  560. /**
  561. * 页面相关事件处理函数--监听用户下拉动作
  562. */
  563. onPullDownRefresh: function () {},
  564. /**
  565. * 页面上拉触底事件的处理函数
  566. */
  567. onReachBottom: function () {},
  568. /**
  569. * 用户点击右上角分享
  570. */
  571. onShareAppMessage: function () {},
  572. antmoveAction: function () {
  573. //执行时动态赋值,请勿删除
  574. }
  575. });