index.js 12 KB

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