visitor_make.js 15 KB

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