index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. import { snConfig, updateConfig } from '../../../utils/api/api'
  2. import { getWaterDrop, throttle } from '../../../utils/index/index'
  3. const app = getApp()
  4. Page({
  5. data: {
  6. radioList: [{
  7. name: '是否打印访客单',
  8. val: 'printVisitorList',
  9. chooseItem: [],
  10. },
  11. {
  12. name: '是否启用签离',
  13. val: 'signOut',
  14. chooseItem: [],
  15. },
  16. {
  17. name: '启用风险人员核查',
  18. val: 'riskCheck',
  19. chooseItem: [],
  20. },
  21. {
  22. name: '首页隐藏 通讯录、访客记录 等按钮',
  23. val: 'hiddenButton',
  24. chooseItem: [],
  25. },
  26. // {
  27. // name: '隐藏底部导航栏',
  28. // val: 'hideNavigationBar',
  29. // chooseItem: [],
  30. // },
  31. {
  32. name: '启用注意事项提示语',
  33. val: 'reminderAuth',
  34. chooseItem: [],
  35. },
  36. ],
  37. checkBoxList: [{
  38. name: '访客记录不脱敏',
  39. val: 'notDesensitizedColumn',
  40. chooseItem: [{
  41. value: 1,
  42. name: '姓名',
  43. checked: false
  44. },
  45. {
  46. value: 2,
  47. name: '身份证',
  48. checked: false
  49. },
  50. {
  51. value: 3,
  52. name: '手机',
  53. checked: false
  54. }],
  55. },
  56. {
  57. name: '登记页不脱敏',
  58. val: 'registerNotDesensitizedColumn',
  59. chooseItem: [{
  60. value: 1,
  61. name: '姓名',
  62. checked: false
  63. },
  64. {
  65. value: 2,
  66. name: '身份证',
  67. checked: false
  68. },],
  69. },
  70. ],
  71. form: {
  72. printVisitorList: false, // 是否打印访客单
  73. signOut: true, // 是否启用签离
  74. riskCheck: false, // 启用风险人员核查
  75. hiddenButton: false, // 首页隐藏设置、通讯录等按钮
  76. // hideNavigationBar: false, // 隐藏底部导航栏
  77. reminderAuth: false, // 启用注意事项提示语
  78. generalQrcode: true, // 启用通用二维码
  79. generalQrcodeTitle: "", // 通用二维码标题
  80. ethQrcode: true, // 启用梯控二维码
  81. ethQrcodeTitle: "梯控二维码", // 梯控二维码标题
  82. ethQrcodeUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/api/v1/fkj/visitor/eth/qrCode", // 梯控二维码接口
  83. notDesensitizedColumn: [], // 访客记录不脱敏
  84. registerNotDesensitizedColumn: [], // 登记页不脱敏
  85. confirmCountdownSwitch: true, // 是否启用确定倒计时
  86. confirmCountdownTime: 15,
  87. },
  88. // 梯控
  89. isShowTK: false,
  90. TKList: ['https://tx.hz-hanghui.com:8088/yx-fyzd/api/v1/fkj/visitor/eth/qrCode'],
  91. isPortraitScreen: false,// 是否为竖屏:true竖屏 false横屏
  92. screenIntervalId: null, //定时器
  93. },
  94. async onLoad() {
  95. my.hideBackHome();
  96. const _this = this
  97. this.initScreenType().then(isPortraitScreenRes => {
  98. console.log('isPortraitScreenRes', isPortraitScreenRes)
  99. _this.setData({
  100. isPortraitScreen: isPortraitScreenRes
  101. })
  102. })
  103. await this.initRadioDefaultData()
  104. await this.initData()
  105. // my.showLoading()
  106. },
  107. initScreenType() {
  108. let that = this
  109. return new Promise((resolve, reject) => {
  110. if (app.globalData.isPortraitScreen) {
  111. if (app.globalData.isPortraitScreen != null) {
  112. resolve(app.globalData.isPortraitScreen)
  113. }
  114. } else {
  115. that.data.screenIntervalId = setInterval(function () {
  116. console.log('asdasdsaddasdad', app.globalData)
  117. if (app.globalData.isPortraitScreen != null) {
  118. resolve(app.globalData.isPortraitScreen)
  119. clearInterval(that.data.screenIntervalId);
  120. }
  121. }, 1000);
  122. }
  123. })
  124. },
  125. // 赋值
  126. async initData(e) {
  127. my.showLoading()
  128. try {
  129. let dto = {
  130. sn: app.globalData.sn,
  131. token: app.globalData.FKJConfiguration,
  132. }
  133. let res = await snConfig(dto);
  134. let resultData = res.data || {}
  135. console.log(resultData)
  136. let {
  137. radioList,
  138. checkBoxList
  139. } = this.data
  140. radioList.forEach((radioItem) => {
  141. if (typeof (resultData[radioItem.val]) !== 'undefined') {
  142. let checkValue = !!resultData[radioItem.val]
  143. radioItem.chooseItem[0].checked = checkValue
  144. radioItem.chooseItem[1].checked = !checkValue
  145. }
  146. });
  147. checkBoxList.forEach((checkBoxItem) => {
  148. if (typeof (resultData[checkBoxItem.val]) !== 'undefined') {
  149. let checkValue = resultData[checkBoxItem.val]
  150. checkBoxItem.chooseItem.forEach((cItem, cIndex) => {
  151. cItem.checked = checkValue.includes(cItem.value);
  152. })
  153. }
  154. });
  155. this.setData({
  156. radioList,
  157. checkBoxList,
  158. form: resultData
  159. })
  160. } catch (error) { } finally {
  161. my.hideLoading()
  162. }
  163. },
  164. // 处理单选默认数据
  165. initRadioDefaultData() {
  166. let options = [{
  167. value: true,
  168. name: '是',
  169. checked: false
  170. },
  171. {
  172. value: false,
  173. name: '否',
  174. checked: false
  175. },
  176. ]
  177. let {
  178. radioList,
  179. checkBoxList
  180. } = this.data
  181. radioList.forEach(radioItem => {
  182. radioItem.chooseItem = JSON.parse(JSON.stringify(options))
  183. let isTrue = ['signOut', 'generalQrcode', 'ethQrcode'].includes(radioItem.val)
  184. radioItem.chooseItem[0].checked = isTrue
  185. radioItem.chooseItem[1].checked = !isTrue
  186. });
  187. checkBoxList.forEach((checkBoxItem) => {
  188. checkBoxItem.chooseItem.forEach((cItem, cIndex) => {
  189. cItem.checked = false;
  190. })
  191. });
  192. this.setData({
  193. checkBoxList,
  194. radioList
  195. })
  196. },
  197. // 单选选中
  198. onRadioChange(e) {
  199. console.log('onRadioChange', e)
  200. let currentItem = e.currentTarget.dataset.item;
  201. let currentIndex = e.currentTarget.dataset.index;
  202. let checkIndex = e.currentTarget.dataset.checkIndex;
  203. let checkValue = false;
  204. currentItem.chooseItem.forEach((cItem, cIndex) => {
  205. if (cIndex == currentIndex) {
  206. cItem.checked = true
  207. checkValue = cItem.value
  208. } else {
  209. cItem.checked = false
  210. }
  211. })
  212. console.log(currentItem.chooseItem, currentFormItem)
  213. let currentRadioItem = `[radioList[${checkIndex}]]`;
  214. let currentFormItem = `form[${currentItem.val}]`;
  215. this.setData({
  216. [currentRadioItem]: currentItem,
  217. [currentFormItem]: checkValue
  218. })
  219. },
  220. // 多选选中
  221. onCheckBoxChange(e) {
  222. console.log(e)
  223. let currentItem = e.currentTarget.dataset.item;
  224. let currentIndex = e.currentTarget.dataset.index;
  225. let checkIndex = e.currentTarget.dataset.checkIndex;
  226. currentItem.chooseItem.forEach((cItem, cIndex) => {
  227. if (cIndex == currentIndex) {
  228. cItem.checked = !cItem.checked
  229. }
  230. })
  231. let checkValue = (currentItem.chooseItem || []).filter(v => v.checked).map(mI => mI.value);
  232. let currentCheckBoxItem = `[checkBoxList[${checkIndex}]]`;
  233. let currentFormItem = `form[${currentItem.val}]`;
  234. this.setData({
  235. [currentCheckBoxItem]: currentItem,
  236. [currentFormItem]: checkValue
  237. })
  238. },
  239. onSwitchChange(e) {
  240. let key = e.currentTarget.dataset.fieldKey
  241. let value = e.currentTarget.dataset.checked
  242. console.log(key, value)
  243. let checkValue = !value
  244. let forKey = `form[${key}]`
  245. switch (key) {
  246. case 'generalQrcode': // 启用通用二维码
  247. if (!checkValue) {
  248. this.setData({
  249. 'form.generalQrcodeTitle': '', // 通用二维码标题
  250. })
  251. }
  252. this.setData({
  253. [forKey]: checkValue
  254. })
  255. break;
  256. case 'ethQrcode': // 启用梯控二维码
  257. if (checkValue) {
  258. this.setData({
  259. 'form.ethQrcodeTitle': '梯控二维码', // 梯控二维码标题
  260. 'form.ethQrcodeUrl': 'https://tx.hz-hanghui.com:8088/yx-fyzd/api/v1/fkj/visitor/eth/qrCode', // 梯控二维码接口
  261. })
  262. }
  263. this.setData({
  264. [forKey]: checkValue
  265. })
  266. break;
  267. case 'confirmCountdownSwitch': // 标语页确定倒计时
  268. if (!checkValue) {
  269. this.setData({
  270. 'form.confirmCountdownTime': 15
  271. })
  272. }
  273. this.setData({
  274. [forKey]: checkValue
  275. })
  276. break;
  277. }
  278. },
  279. // 减
  280. minus(e) {
  281. let key = 'confirmCountdownTime'
  282. let value = this.data.form[key]
  283. let NameVal = `form[${key}]`
  284. if (value <= 0 || !value) {
  285. return
  286. }
  287. this.setData({
  288. [NameVal]: value - 1
  289. })
  290. },
  291. // 加
  292. add(e) {
  293. let key = 'confirmCountdownTime'
  294. let value = this.data.form[key]
  295. if (!value) {
  296. value = 0
  297. }
  298. let NameVal = `form[${key}]`
  299. this.setData({
  300. [NameVal]: value + 1
  301. })
  302. },
  303. // 二维码相关字段选中操作
  304. getVal(e) {
  305. let key = e.currentTarget.dataset.key
  306. let val = e.currentTarget.dataset.val
  307. console.log(key, val)
  308. let checkValue = e.detail.value
  309. let forKey = `form[${key}]`
  310. switch (key) {
  311. case 'TK':
  312. this.setData({
  313. 'form.ethQrcodeUrl': val
  314. })
  315. break;
  316. case 'generalQrcode': // 启用通用二维码
  317. if (!checkValue) {
  318. this.setData({
  319. 'form.generalQrcodeTitle': '', // 通用二维码标题
  320. })
  321. }
  322. this.setData({
  323. [forKey]: checkValue
  324. })
  325. break;
  326. case 'ethQrcode': // 启用梯控二维码
  327. if (checkValue) {
  328. this.setData({
  329. 'form.ethQrcodeTitle': '梯控二维码', // 梯控二维码标题
  330. 'form.ethQrcodeUrl': 'https://tx.hz-hanghui.com:8088/yx-fyzd/api/v1/fkj/visitor/eth/qrCode', // 梯控二维码接口
  331. })
  332. }
  333. this.setData({
  334. [forKey]: checkValue
  335. })
  336. break;
  337. case 'generalQrcodeTitle': // 通用二维码标题
  338. case 'ethQrcodeTitle': // 梯控二维码标题
  339. case 'ethQrcodeUrl': // 梯控二维码接口
  340. case 'confirmCountdownTime': // 倒计时时长(s)
  341. this.setData({
  342. [forKey]: checkValue
  343. })
  344. break;
  345. }
  346. },
  347. // 遮罩层
  348. closeMask() {
  349. this.setData({
  350. isShowTK: false,
  351. })
  352. },
  353. // 打开选择框
  354. openMask(e) {
  355. let key = e.currentTarget.dataset.key
  356. switch (key) {
  357. case 'TK':
  358. let {
  359. isShowTK
  360. } = this.data
  361. this.setData({
  362. isShowTK: !isShowTK
  363. })
  364. break;
  365. default:
  366. break;
  367. }
  368. },
  369. clickAudio() {
  370. this.setData({
  371. isShowTK: false,
  372. })
  373. getWaterDrop()
  374. },
  375. sure: throttle(async function (e) {
  376. let {
  377. form
  378. } = this.data
  379. console.log(form)
  380. form.modifyType = app.globalData.modifyType[0];
  381. form.token = app.globalData.FKJConfiguration;
  382. form.sn = app.globalData.sn;
  383. my.showLoading()
  384. try {
  385. let res = await updateConfig(form)
  386. app.globalData.snDisposition.printVisitorList = form.printVisitorList;
  387. app.globalData.snDisposition.signOut = form.signOut;
  388. app.globalData.snDisposition.riskCheck = form.riskCheck;
  389. app.globalData.snDisposition.hiddenButton = form.hiddenButton;
  390. app.globalData.snDisposition.reminderAuth = form.reminderAuth;
  391. app.globalData.snDisposition.generalQrcode = form.generalQrcode;
  392. app.globalData.snDisposition.generalQrcodeTitle = form.generalQrcodeTitle;
  393. app.globalData.snDisposition.ethQrcode = form.ethQrcode;
  394. app.globalData.snDisposition.ethQrcodeTitle = form.ethQrcodeTitle;
  395. app.globalData.snDisposition.ethQrcodeUrl = form.ethQrcodeUrl;
  396. app.globalData.snDisposition.notDesensitizedColumn = form.notDesensitizedColumn;
  397. app.globalData.snDisposition.registerNotDesensitizedColumn = form.registerNotDesensitizedColumn;
  398. app.globalData.snDisposition.confirmCountdownSwitch = form.confirmCountdownSwitch;
  399. app.globalData.snDisposition.confirmCountdownTime = form.confirmCountdownTime;
  400. // console.log(app.globalData.snDisposition);
  401. my.setStorageSync({
  402. data: app.globalData.snDisposition,
  403. key: 'snDisposition'
  404. });
  405. my.reLaunch({
  406. url: "/pages/settings/index/index"
  407. })
  408. } catch (error) {
  409. console.log(error);
  410. } finally {
  411. my.hideLoading()
  412. }
  413. }, 5000),
  414. });