index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. <template>
  2. <div>
  3. <el-container>
  4. <!-- 左侧树形结构 -->
  5. <el-scrollbar max-height="75vh">
  6. <el-aside>
  7. <div class="JKWTree-tree">
  8. <h3>计件工计时单维护</h3>
  9. <el-tree
  10. :data="treeData"
  11. :props="defaultProps"
  12. highlight-current="true"
  13. @node-click="handleNodeClick"
  14. />
  15. </div>
  16. </el-aside>
  17. </el-scrollbar>
  18. <el-container>
  19. <el-main>
  20. <!-- 按钮区域 -->
  21. <div class="gva-table-box">
  22. <div class="gva-btn-list">
  23. <el-row :span="6">
  24. <el-input
  25. v-model="searchInfo"
  26. placeholder="输入员工编号"
  27. />
  28. </el-row>
  29. <el-button
  30. type="primary"
  31. :icon="Search"
  32. @click="onSearch"
  33. >搜索</el-button>
  34. <el-button
  35. type="primary"
  36. :icon="Search"
  37. @click="handleShowAdd"
  38. >新增</el-button>
  39. <el-button
  40. type="primary"
  41. :icon="Refresh"
  42. >重置</el-button>
  43. <div style="margin-left: auto;">
  44. <el-button
  45. type="primary"
  46. :icon="Download"
  47. @click="exportExcel"
  48. >导出到Excel</el-button>
  49. </div>
  50. </div>
  51. <!-- 数据展示 -->
  52. <el-table
  53. ref="multipleTable"
  54. style="width: 100%"
  55. tooltip-effect="dark"
  56. :data="tableData"
  57. row-key="ID"
  58. highlight-current-row
  59. border
  60. show-overflow-tooltip="true"
  61. :row-style="{ height: '20px' }"
  62. :cell-style="{ padding: '0px' }"
  63. :header-row-style="{ height: '20px' }"
  64. :header-cell-style="{ padding: '0px' }"
  65. @selection-change="handleSelectionChange"
  66. @row-dblclick="doubleClick"
  67. @row-click="Click"
  68. >
  69. <el-table-column
  70. type="selection"
  71. width="55"
  72. />
  73. <!-- 循环渲染列 -->
  74. <el-table-column
  75. v-for=" column in tableColumns "
  76. :key="column.prop"
  77. :prop="column.prop"
  78. :label="column.label"
  79. :width="column.width"
  80. />
  81. </el-table>
  82. <!-- 分页 -->
  83. <div class="gva-pagination">
  84. <el-pagination
  85. v-model:current-page="page"
  86. v-model:page-size="limit"
  87. layout="total, sizes, prev, pager, next, jumper"
  88. :page-sizes="[10, 30, 50, 100]"
  89. :total="total"
  90. @current-change="handleCurrentChange"
  91. @size-change="handleSizeChange"
  92. />
  93. </div>
  94. </div>
  95. <!-- 弹出框 -->
  96. <el-dialog
  97. v-model="dialogFormVisible"
  98. :before-close="closeDialog"
  99. title="计件工计时单维护"
  100. destroy-on-close
  101. width="800px"
  102. >
  103. <!-- <el-scrollbar height="500px"> -->
  104. <el-form
  105. ref="elFormRef"
  106. :model="detailData"
  107. label-position="left"
  108. :rules="rule"
  109. >
  110. <!-- 日期 -->
  111. <el-row>
  112. <el-form-item
  113. label="日期"
  114. prop="name"
  115. >
  116. <el-input
  117. v-model="detailData.wgjs_rq"
  118. :clearable="true"
  119. style="width: 100px;"
  120. />
  121. </el-form-item>
  122. </el-row>
  123. <!-- 标题栏 -->
  124. <el-row :gutter="10">
  125. <el-col :span="3">
  126. <span>员工编号</span>
  127. </el-col>
  128. <el-col :span="3">
  129. <span>员工姓名</span>
  130. </el-col>
  131. <el-col :span="3">
  132. <span>计时</span>
  133. </el-col>
  134. <el-col :span="12">
  135. <span>原因备注</span>
  136. </el-col>
  137. <el-col :span="3">
  138. <span>冲月定额</span>
  139. </el-col>
  140. </el-row>
  141. <!-- 员工1 -->
  142. <el-row
  143. :gutter="5"
  144. style="margin-top: 10px;"
  145. >
  146. <el-col :span="3">
  147. <el-input
  148. v-model="detailData.wgjs_bh1"
  149. :clearable="true"
  150. />
  151. </el-col>
  152. <el-col :span="3">
  153. <el-input
  154. v-model="detailData.name1"
  155. :clearable="true"
  156. />
  157. </el-col>
  158. <el-col :span="3">
  159. <el-input
  160. v-model="detailData.wgjs_js1"
  161. :clearable="true"
  162. />
  163. </el-col>
  164. <el-col :span="12">
  165. <el-input
  166. v-model="detailData.wgjs_yy1"
  167. :clearable="true"
  168. />
  169. </el-col>
  170. <el-col :span="3">
  171. <el-input
  172. v-model="detailData.wgjs_冲定额1"
  173. :clearable="true"
  174. />
  175. </el-col>
  176. </el-row>
  177. <!-- 员工2 -->
  178. <el-row
  179. :gutter="5"
  180. style="margin-top: 10px;"
  181. >
  182. <el-col :span="3">
  183. <el-input
  184. v-model="detailData.wgjs_bh2"
  185. :clearable="true"
  186. />
  187. </el-col>
  188. <el-col :span="3">
  189. <el-input
  190. v-model="detailData.name2"
  191. :clearable="true"
  192. />
  193. </el-col>
  194. <el-col :span="3">
  195. <el-input
  196. v-model="detailData.wgjs_js2"
  197. :clearable="true"
  198. />
  199. </el-col>
  200. <el-col :span="12">
  201. <el-input
  202. v-model="detailData.wgjs_yy2"
  203. :clearable="true"
  204. />
  205. </el-col>
  206. <el-col :span="3">
  207. <el-input
  208. v-model="detailData.wgjs_冲定额2"
  209. :clearable="true"
  210. />
  211. </el-col>
  212. </el-row>
  213. <!-- 员工3 -->
  214. <el-row
  215. :gutter="5"
  216. style="margin-top: 10px;"
  217. >
  218. <el-col :span="3">
  219. <el-input
  220. v-model="detailData.wgjs_bh3"
  221. :clearable="true"
  222. />
  223. </el-col>
  224. <el-col :span="3">
  225. <el-input
  226. v-model="detailData.name3"
  227. :clearable="true"
  228. />
  229. </el-col>
  230. <el-col :span="3">
  231. <el-input
  232. v-model="detailData.wgjs_js3"
  233. :clearable="true"
  234. />
  235. </el-col>
  236. <el-col :span="12">
  237. <el-input
  238. v-model="detailData.wgjs_yy3"
  239. :clearable="true"
  240. />
  241. </el-col>
  242. <el-col :span="3">
  243. <el-input
  244. v-model="detailData.wgjs_冲定额3"
  245. :clearable="true"
  246. />
  247. </el-col>
  248. </el-row>
  249. <!-- 员工4 -->
  250. <el-row
  251. :gutter="5"
  252. style="margin-top: 10px;"
  253. >
  254. <el-col :span="3">
  255. <el-input
  256. v-model="detailData.wgjs_bh4"
  257. :clearable="true"
  258. />
  259. </el-col>
  260. <el-col :span="3">
  261. <el-input
  262. v-model="detailData.name4"
  263. :clearable="true"
  264. />
  265. </el-col>
  266. <el-col :span="3">
  267. <el-input
  268. v-model="detailData.wgjs_js4"
  269. :clearable="true"
  270. />
  271. </el-col>
  272. <el-col :span="12">
  273. <el-input
  274. v-model="detailData.wgjs_yy4"
  275. :clearable="true"
  276. />
  277. </el-col>
  278. <el-col :span="3">
  279. <el-input
  280. v-model="detailData.wgjs_冲定额4"
  281. :clearable="true"
  282. />
  283. </el-col>
  284. </el-row>
  285. <!-- 员工5 -->
  286. <el-row
  287. :gutter="5"
  288. style="margin-top: 10px;"
  289. >
  290. <el-col :span="3">
  291. <el-input
  292. v-model="detailData.wgjs_bh5"
  293. :clearable="true"
  294. />
  295. </el-col>
  296. <el-col :span="3">
  297. <el-input
  298. v-model="detailData.name5"
  299. :clearable="true"
  300. />
  301. </el-col>
  302. <el-col :span="3">
  303. <el-input
  304. v-model="detailData.wgjs_js5"
  305. :clearable="true"
  306. />
  307. </el-col>
  308. <el-col :span="12">
  309. <el-input
  310. v-model="detailData.wgjs_yy5"
  311. :clearable="true"
  312. />
  313. </el-col>
  314. <el-col :span="3">
  315. <el-input
  316. v-model="detailData.wgjs_冲定额5"
  317. :clearable="true"
  318. />
  319. </el-col>
  320. </el-row>
  321. <!-- 员工6 -->
  322. <el-row
  323. :gutter="5"
  324. style="margin-top: 10px;"
  325. >
  326. <el-col :span="3">
  327. <el-input
  328. v-model="detailData.wgjs_bh6"
  329. :clearable="true"
  330. />
  331. </el-col>
  332. <el-col :span="3">
  333. <el-input
  334. v-model="detailData.name6"
  335. :clearable="true"
  336. />
  337. </el-col>
  338. <el-col :span="3">
  339. <el-input
  340. v-model="detailData.wgjs_js6"
  341. :clearable="true"
  342. />
  343. </el-col>
  344. <el-col :span="12">
  345. <el-input
  346. v-model="detailData.wgjs_yy6"
  347. :clearable="true"
  348. />
  349. </el-col>
  350. <el-col :span="3">
  351. <el-input
  352. v-model="detailData.wgjs_冲定额6"
  353. :clearable="true"
  354. />
  355. </el-col>
  356. </el-row>
  357. </el-form>
  358. <template #footer>
  359. <div class="dialog-footer">
  360. <el-button @click="closeDialog">取 消</el-button>
  361. <el-button
  362. type="primary"
  363. @click="enterDialog"
  364. >确 定</el-button>
  365. </div>
  366. </template>
  367. </el-dialog>
  368. </el-main>
  369. </el-container>
  370. </el-container>
  371. </div>
  372. </template>
  373. <script setup>
  374. import {
  375. createCompany,
  376. deleteCompany,
  377. deleteCompanyByIds,
  378. updateCompany,
  379. findCompany,
  380. getCompanyList
  381. } from '@/api/company'
  382. // 全量引入格式化工具 请按需保留
  383. import { getDictFunc, formatDate, formatBoolean, filterDict, ReturnArrImg, onDownloadFile } from '@/utils/format'
  384. import { ElMessage, ElMessageBox } from 'element-plus'
  385. import { Search, Refresh, Download } from '@element-plus/icons-vue'
  386. import { ref, reactive, onMounted, onBeforeMount } from 'vue'
  387. import { getSide, getTable, getDetail, updateData, getLocate ,createData} from '@/api/mes_api_gty/timesheet'
  388. defineOptions({
  389. name: '08Timesheet'
  390. })
  391. // 侧边栏数据请求
  392. const treeData = reactive([])
  393. const getSideData = async() => {
  394. const response = await getSide()
  395. if (response.code === 0) {
  396. const transformedData = response.data.map(item => ({
  397. label: item.date,
  398. params: {
  399. date: item.date.substring(0, 4) + '-' + item.date.substring(4),
  400. },
  401. }))
  402. treeData.splice(0, treeData.length, ...transformedData)
  403. }
  404. }
  405. getSideData()
  406. // 验证规则
  407. const rule = reactive({
  408. })
  409. const elFormRef = ref()
  410. const elSearchFormRef = ref()
  411. // ============== 表格页面 ==============
  412. const tableColumns = [
  413. { prop: 'wgjs_rq', label: '日期', width: 100 },
  414. { prop: 'wgjs_bh1', label: '员工编号1', width: 100 },
  415. { prop: 'name1', label: '姓名1', width: 100 },
  416. { prop: 'department', label: '所在部门', width: 100 },
  417. { prop: 'wgjs_js1', label: '计时1', width: 100 },
  418. { prop: 'wgjs_yy1', label: '原因1', width: 100 },
  419. { prop: 'wgjs_bh2', label: '员工编号2', width: 100 },
  420. { prop: 'name2', label: '姓名2', width: 100 },
  421. { prop: 'wgjs_js2', label: '计时2', width: 100 },
  422. { prop: 'wgjs_yy2', label: '原因2', width: 100 },
  423. { prop: 'wgjs_bh3', label: '员工编号3', width: 100 },
  424. { prop: 'name3', label: '姓名3', width: 100 },
  425. { prop: 'wgjs_js3', label: '计时3', width: 100 },
  426. { prop: 'wgjs_yy3', label: '原因3', width: 100 },
  427. { prop: 'wgjs_bh4', label: '员工编号4', width: 100 },
  428. { prop: 'name4', label: '姓名4', width: 100 },
  429. { prop: 'wgjs_js4', label: '计时4', width: 100 },
  430. { prop: 'wgjs_yy4', label: '原因4', width: 100 },
  431. { prop: 'wgjs_bh5', label: '员工编号5', width: 100 },
  432. { prop: 'name5', label: '姓名5', width: 100 },
  433. { prop: 'wgjs_js5', label: '计时5', width: 100 },
  434. { prop: 'wgjs_yy5', label: '原因5', width: 100 },
  435. { prop: 'wgjs_bh6', label: '员工编号6', width: 100 },
  436. { prop: 'name6', label: '姓名6', width: 100 },
  437. { prop: 'wgjs_js6', label: '计时6', width: 100 },
  438. { prop: 'wgjs_yy6', label: '原因6', width: 100 },
  439. ]
  440. const tableData = reactive([])
  441. const page = ref(1)
  442. const total = ref(0)
  443. const limit = ref(10)
  444. const searchInfo = ref('')
  445. const params = {
  446. date: '',
  447. search: '',
  448. type: '',
  449. }
  450. const getTableData = async(params) => {
  451. const response = await getTable(params)
  452. if (response.code === 0) {
  453. total.value = response.data.total
  454. tableData.splice(0, tableData.length, ...response.data.rows)
  455. }
  456. }
  457. // 搜索
  458. const getLocateData = async(params) => {
  459. const res = await getLocate(params)
  460. if (res.code === 0) {
  461. total.value = res.data.total
  462. tableData.splice(0, tableData.length, ...res.data.rows)
  463. }
  464. }
  465. // 分页设置
  466. const handleSizeChange = () => {
  467. switch (params.type) {
  468. case 'getTableData':
  469. getTableData({ date: params.date, page: page.value.toString(), limit: limit.value.toString() })
  470. break
  471. case 'getLocateData':
  472. getLocateData({ date: params.date.replace('-', ''),
  473. search: params.search,
  474. page: page.value.toString(),
  475. limit: limit.value.toString() })
  476. break
  477. default:
  478. break
  479. }
  480. }
  481. // 页面跳转
  482. const handleCurrentChange = () => {
  483. switch (params.type) {
  484. case 'getTableData':
  485. getTableData({ date: params.date, page: page.value.toString(), limit: limit.value.toString() })
  486. break
  487. case 'getLocateData':
  488. getLocateData({ date: params.date.replace('-', ''),
  489. search: params.search,
  490. page: page.value.toString(),
  491. limit: limit.value.toString() })
  492. break
  493. default:
  494. break
  495. }
  496. }
  497. const handleNodeClick = (node, check) => {
  498. if (node.params) {
  499. params.date = node.params.date
  500. params.type = 'getTableData'
  501. page.value = 1
  502. handleCurrentChange()
  503. }
  504. }
  505. // 新增数据
  506. const handleShowAdd = async () => {
  507. const res = await getDetail({ wgjs_rq: value1.value, wgjs_bh1: value2.value });
  508. if (res.code === 0) {
  509. type.value='add'
  510. Object.assign(detailData, res.data);
  511. dialogFormVisible.value = true
  512. }
  513. };
  514. // 搜索
  515. function onSearch() {
  516. params.search = searchInfo.value
  517. params.type = 'getLocateData'
  518. page.value = 1
  519. handleCurrentChange()
  520. }
  521. // ============== 详情页面 ==============
  522. const detailData = reactive({})
  523. // 行为控制标记(弹窗内部需要增还是改)
  524. const type = ref('')
  525. // 弹窗控制标记
  526. const dialogFormVisible = ref(false)
  527. // 双击表格操作
  528. async function doubleClick(row, column, event) {
  529. type.value = 'update'
  530. const { wgjs_rq, wgjs_bh1 } = row
  531. const res = await getDetail({ wgjs_rq, wgjs_bh1 })
  532. if (res.code === 0) {
  533. Object.assign(detailData, res.data)
  534. dialogFormVisible.value = true
  535. }
  536. }
  537. const value1=ref()
  538. const value2=ref()
  539. // 单击表格操作
  540. async function Click(row, column, event) {
  541. const { wgjs_rq, wgjs_bh1 } = row
  542. value1.value=wgjs_rq
  543. value2.value=wgjs_bh1
  544. // console.log(wgjs_rq)
  545. // console.log(wgjs_bh1)
  546. // const res = await getDetail({ wgjs_rq, wgjs_bh1 })
  547. // if (res.code === 0) {
  548. // Object.assign(detailData, res.data)
  549. // dialogFormVisible.value = true
  550. // }
  551. }
  552. // 更新数据
  553. const enterDialog = async() => {
  554. if (type.value === 'update') {
  555. updateDetailData()
  556. } else if (type.value === 'add') {
  557. addDetailData()
  558. }
  559. }
  560. //新增
  561. const addDetailData = async() => {
  562. const restoredData = {
  563. wgjs_rq: detailData.wgjs_rq,
  564. wgjs_bh1:detailData.wgjs_bh1,
  565. wgjs_js1:detailData.wgjs_js1,
  566. wgjs_yy1:detailData.wgjs_yy1,
  567. wgjs_冲定额1:detailData.wgjs_冲定额1,
  568. wgjs_bh2:detailData.wgjs_bh2,
  569. wgjs_js2:detailData.wgjs_js2,
  570. wgjs_yy2:detailData.wgjs_yy2,
  571. wgjs_冲定额2:detailData.wgjs_冲定额2,
  572. wgjs_bh3:detailData.wgjs_bh3,
  573. wgjs_js3:detailData.wgjs_js3,
  574. wgjs_yy3:detailData.wgjs_yy3,
  575. wgjs_冲定额3:detailData.wgjs_冲定额3,
  576. wgjs_bh4:detailData.wgjs_bh4,
  577. wgjs_js4:detailData.wgjs_js4,
  578. wgjs_yy4:detailData.wgjs_yy4,
  579. wgjs_冲定额4:detailData.wgjs_冲定额4,
  580. wgjs_bh5:detailData.wgjs_bh5,
  581. wgjs_js5:detailData.wgjs_js5,
  582. wgjs_yy5:detailData.wgjs_yy5,
  583. wgjs_冲定额5:detailData.wgjs_冲定额5,
  584. wgjs_bh6:detailData.wgjs_bh6,
  585. wgjs_js6:detailData.wgjs_js6,
  586. wgjs_yy6:detailData.wgjs_yy6,
  587. wgjs_冲定额6:detailData.wgjs_冲定额6,
  588. }
  589. console.log(restoredData)
  590. const res = await createData(restoredData)
  591. console.log(res)
  592. // console.log(res)
  593. // if (res.code === 0) {
  594. // ElMessage({
  595. // type: 'success',
  596. // message: '新增成功',
  597. // })
  598. // dialogFormVisible.value = false
  599. // }
  600. }
  601. //修改
  602. const updateDetailData = async() => {
  603. const obj = detailData
  604. for (let i = 1; i <= 6; i++) {
  605. delete obj[`name${i}`]
  606. }
  607. const res = await updateData(obj)
  608. if (res.code === 0) {
  609. ElMessage({
  610. type: 'success',
  611. message: '更新成功'
  612. })
  613. params.type = 'getTableData'
  614. // page.value = 1
  615. handleCurrentChange()
  616. dialogFormVisible.value = false
  617. }
  618. }
  619. // 获取需要的字典 可能为空 按需保留
  620. const setOptions = async() => {
  621. }
  622. // 获取需要的字典 可能为空 按需保留
  623. setOptions()
  624. // 多选数据
  625. const multipleSelection = ref([])
  626. // 多选
  627. const handleSelectionChange = (val) => {
  628. multipleSelection.value = val
  629. }
  630. // 批量删除控制标记
  631. const deleteVisible = ref(false)
  632. // 多选删除
  633. const onDelete = async() => {
  634. const ids = []
  635. if (multipleSelection.value.length === 0) {
  636. ElMessage({
  637. type: 'warning',
  638. message: '请选择要删除的数据'
  639. })
  640. return
  641. }
  642. multipleSelection.value &&
  643. multipleSelection.value.map(item => {
  644. ids.push(item.ID)
  645. })
  646. const res = await deleteCompanyByIds({ ids })
  647. if (res.code === 0) {
  648. ElMessage({
  649. type: 'success',
  650. message: '删除成功'
  651. })
  652. if (tableData.value.length === ids.length && page.value > 1) {
  653. page.value--
  654. }
  655. deleteVisible.value = false
  656. getTableData()
  657. }
  658. }
  659. // 更新行
  660. const updateCompanyFunc = async(row) => {
  661. const res = await findCompany({ ID: row.ID })
  662. type.value = 'update'
  663. if (res.code === 0) {
  664. detailData.value = res.data.recompany
  665. dialogFormVisible.value = true
  666. }
  667. }
  668. // 关闭弹窗
  669. const closeDialog = () => {
  670. dialogFormVisible.value = false
  671. }
  672. // 导出excel
  673. function exportExcel() {
  674. console.log('导出到excel')
  675. }
  676. // 生命周期钩子
  677. onMounted(() => {
  678. })
  679. </script>
  680. <style scoped>
  681. .JKWTree-container {
  682. display: flex;
  683. }
  684. .JKWTree-tree {
  685. width: 300px;
  686. background-color: #fff;
  687. padding: 10px;
  688. margin-right: 20px;
  689. }
  690. .JKWTree-tree h3 {
  691. font-size: 15px;
  692. font-weight: 700;
  693. margin: 10px 0;
  694. }
  695. .JKWTree-content {
  696. flex: 1;
  697. }
  698. /* 选中某行时的背景色 */
  699. :deep(.el-table__body tr.current-row) > td {
  700. background: #ff80ff !important;
  701. }
  702. </style>