index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. import {
  2. getDate,
  3. getWaterDrop,
  4. formatTime
  5. } from '../../../utils/index/index'
  6. import {
  7. publicInterface,
  8. } from '../../../utils/api/api'
  9. const app = getApp()
  10. Page({
  11. data: {
  12. formPath: null, //从哪个页面来
  13. searchList: [{
  14. name: '姓名',
  15. val: 'name',
  16. placeholder: '请输入姓名',
  17. },
  18. {
  19. name: '身份证',
  20. val: 'idNumber',
  21. placeholder: '请输入身份证',
  22. },
  23. {
  24. name: '手机号',
  25. val: 'phone',
  26. placeholder: '请输入手机号',
  27. },
  28. {
  29. name: '来访单位',
  30. val: 'company',
  31. placeholder: '请输入来访单位',
  32. },
  33. {
  34. name: '受访人',
  35. val: 'visiteeXm',
  36. placeholder: '请输入受访人',
  37. },
  38. {
  39. name: '受访部门',
  40. val: 'visiteeBm',
  41. placeholder: '请输入受访部门',
  42. },
  43. ],
  44. isShowSearch: false, // 搜索项
  45. dateRangePickerVisible: false,
  46. searchForm: {
  47. name: '',
  48. phone: '',
  49. idNumber: '',
  50. defaultDateRange: null,
  51. startTime: '',
  52. endTime: '',
  53. sn: '',
  54. company: '',
  55. visiteeXm: '',
  56. visiteeBm: '',
  57. carno: '',
  58. signOutStartTime: '',
  59. signOutEndTime: '',
  60. reason: '',
  61. },
  62. notDesensitizedColumn: [],
  63. signOutList: [{
  64. id: true,
  65. name: '已签离'
  66. },
  67. {
  68. id: false,
  69. name: '未签离'
  70. },
  71. ],
  72. tableList: [], // 表格展示数据
  73. pagination: {
  74. // 分页
  75. current: 1, // 当前页码
  76. pageSize: 8, // 每页条数
  77. pageNum: 0, //总页数
  78. total: 0, // 总数
  79. },
  80. causeMatterList: [],
  81. provinceArr: ["粤", "京", "津", "渝", "沪", "冀", "晋", "辽", "吉", "黑", "苏", "浙", "皖", "闽", "赣", "鲁", "豫", "鄂", "湘", "琼", "川", "贵", "云", "陕", "甘", "青", "蒙", "桂", "宁", "新", "藏", "使", "领", "警", "学", "港", "澳"],
  82. strArr: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"],
  83. hiddenPro: true, // 隐藏省份键盘
  84. hiddenStr: true, // 隐藏数字字母键盘
  85. carnum: '', //车牌号码
  86. // 键盘结束
  87. downBtn: '关闭',
  88. isPortraitScreen: false,// 是否为竖屏:true竖屏 false横屏
  89. screenIntervalId: null, //定时器
  90. },
  91. onLoad(e) {
  92. my.hideBackHome();
  93. const _this = this
  94. this.initScreenType().then(isPortraitScreenRes => {
  95. _this.setData({
  96. isPortraitScreen: isPortraitScreenRes
  97. })
  98. })
  99. let visitReasonList = (app.globalData.snDisposition.visitReason || '业务拜访/会议邀请/施工单位/其他事项').split('/');
  100. this.setData({
  101. causeMatterList: visitReasonList,
  102. formPath: e.formPath || null,
  103. notDesensitizedColumn: app.globalData.snDisposition.notDesensitizedColumn
  104. })
  105. this.data.searchFormCopy = JSON.parse(JSON.stringify(this.data.searchForm));
  106. this.getTable()
  107. },
  108. initScreenType() {
  109. let that = this
  110. return new Promise((resolve, reject) => {
  111. if (app.globalData.isPortraitScreen) {
  112. if (app.globalData.isPortraitScreen != null) {
  113. resolve(app.globalData.isPortraitScreen)
  114. }
  115. } else {
  116. that.data.screenIntervalId = setInterval(function () {
  117. if (app.globalData.isPortraitScreen != null) {
  118. resolve(app.globalData.isPortraitScreen)
  119. clearInterval(that.data.screenIntervalId);
  120. }
  121. }, 1000);
  122. }
  123. })
  124. },
  125. async getTable(newCurrent = 1) {
  126. let {
  127. searchForm,
  128. pagination: { pageSize },
  129. carnum
  130. } = this.data;
  131. searchForm.sn = app.globalData.sn
  132. let params = {
  133. data: {
  134. ...searchForm,
  135. carno: carnum
  136. },
  137. pageNum: newCurrent,
  138. pageSize,
  139. }
  140. my.showLoading()
  141. try {
  142. let res = await publicInterface({
  143. prop: 'fkjRecordUrl',
  144. defaultProp: '/visitorReportPageList',
  145. data: params,
  146. method: 'post',
  147. errorTip: '访客记录api请求失败'
  148. })
  149. const resData = res.data || {}
  150. this.setData({
  151. 'pagination.current': newCurrent,
  152. 'pagination.pageNum': resData.pages,
  153. 'pagination.total': resData.total,
  154. tableList: resData.list,
  155. })
  156. } catch (error) {
  157. my.hideLoading();
  158. console.log(error);
  159. my.showToast({
  160. content: error.msg || '访客记录api请求失败',
  161. duration: 2000
  162. });
  163. } finally {
  164. my.hideLoading()
  165. }
  166. },
  167. // 是否显示搜索项
  168. getIsShow() {
  169. let {
  170. isShowSearch
  171. } = this.data
  172. this.setData({
  173. isShowSearch: !isShowSearch,
  174. })
  175. },
  176. clickAudio() {
  177. getWaterDrop()
  178. },
  179. //签离
  180. async signOff(e) {
  181. let item = e.currentTarget.dataset.item
  182. let data = {
  183. sn: app.globalData.sn,
  184. userVisitorListDetailId: item.userVisitorListDetailId,
  185. }
  186. try {
  187. let res = await publicInterface({
  188. prop: 'fkjSignOutUrl',
  189. defaultProp: '/visitorSignOut',
  190. data: data,
  191. method: 'post',
  192. errorTip: '手动签离api请求失败'
  193. })
  194. my.showToast({
  195. content: '签离成功',
  196. duration: 2000
  197. });
  198. let {
  199. pagination: { current },
  200. } = this.data
  201. this.getTable(current)
  202. } catch (error) {
  203. console.log(error);
  204. my.showToast({
  205. content: error.msg || '手动签离api请求失败',
  206. duration: 2000
  207. });
  208. }
  209. },
  210. getVal(e) {
  211. let key = e.currentTarget.dataset.key
  212. let searchFormKey = `searchForm[${key}]`
  213. let causeMatterList = this.data.causeMatterList
  214. let signOutList = this.data.signOutList
  215. switch (key) {
  216. case 'reason':
  217. this.setData({
  218. 'searchForm.reason': causeMatterList[e.detail.value],
  219. })
  220. break;
  221. case 'isSignOut':
  222. this.setData({
  223. 'searchForm.isSignOut': signOutList[e.detail.value].id,
  224. 'searchForm.isSignOutName': signOutList[e.detail.value].name,
  225. })
  226. break;
  227. default:
  228. this.setData({
  229. [searchFormKey]: e.detail.value
  230. })
  231. break;
  232. }
  233. },
  234. // 获取日期
  235. datePicker(e) {
  236. my.datePicker({
  237. format: 'yyyy-MM-dd HH:mm:ss', //返回的日期格式
  238. currentDate: getDate(), //初始选择的日期时间,默认当前时间
  239. startDate: '2012-01-01 11:11:11', //最小日期时间
  240. endDate: getDate(), //最大日期时间
  241. success: res => {
  242. let key = e.currentTarget.dataset.key
  243. this.setData({
  244. [`searchForm.${key}`]: res.date
  245. });
  246. },
  247. });
  248. },
  249. // 查询
  250. inquireFun() {
  251. my.showLoading()
  252. try {
  253. this.setData({
  254. 'pagination.current': 1,
  255. })
  256. this.getTable()
  257. } catch (error) {
  258. console.log(error);
  259. } finally {
  260. my.hideLoading()
  261. }
  262. },
  263. //清空
  264. clearFun() {
  265. let searchForm = JSON.parse(JSON.stringify(this.data.searchFormCopy));
  266. console.log(searchForm)
  267. this.setData({
  268. searchForm,
  269. carnum: '',
  270. hiddenPro: true, // 隐藏省份键盘
  271. hiddenStr: true, // 隐藏数字字母键盘
  272. downBtn: '关闭',
  273. })
  274. this.getTable()
  275. },
  276. // 上一页
  277. previousFun() {
  278. let {
  279. pagination: { current },
  280. } = this.data
  281. if (current <= 1) {
  282. return
  283. }
  284. let newCurrent = current - 1;
  285. this.getTable(newCurrent)
  286. },
  287. // 下一页
  288. nextFun() {
  289. let {
  290. pagination: { pageNum, current },
  291. } = this.data
  292. if (current >= pageNum) {
  293. return
  294. }
  295. let newCurrent = current + 1;
  296. this.getTable(newCurrent)
  297. },
  298. handleTriggerControlledDateRangePicker(visible, e) {
  299. console.log('handleTriggerControlledDateRangePicker', visible, e);
  300. this.setData({
  301. dateRangePickerVisible: visible,
  302. });
  303. },
  304. handleRangeOk(date, format, e) {
  305. console.log('onRangeOk', date, format, e);
  306. this.setData({
  307. 'searchForm.startTime': formatTime(date[0], 'YYYY-MM-DD HH:NN:SS'),
  308. 'searchForm.endTime': formatTime(date[1], 'YYYY-MM-DD HH:NN:SS'),
  309. 'searchForm.defaultDateRange': date,
  310. })
  311. },
  312. // 关闭
  313. closeFun() {
  314. my.reLaunch({
  315. url: this.data.formPath ? '/pages/home/index' : '/pages/settings/index/index',
  316. })
  317. },
  318. // 键盘函数开始
  319. proTap(e) { //点击省份
  320. let that = this;
  321. let province = e.currentTarget.dataset.province;
  322. let carnum = this.data.carnum;
  323. if (carnum.length < 1) { //避免连续点击
  324. carnum += province;
  325. }
  326. this.setData({
  327. carnum: carnum,
  328. hiddenPro: true,
  329. hiddenStr: false,
  330. })
  331. },
  332. strTap(e) { //点击字母数字
  333. let that = this;
  334. this.setData({
  335. waiting: true
  336. })
  337. let province = e.currentTarget.dataset.str;
  338. let carnum = this.data.carnum;
  339. // console.log(carnum.length)
  340. if (carnum.length <= 8) { //避免连续点击
  341. carnum += province;
  342. console.log(carnum);
  343. }
  344. this.setData({
  345. notNum: false,
  346. carnum: carnum,
  347. })
  348. this.setData({
  349. notNum: false,
  350. carnum: carnum,
  351. })
  352. setTimeout(() => {
  353. that.setData({
  354. waiting: false
  355. })
  356. }, 100);
  357. if (carnum.length > 6) {
  358. this.setData({
  359. downBtn: '完成',
  360. strDisabled: true,
  361. })
  362. // this.searchCardInfo()
  363. return; // 车牌长度最多为7个
  364. }
  365. },
  366. backSpace() { //退格
  367. let carnum = this.data.carnum;
  368. if (carnum.length <= 7) {
  369. this.setData({
  370. downBtn: '关闭',
  371. strDisabled: false,
  372. })
  373. }
  374. var arr = carnum.split('');
  375. arr.splice(-1, 1)
  376. var str = arr.join('')
  377. if (arr.length < 2) {
  378. this.setData({
  379. notNum: true
  380. })
  381. }
  382. if (str == '') {
  383. this.setData({
  384. hiddenPro: false,
  385. hiddenStr: true
  386. })
  387. }
  388. this.setData({
  389. carnum: str
  390. })
  391. },
  392. backKeyboard() { //返回省份键盘
  393. if (this.data.carnum.length > 6) {
  394. this.setData({
  395. downBtn: '完成',
  396. hiddenPro: true,
  397. hiddenStr: false
  398. })
  399. } else if (this.data.carnum.length > 0) {
  400. this.setData({
  401. hiddenPro: true,
  402. hiddenStr: false
  403. })
  404. } else {
  405. this.setData({
  406. hiddenPro: false,
  407. hiddenStr: true
  408. })
  409. }
  410. },
  411. applyNum() {
  412. this.setData({
  413. hiddenPro: true,
  414. hiddenStr: true,
  415. })
  416. },
  417. // 点击其他地方关闭弹窗
  418. hidePopup() {
  419. if (!this.data.hiddenPro || !this.data.hiddenStr) {
  420. this.applyNum();
  421. }
  422. },
  423. });