subscribe.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div>
  3. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="submit">
  4. <template #materiel>
  5. <div style="width: 100%">
  6. <div style="margin-bottom: 10px">
  7. <el-button type="primary" @click="clickMateriel()" v-preReClick>选择物料</el-button>
  8. </div>
  9. <el-table :data="formData.data.applyBuyBomList" :row-style="{ height: '35px' }" header-row-class-name="tableHeader">
  10. <el-table-column label="品号" prop="bomSpecCode" width="140" />
  11. <el-table-column label="品名" prop="bomSpecName" min-width="220" />
  12. <el-table-column label="颜色" prop="bomSpecColour" width="160" />
  13. <el-table-column label="尺寸(长宽高,cm)" prop="name" width="160">
  14. <template #default="{ row }">
  15. <div>{{ row.bomSpecLength }} * {{ row.bomSpecWidth }} * {{ row.bomSpecHeight }}</div>
  16. </template>
  17. </el-table-column>
  18. <el-table-column label="申购数量" width="160">
  19. <template #default="{ row, $index }">
  20. <el-form-item :prop="'applyBuyBomList.' + $index + '.quantity'" :rules="rules.quantity" :inline-message="true" style="width: 100%">
  21. <el-input-number
  22. onmousewheel="return false;"
  23. v-model="row.quantity"
  24. placeholder="申购数量"
  25. style="width: 100%"
  26. :controls="false"
  27. :min="0"
  28. :precision="0" />
  29. </el-form-item>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="操作" align="center" fixed="right" width="60">
  33. <template #default="{ $index }">
  34. <el-button type="danger" @click="clickDelete($index)" text>删除</el-button>
  35. </template>
  36. </el-table-column>
  37. </el-table>
  38. </div>
  39. </template>
  40. <template #file>
  41. <div style="width: 100%">
  42. <div v-for="(item, index) in fileList" :key="index">
  43. <a style="color: #409eff; cursor: pointer; word-break: break-all" @click="onPreviewFile(item.url)">{{ item.url }}</a>
  44. </div>
  45. </div>
  46. </template>
  47. </byForm>
  48. <el-dialog title="选择物料" v-if="openMateriel" v-model="openMateriel" width="90%">
  49. <SelectBOM :selectStatus="true" @selectBOM="selectMateriel"></SelectBOM>
  50. <template #footer>
  51. <el-button @click="openMateriel = false" size="large">关 闭</el-button>
  52. </template>
  53. </el-dialog>
  54. </div>
  55. </template>
  56. <script setup>
  57. import byForm from "/src/components/byForm/index";
  58. import { useRoute } from "vue-router";
  59. import moment from "moment";
  60. import SelectBOM from "/src/views/group/BOM/management/index";
  61. import { ElMessage } from "element-plus";
  62. import subscribeStore from "/src/store/modules/subscribe";
  63. const route = useRoute();
  64. // 接收父组件的传值
  65. const props = defineProps({
  66. queryData: Object,
  67. });
  68. const { proxy } = getCurrentInstance();
  69. const formData = reactive({
  70. data: {
  71. applyName: proxy.useUserStore().user.nickName,
  72. applyTime: moment().format("yyyy-MM-DD HH:mm:ss"),
  73. remark: "",
  74. applyBuyBomList: [],
  75. },
  76. });
  77. const judgeStatus = () => {
  78. if (route.query.processType == 20 || route.query.processType == 10) {
  79. return true;
  80. }
  81. if (props.queryData.recordList && props.queryData.recordList.length > 0) {
  82. let data = props.queryData.recordList.filter((item) => item.status === 2 && item.nodeType !== 1);
  83. if (data && data.length > 0) {
  84. return true;
  85. }
  86. }
  87. return false;
  88. };
  89. const formOption = reactive({
  90. inline: true,
  91. labelWidth: "120px",
  92. itemWidth: 100,
  93. rules: [],
  94. labelPosition: "right",
  95. disabled: false,
  96. });
  97. const formConfig = computed(() => {
  98. return [
  99. {
  100. type: "title",
  101. title: "申购单",
  102. label: "",
  103. },
  104. {
  105. type: "input",
  106. prop: "applyName",
  107. label: "申购人",
  108. itemType: "text",
  109. itemWidth: 51,
  110. },
  111. {
  112. type: "date",
  113. prop: "applyTime",
  114. label: "申购时间",
  115. format: "YYYY-MM-DD HH:mm:ss",
  116. itemType: "datetime",
  117. itemWidth: 51,
  118. },
  119. {
  120. type: "input",
  121. prop: "remark",
  122. label: "申购说明",
  123. itemType: "textarea",
  124. itemWidth: 51,
  125. },
  126. {
  127. type: "title",
  128. title: "申购清单",
  129. label: "",
  130. },
  131. {
  132. type: "slot",
  133. slotName: "materiel",
  134. },
  135. route.query && route.query.processType == "20"
  136. ? {
  137. type: "title",
  138. title: "附件",
  139. label: "",
  140. }
  141. : {},
  142. route.query && route.query.processType == "20"
  143. ? {
  144. type: "slot",
  145. slotName: "file",
  146. label: "附件",
  147. }
  148. : {},
  149. ];
  150. });
  151. const rules = ref({
  152. applyName: [{ required: true, message: "请输入申购人", trigger: "blur" }],
  153. applyTime: [{ required: true, message: "请选择申购时间", trigger: "change" }],
  154. quantity: [{ required: true, message: "请输入申购数量", trigger: "blur" }],
  155. });
  156. const openMateriel = ref(false);
  157. const clickMateriel = () => {
  158. openMateriel.value = true;
  159. };
  160. const selectMateriel = (row) => {
  161. if (formData.data.applyBuyBomList && formData.data.applyBuyBomList.length > 0) {
  162. let list = formData.data.applyBuyBomList.filter((item) => item.bomSpecId === row.id);
  163. if (list && list.length > 0) {
  164. return ElMessage("请勿重复添加!");
  165. }
  166. }
  167. formData.data.applyBuyBomList.push({
  168. bomSpecId: row.id,
  169. bomSpecCode: row.code,
  170. bomSpecName: row.name,
  171. bomSpecColour: row.colour,
  172. bomSpecLength: row.length,
  173. bomSpecWidth: row.width,
  174. bomSpecHeight: row.height,
  175. quantity: undefined,
  176. });
  177. ElMessage({ message: "选择完成", type: "success" });
  178. };
  179. const clickDelete = (index) => {
  180. formData.data.applyBuyBomList.splice(index, 1);
  181. };
  182. const handleSubmit = async (flag) => {
  183. if (flag) {
  184. return true;
  185. } else {
  186. let status = await proxy.$refs.submit.handleSubmit(() => {});
  187. if (status) {
  188. if (!(formData.data.applyBuyBomList && formData.data.applyBuyBomList.length > 0)) {
  189. ElMessage("请添加物料");
  190. return false;
  191. }
  192. return true;
  193. } else {
  194. setTimeout(() => {
  195. const errorDiv = document.getElementsByClassName("is-error");
  196. errorDiv[0].scrollIntoView();
  197. }, 0);
  198. }
  199. return false;
  200. }
  201. };
  202. const getFormData = () => {
  203. return proxy.deepClone(formData.data);
  204. };
  205. const fileList = ref([]);
  206. watch(
  207. () => props.queryData,
  208. (newValue) => {
  209. formOption.disabled = judgeStatus();
  210. if (props.queryData && ["10", "20", "30", "40"].includes(route.query.processType)) {
  211. formData.data = proxy.deepClone(newValue);
  212. if (route.query.processType == "20" && formData.data.id) {
  213. proxy.post("/fileInfo/getList", { businessIdList: [formData.data.id] }).then((fileObj) => {
  214. if (fileObj[formData.data.id] && fileObj[formData.data.id].length > 0) {
  215. fileList.value = fileObj[formData.data.id].map((item) => {
  216. return {
  217. raw: item,
  218. name: item.fileName,
  219. url: item.fileUrl,
  220. };
  221. });
  222. } else {
  223. fileList.value = [];
  224. }
  225. });
  226. }
  227. }
  228. },
  229. {
  230. deep: true,
  231. }
  232. );
  233. const onPreviewFile = (path) => {
  234. window.open(path, "_blank");
  235. };
  236. onMounted(() => {
  237. if (route.query.subscribeStatus) {
  238. if (subscribeStore().subscribe.list && subscribeStore().subscribe.list.length > 0) {
  239. formData.data.applyBuyBomList = subscribeStore().subscribe.list.map((item) => {
  240. return {
  241. bomSpecId: item.bomSpecId,
  242. bomSpecCode: item.bomSpecCode,
  243. bomSpecName: item.bomSpecName,
  244. bomSpecColour: item.colour,
  245. bomSpecLength: item.length,
  246. bomSpecWidth: item.width,
  247. bomSpecHeight: item.height,
  248. quantity: undefined,
  249. };
  250. });
  251. }
  252. }
  253. });
  254. // 向父组件暴露
  255. defineExpose({ getFormData, handleSubmit });
  256. </script>
  257. <style lang="scss" scoped>
  258. ::v-deep(.el-input-number .el-input__inner) {
  259. text-align: left;
  260. }
  261. :deep(.el-dialog) {
  262. margin-top: 10px !important;
  263. margin-bottom: 10px !important;
  264. }
  265. </style>