maintain.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. <template>
  2. <div class="global-variable">
  3. <div class="inquire">
  4. <div class="condition">
  5. <p>部件名称:</p>
  6. <el-input v-model="nameOfparts" size="small"></el-input>
  7. <el-button type="primary" @click="GETquery" size="small"
  8. >查询</el-button
  9. >
  10. </div>
  11. <el-button plain size="small" @click="newly">新增</el-button>
  12. </div>
  13. <div class="assemblyList">
  14. <el-table :data="tableData" border style="width: 100%">
  15. <el-table-column prop="unitModuleName" align="center" label="部件模块">
  16. </el-table-column>
  17. <el-table-column prop="contentsName" align="center " label="部件名称 ">
  18. </el-table-column>
  19. <el-table-column
  20. prop="associatedFunctionTypeName"
  21. align="center"
  22. label="部件类型 "
  23. >
  24. </el-table-column>
  25. <el-table-column prop="contentsType" align="center" label="部件编码">
  26. </el-table-column>
  27. <el-table-column prop="createTime" align="center" label="创建时间" >
  28. </el-table-column>
  29. <el-table-column prop="updateTime" align="center" label="维护时间" >
  30. </el-table-column>
  31. <el-table-column fixed="right" align="center" label="操作" >
  32. <template slot-scope="scope">
  33. <!-- <el-button @click="handleClick(scope.row)" type="text" size="small"
  34. >编辑</el-button
  35. > -->
  36. <el-button
  37. v-if="scope.row.associatedFunctionType === 1"
  38. @click="ONallocation(scope.row)"
  39. type="text"
  40. size="small"
  41. >部件配置</el-button
  42. >
  43. <el-button
  44. v-if="scope.row.associatedFunctionType === 2"
  45. @click="ONbrand(scope.row)"
  46. type="text"
  47. size="small"
  48. >品牌维护</el-button
  49. >
  50. <el-button @click="ONdelete(scope.row)" type="text" size="small"
  51. >删除</el-button
  52. >
  53. </template>
  54. </el-table-column>
  55. </el-table>
  56. <el-pagination
  57. @size-change="handleSizeChange"
  58. @current-change="handleCurrentChange"
  59. :current-page.sync="pageNum"
  60. :page-size="pageSize"
  61. layout="total, prev, pager, next"
  62. :total="total"
  63. class="fenye"
  64. >
  65. </el-pagination>
  66. </div>
  67. <el-dialog
  68. title="新增部件"
  69. :visible.sync="dialogVisible"
  70. width="20%"
  71. :before-close="handleClose"
  72. >
  73. <p style="margin-bottom: 20px">
  74. 部件模块:<el-select v-model="modulevalue" placeholder="请选择">
  75. <el-option
  76. v-for="item in moduleoptions"
  77. :key="item.contentsValue"
  78. :label="item.contentsName"
  79. :value="item.contentsValue"
  80. >
  81. </el-option>
  82. </el-select>
  83. </p>
  84. <p style="margin-bottom: 20px">
  85. 部件名称:<el-select v-model="namevalue" placeholder="请选择">
  86. <el-option
  87. v-for="item in nameoptions"
  88. :key="item.contentsValue"
  89. :label="item.contentsName"
  90. :value="item.contentsValue"
  91. >
  92. </el-option>
  93. </el-select>
  94. </p>
  95. <p style="margin-bottom: 20px">
  96. 功能类型:<el-select v-model="functionvalue" placeholder="请选择">
  97. <el-option
  98. v-for="item in functionoptions"
  99. :key="item.contentsValue"
  100. :label="item.contentsName"
  101. :value="item.contentsValue"
  102. >
  103. </el-option>
  104. </el-select>
  105. </p>
  106. <div class="button-container">
  107. <el-button
  108. class="but"
  109. size="small"
  110. type="primary"
  111. @click="handleConfirm"
  112. >
  113. 确定
  114. </el-button>
  115. </div>
  116. </el-dialog>
  117. <!-- 关联 -->
  118. <el-drawer
  119. title="新增"
  120. :visible.sync="drawer"
  121. size="23%"
  122. :with-header="true"
  123. @close="handleClose"
  124. class="drawers"
  125. >
  126. <div class="drawersDIV">
  127. <el-input
  128. size="small "
  129. placeholder="请输入品牌"
  130. v-model="brandvalue"
  131. ></el-input>
  132. <span>-</span>
  133. <el-input
  134. size="small "
  135. placeholder="请输入型号"
  136. v-model="modelvalue"
  137. ></el-input>
  138. <el-button
  139. size="small"
  140. type="primary"
  141. style="margin-left: 5px"
  142. @click="fetchData"
  143. >查询</el-button
  144. >
  145. <el-button size="small" @click="newtype('1')">新增</el-button>
  146. <el-table :data="relevanceData" border style="width: 100%">
  147. <el-table-column prop="manufacture" label="品牌"> </el-table-column>
  148. <el-table-column prop="modelNumber" label="型号"> </el-table-column>
  149. <el-table-column fixed="right" label="操作" width="100">
  150. <template slot-scope="scope">
  151. <el-button
  152. @click="handleClick(scope.row)"
  153. type="text"
  154. size="small"
  155. >编辑</el-button
  156. >
  157. <el-button type="text" @click="DELpingpai(scope.row)" size="small"
  158. >删除</el-button
  159. >
  160. </template>
  161. </el-table-column>
  162. </el-table>
  163. <el-pagination
  164. @size-change="drawerhandleSizeChange"
  165. @current-change="drawerhandleCurrentChange"
  166. :current-page.sync="pageNum"
  167. :page-size="pageSize"
  168. :pager-count="5"
  169. layout="prev, pager, next"
  170. :total="drawertotal"
  171. class="fenye"
  172. >
  173. </el-pagination>
  174. </div>
  175. </el-drawer>
  176. <el-dialog
  177. title="新增部件"
  178. :visible.sync="relevanceVisible"
  179. width="20%"
  180. :before-close="handleClose"
  181. >
  182. <p class="maintain">
  183. 品牌:<span class="one"
  184. ><el-input v-model="brand" size="small"></el-input
  185. ></span>
  186. </p>
  187. <p class="maintain">
  188. 型号:<span class="one"
  189. ><el-input v-model="guige" size="small"></el-input
  190. ></span>
  191. </p>
  192. <div class="button-container">
  193. <el-button class="but" size="small" type="primary" @click="Glsubmit">
  194. 确定
  195. </el-button>
  196. </div>
  197. </el-dialog>
  198. <!-- 非 -->
  199. <el-drawer
  200. title="新增"
  201. :visible.sync="notdrawer"
  202. size="22%"
  203. :with-header="true"
  204. class="drawers"
  205. >
  206. <div class="drawersDIV">
  207. <el-button
  208. style="margin-bottom: 10px"
  209. size="small"
  210. @click="newtype('2')"
  211. >新增</el-button
  212. >
  213. <el-table :data="nothaveData" border style="width: 100%">
  214. <el-table-column prop="contentsName" label="属性名称">
  215. </el-table-column>
  216. <el-table-column fixed="right" label="操作" width="100">
  217. <template slot-scope="scope">
  218. <el-button @click="compile(scope.row)" type="text" size="small"
  219. >编辑</el-button
  220. >
  221. <el-button type="text" @click="DELshuxing(scope.row)" size="small"
  222. >删除</el-button
  223. >
  224. </template>
  225. </el-table-column>
  226. </el-table>
  227. </div>
  228. </el-drawer>
  229. <el-dialog
  230. title="新增部件"
  231. :visible.sync="maintainVisible"
  232. width="22%"
  233. :before-close="handleClose"
  234. >
  235. <p class="maintain">
  236. 名称:<span class="one"
  237. ><el-input v-model="bujianval" size="small"></el-input></span
  238. ><span class="Sptwo">
  239. <el-button class="but" size="small" type="primary" @click="submit">
  240. 确定
  241. </el-button></span
  242. >
  243. </p>
  244. </el-dialog>
  245. </div>
  246. </template>
  247. <script>
  248. import {
  249. getDictList,
  250. createUnitDict,
  251. getUnitDictConstantsPage,
  252. delUnitDict,
  253. createUnitDictProperty,
  254. getUnitDictConstantsList,
  255. delUnitDictProperty,
  256. updateUnitDictProperty,
  257. saveUnitDictBrandModel,
  258. getUnitDictBrandModelPage,
  259. delUnitDictBrandModel,
  260. updateUnitDictBrandModel,
  261. } from "@/api/maintain.js";
  262. export default {
  263. data() {
  264. return {
  265. nameOfparts: "",
  266. tableData: [],
  267. drawer: false,
  268. notdrawer: false,
  269. dialogVisible: false,
  270. maintainVisible: false,
  271. relevanceVisible: false,
  272. modulevalue: "",
  273. moduleoptions: [],
  274. namevalue: "",
  275. nameoptions: [],
  276. functionvalue: "",
  277. functionoptions: [],
  278. checked: "0",
  279. drawervalue: "",
  280. brand: "",
  281. guige: "",
  282. rowList: {},
  283. bujianval: "",
  284. nothaveData: [],
  285. editType: "",
  286. currentRow: "",
  287. compilerow: {},
  288. total: 0,
  289. drawertotal: 0,
  290. pageNum: 1,
  291. pageSize: 10,
  292. relevanceData: [],
  293. drawerList: {},
  294. brandvalue: "",
  295. modelvalue: "",
  296. pprow: {},
  297. };
  298. },
  299. created() {
  300. this.GETquery();
  301. this.GETmokuai();
  302. },
  303. methods: {
  304. load() {
  305. this.$message.success("加载下一页");
  306. this.tableData = this.tableData.concat(exampleData);
  307. //此时也可以调用接口,然后做数组的拼接
  308. },
  309. // 查询
  310. GETquery() {
  311. const params = {
  312. contentsName: this.nameOfparts,
  313. pageNum: this.pageNum,
  314. pageSize: this.pageSize,
  315. };
  316. getUnitDictConstantsPage(params).then((res) => {
  317. this.tableData = res.data.list;
  318. this.total = res.data.totalSize;
  319. });
  320. },
  321. // 获取属性
  322. GETmokuai() {
  323. getDictList({ dictType: 3 }).then((res) => {
  324. this.moduleoptions = res.data;
  325. });
  326. getDictList({ dictType: 4 }).then((res) => {
  327. this.nameoptions = res.data;
  328. });
  329. getDictList({ dictType: 5 }).then((res) => {
  330. this.functionoptions = res.data;
  331. });
  332. },
  333. // 打开新增
  334. newly() {
  335. this.dialogVisible = true;
  336. },
  337. // 新增属性
  338. handleConfirm() {
  339. // 构建 params 对象
  340. const params = {
  341. associatedFunctionType: this.functionvalue,
  342. contentsDictKey: this.namevalue,
  343. contentsName:
  344. this.nameoptions.find((item) => item.contentsValue === this.namevalue)
  345. ?.contentsName || "", // 赋值nameoptions当前选中的label
  346. unitModule: this.modulevalue,
  347. parentId: 0,
  348. };
  349. // 验证 params 中的字段是否为空
  350. if (
  351. !params.associatedFunctionType ||
  352. !params.contentsDictKey ||
  353. !params.contentsName ||
  354. !params.unitModule
  355. ) {
  356. this.$message({
  357. message: "请确保所有字段都已填写!",
  358. type: "warning",
  359. });
  360. return; // 阻止提交
  361. }
  362. // 提交数据
  363. createUnitDict(params).then((res) => {
  364. if (res.status === true) {
  365. this.$message({
  366. message: "恭喜你,这是一条成功消息",
  367. type: "success",
  368. });
  369. this.dialogVisible = false;
  370. this.GETquery();
  371. this.handleClose();
  372. }
  373. });
  374. },
  375. // 删除
  376. ONdelete(row) {
  377. this.$confirm(
  378. `确定要删除该项吗?(部件模块:${row.unitModuleName},部件名称:${row.contentsName})`,
  379. "删除确认",
  380. {
  381. confirmButtonText: "确定",
  382. cancelButtonText: "取消",
  383. type: "warning",
  384. }
  385. )
  386. .then(() => {
  387. // Proceed with deletion after confirmation
  388. const params = {
  389. contentsType: row.contentsType,
  390. id: row.id,
  391. };
  392. delUnitDict(params).then((res) => {
  393. if (res.status === true) {
  394. this.tableData = this.tableData.filter(
  395. (item) => item.id !== row.id
  396. );
  397. this.GETquery();
  398. this.$message({
  399. type: "success",
  400. message: "删除成功!",
  401. });
  402. } else {
  403. this.$message({
  404. type: "error",
  405. message: "删除失败,请稍后再试。",
  406. });
  407. }
  408. });
  409. })
  410. .catch(() => {
  411. // User canceled the deletion
  412. this.$message({
  413. type: "info",
  414. message: "删除已取消。",
  415. });
  416. });
  417. },
  418. // 分页
  419. handleSizeChange(pageSize) {
  420. this.pageSize = pageSize; // 更新每页显示条数
  421. this.GETquery(); // 重新获取数据
  422. },
  423. handleCurrentChange(pageNum) {
  424. this.pageNum = pageNum; // 更新当前页
  425. this.GETquery(); // 重新获取数据
  426. },
  427. // 常用类型
  428. ONallocation(row) {
  429. this.rowList = row;
  430. this.notdrawer = true;
  431. getUnitDictConstantsList({
  432. contentsType: this.rowList.contentsType,
  433. }).then((res) => {
  434. this.nothaveData = res.data;
  435. });
  436. },
  437. // 删除常用
  438. DELshuxing(row) {
  439. const params = {
  440. updateBy: row.updateBy,
  441. id: row.id,
  442. };
  443. delUnitDictProperty(params).then((res) => {
  444. this.nothaveData = this.nothaveData.filter(
  445. (item) => item.id !== row.id
  446. );
  447. });
  448. },
  449. // 编辑常用
  450. compile(row) {
  451. this.maintainVisible = true;
  452. this.bujianval = row.contentsName;
  453. this.compilerow = row;
  454. this.editType = "edit"; // 设置编辑模式
  455. },
  456. // 提交
  457. submit() {
  458. const params = {
  459. contentsName: this.bujianval,
  460. contentsType: this.rowList.contentsType,
  461. parentId: this.rowList.id,
  462. unitModule: this.rowList.unitModule,
  463. contentsDictKey: 0,
  464. };
  465. console.log(params, "1");
  466. if (this.editType === "edit") {
  467. // 编辑操作
  468. const updateParams = {
  469. contentsName: this.bujianval,
  470. id: this.compilerow.id, // 编辑时需要传递项的 ID
  471. updateBy: 0, // 更新人的 ID(如果需要)
  472. };
  473. console.log(updateParams, "2");
  474. updateUnitDictProperty(updateParams).then((res) => {
  475. this.maintainVisible = false;
  476. getUnitDictConstantsList({
  477. contentsType: this.rowList.contentsType,
  478. }).then((res) => {
  479. this.nothaveData = res.data;
  480. });
  481. });
  482. } else {
  483. // 新增操作
  484. createUnitDictProperty(params).then((res) => {
  485. this.maintainVisible = false;
  486. getUnitDictConstantsList({
  487. contentsType: this.rowList.contentsType,
  488. }).then((res) => {
  489. this.nothaveData = res.data;
  490. });
  491. });
  492. }
  493. this.handleClose();
  494. },
  495. // 品牌
  496. drawerhandleSizeChange(newSize) {
  497. this.pageSize = newSize;
  498. this.fetchData();
  499. },
  500. drawerhandleCurrentChange(newPage) {
  501. this.pageNum = newPage;
  502. this.fetchData();
  503. },
  504. fetchData() {
  505. const params = {
  506. contentsDictKey: this.drawerList.contentsDictKey,
  507. manufacture: this.brandvalue,
  508. modelNumber: this.modelvalue,
  509. pageNum: this.pageNum,
  510. pageSize: this.pageSize,
  511. };
  512. getUnitDictBrandModelPage(params).then((res) => {
  513. this.relevanceData = res.data.list;
  514. this.drawertotal = res.data.totalSize;
  515. });
  516. },
  517. ONbrand(row) {
  518. this.drawer = true;
  519. this.drawerList = row;
  520. console.log(row);
  521. this.fetchData();
  522. },
  523. // 提交品牌
  524. Glsubmit() {
  525. const params = {
  526. manufacture: this.brand,
  527. modelNumber: this.guige,
  528. unitType: this.drawerList ? this.drawerList.contentsDictKey : "", // 确保 this.drawerList 存在
  529. };
  530. if (!params.manufacture || !params.modelNumber || !params.unitType) {
  531. this.$message({
  532. message: "请确保所有字段都已填写!",
  533. type: "warning",
  534. });
  535. return;
  536. }
  537. if (this.editType === "edit") {
  538. // Edit operation
  539. const updateParams = {
  540. id: this.pprow.id, // The ID of the item being edited
  541. manufacture: params.manufacture,
  542. modelNumber: params.modelNumber,
  543. unitType: params.unitType,
  544. };
  545. updateUnitDictBrandModel(updateParams).then((res) => {
  546. if (res.status === true) {
  547. this.$message({
  548. message: "更新成功!",
  549. type: "success",
  550. });
  551. this.notdrawer = false;
  552. this.handleClose();
  553. this.editType = null; // Reset editType after a successful edit
  554. if (this.drawerList) {
  555. this.ONbrand(this.drawerList);
  556. } else {
  557. this.$message({
  558. message: "未选择有效的部件信息,无法更新相关数据。",
  559. type: "error",
  560. });
  561. }
  562. }
  563. });
  564. } else {
  565. // New entry
  566. saveUnitDictBrandModel(params).then((res) => {
  567. if (res.status === true) {
  568. this.$message({
  569. message: "恭喜你,这是一条成功消息",
  570. type: "success",
  571. });
  572. this.notdrawer = false;
  573. this.handleClose();
  574. if (this.drawerList) {
  575. this.ONbrand(this.drawerList);
  576. } else {
  577. this.$message({
  578. message: "未选择有效的部件信息,无法更新相关数据。",
  579. type: "error",
  580. });
  581. }
  582. }
  583. });
  584. }
  585. },
  586. //删除品牌
  587. DELpingpai(row) {
  588. this.$confirm("确定删除该品牌吗?", "提示", {
  589. confirmButtonText: "确定",
  590. cancelButtonText: "取消",
  591. type: "warning",
  592. })
  593. .then(() => {
  594. delUnitDictBrandModel({ id: row.id }).then((res) => {
  595. if (res.status === true) {
  596. this.$message({
  597. type: "success",
  598. message: "删除成功!",
  599. });
  600. this.relevanceData = this.relevanceData.filter(
  601. (item) => item.id !== row.id
  602. );
  603. } else {
  604. this.$message({
  605. type: "error",
  606. message: "删除失败,请重试!",
  607. });
  608. }
  609. });
  610. })
  611. .catch(() => {
  612. // 用户点击了"取消"
  613. this.$message({
  614. type: "info",
  615. message: "已取消删除操作",
  616. });
  617. });
  618. },
  619. handleClick(row) {
  620. this.pprow = row;
  621. this.relevanceVisible = true;
  622. this.brand = row.manufacture;
  623. this.guige = row.modelNumber;
  624. this.editType = "edit"; // 设置编辑模式
  625. },
  626. // 清空选项
  627. handleClose() {
  628. this.modulevalue = "";
  629. this.namevalue = "";
  630. this.functionvalue = "";
  631. this.bujianval = "";
  632. this.brand = "";
  633. this.guige = "";
  634. this.brandvalue = "";
  635. this.modelvalue = "";
  636. this.dialogVisible = false;
  637. this.maintainVisible = false;
  638. this.relevanceVisible = false;
  639. this.drawer = false;
  640. },
  641. newtype(type) {
  642. if (type === "1") {
  643. this.relevanceVisible = true;
  644. } else if (type === "2") {
  645. this.maintainVisible = true;
  646. }
  647. },
  648. },
  649. };
  650. </script>
  651. <style lang="scss" scoped>
  652. .inquire {
  653. display: flex;
  654. justify-content: space-between;
  655. .condition {
  656. display: flex;
  657. p {
  658. width: 80px;
  659. line-height: 32px;
  660. }
  661. .el-input {
  662. width: 220px;
  663. margin-right: 20px;
  664. }
  665. }
  666. }
  667. .assemblyList {
  668. margin: 20px 0;
  669. }
  670. .fenye {
  671. margin: 20px auto;
  672. text-align: center;
  673. }
  674. .button-container {
  675. display: flex;
  676. justify-content: center;
  677. margin-top: 20px;
  678. .but {
  679. width: 100px;
  680. }
  681. }
  682. .drawers {
  683. .drawersDIV {
  684. padding: 0 20px;
  685. margin-bottom: 20px;
  686. }
  687. .el-input {
  688. width: 100px;
  689. // margin-right: 20px;
  690. margin-bottom: 20px;
  691. }
  692. }
  693. .maintain {
  694. margin-bottom: 20px;
  695. .el-input {
  696. width: 220px;
  697. }
  698. .Sptwo {
  699. margin-left: 10px;
  700. }
  701. }
  702. </style>