RecordsFinance.vue 11 KB

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