index.js 9.8 KB

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