index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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. // 表格列配置
  147. columns() {
  148. const opt = {
  149. first: [
  150. // {
  151. // prop: 'deliveryTime',
  152. // label: '预测交货日期',
  153. // align: 'center',
  154. // showOverflowTooltip: true,
  155. // minWidth: 110
  156. // }
  157. ],
  158. second: [
  159. // {
  160. // prop: 'formingTime',
  161. // label: '实际生产日期',
  162. // align: 'center',
  163. // showOverflowTooltip: true,
  164. // minWidth: 110
  165. // },
  166. {
  167. prop: 'releaseTime',
  168. label: '工单发布日期',
  169. align: 'center',
  170. showOverflowTooltip: true,
  171. minWidth: 110
  172. },
  173. {
  174. prop: 'planFormingTime',
  175. label: '预测生产日期',
  176. align: 'center',
  177. showOverflowTooltip: true,
  178. minWidth: 110
  179. },
  180. {
  181. prop: 'deliveryTime',
  182. label: '预测交货日期',
  183. align: 'center',
  184. showOverflowTooltip: true,
  185. minWidth: 110
  186. },
  187. {
  188. prop: 'formingTime',
  189. label: '实际交货日期',
  190. align: 'center',
  191. showOverflowTooltip: true,
  192. minWidth: 110
  193. }
  194. ]
  195. };
  196. return [
  197. {
  198. columnKey: 'index',
  199. label: '序号',
  200. type: 'index',
  201. width: 55,
  202. align: 'center',
  203. showOverflowTooltip: true,
  204. fixed: 'left'
  205. },
  206. {
  207. slot: 'code',
  208. prop: 'code',
  209. action: 'code',
  210. label: '计划编号',
  211. align: 'center',
  212. showOverflowTooltip: true,
  213. minWidth: 180
  214. },
  215. {
  216. prop: 'productCode',
  217. label: '产品编码',
  218. align: 'center',
  219. showOverflowTooltip: true,
  220. minWidth: 140
  221. },
  222. {
  223. prop: 'brandNo',
  224. label: '牌号',
  225. align: 'center',
  226. showOverflowTooltip: true
  227. },
  228. {
  229. prop: 'batchNo',
  230. label: '批号',
  231. align: 'center',
  232. minWidth: 100,
  233. showOverflowTooltip: true
  234. },
  235. {
  236. prop: 'model',
  237. label: '型号',
  238. align: 'center',
  239. showOverflowTooltip: true
  240. },
  241. {
  242. prop: 'priority',
  243. label: '优先级',
  244. align: 'center',
  245. minWidth: 120,
  246. slot: 'priority',
  247. sortable: 'custom'
  248. },
  249. {
  250. prop: 'productNum',
  251. label: '计划数量',
  252. align: 'center',
  253. showOverflowTooltip: true
  254. },
  255. {
  256. prop: 'productWeight',
  257. label: '计划重量',
  258. align: 'center',
  259. showOverflowTooltip: true,
  260. slot: 'productWeight'
  261. },
  262. {
  263. prop: 'requiredFormingNum',
  264. label: '要求生产数量',
  265. align: 'center',
  266. showOverflowTooltip: true
  267. },
  268. {
  269. prop: 'newSumOrderWeight',
  270. label: '要求生产重量',
  271. align: 'center',
  272. showOverflowTooltip: true,
  273. slot: 'newSumOrderWeight'
  274. },
  275. // {
  276. // prop: '',
  277. // label: '已生产数量',
  278. // align: 'center',
  279. // showOverflowTooltip: true,
  280. // minWidth: 110
  281. // },
  282. {
  283. prop: 'reqMoldTime',
  284. label: '要求生产日期',
  285. align: 'center',
  286. showOverflowTooltip: true,
  287. minWidth: 110
  288. },
  289. ...opt[this.activeName],
  290. {
  291. prop: 'orderType',
  292. label: '计划类型',
  293. align: 'center',
  294. showOverflowTooltip: true,
  295. formatter: (row) => {
  296. const obj = this.planType.find((i) => i.value == row.planType);
  297. return obj && obj.label;
  298. }
  299. },
  300. {
  301. prop: 'createTime',
  302. label: '创建时间',
  303. align: 'center',
  304. showOverflowTooltip: true,
  305. minWidth: 110
  306. },
  307. {
  308. columnKey: 'status',
  309. slot: 'status',
  310. label: '状态',
  311. align: 'center',
  312. formatter: (row) => {
  313. const obj = this.statusOpt[this.activeName].find(
  314. (i) => i.value == row.status
  315. );
  316. return obj && obj.label;
  317. }
  318. },
  319. // ...(this.activeName === 'second'
  320. // ? [
  321. // {
  322. // prop: 'releaseTime',
  323. // label: '发布时间',
  324. // align: 'center',
  325. // showOverflowTooltip: true,
  326. // minWidth: 110
  327. // }
  328. // ]
  329. // : []),
  330. ...(this.activeName === 'first'
  331. ? [
  332. {
  333. columnKey: 'action',
  334. label: '操作',
  335. width: 250,
  336. align: 'center',
  337. resizable: false,
  338. fixed: 'right',
  339. slot: 'action',
  340. showOverflowTooltip: true
  341. }
  342. ]
  343. : [])
  344. ];
  345. }
  346. },
  347. methods: {
  348. statusFormatter(status) {
  349. const obj = this.statusOpt[this.activeName].find(
  350. (i) => i.value == status
  351. );
  352. return obj && obj.label;
  353. },
  354. /* 表格数据源 */
  355. datasource({ page, limit, where }) {
  356. return getList({
  357. pageNum: page,
  358. size: limit,
  359. ...where,
  360. ...this.sort
  361. });
  362. },
  363. // 发布工单
  364. handleOrderPublish(type, row) {
  365. this.$confirm('发布工单后不可撤回,确定发布吗?', '发布确认')
  366. .then(async () => {
  367. const loading = this.$loading({
  368. lock: true,
  369. fullscreen: true,
  370. text: '工单发布中...'
  371. });
  372. try {
  373. let code = row.workOrderCode;
  374. if (!code) {
  375. code = await getCode('product_order_code');
  376. }
  377. // 反显对象会报错 status
  378. const data = await release([row.id]);
  379. if (data || data === 0) {
  380. this.$message.success('发布成功!');
  381. } else {
  382. this.$message.error('发布失败,请重新发布!');
  383. }
  384. this.reload();
  385. } catch (error) {
  386. console.error(error);
  387. }
  388. loading.close();
  389. })
  390. .catch((err) => {
  391. console.error(err);
  392. });
  393. // this.$router.push({
  394. // path: '/productionPlan/workOrderPublish',
  395. // query: {
  396. // type,
  397. // id: row.id
  398. // }
  399. // });
  400. },
  401. // 修改计划
  402. planEdit({ id }) {
  403. this.$router.push({
  404. path: '/saleOrder/salesToProduction',
  405. query: {
  406. type: 'edit',
  407. id
  408. }
  409. });
  410. },
  411. handleTabChange() {
  412. this.$refs.searchRef.reset();
  413. },
  414. /* 刷新表格 */
  415. reload(where) {
  416. this.$nextTick(() => {
  417. this.$refs.table.reload({ page: 1, where });
  418. });
  419. },
  420. goDetail({ id }) {
  421. this.$router.push({
  422. path: '/productionPlan/detail/' + id
  423. });
  424. },
  425. handleDelete({ id }) {
  426. this.$confirm('确定删除当前数据?', '提示')
  427. .then(async () => {
  428. await del(id);
  429. this.$message.success('删除成功!');
  430. this.reload();
  431. })
  432. .catch((err) => {
  433. console.error(err);
  434. });
  435. },
  436. onSortChange(e) {
  437. let sort = {
  438. orderBy: e.order,
  439. sortName: e.prop,
  440. }
  441. this.sort = sort
  442. this.reload()
  443. },
  444. sortTop(row) {
  445. row.priority = Number(row.priority) + 1;
  446. this.priorityChange(row);
  447. },
  448. sortBottom(row) {
  449. if (row.priority <= 1) {
  450. return;
  451. }
  452. row.priority = Number(row.priority) - 1;
  453. this.priorityChange(row);
  454. },
  455. priorityChange(row) {
  456. if (row.priority > 10) {
  457. row.priority = 10; // 如果大于 10,则设置为 10
  458. } else if (row.priority < 0) {
  459. row.priority = 0; // 如果小于 0,则设置为 0
  460. }
  461. this.priorityFn(row);
  462. },
  463. priorityFn: debounce(function (row) {
  464. let params = {
  465. id: row.id,
  466. priority: row.priority
  467. };
  468. updatePriority(params).then((res) => {});
  469. }, 800)
  470. }
  471. };
  472. </script>
  473. <style lang="scss" scoped></style>