index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <div class="tenant">
  3. <div class="content">
  4. <byTable
  5. :source="sourceList.data"
  6. :pagination="sourceList.pagination"
  7. :config="config"
  8. :loading="loading"
  9. highlight-current-row
  10. :selectConfig="selectConfig"
  11. :table-events="{
  12. select: select,
  13. }"
  14. :action-list="[
  15. {
  16. text: '添加计划',
  17. action: () => openModal('add'),
  18. },
  19. ]"
  20. @get-list="getList"
  21. >
  22. </byTable>
  23. </div>
  24. <el-dialog
  25. :title="modalType == 'add' ? '添加计划' : '查看计划'"
  26. v-model="dialogVisible"
  27. width="700"
  28. v-loading="loading"
  29. destroy-on-close
  30. >
  31. <byForm
  32. :formConfig="formConfig"
  33. :formOption="formOption"
  34. v-model="formData.data"
  35. :rules="rules"
  36. ref="byform"
  37. >
  38. <template #list>
  39. <div style="width: 100%">
  40. <el-table :data="formData.data.productionTaskList">
  41. <el-table-column prop="quantity" label="任务数量" />
  42. <el-table-column prop="personLiableName" label="负责人" />
  43. <el-table-column
  44. prop="status"
  45. label="完成状态"
  46. :formatter="(row) => dictValueLabel(row.status, statusData)"
  47. />
  48. </el-table>
  49. </div>
  50. </template>
  51. </byForm>
  52. <template #footer>
  53. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  54. <el-button
  55. type="primary"
  56. @click="submitForm()"
  57. size="large"
  58. :loading="submitLoading"
  59. v-if="modalType == 'add'"
  60. >
  61. 确 定
  62. </el-button>
  63. </template>
  64. </el-dialog>
  65. </div>
  66. </template>
  67. <script setup>
  68. import { ElMessage, ElMessageBox } from "element-plus";
  69. import byTable from "@/components/byTable/index";
  70. import byForm from "@/components/byForm/index";
  71. const { proxy } = getCurrentInstance();
  72. const loading = ref(false);
  73. const submitLoading = ref(false);
  74. const sourceList = ref({
  75. data: [],
  76. pagination: {
  77. total: 3,
  78. pageNum: 1,
  79. pageSize: 10,
  80. keyword: "",
  81. },
  82. });
  83. const dialogVisible = ref(false);
  84. const modalType = ref("add");
  85. const rules = ref({
  86. workOrderId: [{ required: true, message: "请选择工单", trigger: "change" }],
  87. startDate: [
  88. { required: true, message: "请选择计划开始时间", trigger: "change" },
  89. ],
  90. stopDate: [
  91. { required: true, message: "请选择计划结束时间", trigger: "change" },
  92. ],
  93. quantity: [{ required: true, message: "请输入计划数量", trigger: "blur" }],
  94. });
  95. const workOrderData = ref([]);
  96. const workOrderDataOne = ref([]);
  97. const statusData = ref([
  98. {
  99. label: "未开始",
  100. value: "0",
  101. },
  102. {
  103. label: "进行中",
  104. value: "1",
  105. },
  106. {
  107. label: "完成",
  108. value: "2",
  109. },
  110. ]);
  111. const selectConfig = reactive([
  112. {
  113. label: "计划状态",
  114. prop: "status",
  115. data: statusData.value,
  116. },
  117. ]);
  118. const config = computed(() => {
  119. return [
  120. {
  121. attrs: {
  122. label: "工单单号",
  123. prop: "workOrderCode",
  124. },
  125. },
  126. {
  127. attrs: {
  128. label: "计划单号",
  129. prop: "code",
  130. },
  131. },
  132. {
  133. attrs: {
  134. label: "计划开始时间",
  135. prop: "startDate",
  136. },
  137. },
  138. {
  139. attrs: {
  140. label: "计划结束时间",
  141. prop: "stopDate",
  142. },
  143. },
  144. {
  145. attrs: {
  146. label: "产品名称",
  147. prop: "productName",
  148. },
  149. },
  150. {
  151. attrs: {
  152. label: "规格型号",
  153. prop: "productSpec",
  154. },
  155. },
  156. {
  157. attrs: {
  158. label: "计划数量",
  159. prop: "quantity",
  160. },
  161. },
  162. {
  163. attrs: {
  164. label: "计划状态",
  165. prop: "status",
  166. },
  167. render(status) {
  168. return proxy.dictValueLabel(status, statusData.value);
  169. },
  170. },
  171. {
  172. attrs: {
  173. label: "操作",
  174. width: "80",
  175. align: "center",
  176. },
  177. renderHTML(row) {
  178. return [
  179. {
  180. attrs: {
  181. label: "查看",
  182. type: "primary",
  183. text: true,
  184. },
  185. el: "button",
  186. click() {
  187. getDtl(row);
  188. },
  189. },
  190. ];
  191. },
  192. },
  193. ];
  194. });
  195. const formData = reactive({
  196. data: {},
  197. });
  198. const formOption = reactive({
  199. inline: true,
  200. labelWidth: 100,
  201. itemWidth: 100,
  202. rules: [],
  203. });
  204. const byform = ref(null);
  205. const formConfig = computed(() => {
  206. return [
  207. {
  208. type: "select",
  209. prop: "workOrderId",
  210. label: "工单",
  211. required: true,
  212. filterable: true,
  213. data:
  214. modalType.value == "add" ? workOrderData.value : workOrderDataOne.value,
  215. fn: (val) => {
  216. changeFn(val);
  217. },
  218. style: {
  219. width: "50%",
  220. },
  221. },
  222. {
  223. type: "input",
  224. itemType: "text",
  225. prop: "productName",
  226. label: "产品名称",
  227. disabled: true,
  228. style: {
  229. width: "50%",
  230. },
  231. },
  232. {
  233. type: "input",
  234. itemType: "text",
  235. prop: "productSpec",
  236. label: "规格型号",
  237. disabled: true,
  238. style: {
  239. width: "50%",
  240. },
  241. },
  242. {
  243. type: "input",
  244. itemType: "text",
  245. prop: "waitQuantity",
  246. label: "待排程数量",
  247. disabled: true,
  248. style: {
  249. width: "50%",
  250. },
  251. isShow: modalType.value == "add",
  252. },
  253. {
  254. type: "date",
  255. itemType: "date",
  256. prop: "startDate",
  257. label: "计划开始时间",
  258. required: true,
  259. style: {
  260. width: "50%",
  261. },
  262. },
  263. {
  264. type: "date",
  265. itemType: "date",
  266. prop: "stopDate",
  267. label: "计划结束时间",
  268. required: true,
  269. style: {
  270. width: "50%",
  271. },
  272. },
  273. {
  274. type: "number",
  275. prop: "quantity",
  276. label: "计划数量",
  277. precision: 0,
  278. min: 1,
  279. controls: false,
  280. style: {
  281. width: "50%",
  282. },
  283. },
  284. {
  285. type: "slot",
  286. slotName: "list",
  287. label: "生产任务",
  288. isShow: modalType.value != "add",
  289. },
  290. ];
  291. });
  292. const getList = async (req) => {
  293. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  294. loading.value = true;
  295. proxy
  296. .post("/productionPlan/page", sourceList.value.pagination)
  297. .then((message) => {
  298. sourceList.value.data = message.rows;
  299. sourceList.value.pagination.total = message.total;
  300. setTimeout(() => {
  301. loading.value = false;
  302. }, 200);
  303. });
  304. };
  305. const openModal = () => {
  306. dialogVisible.value = true;
  307. modalType.value = "add";
  308. formOption.disabled = false;
  309. formData.data = {};
  310. };
  311. const submitForm = () => {
  312. byform.value.handleSubmit(() => {
  313. if (Number(formData.data.quantity) > Number(formData.data.waitQuantity)) {
  314. return ElMessage({
  315. message: "计划数量不可大于待排程数量",
  316. type: "info",
  317. });
  318. }
  319. if (proxy.compareTime(formData.data.startDate, formData.data.stopDate)) {
  320. return ElMessage({
  321. message: "时间选择存在问题",
  322. type: "info",
  323. });
  324. }
  325. submitLoading.value = true;
  326. proxy.post("/productionPlan/add", formData.data).then(
  327. () => {
  328. ElMessage({
  329. message: "添加成功",
  330. type: "success",
  331. });
  332. dialogVisible.value = false;
  333. submitLoading.value = false;
  334. getList();
  335. getDict();
  336. },
  337. (err) => {
  338. console.log(err);
  339. submitLoading.value = false;
  340. }
  341. );
  342. });
  343. };
  344. const getDtl = (row) => {
  345. modalType.value = "detail";
  346. formOption.disabled = true;
  347. proxy.post("/productionPlan/detail", { id: row.id }).then((res) => {
  348. formData.data = res;
  349. changeFn(formData.data.workOrderId);
  350. dialogVisible.value = true;
  351. });
  352. };
  353. const getDict = () => {
  354. proxy
  355. .post("/workOrder/page", { pageNum: 1, pageSize: 9999, isRemaining: "1" })
  356. .then((res) => {
  357. workOrderData.value = res.rows.map((x) => ({
  358. label: x.code,
  359. value: x.id,
  360. ...x,
  361. }));
  362. });
  363. proxy.post("/workOrder/page", { pageNum: 1, pageSize: 9999 }).then((res) => {
  364. workOrderDataOne.value = res.rows.map((x) => ({
  365. label: x.code,
  366. value: x.id,
  367. ...x,
  368. }));
  369. });
  370. };
  371. getDict();
  372. getList();
  373. const changeFn = (val) => {
  374. const current =
  375. modalType.value == "add"
  376. ? workOrderData.value.find((x) => x.value == val)
  377. : workOrderDataOne.value.find((x) => x.value == val);
  378. if (current) {
  379. formData.data.productName = current.productName;
  380. formData.data.productSpec = current.productSpec;
  381. formData.data.waitQuantity = current.remainingQuantity;
  382. }
  383. };
  384. </script>
  385. <style lang="scss" scoped>
  386. .tenant {
  387. padding: 20px;
  388. }
  389. ::v-deep(.el-input-number .el-input__inner) {
  390. text-align: left;
  391. }
  392. </style>