add.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <div class="form" style="padding-bottom: 60px">
  3. <van-nav-bar :title="'工序管理'" :left-text="$t('common.back')" left-arrow @click-left="onClickLeft">
  4. </van-nav-bar>
  5. <testForm v-model="formData.data" :formOption="formOption" :formConfig="formConfig" :rules="rules" @onSubmit="onSubmit" ref="formDom"></testForm>
  6. </div>
  7. </template>
  8. <script setup>
  9. import { ref, reactive, getCurrentInstance, onMounted } from "vue";
  10. import { showSuccessToast, showFailToast } from "vant";
  11. import { useRoute } from "vue-router";
  12. import testForm from "@/components/testForm/index.vue";
  13. const proxy = getCurrentInstance().proxy;
  14. const route = useRoute();
  15. const formDom = ref(null);
  16. const formData = reactive({
  17. data: {
  18. productionTaskDetailList: [],
  19. },
  20. });
  21. const rules = {
  22. productionPlanId: [
  23. { required: true, message: proxy.t("task.selectProductionPlan") },
  24. ],
  25. dueDate: [
  26. { required: true, message: proxy.t("task.selectCompletionDeadline") },
  27. ],
  28. personLiableId: [
  29. { required: true, message: proxy.t("task.selectPrincipal") },
  30. ],
  31. quantity: [
  32. { required: true, message: proxy.t("task.taskQuantityCanNotBeEmpty") },
  33. ],
  34. };
  35. const formOption = reactive({
  36. readonly: false, //用于控制整个表单是否只读
  37. disabled: false,
  38. labelAlign: "top",
  39. scroll: true,
  40. labelWidth: "62pk",
  41. hiddenSubmitBtn: false,
  42. btnConfig: {
  43. isNeed: false,
  44. prop: "productionTaskDetailList",
  45. plain: true,
  46. listTitle: proxy.t("common.productDetails"),
  47. listConfig: [
  48. {
  49. type: "input",
  50. itemType: "text",
  51. label: proxy.t("receive.productSN"),
  52. prop: "productSn",
  53. readonly: true,
  54. },
  55. {
  56. type: "input",
  57. itemType: "text",
  58. label: proxy.t("task.currentProcess"),
  59. prop: "productionProcessesName",
  60. readonly: true,
  61. },
  62. {
  63. type: "input",
  64. itemType: "text",
  65. label: proxy.t("task.accumulatedTimeConsumption"),
  66. prop: "cumulativeTime",
  67. readonly: true,
  68. },
  69. ],
  70. clickFn: () => {},
  71. },
  72. });
  73. const formConfig = reactive([
  74. // {
  75. // type: "picker",
  76. // label: proxy.t('task.productionPlan'),
  77. // prop: "productionPlanId",
  78. // itemType: "onePicker",
  79. // showPicker: false,
  80. // fieldNames: {
  81. // text: "label",
  82. // value: "value",
  83. // },
  84. // data: [],
  85. // changeFn: (option, item, index) => {
  86. // if (option.selectedOptions[0]) {
  87. // formData.data["productionPlanId" + "Name"] =
  88. // option.selectedOptions[0].label;
  89. // formData.data.productionPlanId = option.selectedOptions[0].value;
  90. // formData.data.productName = option.selectedOptions[0].productName;
  91. // formData.data.waitQuantity =
  92. // option.selectedOptions[0].remainingQuantity;
  93. // formData.data.startDate = option.selectedOptions[0].startDate;
  94. // formConfig[index].showPicker = false;
  95. // } else {
  96. // formConfig[index].showPicker = false;
  97. // }
  98. // },
  99. // },
  100. {
  101. type: "input",
  102. itemType: "text",
  103. label: "工序名称",
  104. prop: "name",
  105. readonly: true,
  106. },
  107. {
  108. type: "input",
  109. itemType: "textarea",
  110. label: "工序说明",
  111. prop: "remarks",
  112. readonly: true,
  113. },
  114. // {
  115. // type: "input",
  116. // itemType: "number",
  117. // label: proxy.t('task.scheduledQuantity'),
  118. // prop: "waitQuantity",
  119. // readonly: true,
  120. // },
  121. // {
  122. // type: "input",
  123. // itemType: "number",
  124. // label: proxy.t('task.taskQuantity'),
  125. // prop: "quantity",
  126. // },
  127. // {
  128. // type: "picker",
  129. // label: proxy.t('task.principal'),
  130. // prop: "personLiableId",
  131. // itemType: "onePicker",
  132. // showPicker: false,
  133. // fieldNames: {
  134. // text: "label",
  135. // value: "value",
  136. // },
  137. // data: [],
  138. // },
  139. // {
  140. // type: "picker",
  141. // label: proxy.t('task.completionDeadline'),
  142. // prop: "dueDate",
  143. // itemType: "datePicker",
  144. // showPicker: false,
  145. // split: "-",
  146. // columnsType: ["year", "month", "day"],
  147. // },
  148. ]);
  149. const getDict = () => {
  150. proxy
  151. .post("/productionPlan/page", { pageNum: 1, pageSize: 9999 })
  152. .then((res) => {
  153. formConfig[0].data = res.data.rows.map((item) => {
  154. return {
  155. ...item,
  156. label: item.code,
  157. value: item.id,
  158. };
  159. });
  160. });
  161. proxy.get("/system/user/list?pageNum=1&pageSize=9999").then((res) => {
  162. formConfig[4].data = res.rows.map((item) => {
  163. return {
  164. label: item.userName,
  165. value: item.userId,
  166. };
  167. });
  168. });
  169. };
  170. const onClickLeft = () => history.back();
  171. const onSubmit = () => {
  172. if (Number(formData.data.quantity) > Number(formData.data.waitQuantity)) {
  173. return showFailToast(
  174. proxy.t("task.taskQuantityCanNotBeGreaterThanTheScheduledQuantity")
  175. );
  176. }
  177. if (proxy.compareTime(formData.data.startDate, formData.data.dueDate)) {
  178. return showFailToast(
  179. proxy.t("task.completionDeadlineCanNotBeEarlierThanThePlanStartTime")
  180. );
  181. }
  182. proxy.post("/productionTask/addByJxst", formData.data).then(
  183. (res) => {
  184. setTimeout(() => {
  185. showSuccessToast(proxy.t("common.addSuccess"));
  186. proxy.$router.push("/main/jxskTask");
  187. }, 500);
  188. },
  189. (err) => {
  190. return showFailToast(err.message);
  191. }
  192. );
  193. };
  194. const getDetails = () => {
  195. proxy.post("/productionProcesses/detail", { id: route.query.id }).then(
  196. (res) => {
  197. formData.data = res.data;
  198. },
  199. (err) => {
  200. return showFailToast(err.message);
  201. }
  202. );
  203. };
  204. onMounted(() => {
  205. // getDict();
  206. if (route.query.id) {
  207. getDetails();
  208. formOption.readonly = true; //全部只读
  209. formOption.hiddenSubmitBtn = true; //隐藏提交按钮
  210. }
  211. });
  212. </script>
  213. <style lang="scss" scoped>
  214. .row {
  215. display: flex;
  216. padding: 5px 10px 0 10px;
  217. justify-content: space-between;
  218. align-items: center;
  219. .title {
  220. flex: 1;
  221. }
  222. .delete {
  223. width: 20px;
  224. cursor: pointer;
  225. text-align: center;
  226. }
  227. }
  228. </style>