chengpinrucang.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <template>
  2. <div>
  3. <layout>
  4. <layout-header>
  5. <div class="">
  6. <!-- 按钮部分-->
  7. <el-form ref="elSearchFormRef" class="demo-form-inline" :rules="searchRule" >
  8. <el-form-item>
  9. <!-- <el-input v-model="searchInfo" placeholder="搜索工单编号" clearable style="width: 200px;margin: 5px"></el-input> -->
  10. <el-input v-model="searchInfo" placeholder="输入订单编号" style="width: 180px;" @keyup.enter="onSubmit()"></el-input>
  11. <el-button type="primary" icon="search" @click="onSubmit" title="查询" >查询</el-button>
  12. <el-button type="primary" class="bt" icon="download" @click="hzToExcel" >订单成品导出</el-button>
  13. <!-- <el-button type="primary" class="bt" icon="download" @click="mxToExcel" >导出到Excel(明细)</el-button> -->
  14. </el-form-item>
  15. </el-form>
  16. </div>
  17. </layout-header>
  18. <layout>
  19. <!-- 左侧树侧形结构-->
  20. <layout-sider :resize-directions="['right']" :width="220" style="margin-right: 10px;">
  21. <div class="JKWTree-tree" style="height: 200px">
  22. <h3>产品返工次片合格率汇总</h3>
  23. <el-tree :data="treeData" :props="defaultProps" class="treecolor" @node-click="handleNodeClick" @node-expand="handleNodeExpand">
  24. </el-tree>
  25. </div>
  26. </layout-sider>
  27. <!-- 右侧区域 -->
  28. <layout-content >
  29. <!-- <el-main> -->
  30. <div class="gva-table-box">
  31. <!-- 表格数据 -->
  32. <el-table ref="multipleTable" style="width: 100%;height: 33vh" tooltip-effect="dark"
  33. :row-style="{ height: '25px' }" :header-cell-style="{ padding: '0px' }"
  34. :cell-style="{ padding: '0px' }" :header-row-style="{ height: '20px' }"
  35. :data="hztableData" border row-key="ID"
  36. size="small"
  37. :cell-class-name="gxbgCellClass"
  38. highlight-current-row="true" @row-dblclick="updateCompanyFunc"
  39. @row-click="tableRowClick" :show-overflow-tooltip="true"
  40. @selection-change="handleSelectionChange">
  41. <el-table-column sortable align="center" label="订单编号" prop="订单编号" width="120" />
  42. <el-table-column sortable align="center" label="生产款号" prop="生产款号" width="170" />
  43. <el-table-column sortable align="center" label="款式" prop="款式" width="120" />
  44. <el-table-column sortable align="center" label="制单数量" prop="订单数量" width="120" />
  45. <!-- <el-table-column align="center" label="实裁数量" prop="实裁数量" width="110" /> -->
  46. <el-table-column align="center" label="本月总检完工数量" prop="入仓数量" width="150" />
  47. <el-table-column align="center" label="累计总检完工数量" prop="累计入仓数量" width="150" />
  48. <el-table-column align="center" label="裁剪总产量" prop="裁剪总产量" width="120" />
  49. <el-table-column sortable align="center" label="实际合格率" prop="裁剪合格率" width="120" />
  50. <!-- <el-table-column align="center" label="车缝总产量" prop="车缝总产量" width="200" />
  51. <el-table-column align="center" label="车缝合格率" prop="车缝合格率" width="200" /> -->
  52. <el-table-column align="center" label="返工总数" prop="返工总数" width="120" />
  53. <el-table-column align="center" label="次片总数" prop="次片总数" width="120" />
  54. </el-table>
  55. <!-- 分页 -->
  56. <div class="gva-pagination">
  57. <el-pagination layout="total" :current-page="page" :page-size="pageSize"
  58. :total="total" @current-change="handleCurrentChange" @size-change="handleSizeChange" />
  59. </div>
  60. </div>
  61. <div class="gva-table-box">
  62. <!-- 表格数据 -->
  63. <el-table ref="multipleTable" style="width: 100%;height: 45vh" tooltip-effect="dark"
  64. :row-style="{ height: '25px' }" :header-cell-style="{ padding: '0px' }"
  65. :cell-style="{ padding: '0px' }" :header-row-style="{ height: '20px' }"
  66. :data="mxtableData" border row-key="ID"
  67. size="small"
  68. :cell-class-name="gxbgCellClass"
  69. highlight-current-row="true" @row-dblclick="updateCompanyFunc"
  70. :show-overflow-tooltip="true"
  71. @selection-change="handleSelectionChange">
  72. <el-table-column sortable align="center" label="子订单编号" prop="子订单编号" width="160" />
  73. <el-table-column sortable align="center" label="PO号" prop="生产款号" width="200" />
  74. <el-table-column sortable align="center" label="颜色" prop="颜色" width="160" />
  75. <el-table-column sortable align="center" label="颜色备注" prop="颜色备注" width="200" />
  76. <el-table-column sortable align="center" label="制单数量" prop="zdtotal" width="120" />
  77. <el-table-column align="center" label="本月总检完工数量" prop="入仓数量" width="150" />
  78. <el-table-column align="center" label="累计总检完工数量" prop="累计入仓数量" width="150" />
  79. <el-table-column align="center" label="裁剪数量" prop="裁剪数量" width="100" />
  80. <el-table-column sortable align="center" label="实际合格率" prop="实际合格率" width="120" />
  81. <!-- <el-table-column sortable align="center" label="车缝数量" prop="车缝数量" width="100" />
  82. <el-table-column sortable align="center" label="车缝合格率" prop="车缝合格率" width="120" /> -->
  83. </el-table>
  84. <!-- 分页 -->
  85. <div class="gva-pagination">
  86. <el-pagination layout="total" :current-page="page" :page-size="pageSize"
  87. :total="total" @current-change="handleCurrentChange" @size-change="handleSizeChange" />
  88. </div>
  89. </div>
  90. <el-dialog v-model="onhzexcel" title="汇总数据导出" destroy-on-close style="height: 30%;width: 20%;">
  91. <el-form-item label="选择年月" label-width="100px">
  92. <el-date-picker
  93. v-model="hzrq"
  94. type="month"
  95. placeholder="选择年月"
  96. :default-value="new Date()"
  97. @change="hzonchange_data"
  98. style="width: 200px;"
  99. />
  100. </el-form-item>
  101. <template #footer>
  102. <div class="dialog-footer" style="text-align: right;">
  103. <el-button @click="hzcloseDialog">取消</el-button>
  104. <el-button type="primary" @click="hzonDialog">确定</el-button>
  105. </div>
  106. </template>
  107. </el-dialog>
  108. <el-dialog v-model="onmxexcel" title="明细数据导出" destroy-on-close style="height: 30%;width: 20%;">
  109. <el-form-item label="选择年月" label-width="100px">
  110. <el-date-picker
  111. v-model="mxrq"
  112. type="month"
  113. placeholder="选择年月"
  114. :default-value="new Date()"
  115. @change="mxonchange_data"
  116. style="width: 200px;"
  117. />
  118. </el-form-item>
  119. <template #footer>
  120. <div class="dialog-footer" style="text-align: right;">
  121. <el-button @click="mxcloseDialog">取消</el-button>
  122. <el-button type="primary" @click="mxonDialog">确定</el-button>
  123. </div>
  124. </template>
  125. </el-dialog>
  126. <!-- </el-main> -->
  127. </layout-content>
  128. </layout>
  129. </layout>
  130. </div>
  131. </template>
  132. <script setup>
  133. // 全量引入格式化工具 请按需保留
  134. import { Layout, LayoutSider, LayoutContent } from '@arco-design/web-vue';
  135. import * as XLSX from 'xlsx'
  136. import FileSaver from 'file-saver'
  137. import {ref, reactive} from 'vue'
  138. import { exportExcelFile } from '@/utils/excel'
  139. import {ElMessage} from "element-plus";
  140. import { GetWfpList,GetWfpDataLeft,GetSubOrderStats} from '@/api/mes/job'
  141. defineOptions({name: 'Company'})
  142. // =========== 获取左侧树侧形结构 ===========
  143. const treeData = ref('')
  144. // 获取树形数据
  145. const getTree = async () => {
  146. try {
  147. const response = await GetWfpDataLeft()
  148. const data = response.data
  149. // 获取所有年月键并排序(降序,最近的在上方)
  150. const sortedYearMonths = Object.keys(data).sort((a, b) => {
  151. const yearMonthA = parseInt(a);
  152. const yearMonthB = parseInt(b);
  153. // 降序排列(最近的在上方)
  154. return yearMonthB - yearMonthA;
  155. });
  156. // 转换数据为el-tree需要的格式
  157. treeData.value = sortedYearMonths.map(yearMonth => {
  158. return {
  159. label: `${yearMonth}`,
  160. children: data[yearMonth].map(customer => {
  161. return {
  162. label: `${customer.客户编号} (${customer.total}条)`,
  163. yearMonth: yearMonth,
  164. customerCode: customer.客户编号,
  165. total: customer.total,
  166. }
  167. })
  168. }
  169. })
  170. } catch (error) {
  171. ElMessage.error('获取数据失败')
  172. console.error('获取树形数据失败:', error)
  173. }
  174. }
  175. getTree()
  176. const hztableData = ref([])
  177. const _noderq = ref('')
  178. const _nodecode = ref('')
  179. const handleNodeClick = async (node) => {
  180. // 取消所有节点的颜色
  181. const allNodes = document.querySelectorAll('.treecolor .el-tree-node');
  182. allNodes.forEach(node => {
  183. node.querySelector('.el-tree-node__label').style.color = '';
  184. });
  185. // 获取点击的节点 给当前点击的节点改变颜色【红色】
  186. const clickedNodeId = node['$treeNodeId'];
  187. const clickedNode = document.querySelector(`.treecolor .el-tree-node[data-key="${clickedNodeId}"]`);
  188. if (clickedNode) {
  189. clickedNode.querySelector('.el-tree-node__label').style.color = 'red';
  190. }
  191. _noderq.value = node.yearMonth
  192. _nodecode.value = node.customerCode
  193. console.log('点击节点:', node)
  194. if (!node.children) {
  195. const res = await GetWfpList({sys_rq: node.yearMonth,customer: node.customerCode,})
  196. console.log('获取数据:', res)
  197. if(res.code === 0){
  198. hztableData.value = res.data.result
  199. }
  200. }
  201. }
  202. const mxtableData = ref([])
  203. const tableRowClick = async(row) => {
  204. const res = await GetSubOrderStats({sys_rq: _noderq.value,customer: _nodecode.value,order:row.订单编号})
  205. console.log('获取数据:', res)
  206. if(res.code === 0){
  207. mxtableData.value = res.data.result
  208. }
  209. }
  210. const searchInfo = ref('')
  211. const onSubmit = async () => {
  212. if (!searchInfo.value) {
  213. ElMessage.warning('请输入订单编号');
  214. return;
  215. }else{
  216. const res = await GetWfpList({search:searchInfo.value})
  217. console.log('获取数据:', res)
  218. if(res.code === 0){
  219. hztableData.value = res.data.result
  220. }
  221. }
  222. }
  223. // 通用的导出Excel函数
  224. const exportToExcel = (data, filename = '导出数据.xlsx', sheetName = 'Sheet1') => {
  225. try {
  226. // 创建工作簿和工作表
  227. const wb = XLSX.utils.book_new();
  228. // 如果data是DOM元素(表格)
  229. if (typeof data === 'object' && data.nodeType === 1) {
  230. const worksheet = XLSX.utils.table_to_sheet(data, { raw: true });
  231. convertColumnsToNumber(worksheet);
  232. XLSX.utils.book_append_sheet(wb, worksheet, sheetName);
  233. }
  234. // 如果data是数组(接口数据)
  235. else if (Array.isArray(data)) {
  236. const worksheet = XLSX.utils.json_to_sheet(data);
  237. XLSX.utils.book_append_sheet(wb, worksheet, sheetName);
  238. }
  239. // 如果data已经是worksheet对象
  240. else if (data['!ref']) {
  241. XLSX.utils.book_append_sheet(wb, data, sheetName);
  242. } else {
  243. throw new Error('不支持的导出数据类型');
  244. }
  245. // 导出文件
  246. XLSX.writeFile(wb, filename);
  247. return true;
  248. } catch (error) {
  249. console.error('导出Excel失败:', error);
  250. ElMessage.error('导出失败: ' + error.message);
  251. return false;
  252. }
  253. };
  254. // 列转换为数字的通用函数
  255. const convertColumnsToNumber = (worksheet, startCol = 2) => {
  256. const range = XLSX.utils.decode_range(worksheet['!ref']);
  257. for (let col = startCol; col <= range.e.c; col++) {
  258. for (let row = range.s.r + 1; row <= range.e.r; row++) {
  259. const cellAddress = XLSX.utils.encode_cell({ r: row, c: col });
  260. if (worksheet[cellAddress]) {
  261. const cellValue = worksheet[cellAddress].v;
  262. const numValue = Number(cellValue);
  263. if (!isNaN(numValue) && cellValue !== '') {
  264. worksheet[cellAddress].t = 'n';
  265. worksheet[cellAddress].v = numValue;
  266. worksheet[cellAddress].z = '0';
  267. }
  268. }
  269. }
  270. }
  271. };
  272. const onhzexcel = ref(false)
  273. const onmxexcel = ref(false)
  274. const mxrq = ref('')
  275. const hzrq = ref('')
  276. const hzToExcel = async=> {
  277. onhzexcel.value = true
  278. }
  279. const hzcloseDialog = () => {
  280. onhzexcel.value = false
  281. }
  282. const hzonchange_data = (val) => {
  283. if (val) {
  284. // 将日期对象转换为本地时间的年月格式
  285. const year = val.getFullYear()
  286. const month = (val.getMonth() + 1).toString().padStart(2, '0')
  287. hzrq.value = `${year}${month}`
  288. } else {
  289. hzrq.value = ''
  290. }
  291. }
  292. const hzonDialog = async() => {
  293. if(!hzrq.value){
  294. ElMessage.error('请选择年月')
  295. return
  296. }
  297. const res = await GetWfpList({sys_rq: hzrq.value})
  298. console.log('获取数据:', res)
  299. if(res.code === 0){
  300. // 直接使用接口返回的数据导出
  301. const success = exportToExcel(
  302. res.data.result,
  303. `生产数据汇总_${hzrq.value}.xlsx`,
  304. '生产汇总'
  305. );
  306. if(success) {
  307. ElMessage.success('导出成功');
  308. }
  309. } else {
  310. ElMessage.error(res.msg || '获取数据失败');
  311. }
  312. }
  313. const mxToExcel = async=> {
  314. onmxexcel.value = true
  315. }
  316. const mxcloseDialog = () => {
  317. onmxexcel.value = false
  318. }
  319. const mxonchange_data = (val) => {
  320. if (val) {
  321. // 将日期对象转换为本地时间的年月格式
  322. const year = val.getFullYear()
  323. const month = (val.getMonth() + 1).toString().padStart(2, '0')
  324. mxrq.value = `${year}${month}`
  325. } else {
  326. mxrq.value = ''
  327. }
  328. }
  329. const mxonDialog = async() => {
  330. if(!mxrq.value){
  331. ElMessage.error('请选择年月')
  332. return
  333. }
  334. const res = await GetSubOrderStats({sys_rq: mxrq.value})
  335. console.log('获取数据:', res)
  336. if(res.code === 0){
  337. // 直接使用接口返回的数据导出
  338. const success = exportToExcel(
  339. res.data.result,
  340. `生产数据汇总_${hzrq.value}.xlsx`,
  341. '生产汇总'
  342. );
  343. if(success) {
  344. ElMessage.success('导出成功');
  345. }
  346. } else {
  347. ElMessage.error(res.msg || '获取数据失败');
  348. }
  349. }
  350. </script>
  351. <style scoped>
  352. .form-container {
  353. display: flex;
  354. flex-wrap: wrap;
  355. }
  356. .form-column {
  357. /*flex: 1;*/
  358. margin-right: 15px; /* 调整列之间的间距 */
  359. }
  360. /* 左侧输入框宽度调整 */
  361. .form-column .el-form-item .el-input {
  362. width: 150px; /* 调整左侧输入框的宽度 */
  363. }
  364. :deep(.hui-plan-usage-lows div) {
  365. color: #8c939d !important;
  366. }
  367. :deep(.lan-plan-usage-lows div) {
  368. color: blue !important;
  369. font-weight: bold;
  370. }
  371. /* 媒体查询,根据需要调整断点 */
  372. @media screen and (max-width: 768px) {
  373. .form-column {
  374. flex: 1 0 100%; /* 在小屏幕下变成单列布局 */
  375. margin-right: 0;
  376. }
  377. }
  378. /*:deep(.el-table td .cell) {*/
  379. /* line-height: 30px !important;*/
  380. /*}*/
  381. .JKWTree-container {
  382. display: flex;
  383. }
  384. .JKWTree-tree {
  385. /*width: 300px;*/
  386. background-color: #fff;
  387. padding: 10px;
  388. margin-right: 20px;
  389. }
  390. .JKWTree-tree h3 {
  391. font-size: 15px;
  392. font-weight: 700;
  393. margin: 10px 0;
  394. }
  395. .JKWTree-content {
  396. flex: 1;
  397. }
  398. /* 选中某行时的背景色 */
  399. :deep(.el-table__body tr.current-row) > td {
  400. background: #ff80ff !important;
  401. }
  402. </style>
  403. <style scoped>
  404. :deep(.el-table td .cell) {
  405. line-height: 20px !important;
  406. }
  407. :deep(.el-tabs__header){
  408. margin-bottom: 0;
  409. }
  410. .search{
  411. margin-left: 0px !important;
  412. margin-right: 10px !important;
  413. }
  414. .bt{
  415. margin-left: 2px !important;
  416. padding: 3px !important;
  417. font-size: 12px;
  418. }
  419. .el-tabs__header{
  420. margin: 0px !important;
  421. }
  422. .gva-table-box{
  423. padding: 0px !important;
  424. }
  425. .mab{
  426. margin-bottom: 5px;
  427. }
  428. </style>