add.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div class="form" style="padding-bottom: 60px">
  3. <van-nav-bar
  4. title="生产任务"
  5. left-text="返回"
  6. left-arrow
  7. @click-left="onClickLeft"
  8. >
  9. </van-nav-bar>
  10. <testForm
  11. v-model="formData.data"
  12. :formOption="formOption"
  13. :formConfig="formConfig"
  14. :rules="rules"
  15. @onSubmit="onSubmit"
  16. ref="formDom"
  17. ></testForm>
  18. </div>
  19. </template>
  20. <script setup>
  21. import { ref, reactive, getCurrentInstance, onMounted } from "vue";
  22. import { showSuccessToast, showFailToast } from "vant";
  23. import { useRoute } from "vue-router";
  24. import testForm from "@/components/testForm/index.vue";
  25. const proxy = getCurrentInstance().proxy;
  26. const route = useRoute();
  27. const formDom = ref(null);
  28. const formData = reactive({
  29. data: {
  30. list: [],
  31. },
  32. });
  33. const rules = {
  34. warehouseName: [{ required: true, message: "仓库名称不能为空" }],
  35. productName: [{ required: true, message: "物品名称不能为空" }],
  36. quantity: [{ required: true, message: "入库数量不能为空" }],
  37. };
  38. const formOption = reactive({
  39. readonly: false, //用于控制整个表单是否只读
  40. disabled: false,
  41. labelAlign: "top",
  42. scroll: true,
  43. labelWidth: "62pk",
  44. btnConfig: {
  45. isNeed: false,
  46. prop: "list",
  47. plain: true,
  48. listTitle: "",
  49. listConfig: [],
  50. clickFn: () => {},
  51. },
  52. });
  53. const formConfig = reactive([
  54. {
  55. type: "picker",
  56. label: "生产计划",
  57. prop: "warehouseId",
  58. itemType: "onePicker",
  59. showPicker: false,
  60. fieldNames: {
  61. text: "label",
  62. value: "value",
  63. },
  64. data: [],
  65. },
  66. {
  67. type: "input",
  68. itemType: "text",
  69. label: "产品名称",
  70. prop: "reamlke",
  71. readonly: true,
  72. },
  73. {
  74. type: "input",
  75. itemType: "number",
  76. label: "待排程数量",
  77. prop: "reamlke",
  78. readonly: true,
  79. },
  80. {
  81. type: "input",
  82. itemType: "number",
  83. label: "任务数量",
  84. prop: "reamlke",
  85. },
  86. {
  87. type: "picker",
  88. label: "负责人",
  89. prop: "warehouseId",
  90. itemType: "onePicker",
  91. showPicker: false,
  92. fieldNames: {
  93. text: "label",
  94. value: "value",
  95. },
  96. data: [],
  97. },
  98. {
  99. type: "picker",
  100. label: "完成期限",
  101. prop: "date",
  102. itemType: "datePicker",
  103. showPicker: false,
  104. split: "-",
  105. columnsType: ["year", "month", "day"],
  106. },
  107. ]);
  108. const getDict = () => {
  109. proxy
  110. .post("/productionPlan/page", { pageNum: 1, pageSize: 9999 })
  111. .then((res) => {
  112. formConfig[0].data = res.data.rows.map((item) => {
  113. return {
  114. ...item,
  115. label: item.productName,
  116. value: item.id,
  117. };
  118. });
  119. });
  120. proxy.get("/system/user/list?pageNum=1&pageSize=9999").then((res) => {
  121. formConfig[4].data = res.rows.map((item) => {
  122. return {
  123. label: item.userName,
  124. value: item.userId,
  125. };
  126. });
  127. });
  128. };
  129. const onClickLeft = () => history.back();
  130. const onSubmit = () => {
  131. proxy.post("/productionTask/add", formData.data).then(
  132. (res) => {
  133. setTimeout(() => {
  134. showSuccessToast("添加成功");
  135. proxy.$router.push("/main/task");
  136. }, 500);
  137. },
  138. (err) => {
  139. return showFailToast(err.message);
  140. }
  141. );
  142. };
  143. const getDetails = () => {
  144. proxy.post("/productionTask/detail", { id: route.query.id }).then(
  145. (res) => {
  146. console.log(res, "ada");
  147. },
  148. (err) => {
  149. return showFailToast(err.message);
  150. }
  151. );
  152. };
  153. onMounted(() => {
  154. getDict();
  155. if (route.query.id) {
  156. getDetails();
  157. }
  158. });
  159. </script>
  160. <style lang="scss" scoped>
  161. .row {
  162. display: flex;
  163. padding: 5px 10px 0 10px;
  164. justify-content: space-between;
  165. align-items: center;
  166. .title {
  167. flex: 1;
  168. }
  169. .delete {
  170. width: 20px;
  171. cursor: pointer;
  172. text-align: center;
  173. }
  174. }
  175. </style>