index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import {
  2. getDate,
  3. getWaterDrop,
  4. } from '../../../utils/index/index'
  5. import {
  6. visitorReportPageList,
  7. visitorSignOut
  8. } from '../../../utils/api/api'
  9. const app = getApp()
  10. Page({
  11. data: {
  12. formPath: null, //从哪个页面来
  13. tableList: [],
  14. searchForm: {
  15. data: {
  16. name: '',
  17. phone: '',
  18. idNumber: '',
  19. company: '',// 来访单位
  20. visiteeXm: '',// 来访人
  21. visiteeBm: '',// 来访人部门
  22. carno: '',
  23. startTime: '',
  24. endTime: '',
  25. signOutStartTime: '',
  26. signOutEndTime: '',
  27. reason: '', // 事由
  28. sn: '',
  29. },
  30. pageNum: 1,
  31. pageSize: 9,
  32. },
  33. total: null,
  34. allPageNum: 0,
  35. notDesensitizedColumn: [],
  36. signOutList: [{
  37. id: true,
  38. name: '已签离'
  39. },
  40. {
  41. id: false,
  42. name: '未签离'
  43. },
  44. ],
  45. causeMatterList: []
  46. },
  47. onLoad(e) {
  48. my.hideBackHome();
  49. let visitReasonList = (app.globalData.snDisposition.visitReason || '业务拜访/会议邀请/施工单位/其他事项').split('/');
  50. this.setData({
  51. causeMatterList: visitReasonList,
  52. formPath: e.formPath || null,
  53. notDesensitizedColumn: app.globalData.snDisposition.notDesensitizedColumn
  54. })
  55. this.data.searchFormCopy = JSON.parse(JSON.stringify(this.data.searchForm));
  56. this.getTable()
  57. },
  58. async getTable() {
  59. let {
  60. searchForm,
  61. } = this.data;
  62. searchForm.data.sn = app.globalData.sn
  63. my.showLoading()
  64. try {
  65. let res = await visitorReportPageList(searchForm)
  66. this.setData({
  67. tableList: res.data.list,
  68. total: res.data.total,
  69. allPageNum: Math.ceil(res.data.total / searchForm.pageSize)
  70. })
  71. my.hideLoading();
  72. } catch (error) {
  73. my.hideLoading();
  74. }
  75. },
  76. clickAudio() {
  77. getWaterDrop()
  78. },
  79. //签离
  80. async signOff(e) {
  81. let item = e.currentTarget.dataset.item
  82. let data = {
  83. sn: app.globalData.sn,
  84. userVisitorListDetailId: item.userVisitorListDetailId,
  85. }
  86. let res = await visitorSignOut(data)
  87. my.showToast({
  88. content: '签离成功',
  89. duration: 2000
  90. });
  91. this.getTable()
  92. },
  93. getVal(e) {
  94. let key = e.currentTarget.dataset.key
  95. let key1 = `searchForm.data[${key}]`
  96. let signOutList = this.data.signOutList
  97. let causeMatterList = this.data.causeMatterList
  98. console.log(e.detail.value, causeMatterList[e.detail.value])
  99. switch (key) {
  100. case 'reason':
  101. this.setData({
  102. 'searchForm.data.reason': causeMatterList[e.detail.value],
  103. })
  104. break;
  105. case 'isSignOut':
  106. this.setData({
  107. 'searchForm.data.isSignOut': signOutList[e.detail.value].id,
  108. 'searchForm.data.isSignOutName': signOutList[e.detail.value].name,
  109. })
  110. break;
  111. default:
  112. this.setData({
  113. [key1]: e.detail.value
  114. })
  115. break;
  116. }
  117. },
  118. // 获取日期
  119. datePicker(e) {
  120. my.datePicker({
  121. format: 'yyyy-MM-dd HH:mm:ss', //返回的日期格式
  122. currentDate: getDate(), //初始选择的日期时间,默认当前时间
  123. startDate: '2012-01-01 11:11:11', //最小日期时间
  124. endDate: getDate(), //最大日期时间
  125. success: res => {
  126. let key = e.currentTarget.dataset.key
  127. this.setData({
  128. [`searchForm.data.${key}`]: res.date
  129. });
  130. },
  131. });
  132. },
  133. //清空
  134. clearFun() {
  135. let searchForm = JSON.parse(JSON.stringify(this.data.searchFormCopy));
  136. this.setData({
  137. searchForm
  138. })
  139. this.getTable()
  140. },
  141. // 上一页
  142. previousFun() {
  143. let {
  144. searchForm,
  145. } = this.data
  146. if (searchForm.pageNum <= 1) {
  147. return
  148. }
  149. this.setData({
  150. 'searchForm.pageNum': searchForm.pageNum - 1,
  151. })
  152. this.getTable()
  153. },
  154. // 下一页
  155. nextFun() {
  156. let {
  157. searchForm,
  158. allPageNum,
  159. } = this.data
  160. if (searchForm.pageNum >= allPageNum) {
  161. return
  162. }
  163. this.setData({
  164. 'searchForm.pageNum': searchForm.pageNum + 1,
  165. })
  166. this.getTable()
  167. },
  168. // 关闭
  169. closeFun() {
  170. let url = this.data.formPath ? '/pages/home/index' : '/pages/settings/index/index'
  171. my.reLaunch({
  172. url: url
  173. });
  174. },
  175. });