PointRankDepartment.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <div style=" background-color: #fff; padding:15px;">
  3. <div style="margin-top:2px;" class="inline-block-btn-list">
  4. <el-date-picker
  5. class="first-element-btn"
  6. v-model="filter.time_range"
  7. type="daterange"
  8. value-format="timestamp"
  9. range-separator="至"
  10. start-placeholder="开始日期"
  11. end-placeholder="结束日期"
  12. :picker-options="instantPickerOptions"
  13. @change="onFilterChanged">
  14. </el-date-picker>
  15. <el-cascader
  16. clearable
  17. :options="categoryTree"
  18. change-on-select
  19. v-model="filter.category_id"
  20. @change="onFilterChanged"
  21. placeholder="选择积分分类进行筛选"
  22. class="gap-right-8">
  23. </el-cascader>
  24. <el-select
  25. v-show="false"
  26. v-model="filter.point_type"
  27. @change="onFilterChanged">
  28. <el-option
  29. v-for="item in pointTypes"
  30. :key="item.value"
  31. :label="item.label"
  32. :value="item.value">
  33. </el-option>
  34. </el-select>
  35. </div>
  36. <div v-show="filtersAdvShow" class="inline-block-btn-list inline-block-btn-list-adv">
  37. <el-checkbox class="first-element-btn" style="padding:9px 20px;" border v-model="filter.include_manager" @change="updateEmployeeRange">包含管理者进行排名
  38. </el-checkbox>
  39. <el-select
  40. v-show="false"
  41. v-model="filter.target_id_set"
  42. filterable
  43. multiple
  44. :multiple-limit="15"
  45. placeholder="选择员工进行筛选(最多15个)"
  46. @change="onFilterChanged"
  47. style="width:200px;">
  48. <el-option
  49. v-for="item in employeeOptions"
  50. :key="item.id"
  51. :label="item.name"
  52. :value="item.id">
  53. </el-option>
  54. </el-select>
  55. </div>
  56. <el-table
  57. v-loading="loading"
  58. ref="rankTable"
  59. :data="rankList"
  60. tooltip-effect="dark"
  61. style="width: 100%"
  62. :row-class-name="tableRowClassName"
  63. :header-cell-style="{ textAlign : 'left' }">
  64. <el-table-column label="姓名">
  65. <template slot-scope="scope">
  66. <div class="rank_head">
  67. <img v-if="scope.row.target_img != null" v-bind:src="scope.row.target_img" width="42px" height="42px"/>
  68. <img v-if="scope.row.target_img == null" src="static/images/head_default.png" width="42px" height="42px"/>
  69. {{scope.row.target_name}}</div>
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="部门" prop="dept_name" class-name="text-auxiliary"></el-table-column>
  73. <el-table-column label="排行">
  74. <template slot-scope="scope">
  75. <div class="table-font-number" v-if="(currentPage - 1) * 10 + scope.row.index <= 3">
  76. <img src="static/images/rank_01.png" width="20" v-if="scope.row.index == 1">
  77. <img src="static/images/rank_02.png" width="20" v-if="scope.row.index == 2">
  78. <img src="static/images/rank_03.png" width="20" v-if="scope.row.index == 3">
  79. </div>
  80. <div style="" class="table-font-number" v-if="(currentPage - 1) * 10 + scope.row.index > 3">
  81. NO.{{ (currentPage - 1) * 10 + scope.row.index }}
  82. </div>
  83. <!-- <div>{{scope.row}}</div> -->
  84. </template>
  85. </el-table-column>
  86. <el-table-column label="总分">
  87. <template slot-scope="scope">
  88. <div v-bind:class="'table-font-xl table-font-number ' + (scope.row.p_sum < 0 ? 'point-negative' : 'point-positive')">
  89. {{ scope.row.p_sum }}
  90. </div>
  91. </template>
  92. </el-table-column>
  93. </el-table>
  94. <el-pagination
  95. background
  96. layout="prev, pager, next"
  97. :page-size="10"
  98. :page-sizes="[10, 20, 50, 100]"
  99. :total="totalCount"
  100. :current-page.sync="currentPage"
  101. @current-change="changePage">
  102. </el-pagination>
  103. </div>
  104. </template>
  105. <script>
  106. export default {
  107. data() {
  108. return {
  109. profile: this.$store.getters.user_info,
  110. filtersAdvShow: false,
  111. filter: {
  112. keywords: '',
  113. target_id_set: [],
  114. category_id: [],
  115. dept_id: [],
  116. point_type: 0,
  117. time_range: '',
  118. include_manager: false
  119. },
  120. totalCount: 0,
  121. currentPage: 1,
  122. rankList: null,
  123. categoryTree: [],
  124. deptTree: [],
  125. employeeOptions: [],
  126. pointTypes: [],
  127. loading:false,
  128. instantPickerOptions: {
  129. shortcuts: [{
  130. text: '本周',
  131. onClick(picker) {
  132. const now = new Date(new Date().toLocaleDateString())
  133. let start = now.getTime() - (now.getDay() - 1) * 24 * 60 * 60 * 1000
  134. let end = start + 7 * 24 * 60 * 60 * 1000 - 1000
  135. picker.$emit('pick', [start, end])
  136. }
  137. }, {
  138. text: '上周',
  139. onClick(picker) {
  140. const now = new Date(new Date().toLocaleDateString())
  141. let start = now.getTime() - (now.getDay() + 6) * 24 * 60 * 60 * 1000
  142. let end = start + 7 * 24 * 60 * 60 * 1000 - 1000
  143. picker.$emit('pick', [start, end])
  144. }
  145. }, {
  146. text: '本月',
  147. onClick(picker) {
  148. const now = new Date()
  149. let startDate = new Date(now.getFullYear(), now.getMonth(), 1)
  150. let endDate = new Date(now.getFullYear(), now.getMonth() + 1, 0)
  151. picker.$emit('pick', [startDate.getTime(), endDate.getTime()])
  152. }
  153. }, {
  154. text: '上月',
  155. onClick(picker) {
  156. const now = new Date()
  157. let startDate = new Date(now.getFullYear() - (now.getMonth() > 0 ? 0 : 1), (now.getMonth() + 11) % 12, 1)
  158. let endDate = new Date(now.getFullYear(), now.getMonth(), 0)
  159. picker.$emit('pick', [startDate.getTime(), endDate.getTime()])
  160. }
  161. }, {
  162. text: '本年',
  163. onClick(picker) {
  164. const now = new Date()
  165. let startDate = new Date(now.getFullYear(), 0, 1)
  166. let endDate = new Date(now.getFullYear() + 1, 0, 0)
  167. picker.$emit('pick', [startDate.getTime(), endDate.getTime()])
  168. }
  169. }]
  170. }
  171. }
  172. },
  173. methods: {
  174. tableRowClassName({row, rowIndex}) {
  175. if (row.target_id == this.$store.getters.user_info.id) {
  176. return 'rank-mine';
  177. }
  178. return '';
  179. },
  180. onFilterChanged: function () {
  181. this.currentPage = 1
  182. this.loadRankList()
  183. },
  184. changePage: function (current) {
  185. if (isNaN(current) || current < 1) {
  186. return false
  187. }
  188. this.loadRankList()
  189. },
  190. updateEmployeeRange: function (currentVal) {
  191. if (currentVal) {
  192. this.loadTargetList()
  193. this.onFilterChanged()
  194. } else {
  195. var self = this
  196. this.loadTargetList(() => {
  197. let idArr = self.employeeOptions.map((item) => {
  198. return item.id
  199. })
  200. self.filter.target_id_set = self.filter.target_id_set.filter((item) => idArr.indexOf(item) > -1);
  201. self.onFilterChanged()
  202. })
  203. }
  204. },
  205. //获取控件所需数据
  206. loadWidgetData: function () {
  207. var self = this
  208. this.$http('get','/integral.php/ajax_request_common/prepare_integral_options',{
  209. id: this.profile.id,
  210. category_tree: 1,
  211. dept_tree: 1
  212. }).then(function (response) {
  213. if (response.status == 200) {
  214. var jsonData = response.data
  215. try {
  216. self.categoryTree = jsonData.category_tree
  217. self.deptTree = jsonData.dept_tree
  218. } catch (err) {
  219. console.log(err)
  220. }
  221. }
  222. }).catch(function (error) {
  223. console.log(error)
  224. })
  225. },
  226. //获取可排名的员工列表
  227. loadTargetList: function (callback) {
  228. var self = this
  229. this.$http('get','/integral.php/point_data/load_target_list',{
  230. site_id: this.profile.site_id,
  231. exclude_manager: this.filter.include_manager ? 0 : 1
  232. }).then(function (response) {
  233. if (response.status == 200) {
  234. var jsonData = response.data
  235. try {
  236. self.employeeOptions = jsonData
  237. if (callback) {
  238. callback.call()
  239. }
  240. } catch (err) {
  241. console.log(err)
  242. }
  243. }
  244. }).catch(function (error) {
  245. console.log(error)
  246. });
  247. },
  248. loadPointType: function () {
  249. var self = this
  250. this.$http('get','/integral.php/ajax_request_common/get_point_types').then(function (response) {
  251. if (response.status == 200) {
  252. let jsonData = response.data
  253. try {
  254. self.pointTypes = jsonData
  255. } catch (err) {
  256. console.log(err)
  257. }
  258. }
  259. }).catch(function (error) {
  260. console.log(error)
  261. })
  262. },
  263. loadRankList: function () {
  264. let params = {
  265. site_id: this.profile.site_id,
  266. page: this.currentPage
  267. }
  268. this.filter.dept_id = [this.profile.dept_id]
  269. for (let item in this.filter) {
  270. let value = this.filter[item]
  271. if (item == 'target_id_set') {
  272. if (!value || value.length == 0) {
  273. continue
  274. }
  275. params[item] = value.join(",")
  276. } else if (item == 'category_id' || item == 'dept_id') {
  277. if (!value || value.length == 0) {
  278. continue
  279. }
  280. params[item] = value[value.length - 1]
  281. } else if (item == 'time_range') {
  282. if (!value || value.length < 2) {
  283. continue
  284. }
  285. let timeRangeArr = value.map(x => parseInt(x / 1000))
  286. timeRangeArr[1] += 60 * 60 * 24 - 1
  287. params[item] = timeRangeArr.join(",")
  288. } else if (item == 'include_manager') {
  289. params['exclude_manager'] = value ? 0 : 1
  290. } else {
  291. params[item] = value
  292. }
  293. }
  294. var self = this
  295. self.loading = true
  296. this.$http('get','/integral.php/point_data/rank_by_employee',params).then(function (response) {
  297. if (response.status == 200) {
  298. self.loading = false
  299. let jsonData = response.data
  300. try {
  301. self.totalCount = jsonData.total_count
  302. self.rankList = jsonData.list_data
  303. } catch (err) {
  304. console.log(err)
  305. }
  306. }
  307. }).catch(function (error) {
  308. console.log(error)
  309. })
  310. }
  311. },
  312. created() {
  313. this.loadWidgetData()
  314. this.loadTargetList()
  315. this.loadPointType()
  316. this.loadRankList()
  317. }
  318. }
  319. </script>
  320. <style>
  321. tbody .image-container div.cell {
  322. height: 42px;
  323. }
  324. .el-pagination {
  325. text-align: center;
  326. margin-top: 15px;
  327. }
  328. .el-tabs__header {
  329. margin: 0;
  330. }
  331. .rank_head img{width:30px;
  332. height: 30px;
  333. -webkit-border-radius: 20px;
  334. -moz-border-radius: 20px;
  335. border-radius: 20px; margin-right:5px;}
  336. .rank_head *{
  337. vertical-align: middle;}
  338. </style>