modules.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <div class="global-variable">
  3. <h2 class="TitleH2">主轴</h2>
  4. <zhuzhou
  5. v-if="bearingBrandOptions.length > 0 && lubricantBrandOptions.length > 0"
  6. :rhyPP="lubricantBrandOptions"
  7. :rhyZC="bearingBrandOptions"
  8. :unitBearingsVo="unitBearingsVo"
  9. @update="handleUpdate('unitBearingsDto', $event)"
  10. ></zhuzhou>
  11. <div v-if="clxShow">
  12. <h2 class="TitleH2">齿轮箱</h2>
  13. <Chilunxiang
  14. v-if="
  15. bearingBrandOptions.length > 0 && lubricantBrandOptions.length > 0
  16. "
  17. :clxPP="lubricantBrandOptions"
  18. :clxZC="bearingBrandOptions"
  19. :unitGearDto="unitGearDto"
  20. @update="handleUpdate('unitGearDto', $event)"
  21. ></Chilunxiang>
  22. </div>
  23. <h2 class="TitleH2">发电机</h2>
  24. <Fadianji
  25. v-if="bearingBrandOptions.length > 0 && lubricantBrandOptions.length > 0"
  26. :fdjPP="lubricantBrandOptions"
  27. :fdjZC="bearingBrandOptions"
  28. :unitDynamoDto="unitDynamoDto"
  29. :fdjLQ="coolingoptions"
  30. @update="handleUpdate('unitDynamoDto', $event)"
  31. ></Fadianji>
  32. <el-button @click="ALLsubmit">提交</el-button>
  33. </div>
  34. </template>
  35. <script>
  36. import {
  37. getBrandModelNameOrModelNumber,
  38. getUnitDictRoutineList,
  39. modificationUnit,
  40. getUnitVo,
  41. } from "@/api/maintain";
  42. import Chilunxiang from "./componentBJ/chilunxiang.vue";
  43. import Fadianji from "./componentBJ/fadianji.vue";
  44. import zhuzhou from "./componentBJ/zhuzhou.vue";
  45. import router from "@/router";
  46. export default {
  47. components: { zhuzhou, Chilunxiang, Fadianji },
  48. data() {
  49. return {
  50. clxShow: true,
  51. // 润滑油选项
  52. lubricantBrandOptions: [],
  53. // 轴承选项
  54. bearingBrandOptions: [],
  55. // 主轴的
  56. unitBearingsVo: {},
  57. // 发电机
  58. unitDynamoDto: {},
  59. // 齿轮箱
  60. unitGearDto: {},
  61. // 冷却选项
  62. coolingOptions: [],
  63. // 存储不同子组件的状态
  64. formData: {
  65. millTypeCode: "",
  66. // 主轴
  67. unitBearingsDto: {
  68. code: "",
  69. id: "",
  70. },
  71. // 齿轮箱
  72. unitGearDto: {
  73. code: "",
  74. id: "",
  75. lubricantBrand: "",
  76. lubricantModel: "",
  77. unitGearboxBearingsDtoList: [{ id: "" }],
  78. // 齿轮箱结构集合
  79. unitGearboxStructureDtoList: [{ id: "" }],
  80. },
  81. //发电机
  82. unitDynamoDto: {
  83. id: "",
  84. },
  85. },
  86. submittedData: null,
  87. allParams: {},
  88. coolingoptions: null,
  89. };
  90. },
  91. created() {
  92. this.curvedMotionType = this.$route.query.curvedMotionType;
  93. this.formData.millTypeCode = this.$route.query.millTypeCode;
  94. if (this.curvedMotionType == "2") {
  95. this.clxShow = false;
  96. }
  97. this.GETbrand(); // 加载品牌和型号数据
  98. this.GETecho();
  99. },
  100. methods: {
  101. // 获取品牌和型号数据
  102. GETbrand() {
  103. const params = { unitType: 1 };
  104. const params2 = { unitType: 2 };
  105. const params3 = { contentsType: "UDTC00031" };
  106. getBrandModelNameOrModelNumber(params)
  107. .then((res) => {
  108. // 确保数据有效
  109. if (res && res.data) {
  110. this.bearingBrandOptions = res.data;
  111. } else {
  112. console.error("获取轴承品牌失败:", res);
  113. }
  114. })
  115. .catch((error) => {
  116. console.error("获取轴承品牌请求失败:", error);
  117. });
  118. getBrandModelNameOrModelNumber(params2)
  119. .then((res) => {
  120. // 确保数据有效
  121. if (res && res.data) {
  122. this.lubricantBrandOptions = res.data;
  123. } else {
  124. console.error("获取润滑油品牌失败:", res);
  125. }
  126. })
  127. .catch((error) => {
  128. console.error("获取润滑油品牌请求失败:", error);
  129. });
  130. getUnitDictRoutineList(params3)
  131. .then((res) => {
  132. // 确保数据有效
  133. if (res && res.data) {
  134. this.coolingoptions = res.data;
  135. } else {
  136. console.error("获取冷却选项失败:", res);
  137. }
  138. })
  139. .catch((error) => {
  140. console.error("获取冷却选项请求失败:", error);
  141. });
  142. },
  143. GETecho() {
  144. getUnitVo({ millTypeCode: this.formData.millTypeCode }).then((res) => {
  145. console.log(res.data.unitDynamoVo, "============");
  146. if (res.data.unitBearingsVo != null) {
  147. // 主轴
  148. this.formData.unitBearingsDto.code = res.data.unitBearingsVo.code;
  149. this.formData.unitBearingsDto.id = res.data.unitBearingsVo.id;
  150. }
  151. if (res.data.unitGearVo) {
  152. const unitGearVo = res.data.unitGearVo;
  153. // 齿轮箱基本信息
  154. this.formData.unitGearDto.code = unitGearVo.code || "";
  155. this.formData.unitGearDto.id = unitGearVo.id || "";
  156. // 齿轮箱轴承集合(确保列表存在且是数组)
  157. if (Array.isArray(unitGearVo.unitGearboxBearingsList)) {
  158. this.formData.unitGearDto.unitGearboxBearingsDtoList =
  159. unitGearVo.unitGearboxBearingsList.map((item) => ({
  160. id: item.id || "",
  161. }));
  162. }
  163. // 齿轮箱结构集合(确保列表存在且是数组)
  164. if (Array.isArray(unitGearVo.unitGearboxStructureList)) {
  165. this.formData.unitGearDto.unitGearboxStructureDtoList =
  166. unitGearVo.unitGearboxStructureList.map((item) => ({
  167. id: item.id || "",
  168. }));
  169. }
  170. }
  171. if (res.data.unitDynamoVo != null) {
  172. // 齿轮箱
  173. this.formData.unitDynamoDto.id = res.data.unitDynamoVo.id;
  174. }
  175. this.unitBearingsVo = res.data.unitBearingsVo;
  176. this.unitDynamoDto = res.data.unitDynamoVo;
  177. this.unitGearDto = res.data.unitGearVo;
  178. });
  179. },
  180. /**
  181. * 处理子组件传来的更新事件
  182. * @param {Object} payload 子组件发送的数据
  183. * @param {String} payload.key 要更新的字段
  184. * @param {String} payload.value 字段的新值
  185. */
  186. handleUpdate(componentName, { key, value }) {
  187. if (key && key.includes(".")) {
  188. // 如果 key 包含路径,解析并更新对应路径
  189. const keys = key.split("."); // 分割路径
  190. let target = this.formData;
  191. // 遍历路径逐层深入
  192. for (let i = 0; i < keys.length - 1; i++) {
  193. const keyPart = keys[i];
  194. if (keyPart.includes("[")) {
  195. const [arrayKey, index] = keyPart.split(/[\[\]]/).filter(Boolean);
  196. target = target[arrayKey][index]; // 数组元素访问
  197. } else {
  198. target = target[keyPart]; // 对象访问
  199. }
  200. }
  201. // 最后一层赋值
  202. const lastKey = keys[keys.length - 1];
  203. this.$set(target, lastKey, value); // 使用 $set 确保响应式更新
  204. console.log("更新后的数据:", this.formData);
  205. } else if (this.formData[componentName]) {
  206. // 如果是直接指定 componentName 更新
  207. this.$set(this.formData[componentName], key, value);
  208. console.log("更新后的数据:", this.formData);
  209. } else {
  210. console.error("无效的组件名称或 key");
  211. }
  212. },
  213. ALLsubmit() {
  214. // 轴
  215. console.log(this.formData.unitGearDto);
  216. const unitGearboxBearingsDtoList =
  217. this.formData.unitGearDto.unitGearboxBearingsDtoList.map(
  218. ({ uniqueKey, ...rest }) => rest
  219. );
  220. console.log(unitGearboxBearingsDtoList);
  221. this.formData.unitGearDto.unitGearboxBearingsDtoList =
  222. unitGearboxBearingsDtoList;
  223. // 结构
  224. const unitGearboxStructureDtoList =
  225. this.formData.unitGearDto.unitGearboxStructureDtoList.map(
  226. ({ uniqueKey, ...rest }) => rest
  227. );
  228. console.log(unitGearboxStructureDtoList);
  229. // 汇总所有子组件的数据
  230. this.formData.unitGearDto.unitGearboxStructureDtoList =
  231. unitGearboxStructureDtoList;
  232. this.allParams = { ...this.formData };
  233. // 发送到后端或执行其他操作
  234. this.submitToBackend(this.allParams);
  235. },
  236. /**
  237. * 模拟发送数据到后端
  238. * @param {Object} params 提交的所有参数
  239. */
  240. submitToBackend(params) {
  241. modificationUnit(params).then((res) => {
  242. if (res.code == 200)
  243. this.$router.push({
  244. path: "/home/ledger/milltype",
  245. });
  246. });
  247. // 你可以调用后台 API,例如:axios.post('/api/submit', params);
  248. },
  249. },
  250. };
  251. </script>
  252. <style lang="scss" scoped>
  253. .TitleH2 {
  254. font-weight: 800;
  255. font-size: 28px;
  256. margin: 20px 0;
  257. }
  258. </style>