index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div class="white pa-3">
  3. <m-search :items="searchItems" v-model="searchValues" class="mb-3" @search="onSearch"></m-search>
  4. <BonusTable v-loading="loading" ref="bonusTableRefs" :filter-header="auditStatus !== 0 && auditStatus !== 1 ? [] : ['actions']">
  5. <template #card-tools="{ items }">
  6. <div class="content">
  7. <div>
  8. <!-- 绩效合计:<el-tag>{{ totalAllocationPerformanceSalary }}</el-tag> -->
  9. 可发放绩效: <el-tag>{{ totalGrantPerformanceSalary }}</el-tag>
  10. <m-button
  11. class="ml-3"
  12. type="orange"
  13. :loading="auditStatusLoading"
  14. v-show="auditStatus !== 0 && auditStatus !== 1 && items.length"
  15. @click="onSave">
  16. 确认分配
  17. </m-button>
  18. </div>
  19. </div>
  20. </template>
  21. <template #actions="{ row, items }">
  22. <el-input v-show="auditStatus !== 0 && auditStatus !== 1 && items.length" v-model="values[row.employeePerformanceId]" placeholder="请输入绩效" size="small"></el-input>
  23. </template>
  24. <template #actions-header>
  25. 合计:<el-tag>{{ totalAllocationPerformanceSalary }}</el-tag>
  26. </template>
  27. </BonusTable>
  28. </div>
  29. </template>
  30. <script>
  31. import BonusTable from '../components/bonusTable.vue'
  32. import { dateFormat } from '@/utils/date'
  33. import Decimal from 'decimal.js'
  34. import {
  35. // getAllocationPage,
  36. saveAllocationGrant,
  37. // getAllocationEmployeeCategory,
  38. getAllocationOrganizationCategory,
  39. checkAllocationSubmitStatus,
  40. getAllocationStatistics,
  41. saveAllocation
  42. } from '@/api/bonus'
  43. import { mapGetters } from 'vuex'
  44. export default {
  45. name: 'bonusAllocation',
  46. components: {
  47. BonusTable
  48. },
  49. data () {
  50. return {
  51. auditStatus: null,
  52. auditStatusLoading: false,
  53. values: {},
  54. searchValues: {
  55. month: dateFormat('YYYY-mm', new Date()),
  56. organizationCategory: null
  57. },
  58. query: {},
  59. organizationCategoryItems: [],
  60. totalGrantPerformanceSalary: 0,
  61. loading: false
  62. }
  63. },
  64. computed: {
  65. ...mapGetters(['organizationTree']),
  66. totalAllocationPerformanceSalary () {
  67. return Object.values(this.values).reduce((r, v) => {
  68. return new Decimal(r).plus(v || 0)
  69. }, 0).toFixed(2)
  70. },
  71. searchItems () {
  72. return [
  73. {
  74. label: '月份',
  75. prop: 'month',
  76. type: 'datePicker',
  77. options: {
  78. placeholder: '请选择月份',
  79. clearable: false,
  80. type: 'month',
  81. valueFormat: 'yyyy-MM',
  82. format: 'yyyy 年 MM 月'
  83. }
  84. // handles: {
  85. // change: this.getEmployeeCategoryItems
  86. // }
  87. },
  88. {
  89. label: '分配类型',
  90. prop: 'organizationCategory',
  91. type: 'select',
  92. options: {
  93. clearable: false,
  94. placeholder: '请选择机构类型',
  95. items: this.organizationCategoryItems
  96. }
  97. }
  98. ]
  99. }
  100. },
  101. async mounted () {
  102. await this.getOrganizationCategoryItems()
  103. if (!this.organizationCategoryItems.length) {
  104. this.$message.error('没有操作权限')
  105. return
  106. }
  107. this.query = { ...this.searchValues }
  108. this.$nextTick(() => {
  109. this.$refs.bonusTableRefs && this.onInit()
  110. })
  111. },
  112. methods: {
  113. async onInit (pageInfo) {
  114. this.loading = true
  115. await this.onCheckStatus()
  116. await this.onStatistics()
  117. if (!this.$refs.bonusTableRefs) {
  118. this.loading = false
  119. return
  120. }
  121. const data = await this.$refs.bonusTableRefs.onInit(this.query, pageInfo)
  122. this.loading = false
  123. if (!data) {
  124. return
  125. }
  126. this.values = data.records.reduce((res, item) => {
  127. res[item.employeePerformanceId] = item.allocationPerformanceSalary || null
  128. return res
  129. }, {})
  130. },
  131. async getOrganizationCategoryItems () {
  132. this.loading = true
  133. try {
  134. const { data } = await getAllocationOrganizationCategory()
  135. this.organizationCategoryItems = data.map(e => {
  136. return {
  137. value: e,
  138. label: e
  139. }
  140. })
  141. if (this.organizationCategoryItems.length > 0) {
  142. this.searchValues.organizationCategory = this.organizationCategoryItems[0].value
  143. }
  144. } catch (error) {
  145. this.organizationCategoryItems = []
  146. this.$message.error(error)
  147. } finally {
  148. this.loading = false
  149. }
  150. },
  151. async onSearch () {
  152. if (!this.organizationCategoryItems.length) {
  153. return
  154. }
  155. this.query = { ...this.searchValues }
  156. this.onInit({ current: 1 })
  157. },
  158. // 领导分配绩效薪资
  159. onSave () {
  160. const h = this.$createElement
  161. const _el = [
  162. h('p', undefined, `提交月份:${this.query.month}`)
  163. ]
  164. try {
  165. const el = h('div', [
  166. h('p', undefined, '确定提交所有数据?'),
  167. ..._el
  168. ])
  169. this.$confirm(el, '提示').then(() => {
  170. this.onSaveAll(false)
  171. }).catch(_ => {})
  172. } catch (error) {
  173. this.$message.error(error)
  174. }
  175. },
  176. async onSaveAll (force) {
  177. const employeePerformanceGrantItems = Object.keys(this.values).reduce((res, key) => {
  178. res.push({
  179. employeePerformanceId: key,
  180. allocationPerformanceSalary: this.values[key]
  181. })
  182. return res
  183. }, [])
  184. if (!employeePerformanceGrantItems.length) {
  185. this.$message.error('请先分配金额')
  186. return
  187. }
  188. this.auditStatusLoading = true
  189. try {
  190. await saveAllocationGrant({
  191. ...this.query,
  192. employeePerformanceGrantItems
  193. })
  194. await saveAllocation({
  195. ...this.query,
  196. force: force ? 1 : 0
  197. })
  198. this.$message.success('提交成功')
  199. this.onInit()
  200. } catch (error) {
  201. this.$message.error(error)
  202. } finally {
  203. this.auditStatusLoading = false
  204. }
  205. },
  206. // 查询提交状态
  207. async onCheckStatus () {
  208. this.auditStatusLoading = true
  209. try {
  210. const { data } = await checkAllocationSubmitStatus(this.query)
  211. this.auditStatus = data?.status ?? null
  212. } catch (error) {
  213. this.$message.error(error)
  214. } finally {
  215. this.auditStatusLoading = false
  216. }
  217. },
  218. // 统计分配
  219. async onStatistics () {
  220. try {
  221. const { data } = await getAllocationStatistics(this.query)
  222. const { totalGrantPerformanceSalary } = data
  223. this.totalGrantPerformanceSalary = totalGrantPerformanceSalary
  224. } catch (error) {
  225. this.$message.error(error)
  226. }
  227. }
  228. }
  229. }
  230. </script>
  231. <style lang="scss" scoped>
  232. .content {
  233. display: flex;
  234. justify-content: flex-end;
  235. }
  236. </style>