index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never" v-loading="loading">
  4. <productionPlan-search
  5. @search="reload"
  6. ref="searchRef"
  7. :statusOpt="statusOpt"
  8. :planType="planType"
  9. :activeName="activeName"
  10. >
  11. </productionPlan-search>
  12. <el-tabs v-model="activeName" type="card">
  13. <el-tab-pane label="未发布" name="first"></el-tab-pane>
  14. <el-tab-pane label="已发布" name="second"></el-tab-pane>
  15. </el-tabs>
  16. <!-- 数据表格 -->
  17. <ele-pro-table
  18. ref="table"
  19. :key="activeName"
  20. :initLoad="false"
  21. :columns="columns"
  22. :datasource="datasource"
  23. :cache-key="`${activeName}ProductionPlanTable`"
  24. @sort-change="onSortChange"
  25. >
  26. <template v-slot:code="{ row }">
  27. <el-link type="primary" :underline="false" @click="goDetail(row)">
  28. {{ row.code }}
  29. </el-link>
  30. </template>
  31. <template v-slot:priority="{ row }">
  32. <el-input
  33. v-model="row.priority"
  34. type="number"
  35. size="mini"
  36. :min="0"
  37. :max="10"
  38. @change="priorityChange(row)"
  39. ></el-input>
  40. <el-popover
  41. placement="right"
  42. width="200"
  43. trigger="hover"
  44. content="数值越大优先级越高(0-3普通, 4-6优先, 7-10紧急)"
  45. >
  46. <div class="sort-wrap" slot="reference">
  47. <i class="el-icon-caret-top" @click="sortTop(row)"></i>
  48. <i class="el-icon-caret-bottom" @click="sortBottom(row)"></i>
  49. </div>
  50. </el-popover>
  51. </template>
  52. <template v-slot:productWeight="{ row }">
  53. {{ row.productWeight }} {{ row.weightUnit }}
  54. </template>
  55. <template v-slot:newSumOrderWeight="{ row }">
  56. {{ row.newSumOrderWeight }} {{ row.newWeightUnit }}
  57. </template>
  58. <template v-slot:status="{ row }">
  59. <span :class="{ 'ele-text-danger': row.status == 3 }">
  60. {{ statusFormatter(row.status) }}
  61. </span>
  62. </template>
  63. <!-- 操作列 -->
  64. <template v-slot:action="{ row }">
  65. <el-link
  66. type="primary"
  67. :underline="false"
  68. icon="el-icon-truck"
  69. v-if="row.status == 2"
  70. @click="handleOrderPublish(1, row)"
  71. >
  72. 发布工单
  73. </el-link>
  74. <el-link
  75. type="primary"
  76. v-if="row.status == 3"
  77. :underline="false"
  78. icon="el-icon-truck"
  79. @click="handleOrderPublish(2, row)"
  80. >
  81. 重新发布
  82. </el-link>
  83. <el-link
  84. type="primary"
  85. :underline="false"
  86. icon="el-icon-edit"
  87. @click="planEdit(row)"
  88. >
  89. 修改计划
  90. </el-link>
  91. <el-link
  92. type="primary"
  93. :underline="false"
  94. @click="handleDelete(row)"
  95. icon="el-icon-edit"
  96. >
  97. 删除
  98. </el-link>
  99. </template>
  100. </ele-pro-table>
  101. </el-card>
  102. </div>
  103. </template>
  104. <script>
  105. import { getList, del, updatePriority } from '@/api/productionPlan/index.js';
  106. import productionPlanSearch from './components/productionPlan-search.vue';
  107. import { release } from '@/api/productionPlan/order.js';
  108. import { multiply } from '@/utils/math';
  109. import { getCode } from '@/api/codeManagement';
  110. import { debounce } from 'lodash';
  111. export default {
  112. components: {
  113. productionPlanSearch
  114. },
  115. data() {
  116. return {
  117. activeName: 'first',
  118. // 加载状态
  119. loading: false,
  120. pageType: 'add',
  121. dialogTitle: '',
  122. isBindPlan: false,
  123. statusOpt: {
  124. first: [
  125. { label: '所有状态', value: '3,2' },
  126. { label: '待发布', value: '2' },
  127. { label: '发布失败', value: '3' }
  128. ],
  129. second: [
  130. { label: '所有状态', value: '7,4,5,6' },
  131. { label: '待生产', value: '4' },
  132. { label: '生产中', value: '5' },
  133. { label: '已完成', value: '6' },
  134. { label: '已延期', value: '7' }
  135. ]
  136. },
  137. planType: [
  138. { label: '所有计划类型', value: null },
  139. { label: '内销计划', value: '1' },
  140. { label: '外销计划', value: '2' },
  141. { label: '预制计划', value: '3' }
  142. ]
  143. };
  144. },
  145. computed: {
  146. clientEnvironmentId() {
  147. return this.$store.state.user.info.clientEnvironmentId;
  148. },
  149. // 表格列配置
  150. columns() {
  151. const opt = {
  152. first: [
  153. // {
  154. // prop: 'deliveryTime',
  155. // label: '预测交货日期',
  156. // align: 'center',
  157. // showOverflowTooltip: true,
  158. // minWidth: 110
  159. // }
  160. ],
  161. second: [
  162. // {
  163. // prop: 'formingTime',
  164. // label: '实际生产日期',
  165. // align: 'center',
  166. // showOverflowTooltip: true,
  167. // minWidth: 110
  168. // },
  169. {
  170. prop: 'releaseTime',
  171. label: '工单发布日期',
  172. align: 'center',
  173. showOverflowTooltip: true,
  174. minWidth: 110
  175. },
  176. {
  177. prop: 'planFormingTime',
  178. label: '预测生产日期',
  179. align: 'center',
  180. showOverflowTooltip: true,
  181. minWidth: 110
  182. },
  183. {
  184. prop: 'deliveryTime',
  185. label: '预测交货日期',
  186. align: 'center',
  187. showOverflowTooltip: true,
  188. minWidth: 110
  189. },
  190. {
  191. prop: 'formingTime',
  192. label: '实际交货日期',
  193. align: 'center',
  194. showOverflowTooltip: true,
  195. minWidth: 110
  196. }
  197. ]
  198. };
  199. return [
  200. {
  201. columnKey: 'index',
  202. label: '序号',
  203. type: 'index',
  204. width: 55,
  205. align: 'center',
  206. showOverflowTooltip: true,
  207. fixed: 'left'
  208. },
  209. {
  210. slot: 'code',
  211. prop: 'code',
  212. action: 'code',
  213. label: '计划编号',
  214. align: 'center',
  215. showOverflowTooltip: true,
  216. minWidth: 180
  217. },
  218. {
  219. prop: 'productCode',
  220. label: '产品编码',
  221. align: 'center',
  222. showOverflowTooltip: true,
  223. minWidth: 140
  224. },
  225. {
  226. prop: 'productName',
  227. label: '产品名称',
  228. align: 'center',
  229. showOverflowTooltip: true,
  230. minWidth: 140
  231. },
  232. {
  233. prop: 'brandNo',
  234. label: '牌号',
  235. align: 'center',
  236. showOverflowTooltip: true
  237. },
  238. {
  239. prop: 'batchNo',
  240. label: '批号',
  241. align: 'center',
  242. minWidth: 100,
  243. showOverflowTooltip: true
  244. },
  245. {
  246. prop: 'model',
  247. label: '型号',
  248. align: 'center',
  249. showOverflowTooltip: true
  250. },
  251. {
  252. prop: 'priority',
  253. label: '优先级',
  254. align: 'center',
  255. minWidth: 120,
  256. slot: 'priority',
  257. sortable: 'custom'
  258. },
  259. {
  260. prop: 'productNum',
  261. label: '计划数量'+(this.clientEnvironmentId=='4'?'(方)':''),
  262. align: 'center',
  263. showOverflowTooltip: true
  264. },
  265. {
  266. prop: 'productWeight',
  267. label: '计划重量',
  268. align: 'center',
  269. showOverflowTooltip: true,
  270. slot: 'productWeight'
  271. },
  272. {
  273. prop: 'requiredFormingNum',
  274. label: '要求生产数量'+(this.clientEnvironmentId=='4'?'(方)':''),
  275. align: 'center',
  276. showOverflowTooltip: true
  277. },
  278. {
  279. prop: 'newSumOrderWeight',
  280. label: '要求生产重量',
  281. align: 'center',
  282. showOverflowTooltip: true,
  283. slot: 'newSumOrderWeight'
  284. },
  285. {
  286. prop: 'moCount',
  287. label: '模数',
  288. align: 'center'
  289. },
  290. {
  291. prop: 'blockCount',
  292. label: '块数',
  293. align: 'center'
  294. },
  295. {
  296. prop: 'noWordCount',
  297. label: '未排程块数',
  298. align: 'center',
  299. showOverflowTooltip: true,
  300. minWidth: 110
  301. },
  302. {
  303. prop: 'reqMoldTime',
  304. label: '要求生产日期',
  305. align: 'center',
  306. showOverflowTooltip: true,
  307. minWidth: 110
  308. },
  309. ...opt[this.activeName],
  310. {
  311. prop: 'orderType',
  312. label: '计划类型',
  313. align: 'center',
  314. showOverflowTooltip: true,
  315. formatter: (row) => {
  316. const obj = this.planType.find((i) => i.value == row.planType);
  317. return obj && obj.label;
  318. }
  319. },
  320. {
  321. prop: 'createTime',
  322. label: '创建时间',
  323. align: 'center',
  324. showOverflowTooltip: true,
  325. minWidth: 110
  326. },
  327. {
  328. columnKey: 'status',
  329. slot: 'status',
  330. label: '状态',
  331. align: 'center',
  332. formatter: (row) => {
  333. const obj = this.statusOpt[this.activeName].find(
  334. (i) => i.value == row.status
  335. );
  336. return obj && obj.label;
  337. }
  338. },
  339. // ...(this.activeName === 'second'
  340. // ? [
  341. // {
  342. // prop: 'releaseTime',
  343. // label: '发布时间',
  344. // align: 'center',
  345. // showOverflowTooltip: true,
  346. // minWidth: 110
  347. // }
  348. // ]
  349. // : []),
  350. ...(this.activeName === 'first'
  351. ? [
  352. {
  353. columnKey: 'action',
  354. label: '操作',
  355. width: 250,
  356. align: 'center',
  357. resizable: false,
  358. fixed: 'right',
  359. slot: 'action',
  360. showOverflowTooltip: true
  361. }
  362. ]
  363. : [])
  364. ];
  365. }
  366. },
  367. methods: {
  368. statusFormatter(status) {
  369. const obj = this.statusOpt[this.activeName].find(
  370. (i) => i.value == status
  371. );
  372. return obj && obj.label;
  373. },
  374. /* 表格数据源 */
  375. datasource({ page, limit, where }) {
  376. return getList({
  377. pageNum: page,
  378. size: limit,
  379. ...where,
  380. ...this.sort
  381. });
  382. },
  383. // 发布工单
  384. handleOrderPublish(type, row) {
  385. this.$confirm('发布工单后不可撤回,确定发布吗?', '发布确认')
  386. .then(async () => {
  387. const loading = this.$loading({
  388. lock: true,
  389. fullscreen: true,
  390. text: '工单发布中...'
  391. });
  392. try {
  393. let code = row.workOrderCode;
  394. if (!code) {
  395. code = await getCode('product_order_code');
  396. }
  397. // 反显对象会报错 status
  398. const data = await release([row.id]);
  399. if (data || data === 0) {
  400. this.$message.success('发布成功!');
  401. } else {
  402. this.$message.error('发布失败,请重新发布!');
  403. }
  404. this.reload();
  405. } catch (error) {
  406. console.error(error);
  407. }
  408. loading.close();
  409. })
  410. .catch((err) => {
  411. console.error(err);
  412. });
  413. // this.$router.push({
  414. // path: '/productionPlan/workOrderPublish',
  415. // query: {
  416. // type,
  417. // id: row.id
  418. // }
  419. // });
  420. },
  421. // 修改计划
  422. planEdit({ id }) {
  423. this.$router.push({
  424. path: '/saleOrder/salesToProduction',
  425. query: {
  426. type: 'edit',
  427. id
  428. }
  429. });
  430. },
  431. handleTabChange() {
  432. this.$refs.searchRef.reset();
  433. },
  434. /* 刷新表格 */
  435. reload(where) {
  436. this.$nextTick(() => {
  437. this.$refs.table.reload({ page: 1, where });
  438. });
  439. },
  440. goDetail({ id }) {
  441. this.$router.push({
  442. path: '/productionPlan/detail/' + id
  443. });
  444. },
  445. handleDelete({ id }) {
  446. this.$confirm('确定删除当前数据?', '提示')
  447. .then(async () => {
  448. await del(id);
  449. this.$message.success('删除成功!');
  450. this.reload();
  451. })
  452. .catch((err) => {
  453. console.error(err);
  454. });
  455. },
  456. onSortChange(e) {
  457. let sort = {
  458. orderBy: e.order,
  459. sortName: e.prop
  460. };
  461. this.sort = sort;
  462. this.reload();
  463. },
  464. sortTop(row) {
  465. row.priority = Number(row.priority) + 1;
  466. this.priorityChange(row);
  467. },
  468. sortBottom(row) {
  469. if (row.priority <= 1) {
  470. return;
  471. }
  472. row.priority = Number(row.priority) - 1;
  473. this.priorityChange(row);
  474. },
  475. priorityChange(row) {
  476. if (row.priority > 10) {
  477. row.priority = 10; // 如果大于 10,则设置为 10
  478. } else if (row.priority < 0) {
  479. row.priority = 0; // 如果小于 0,则设置为 0
  480. }
  481. this.priorityFn(row);
  482. },
  483. priorityFn: debounce(function (row) {
  484. let params = {
  485. id: row.id,
  486. priority: row.priority
  487. };
  488. updatePriority(params).then((res) => {});
  489. }, 800)
  490. }
  491. };
  492. </script>
  493. <style lang="scss" scoped></style>