index.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. import {
  2. updateConfig,
  3. snConfig
  4. } from '../../../utils/api/api'
  5. import { getWaterDrop } from '../../../utils/index/index'
  6. const app = getApp()
  7. Page({
  8. data: {
  9. chooseObj: {
  10. usePersonCard: {
  11. chooseItem: [{
  12. name: '是',
  13. checked: true,
  14. value: true,
  15. },
  16. {
  17. name: '否',
  18. checked: false,
  19. value: false,
  20. },
  21. ],
  22. },
  23. noIdcardInputPhone: {
  24. chooseItem: [{
  25. name: '是',
  26. checked: true,
  27. value: true,
  28. },
  29. {
  30. name: '否',
  31. checked: false,
  32. value: false,
  33. },
  34. ],
  35. }
  36. },
  37. form: {},
  38. // 获取受访人列表地址
  39. isShowInterviewee: false,
  40. IntervieweeList: ['https://tx.hz-hanghui.com:8088/yx-fyzd/api/v1/fkj/visitee/list', 'https://noise.hz-hanghui.com:8088/yx-fyzd/api/v1/fkj/visitee/list'],
  41. // 访客记录推送地址
  42. isShowVisitorLog: false,
  43. VisitorLogList: ['https://tx.hz-hanghui.com:8088/yx-fyzd/VisitorRecords', 'https://noise.hz-hanghui.com:8088/yx-fyzd/VisitorRecords'],
  44. // 微信二维码地址
  45. isShowWx: false,
  46. WXList: ['https://tx.hz-hanghui.com:8088/yx-fyzd/faceCheckVisitor?type=2', 'https://noise.hz-hanghui.com:8088/yx-fyzd/faceCheckVisitor?type=2'],
  47. // 支付宝二维码地址
  48. isShowZfb: false,
  49. ZFBList: ['https://tx.hz-hanghui.com:8088/yx-fyzd/faceCheckVisitor?type=2', 'https://noise.hz-hanghui.com:8088/yx-fyzd/faceCheckVisitor?type=2'],
  50. isPortraitScreen: false,// 是否为竖屏:true竖屏 false横屏
  51. screenIntervalId: null, //定时器
  52. },
  53. onLoad() {
  54. my.hideBackHome();
  55. const _this = this
  56. this.initScreenType().then(isPortraitScreenRes => {
  57. console.log('isPortraitScreenRes', isPortraitScreenRes)
  58. _this.setData({
  59. isPortraitScreen: isPortraitScreenRes
  60. })
  61. })
  62. this.getForm()
  63. },
  64. initScreenType() {
  65. let that = this
  66. return new Promise((resolve, reject) => {
  67. if (app.globalData.isPortraitScreen) {
  68. if (app.globalData.isPortraitScreen != null) {
  69. resolve(app.globalData.isPortraitScreen)
  70. }
  71. } else {
  72. that.data.screenIntervalId = setInterval(function () {
  73. console.log('asdasdsaddasdad', app.globalData)
  74. if (app.globalData.isPortraitScreen != null) {
  75. resolve(app.globalData.isPortraitScreen)
  76. clearInterval(that.data.screenIntervalId);
  77. }
  78. }, 1000);
  79. }
  80. })
  81. },
  82. // 赋值
  83. async getForm(e) {
  84. my.showLoading()
  85. try {
  86. let dto = {
  87. sn: app.globalData.sn,
  88. token: app.globalData.FKJConfiguration,
  89. }
  90. let res = await snConfig(dto)
  91. let resultData = res.data || {}
  92. this.setData({
  93. form: resultData
  94. })
  95. let newObj = {
  96. usePersonCard: {
  97. chooseItem: []
  98. },
  99. noIdcardInputPhone: {
  100. chooseItem: []
  101. }
  102. }
  103. Object.keys(this.data.chooseObj).forEach((chooseKey) => {
  104. let chooseItemArr = this.data.chooseObj[chooseKey].chooseItem || []
  105. if (typeof (resultData[chooseKey]) !== 'undefined') {
  106. let checkValue = !!resultData[chooseKey]
  107. chooseItemArr[0].checked = checkValue
  108. chooseItemArr[1].checked = !checkValue
  109. }
  110. newObj[chooseKey].chooseItem = chooseItemArr
  111. });
  112. this.setData({
  113. chooseObj: newObj
  114. })
  115. } catch (error) { } finally {
  116. my.hideLoading()
  117. }
  118. },
  119. // 单选选中
  120. onRadioChange(e) {
  121. let currentItem = e.currentTarget.dataset.item;
  122. let currentIndex = e.currentTarget.dataset.index;
  123. let fieldKey = e.currentTarget.dataset.fieldKey;
  124. console.log('onRadioChange', currentItem, currentIndex, fieldKey)
  125. let checkValue = false;
  126. let chooseItemArr = this.data.chooseObj[fieldKey].chooseItem || []
  127. chooseItemArr.forEach((cItem, cIndex) => {
  128. if (cIndex == currentIndex) {
  129. cItem.checked = true
  130. checkValue = cItem.value
  131. } else {
  132. cItem.checked = false
  133. }
  134. })
  135. console.log(currentItem, chooseItemArr)
  136. this.setData({
  137. [`form.${fieldKey}`]: checkValue,
  138. [`chooseObj.${fieldKey}.chooseItem`]: chooseItemArr
  139. })
  140. },
  141. onSwitchChange(e) {
  142. let key = e.currentTarget.dataset.fieldKey
  143. let value = e.currentTarget.dataset.checked
  144. let checkValue = !value
  145. let forKey = `form[${key}]`
  146. switch (key) {
  147. case 'useAlipayFace': // 启用支付宝刷脸登记
  148. case 'useIdcard': // 启用刷身份证登记
  149. case 'noIdcardRegister': // 启用无证登记
  150. case 'wxScanRegister': // 启用微信扫码登记
  151. case 'zfbScanRegister': // 启用支付宝扫码登记
  152. this.setData({
  153. [forKey]: checkValue
  154. })
  155. break;
  156. case 'ethQrcode': // 启用梯控二维码
  157. if (checkValue) {
  158. this.setData({
  159. 'form.ethQrcodeTitle': '梯控二维码', // 梯控二维码标题
  160. 'form.ethQrcodeUrl': 'https://tx.hz-hanghui.com:8088/yx-fyzd/api/v1/fkj/visitor/eth/qrCode', // 梯控二维码接口
  161. })
  162. }
  163. this.setData({
  164. [forKey]: checkValue
  165. })
  166. break;
  167. }
  168. },
  169. getVal(e) {
  170. let key = e.currentTarget.dataset.key
  171. let name = e.currentTarget.dataset.name
  172. let key1 = `form[${key}]`
  173. switch (key) {
  174. case 'transitPushUrl':
  175. this.setData({
  176. [key1]: name
  177. })
  178. break;
  179. case 'visiteeUrl':
  180. this.setData({
  181. [key1]: name
  182. })
  183. break;
  184. case 'zfbQrcodeUrl':
  185. this.setData({
  186. [key1]: name
  187. })
  188. break;
  189. case 'wxQrcodeUrl':
  190. this.setData({
  191. [key1]: name
  192. })
  193. break;
  194. default:
  195. this.setData({
  196. [key1]: e.detail.value
  197. })
  198. break;
  199. }
  200. },
  201. // 遮罩层
  202. closeMask() {
  203. getWaterDrop()
  204. this.setData({
  205. isShowInterviewee: false,
  206. isShowVisitorLog: false,
  207. isShowWx: false,
  208. isShowZfb: false,
  209. })
  210. },
  211. openChoose(e) {
  212. this.setData({
  213. isShowVisitorLog: false,
  214. isShowInterviewee: false,
  215. isShowWx: false,
  216. isShowZfb: false,
  217. })
  218. let key = e.currentTarget.dataset.key
  219. switch (key) {
  220. case 'transitPushUrl':
  221. this.setData({
  222. isShowVisitorLog: !this.data.isShowVisitorLog
  223. })
  224. break;
  225. case 'visiteeUrl':
  226. this.setData({
  227. isShowInterviewee: !this.data.isShowInterviewee
  228. })
  229. break;
  230. case 'wxQrcodeUrl':
  231. this.setData({
  232. isShowWx: !this.data.isShowWx
  233. })
  234. break;
  235. case 'zfbQrcodeUrl':
  236. this.setData({
  237. isShowZfb: !this.data.isShowZfb
  238. })
  239. break;
  240. default:
  241. break;
  242. }
  243. },
  244. async sure() {
  245. let {
  246. form
  247. } = this.data
  248. form.modifyType = app.globalData.modifyType[1],
  249. form.token = app.globalData.FKJConfiguration
  250. my.showLoading()
  251. try {
  252. // 以下字段根据切换条件重置为默认值
  253. const fieldArr = [
  254. 'useIdcard', 'noIdcardRegister', 'wxScanRegister', 'zfbScanRegister'
  255. ]
  256. fieldArr.forEach(field => {
  257. const fieldValue = form[field]
  258. switch (field) {
  259. // 启用身份证功能
  260. case 'useIdcard':
  261. if (!fieldValue) {
  262. form = {
  263. ...form,
  264. usePersonCard: true // 刷证是否人证比对 默认值:true
  265. }
  266. }
  267. break
  268. // 启用无证登记
  269. case 'noIdcardRegister':
  270. if (!fieldValue) {
  271. form = {
  272. ...form,
  273. noIdcardInputPhone: true // 无证是否输入手机号 默认值:true
  274. }
  275. }
  276. break
  277. // 启用微信扫码登记
  278. case 'wxScanRegister':
  279. if (!fieldValue) {
  280. form = {
  281. ...form,
  282. wxQrcodeUrl: '' // 微信二维码地址
  283. }
  284. }
  285. break
  286. // 启用支付宝扫码登记
  287. case 'zfbScanRegister':
  288. if (!fieldValue) {
  289. form = {
  290. ...form,
  291. zfbQrcodeUrl: '' // 支付宝二维码地址
  292. }
  293. }
  294. break
  295. }
  296. })
  297. let res = await updateConfig(form)
  298. app.globalData.snDisposition.useAlipayFace = form.useAlipayFace;
  299. app.globalData.snDisposition.useIdcard = form.useIdcard;
  300. app.globalData.snDisposition.usePersonCard = form.usePersonCard;
  301. app.globalData.snDisposition.noIdcardRegister = form.noIdcardRegister;
  302. app.globalData.snDisposition.noIdcardInputPhone = form.noIdcardInputPhone;
  303. app.globalData.snDisposition.wxScanRegister = form.wxScanRegister;
  304. app.globalData.snDisposition.wxQrcodeUrl = form.wxQrcodeUrl;
  305. app.globalData.snDisposition.zfbScanRegister = form.zfbScanRegister;
  306. app.globalData.snDisposition.zfbQrcodeUrl = form.zfbQrcodeUrl;
  307. app.globalData.snDisposition.transitPushUrl = form.transitPushUrl;
  308. app.globalData.snDisposition.visiteeUrl = form.visiteeUrl;
  309. // console.log(app.globalData.snDisposition);
  310. my.setStorageSync({
  311. data: app.globalData.snDisposition,
  312. key: 'snDisposition'
  313. });
  314. my.reLaunch({
  315. url: "/pages/settings/index/index"
  316. })
  317. } catch (error) {
  318. console.log(error);
  319. } finally {
  320. my.hideLoading()
  321. }
  322. },
  323. });