index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <div class="main-container">
  3. <ibps-container
  4. class="page"
  5. >
  6. <template>
  7. <ibps-crud
  8. key="istree"
  9. ref="crud"
  10. :data="listData"
  11. :toolbars="listConfig.toolbars"
  12. :search-form="listConfig.searchForm"
  13. :pk-key="pkKey"
  14. :columns="listConfig.columns"
  15. :loading="loading"
  16. :pagination="pagination"
  17. :display-field="tableTitle"
  18. :index-row="false"
  19. @sort-change="handleSortChange"
  20. @action-event="handleAction"
  21. @pagination-change="handlePaginationChange"
  22. >
  23. <template
  24. slot="userIdSlot"
  25. slot-scope="{row}"
  26. >
  27. <ibps-user-selector
  28. type="user"
  29. :value="row.id_"
  30. readonly-text="text"
  31. :disabled="true"
  32. :multiple="true"
  33. />
  34. </template>
  35. <template
  36. slot="positionIdSlot"
  37. slot-scope="{row}"
  38. >
  39. <ibps-user-selector
  40. type="position"
  41. :value="row.positions_"
  42. readonly-text="text"
  43. :disabled="true"
  44. :multiple="true"
  45. />
  46. </template>
  47. <template
  48. slot="customButton"
  49. slot-scope="{row}"
  50. >
  51. <el-button type="text" icon="el-icon-view" @click="goLook(row)">查阅</el-button>
  52. </template>
  53. <template slot="user">
  54. <ibps-user-selector
  55. v-model="user"
  56. type="user"
  57. readonly-text="text"
  58. :multiple="true"
  59. />
  60. </template>
  61. <template slot="position">
  62. <ibps-user-selector
  63. v-model="pos"
  64. type="position"
  65. readonly-text="text"
  66. :multiple="false"
  67. />
  68. </template>
  69. <template slot="time">
  70. <el-date-picker
  71. v-model="selectItem"
  72. size="mini"
  73. type="daterange"
  74. :picker-options="pickerOptions"
  75. range-separator="至"
  76. start-placeholder="开始日期"
  77. end-placeholder="结束日期"
  78. align="right"
  79. value-format="yyyy-MM-dd"
  80. />
  81. </template>
  82. </ibps-crud>
  83. </template>
  84. </ibps-container>
  85. <TrainingStatic v-if="dialogVisible" :params="params" @close="close" />
  86. </div>
  87. </template>
  88. <script>
  89. import ActionUtils from '@/utils/action'
  90. import FixHeight from '@/mixins/height'
  91. import ibpsUserSelector from '@/business/platform/org/selector'
  92. import { getUserStatisticList } from '@/api/platform/org/employee'
  93. import TrainingStatic from './trainingStatic.vue'
  94. export default {
  95. components: {
  96. ibpsUserSelector, TrainingStatic
  97. },
  98. mixins: [FixHeight],
  99. data () {
  100. const { level, userList } = this.$store.getters
  101. return {
  102. level: level.second || level.first,
  103. userList: userList,
  104. dialogVisible: false,
  105. params: {},
  106. loading: false,
  107. selectItem: '',
  108. pickerOptions: {
  109. shortcuts: [{
  110. text: '最近一周',
  111. onClick (picker) {
  112. const end = new Date()
  113. const start = new Date()
  114. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
  115. picker.$emit('pick', [start, end])
  116. }
  117. }, {
  118. text: '最近一个月',
  119. onClick (picker) {
  120. const end = new Date()
  121. const start = new Date()
  122. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
  123. picker.$emit('pick', [start, end])
  124. }
  125. }, {
  126. text: '最近三个月',
  127. onClick (picker) {
  128. const end = new Date()
  129. const start = new Date()
  130. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
  131. picker.$emit('pick', [start, end])
  132. }
  133. }]
  134. },
  135. allData: [],
  136. pkKey: 'id', // 主键 如果主键不是pk需要传主键
  137. pkValue: '',
  138. templateKey: '',
  139. visible: false,
  140. categoryKey: '',
  141. tableTitle: '内部培训统计',
  142. listData: [],
  143. selectListData: [],
  144. bianlistData: {
  145. dataResult: [],
  146. pageResult: {
  147. limit: 0,
  148. page: 0,
  149. totalCount: 0,
  150. totalPages: 0
  151. }
  152. },
  153. // listTreeData: [],
  154. listConfig: {
  155. // 工具栏
  156. toolbars: [
  157. { key: 'search' }
  158. ],
  159. // 查询条件
  160. searchForm: {
  161. forms: [
  162. { prop: '', label: '姓名', fieldType: 'slot', slotName: 'user' },
  163. { prop: '', label: '部门', fieldType: 'slot', slotName: 'position' },
  164. { prop: '', label: '统计时段', fieldType: 'slot', slotName: 'time' }
  165. ]
  166. },
  167. // 表格字段配置
  168. columns: [
  169. { prop: 'id_', label: '姓名', width: 100, slotName: 'userIdSlot' },
  170. { prop: 'positions_', label: '部门', width: 120, slotName: 'positionIdSlot' },
  171. { prop: 'jian_ding_zi_ge_z', label: '工号', width: 140 },
  172. { prop: 'planedjoin', label: '应参训次数', width: 120 },
  173. { prop: 'truejoin', label: '实参训次数', width: 120 },
  174. { prop: 'participationRate', label: '参训率', width: 120 },
  175. { label: '操作', width: 120, slotName: 'customButton' }
  176. ]
  177. },
  178. pagination: {
  179. limit: 20, page: 1
  180. },
  181. sorts: {},
  182. sqlWhere: {},
  183. searchWhere: {},
  184. user: '',
  185. pos: ''
  186. }
  187. },
  188. mounted () {
  189. this.getDatas()
  190. },
  191. methods: {
  192. close () {
  193. this.dialogVisible = false
  194. this.getDatas()
  195. },
  196. goLook (row) {
  197. this.params.peixunrenyuan = row.id_
  198. if (this.selectItem && this.selectItem.length > 0) {
  199. this.params.time = [this.selectItem[0], this.selectItem[1]]
  200. } else {
  201. delete this.params.time
  202. }
  203. this.dialogVisible = true
  204. },
  205. async getDatas () {
  206. this.loading = true
  207. const params = {
  208. diDian: this.level
  209. }
  210. if (this.user) {
  211. params.userId = this.user
  212. }
  213. if (this.pos) {
  214. params.deptId = this.pos
  215. }
  216. if (this.selectItem && this.selectItem.length > 0) {
  217. const [start, end] = this.selectItem
  218. params.startTime = start
  219. params.endTime = end
  220. }
  221. console.log('params', params)
  222. try {
  223. const { data: tempList } = await getUserStatisticList(params)
  224. console.log('接口数据', tempList)
  225. tempList.forEach(item => { item.jian_ding_zi_ge_z = item.jian_ding_zi_ge_z ? item.jian_ding_zi_ge_z : '/' })
  226. // 默认参训率排序
  227. tempList.sort((a, b) => {
  228. return b.participationRate.split('%')[0] - a.participationRate.split('%')[0]
  229. })
  230. this.selectListData = JSON.parse(JSON.stringify(tempList))
  231. this.bianlistData.pageResult.totalCount = tempList.length
  232. this.bianlistData.pageResult.totalPages = Math.ceil(tempList.length / this.pagination.limit)
  233. this.bianlistData.pageResult.limit = this.pagination.limit
  234. this.bianlistData.pageResult.page = 1
  235. let filterDatas = []
  236. if (this.pagination.limit > tempList.length) {
  237. filterDatas = JSON.parse(JSON.stringify(tempList))
  238. } else {
  239. for (let index = 0; index < this.bianlistData.pageResult.limit; index++) {
  240. filterDatas.push(tempList[index])
  241. }
  242. }
  243. this.bianlistData.dataResult = filterDatas
  244. ActionUtils.handleListData(this, this.bianlistData)
  245. this.loading = false
  246. } catch (error) {
  247. if (error.message === '服务器君开小差了,请稍后再试') {
  248. this.$message.error('找不到接口,请切换服务环境')
  249. }
  250. this.loading = false
  251. }
  252. },
  253. refreshData () {
  254. this.listData = []
  255. this.getDatas()
  256. },
  257. /**
  258. * 处理按钮事件
  259. */
  260. handleAction (command, position, selection, data, index, button) {
  261. switch (command) {
  262. case 'search':// 查询
  263. this.refreshData()
  264. break
  265. default:
  266. break
  267. }
  268. },
  269. /**
  270. * 处理排序
  271. */
  272. handleSortChange (sort) {
  273. this.getDatas()
  274. },
  275. // 处理分页事件
  276. handlePaginationChange (page) {
  277. ActionUtils.setPagination(this.pagination, page)
  278. this.bianlistData.pageResult.limit = page.limit
  279. this.bianlistData.pageResult.page = page.page
  280. const filterDatas = []
  281. if (this.selectListData.length >= (page.limit * page.page)) {
  282. for (let index = (page.limit * page.page) - page.limit; index < (page.limit * page.page); index++) {
  283. filterDatas.push(this.selectListData[index])
  284. }
  285. this.bianlistData.dataResult = JSON.parse(JSON.stringify(filterDatas))
  286. } else {
  287. for (let index = (page.limit * page.page) - page.limit; index < this.selectListData.length; index++) {
  288. filterDatas.push(this.selectListData[index])
  289. }
  290. this.bianlistData.dataResult = JSON.parse(JSON.stringify(filterDatas))
  291. }
  292. ActionUtils.handleListData(this, this.bianlistData)
  293. }
  294. }
  295. }
  296. </script>