index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. const _my = require("../../__antmove/api/index.js")(my);
  2. const wx = _my;
  3. const app = getApp();
  4. const {
  5. getBuildingList,
  6. userWhiteCheck,
  7. getCompanyList
  8. } = require("../../utils/api/api");
  9. import international from "../../international/appointment_scence/index";
  10. import { showToast } from "../../utils/func/request";
  11. import { getContextByAdminId } from "../../utils/api/customField";
  12. import { getThreeCodeByAdminId } from "../../utils/api/three_yards";
  13. import { iotVspInit, iotVspUniqueId } from '/utils/ioTVsp/index'
  14. const {
  15. desensitization
  16. } = require("../../utils/util");
  17. // pages/make_appointment/changeUserInfo/index.js
  18. Page({
  19. /**
  20. * 页面的初始数据
  21. */
  22. data: {
  23. international: international,
  24. language: "ch",
  25. isDisabled: false,
  26. isSubmit: false,
  27. userInfo: null,
  28. adminInfo: app.data.adminInfo,
  29. phone: app.data.userInfo ? app.data.userInfo.phone : null,
  30. building_list: [],
  31. //楼宇列表
  32. buildingAdminId: null,
  33. buildingName: null,
  34. buildingIndex: null,
  35. companyList: [],
  36. //公司列表
  37. companyAdminId: null,
  38. companyName: null,
  39. //是否显示企业名称&存储企业名称
  40. companyIndex: null,
  41. isRegularQRCode: false,
  42. //是否是扫企业常客码进入,需满足扫码的企业id和选择的企业id必需相同&常客的type必需为1
  43. isShowApplet: false,
  44. //是否开启自定义字段
  45. threeCodeList: [],
  46. //是否开启三码
  47. temporary_adminInfo: app.data.temporary_adminInfo || null,
  48. //判断是否是扫描进来
  49. newCompanyList: [] //允许被显示的企业列表
  50. },
  51. // 获取认证状态
  52. getCertificationState(e) {
  53. let that = this;
  54. if (e.detail) {
  55. wx.showModal({
  56. title: "温馨提醒",
  57. content: app.data.language === "ch" ? "认证成功~" : "change person message successfully ~",
  58. showCancel: false,
  59. success() {
  60. wx.setStorageSync("language", app.data.language);
  61. //返回上一页
  62. wx.navigateBack({
  63. delta: 1
  64. });
  65. }
  66. });
  67. } else {
  68. wx.showModal({
  69. title: "温馨提醒",
  70. content: app.data.language === "ch" ? "认证失败,再试一次吧~" : "change failed , please try again ~",
  71. showCancel: false
  72. });
  73. }
  74. },
  75. // 获取是否可以展示信息
  76. getUpdateState(e) {
  77. if (e.detail) {
  78. this.setData({
  79. language: app.data.language,
  80. userInfo: app.data.temporary_userInfo,
  81. isDisabled: false
  82. });
  83. }
  84. },
  85. //更新视图
  86. updateSetting() {
  87. this.setData({
  88. language: app.data.language,
  89. userInfo: app.data.userInfo,
  90. isDisabled: true
  91. });
  92. },
  93. //获取输入or选择的内容
  94. getValue(e) {
  95. switch (e.currentTarget.dataset.type) {
  96. case "buildingAdminId":
  97. this.setData({
  98. buildingAdminId: e.detail.adminId,
  99. buildingName: e.detail.name
  100. });
  101. this.getCompanyList();
  102. this.getContextByAdminId(e.detail.adminId);
  103. this.getThreeCodeByAdminId(e.detail.adminId);
  104. break;
  105. case "companyAdminId":
  106. this.setData({
  107. companyAdminId: e.detail.adminId
  108. });
  109. this.data.companyName = e.detail.name;
  110. break;
  111. default:
  112. form[e.currentTarget.dataset.type] = e.detail;
  113. break;
  114. }
  115. this.canOperation();
  116. },
  117. // 判断提交按钮是否禁用
  118. canOperation() {
  119. let {
  120. buildingAdminId,
  121. companyAdminId,
  122. isSubmit,
  123. isRegularQRCode,
  124. isFillFields,
  125. isthreeYards
  126. } = this.data;
  127. isSubmit = buildingAdminId != null && companyAdminId != null && isFillFields && isthreeYards ? true : false;
  128. isRegularQRCode = app.data.temporary_adminInfo && app.data.temporary_adminInfo.visiteeCompanyId === companyAdminId && app.data.type === 1;
  129. this.setData({
  130. isSubmit,
  131. isRegularQRCode
  132. });
  133. },
  134. // 提交
  135. sure() {
  136. let {
  137. buildingAdminId,
  138. buildingName,
  139. companyAdminId,
  140. companyName,
  141. isRegularQRCode,
  142. isFillFields,
  143. isthreeYards
  144. } = this.data;
  145. if (buildingAdminId && companyAdminId) {
  146. let data = {
  147. adminId: buildingAdminId,
  148. userId: app.data.userInfo.userId,
  149. companyAdminId: companyAdminId,
  150. type: isRegularQRCode ? 1 : 0,
  151. addCustomList: isFillFields == true ? null : isFillFields,
  152. hs: isthreeYards.hs || null,
  153. hsPhoto: isthreeYards.hsPhoto || null,
  154. jkm: isthreeYards.jkm || null,
  155. jkmPhoto: isthreeYards.jkmPhoto || null,
  156. xc: isthreeYards.xc || null,
  157. xcPhoto: isthreeYards.xcPhoto || null,
  158. xcPhone: isthreeYards.xcPhone || null
  159. };
  160. wx.showLoading({
  161. title: "加载中..."
  162. });
  163. userWhiteCheck(data).then(res => {
  164. const that = this;
  165. if (res.code == 200) {
  166. let adminInfo = {
  167. adminId: buildingAdminId,
  168. buildingName: buildingName,
  169. companyAdminId: companyAdminId,
  170. companyName: res.data[0].companyName,
  171. userWhitelistId: res.data[0].userWhitelistId
  172. };
  173. wx.setStorageSync("adminInfo", adminInfo);
  174. app.data.adminInfo = adminInfo;
  175. my.alert({
  176. title: '提示',
  177. content: '恭喜绑定企业成功~',
  178. complete() {
  179. that.setData({
  180. companyName: companyName
  181. });
  182. iotVspUniqueId(app.data.userInfo.idNumber, app.data.userInfo.username, app.data.userInfo.phone, app.data.userInfo.avatar).then((res) => {
  183. if(res) {
  184. my.navigateBack()
  185. }
  186. })
  187. }
  188. });
  189. } else {
  190. showToast(res.msg);
  191. }
  192. }).finally(() => {
  193. wx.hideLoading();
  194. });
  195. } else {
  196. showToast("请选择所在楼宇");
  197. }
  198. },
  199. // 查找企业
  200. getCompanyList() {
  201. wx.showLoading({
  202. title: "获取企业列表..."
  203. });
  204. this.setData({
  205. companyAdminId: null
  206. });
  207. this.data.companyName = null;
  208. let data = {
  209. adminId: this.data.buildingAdminId
  210. };
  211. getCompanyList(data).then(res => {
  212. wx.hideLoading();
  213. if (res.code === 200) {
  214. let companyIndex = null;
  215. let newCompanyList = [];
  216. if (res.data.length > 0) {
  217. res.data.forEach(item => {
  218. if (item.isCanSearch) {
  219. newCompanyList.push(item);
  220. }
  221. });
  222. if (app.data.temporary_adminInfo) {
  223. let index = res.data.findIndex(item => {
  224. return item.adminId === app.data.temporary_adminInfo.visiteeCompanyId;
  225. });
  226. if (index > -1) {
  227. companyIndex = index;
  228. this.setData({
  229. companyAdminId: res.data[index].adminId
  230. });
  231. this.data.companyName = res.data[index].name;
  232. }
  233. } else if (newCompanyList.length === 1) {
  234. companyIndex = 0;
  235. this.setData({
  236. companyAdminId: newCompanyList[0].adminId
  237. });
  238. this.data.companyName = newCompanyList[0].name;
  239. } else if (app.data.adminInfo) {
  240. let index = res.data.findIndex(item => {
  241. return item.adminId === app.data.adminInfo.companyAdminId;
  242. });
  243. if (index > -1) {
  244. companyIndex = index;
  245. this.setData({
  246. companyAdminId: res.data[index].adminId
  247. });
  248. this.data.companyName = res.data[index].name;
  249. }
  250. }
  251. } else {
  252. showToast("该楼宇下暂无企业");
  253. }
  254. this.canOperation();
  255. this.setData({
  256. companyList: res.data,
  257. companyIndex: companyIndex,
  258. newCompanyList
  259. });
  260. } else {
  261. showToast(res.msg);
  262. }
  263. });
  264. },
  265. // 获取楼宇列表
  266. getBuildingList() {
  267. getBuildingList().then(res => {
  268. let buildingIndex = null;
  269. if (app.data.temporary_adminInfo) {
  270. let index = res.data.findIndex(item => {
  271. return item.adminId === app.data.temporary_adminInfo.visiteeBuildingId;
  272. });
  273. if (index > -1) {
  274. buildingIndex = index;
  275. this.setData({
  276. buildingAdminId: res.data[index].adminId
  277. });
  278. this.data.buildingName = res.data[index].name;
  279. this.getCompanyList();
  280. this.getContextByAdminId(this.data.buildingAdminId);
  281. this.getThreeCodeByAdminId(this.data.buildingAdminId);
  282. }
  283. } else if (res.data.length === 1) {
  284. this.setData({
  285. buildingAdminId: res.data[0].adminId
  286. });
  287. this.data.buildingName = res.data[0].name;
  288. this.getCompanyList();
  289. this.getContextByAdminId(this.data.buildingAdminId);
  290. this.getThreeCodeByAdminId(this.data.buildingAdminId);
  291. buildingIndex = 0;
  292. } else if (app.data.adminInfo) {
  293. let index = res.data.findIndex(item => {
  294. return item.adminId === app.data.adminInfo.adminId;
  295. });
  296. if (index > -1) {
  297. buildingIndex = index;
  298. this.setData({
  299. buildingAdminId: res.data[index].adminId
  300. });
  301. this.data.buildingName = res.data[index].name;
  302. this.getCompanyList();
  303. }
  304. this.getContextByAdminId(this.data.buildingAdminId);
  305. this.getThreeCodeByAdminId(this.data.buildingAdminId);
  306. }
  307. this.setData({
  308. building_list: res.data,
  309. buildingIndex: buildingIndex
  310. });
  311. });
  312. },
  313. //获取是否有自定义字段
  314. getContextByAdminId(orgId) {
  315. return getContextByAdminId(orgId).then(res => {
  316. this.setData({
  317. isShowApplet: res.data,
  318. isFillFields: !res.data
  319. });
  320. this.canOperation();
  321. });
  322. },
  323. // 判断是否填写完成
  324. isFillFields(e) {
  325. this.data.isFillFields = e.detail;
  326. this.canOperation();
  327. },
  328. // 查询三码信息
  329. getThreeCodeByAdminId(adminId) {
  330. getThreeCodeByAdminId({
  331. adminId
  332. }).then(res => {
  333. //暂时关闭常客三码功能-s
  334. res.data.threeCodeList = [];
  335. this.data.isthreeYards = {
  336. hsPhoto: "http://hanghui.oss-cn-gz-ysgzlt-d01-a.ltops.gzdata.com.cn/photo/20221125/66bb7a8feac6425d9b87f57351d4ca08.jpg",
  337. jkm: "绿码",
  338. xc: "1"
  339. };
  340. this.canOperation();
  341. //暂时关闭常客三码功能-d
  342. this.setData({
  343. threeCodeList: res.data.threeCodeList,
  344. hsHour: res.data.hsHour
  345. });
  346. //暂时关闭常客三码功能-s
  347. // if (res.data.threeCodeList.length == 0) {
  348. // this.data.isthreeYards = true
  349. // this.canOperation()
  350. // }
  351. //暂时关闭常客三码功能-d
  352. });
  353. },
  354. // 三码填写内容
  355. isthreeYards(e) {
  356. this.data.isthreeYards = e.detail;
  357. this.canOperation();
  358. },
  359. /**
  360. * 生命周期函数--监听页面加载
  361. */
  362. onLoad: function (options) {
  363. let userInfo = JSON.parse(JSON.stringify(app.data.userInfo));
  364. if (userInfo) {
  365. userInfo.username = desensitization(userInfo.username, 1, 2);
  366. userInfo.idNumber = desensitization(userInfo.idNumber, 6, 14);
  367. userInfo.phone = desensitization(userInfo.phone, 3, 7);
  368. }
  369. this.setData({
  370. language: app.data.language,
  371. userInfo: app.data.language === "ch" ? userInfo : null,
  372. isDisabled: false,
  373. adminInfo: app.data.adminInfo
  374. });
  375. this.getBuildingList();
  376. },
  377. /**
  378. * 生命周期函数--监听页面初次渲染完成
  379. */
  380. onReady: function () {
  381. iotVspInit((res) => {
  382. // my.alert({content: 'iotVspInit-->' + JSON.stringify(res)})
  383. my.navigateBack()
  384. if(res.success) {
  385. setTimeout(() => {
  386. my.navigateBack()
  387. }, 500)
  388. }
  389. })
  390. },
  391. /**
  392. * 生命周期函数--监听页面显示
  393. */
  394. onShow: function () {},
  395. /**
  396. * 生命周期函数--监听页面隐藏
  397. */
  398. onHide: function () {},
  399. /**
  400. * 生命周期函数--监听页面卸载
  401. */
  402. onUnload: function () {},
  403. /**
  404. * 页面相关事件处理函数--监听用户下拉动作
  405. */
  406. onPullDownRefresh: function () {},
  407. /**
  408. * 页面上拉触底事件的处理函数
  409. */
  410. onReachBottom: function () {},
  411. /**
  412. * 用户点击右上角分享
  413. */
  414. onShareAppMessage: function () {},
  415. antmoveAction: function () {
  416. //执行时动态赋值,请勿删除
  417. }
  418. });