RecordsFinance.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <script setup lang="ts">
  2. import { User_List } from '@/api/user/index'
  3. import { GlobalStore } from '@/stores/index'
  4. import { getFormatDuration } from '@/utils/common'
  5. import Drawer from '@/components/Drawer/index.vue'
  6. import TableBase from '@/components/TableBase/index.vue'
  7. import type { FormInstance, FormRules } from 'element-plus'
  8. import { ElMessage, ElMessageBox } from 'element-plus'
  9. import { ColumnProps } from '@/components/TableBase/interface/index'
  10. import Pagination from '@/components/TableBase/components/Pagination.vue'
  11. import { ref, reactive, onMounted, computed, onUnmounted, nextTick } from 'vue'
  12. import { Leave_Finance_List, Leave_Deduct, LeaveType_List } from '@/api/workAttendance/index'
  13. const TableData = ref()
  14. const LeaveType = ref<any[]>([])
  15. const globalStore = GlobalStore()
  16. const ruleFormRef = ref<FormInstance>()
  17. const initParam = { User_tokey: globalStore.GET_User_tokey }
  18. const drawerRef = ref<InstanceType<typeof Drawer> | null>(null)
  19. const LeaveTableRef = ref<InstanceType<typeof TableBase> | null>(null)
  20. let date = new Date()
  21. const month = date.getMonth()
  22. const year = date.getFullYear()
  23. const salaryFromData = ref({
  24. year: year + '',
  25. month: (month < 10 ? '0' : '') + month,
  26. T_uuid: ''
  27. })
  28. // 搜索以及参数
  29. const columns: ColumnProps[] = [
  30. { prop: 'T_name', label: '姓名', name: 'T_name' },
  31. { prop: 'T_post_name', label: '职位', ellipsis: true }
  32. ]
  33. const userColums: ColumnProps[] = [
  34. { prop: 'T_type_name', label: '请假类型' },
  35. { prop: 'T_start_time', label: '开始时间', ellipsis: true },
  36. { prop: 'T_end_time', label: '结束时间', ellipsis: true },
  37. { prop: 'T_duration', label: '请假时长', name: 'T_duration' },
  38. { prop: 'T_text', label: '理由' },
  39. { prop: 'T_State', label: '审核', name: 'T_State' }
  40. ]
  41. const dateCom = computed(() => {
  42. return `${salaryFromData.value.year}-${salaryFromData.value.month}`
  43. })
  44. const LeaveinitParam = reactive({
  45. User_tokey: globalStore.GET_User_tokey,
  46. T_uuid: '',
  47. T_month: dateCom.value
  48. })
  49. const getSalaryParams = (row: any) => {
  50. userInfo.name = row.T_name
  51. userInfo.T_dept = row.T_dept_name
  52. userInfo.T_post = row.T_post_name
  53. LeaveinitParam.T_uuid = row.T_uuid
  54. LeaveTableRef.value && LeaveTableRef.value.searchTable()
  55. }
  56. const salarDateMonthChange = (val: string) => {
  57. if (!val) return
  58. if (!LeaveinitParam.T_uuid) {
  59. ElMessage.warning('请选择员工!!!')
  60. }
  61. LeaveinitParam.T_month = dateCom.value
  62. LeaveTableRef.value && LeaveTableRef?.value.searchTable()
  63. }
  64. const salarDateYearChange = (val: string) => {
  65. if (!val) return
  66. if (!LeaveinitParam.T_uuid) {
  67. ElMessage.warning('请选择员工!!!')
  68. }
  69. LeaveinitParam.T_month = dateCom.value
  70. LeaveTableRef.value && LeaveTableRef.value.searchTable()
  71. }
  72. const userInfo = reactive({
  73. squareUrl: 'https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png',
  74. name: '',
  75. T_dept: '',
  76. T_post: ''
  77. })
  78. const onResize = () => {
  79. const height = document.documentElement.clientHeight
  80. return height - 140 - 74 - 60 - 4 * 12
  81. }
  82. const getTableData = async () => {
  83. const res: any = await User_List({ ...initParam })
  84. TableData.value = res.Data.Data
  85. pageable.total = res.Data.Num
  86. }
  87. onMounted(async () => {
  88. await getTableData()
  89. })
  90. const pageable = reactive({
  91. pageNum: 1,
  92. pageSize: 10,
  93. total: 0,
  94. small: false,
  95. disabled: false
  96. })
  97. const handleSizeChange = (val: number) => {
  98. pageable.pageSize = val
  99. LeaveTableRef.value?.getTableList()
  100. }
  101. const handleCurrentChange = (val: number) => {
  102. pageable.pageNum = val
  103. LeaveTableRef.value?.getTableList()
  104. }
  105. let clientHeight = ref(0)
  106. const onContentResize = () => {
  107. const height = document.documentElement.clientHeight
  108. clientHeight.value = height - 140 - 60 - 3 * 12
  109. }
  110. onMounted(() => {
  111. onContentResize()
  112. window.onresize = onContentResize
  113. })
  114. onUnmounted(() => (window.onresize = null))
  115. const tableRowClassName = (data: any): any => {
  116. //判断是否相等,相同时改变背景颜色
  117. let user: any = undefined
  118. if (data.row.T_uuid === LeaveinitParam.T_uuid) {
  119. user = data.row
  120. }
  121. if (user !== undefined) {
  122. let rowBackground = {
  123. background: '#f0f9eb',
  124. color: '#67c23a'
  125. }
  126. return rowBackground
  127. } else {
  128. return ''
  129. }
  130. }
  131. const dataCallback = (res: any): any => {
  132. return res.Data.Data.filter((item: any) => item.T_approver)
  133. }
  134. // drawer
  135. const form = reactive({
  136. T_type: '',
  137. T_duration: 0,
  138. hover: 0,
  139. minute: 0,
  140. T_text: ''
  141. })
  142. const duration = computed(() => {
  143. return form.hover * 60 + form.minute
  144. })
  145. const rules = reactive<FormRules>({
  146. T_type: [{ required: true, message: '请选择扣除类型', trigger: 'blur' }],
  147. T_duration: [{ required: true, message: '请输入扣除时长', trigger: 'blur' }],
  148. T_text: [{ required: true, message: '请输入扣除理由', trigger: 'blur' }]
  149. })
  150. type Fn = () => void
  151. const Deductduraton = async () => {
  152. !LeaveType.value.length && getLeaveTypeList()
  153. drawerRef.value?.openDrawer()
  154. }
  155. const getLeaveTypeList = async () => {
  156. const res: any = await LeaveType_List({ User_tokey: globalStore.GET_User_tokey, T_deduct: 1 })
  157. if (res.Code === 200) {
  158. LeaveType.value = res.Data
  159. }
  160. }
  161. const callbackDrawer = (done: Fn) => {
  162. nextTick(() => {
  163. resetForm(ruleFormRef.value)
  164. done()
  165. })
  166. }
  167. const resetForm = (formEl: FormInstance | undefined) => {
  168. if (!formEl) return
  169. form.hover = 0
  170. form.minute = 0
  171. formEl.resetFields()
  172. }
  173. const AddLeave = (formEl: FormInstance | undefined) => {
  174. if (!formEl) return
  175. form.T_duration = duration.value
  176. formEl.validate(async valid => {
  177. if (valid) {
  178. open()
  179. }
  180. })
  181. }
  182. const open = () => {
  183. ElMessageBox.confirm('确定扣除?扣除后无法修改?', '警告', {
  184. confirmButtonText: '确定',
  185. cancelButtonText: '取消',
  186. type: 'warning'
  187. })
  188. .then(async () => {
  189. const params = {
  190. User_tokey: globalStore.GET_User_tokey,
  191. T_type: form.T_type,
  192. T_duration: form.T_duration,
  193. T_text: form.T_text,
  194. T_uuid: LeaveinitParam.T_uuid,
  195. T_month: dateCom.value
  196. }
  197. const res: any = await Leave_Deduct(params)
  198. if (res.Code === 200) {
  199. ElMessage.success('扣除成功!')
  200. nextTick(() => {
  201. drawerRef.value?.closeDrawer()
  202. resetForm(ruleFormRef.value)
  203. })
  204. }
  205. })
  206. .catch(() => {
  207. ElMessage.info('取消成功!')
  208. })
  209. }
  210. </script>
  211. <template>
  212. <div class="RecordsFinance">
  213. <div style="width: 290px; display: flex; padding: 20px; background: #fff; flex-direction: column">
  214. <el-table
  215. class="h-100"
  216. style="width: 100%; height: 100%; flex: 1"
  217. :data="TableData"
  218. @row-click="getSalaryParams"
  219. :row-style="tableRowClassName"
  220. >
  221. <el-table-column
  222. align="center"
  223. v-for="item in columns"
  224. :label="item.label"
  225. :prop="item.prop"
  226. :key="item.prop"
  227. />
  228. </el-table>
  229. <Pagination
  230. layout="total, prev, pager, next"
  231. :pageable="pageable"
  232. :handleSizeChange="handleSizeChange"
  233. :handleCurrentChange="handleCurrentChange"
  234. />
  235. </div>
  236. <transition
  237. leave-active-class="animate__animated animate__bounceOutRight"
  238. enter-active-class="animate__animated animate__bounceInDown"
  239. >
  240. <el-row class="h-100 f-1 margin-left-3" v-if="LeaveinitParam.T_uuid">
  241. <el-col :span="24" class="h-100" style="overflow: hidden">
  242. <el-card class="m-b-3">
  243. <h3 class="title m-b-5">员工基本信息</h3>
  244. <div class="info-content">
  245. <el-avatar shape="square" size="large" :src="userInfo.squareUrl" />
  246. <div class="info-name">
  247. <h4 class="m-b-3">名字:{{ userInfo.name }}</h4>
  248. <h4>
  249. <span>部门:{{ userInfo.T_dept }}</span>
  250. <span>岗位:{{ userInfo.T_post }}</span>
  251. </h4>
  252. </div>
  253. </div>
  254. </el-card>
  255. <el-card class="m-b-3">
  256. <el-row :gutter="20">
  257. <el-col :span="10" class="d-flex justify-start">
  258. <span class="demonstration">年:</span>
  259. <el-date-picker
  260. v-model="salaryFromData.year"
  261. value-format="YYYY"
  262. type="year"
  263. placeholder="请选择年"
  264. @change="salarDateYearChange"
  265. />
  266. <span class="demonstration">月:</span>
  267. <el-date-picker
  268. v-model="salaryFromData.month"
  269. popper-class="picker-date"
  270. value-format="MM"
  271. format="MM"
  272. type="month"
  273. placeholder="请选择月"
  274. @change="salarDateMonthChange"
  275. />
  276. </el-col>
  277. <el-col :span="12" class="d-flex justify-end">
  278. <el-button type="primary" @click="Deductduraton">扣除时长</el-button>
  279. </el-col>
  280. </el-row>
  281. </el-card>
  282. <div :style="{ height: clientHeight + 'px' }">
  283. <TableBase
  284. v-if="LeaveinitParam.T_uuid"
  285. ref="LeaveTableRef"
  286. :columns="userColums"
  287. :requestApi="Leave_Finance_List"
  288. :initParam="LeaveinitParam"
  289. layout="total,prev, pager, next"
  290. :onResize="onResize"
  291. :displayHeader="true"
  292. :dataCallback="dataCallback"
  293. >
  294. <template #T_duration="{ row }">{{ getFormatDuration(row.T_duration) }}</template>
  295. <template #T_State="{ row }">
  296. <el-tag v-if="row.T_State === 1" type="success">通过</el-tag>
  297. <el-tag v-else-if="row.T_State === 2" type="warning">未通过</el-tag>
  298. <el-tag v-else type="danger">待审核</el-tag>
  299. </template>
  300. </TableBase>
  301. </div>
  302. </el-col>
  303. </el-row>
  304. </transition>
  305. <Drawer ref="drawerRef" :handleClose="callbackDrawer">
  306. <template #header="{ params }">
  307. <h4 :id="params.titleId" :class="params.titleClass">扣除时长</h4>
  308. </template>
  309. <el-form ref="ruleFormRef" :model="form" :rules="rules">
  310. <el-form-item label="扣除类型:" label-width="100px" prop="T_type">
  311. <el-select v-model="form.T_type" placeholder="请选择扣除类型">
  312. <el-option v-for="item in LeaveType" :key="item.Id" :label="item.T_name" :value="item.Id" />
  313. </el-select>
  314. </el-form-item>
  315. <el-form-item label="扣除时长:" label-width="100px" prop="T_duration">
  316. <div class="d-flex">
  317. <el-input type="text" v-model.number="form.hover"><template #suffix> 小时 </template></el-input
  318. ><el-input type="text" v-model.number="form.minute">
  319. <template #suffix> 分钟 </template>
  320. </el-input>
  321. </div>
  322. </el-form-item>
  323. <el-form-item label="扣除理由:" label-width="100px" prop="T_text">
  324. <el-input
  325. v-model="form.T_text"
  326. autocomplete="off"
  327. type="textarea"
  328. :autosize="{ minRows: 4, maxRows: 6 }"
  329. placeholder="请输入扣除理由"
  330. />
  331. </el-form-item>
  332. <div class="d-flex">
  333. <el-button type="primary" @click="AddLeave(ruleFormRef)">提交</el-button>
  334. </div>
  335. </el-form>
  336. </Drawer>
  337. </div>
  338. </template>
  339. <style scoped lang="scss">
  340. .RecordsFinance {
  341. display: flex;
  342. height: 100%;
  343. overflow: hidden;
  344. .w-100 {
  345. width: 100%;
  346. }
  347. }
  348. .d-flex {
  349. display: flex;
  350. justify-content: center;
  351. align-items: center;
  352. flex-wrap: nowrap;
  353. }
  354. .justify-start {
  355. justify-content: start;
  356. }
  357. .justify-end {
  358. justify-content: end;
  359. }
  360. .input-suffix {
  361. width: 100%;
  362. flex-direction: column;
  363. .w-50 {
  364. width: 12.5rem;
  365. }
  366. .inline-flex {
  367. white-space: nowrap;
  368. display: inline-flex;
  369. }
  370. }
  371. .title {
  372. text-align: left;
  373. }
  374. .info-content {
  375. display: flex;
  376. color: #606266;
  377. .info-name {
  378. display: flex;
  379. flex-direction: column;
  380. padding-left: 0.75rem;
  381. span:first-child {
  382. margin-right: 2rem;
  383. }
  384. }
  385. }
  386. </style>