wbsinfo.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <template>
  2. <basic-container>
  3. <div class="search-box">
  4. <div class="search-box-left">
  5. <el-input v-model="query.wbsName" placeholder="请输入名称" style="width: 200px;" class="filter-item" size="small"/>
  6. <el-select v-model="query.projectId" placeholder="项目名称" clearable style="width: 200px" class="filter-item" size="small">
  7. <el-option v-for="item in projectList" :key="item.id" :label="item.projectAlias" :value="item.id" />
  8. </el-select>
  9. <el-select v-model="query.wbsType" placeholder="划分类型" clearable style="width: 200px" class="filter-item" size="small">
  10. <el-option v-for="item in tabTypeList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey" />
  11. </el-select>
  12. <el-button type="primary" @click="searchClick" class="custom-primary-btn" size="small">搜索</el-button>
  13. <el-button type="info" @click="clearSearch" size="small">清空</el-button>
  14. </div>
  15. <div class="header-box-right">
  16. <el-button
  17. type="primary"
  18. size="small"
  19. icon="el-icon-plus"
  20. @click="handleAdd"
  21. >新增
  22. </el-button>
  23. <el-button
  24. type="warning"
  25. size="small"
  26. icon="el-icon-sort"
  27. @click="handleSort"
  28. >排序
  29. </el-button>
  30. <el-button
  31. type="danger"
  32. size="small"
  33. icon="el-icon-delete"
  34. v-if="permission.wbsinfo_delete"
  35. @click="handleDelete"
  36. >删 除
  37. </el-button>
  38. <!-- 新增元素按钮 -->
  39. <el-button
  40. size="small"
  41. style="background-color:#FFA042;color:white;font-weight:bold;border-color: #FFA042;"
  42. plain
  43. v-if="permission.wbsinfo_delete"
  44. @click="handleElement"
  45. >元素库
  46. </el-button>
  47. <el-button
  48. size="small"
  49. style="background-color:#2550A2;color:white;font-weight:bold;border-color: #2550A2;"
  50. plain
  51. v-if="permission.wbsinfo_delete"
  52. @click="handleParameter"
  53. >参数库
  54. </el-button>
  55. </div>
  56. </div>
  57. <avue-crud
  58. :option="option"
  59. :table-loading="loading"
  60. :data="data"
  61. :page.sync="page"
  62. :permission="permissionList"
  63. :before-open="beforeOpen"
  64. v-model="form"
  65. ref="crud"
  66. @row-update="rowUpdate"
  67. @row-save="rowSave"
  68. @row-del="rowDel"
  69. @search-change="searchChange"
  70. @search-reset="searchReset"
  71. @selection-change="selectionChange"
  72. @current-change="currentChange"
  73. @size-change="sizeChange"
  74. @refresh-change="refreshChange"
  75. @on-load="onLoad"
  76. :search.sync="search"
  77. >
  78. <template slot-scope="{disabled,size}" slot="projectInfoListSearch">
  79. <el-select v-model="search.projectId" placeholder="项目名称" filterable clearable>
  80. <el-option
  81. v-for="item in projectList"
  82. :key="item.id"
  83. :label="item.projectAlias"
  84. :value="item.id">
  85. </el-option>
  86. </el-select>
  87. </template>
  88. <template slot="menuRight">
  89. </template>
  90. <template
  91. slot-scope="{row,index}"
  92. slot="menu"
  93. >
  94. <el-button
  95. type="text"
  96. icon="el-icon-edit"
  97. size="mini"
  98. v-if="permission.wbsinfo_tree_edit"
  99. @click="toEdit(row,index)"
  100. >编辑wbs库</el-button>
  101. </template>
  102. <template
  103. slot-scope="{row}"
  104. slot="wbsType"
  105. >
  106. <!-- <el-tag>{{ row.wbsType }}</el-tag> -->
  107. <el-tag
  108. size="small"
  109. v-for="item in generateTagItems(row.wbsType)"
  110. :key="item.label"
  111. :type="item.type"
  112. effect="dark"
  113. class="mr-3 custom-ellipse-tag"
  114. :class="`custom-tag-type-${item.type}`"
  115. >
  116. {{ item.label }}
  117. </el-tag>
  118. </template>
  119. <template slot-scope="{row}" slot="projectInfoList">
  120. <el-tooltip
  121. v-for="item in row.projectInfoList"
  122. :key="item.id"
  123. :content="item.projectName"
  124. placement="top"
  125. :disabled="true"
  126. >
  127. <el-tag
  128. size="small"
  129. type="info"
  130. class="custom-ellipse-tag1 ellipsis-tag"
  131. >
  132. {{item.projectName}}
  133. </el-tag>
  134. </el-tooltip>
  135. </template>
  136. </avue-crud>
  137. <!-- wbs排序弹窗 -->
  138. <ContractSort
  139. ref="contractSortRef"
  140. title="wbs排序弹窗"
  141. :sortProLoad="sortProLoad"
  142. @confirm="handleSortConfirm"
  143. />
  144. </basic-container>
  145. </template>
  146. <script>
  147. import { getList, getDetail, add, update, remove,sortWbs } from "@/api/manager/wbsinfo";
  148. import { mapGetters } from "vuex";
  149. import { getDictionary } from "@/api/system/dict";
  150. import ContractSort from './ContractSort.vue'
  151. import { getProjectListPage } from "@/api/manager/projectinfo";
  152. export default {
  153. components: {
  154. ContractSort
  155. },
  156. data () {
  157. return {
  158. form: {},
  159. query: {},
  160. loading: true,
  161. page: {
  162. pageSize: 20,
  163. currentPage: 1,
  164. total: 0
  165. },
  166. selectionList: [],
  167. option: {
  168. menuWidth: 300,
  169. height: 'auto',
  170. calcHeight: 30,
  171. tip: false,
  172. searchMenuSpan: 6,
  173. border: true,
  174. index: true,
  175. viewBtn: true,
  176. addBtn: false,
  177. selection: true,
  178. refreshBtn:false,
  179. searchShowBtn: false,
  180. columnBtn: false,
  181. dialogClickModal: false,
  182. searchShow: false,
  183. column: [
  184. {
  185. label: "创建时间",
  186. prop: "createTime",
  187. editDetail: true,
  188. addDisabled: true,
  189. hide: true,
  190. },
  191. {
  192. label: "wbs名称",
  193. prop: "wbsName",
  194. search: true,
  195. width: 180,
  196. rules: [{
  197. required: true,
  198. message: "请输入wbs名称",
  199. trigger: "blur"
  200. }]
  201. },
  202. {
  203. label: "划分类型",
  204. slot: true,
  205. search: true,
  206. width: 120,
  207. type: "select",
  208. dicUrl: "/api/blade-system/dict/dictionary?code=wbs_type",
  209. props: {
  210. label: "dictValue",
  211. value: "dictKey"
  212. },
  213. dataType: "number",
  214. prop: "wbsType",
  215. rules: [{
  216. required: true,
  217. message: "请选择划分类型",
  218. trigger: "blur"
  219. }],
  220. },
  221. {
  222. label: "是否启用",
  223. prop: "status",
  224. hide: true,
  225. rules: [{
  226. required: true,
  227. message: "是否启用",
  228. trigger: "blur"
  229. }],
  230. type: "radio",
  231. dicData: [
  232. {
  233. label: "否",
  234. value: 0
  235. },
  236. {
  237. label: "是",
  238. value: 1
  239. }
  240. ],
  241. },
  242. {
  243. label: "引用项目",
  244. prop: "projectInfoList",
  245. display: false,
  246. search: true,
  247. slot:true,
  248. },
  249. ]
  250. },
  251. data: [],
  252. search:{
  253. wbsName: '',
  254. wbsType: '',
  255. projectId:''
  256. },
  257. wbsTypeList:[],
  258. sortProLoad:false,
  259. wbsList:[],
  260. sortWbsList:[],
  261. projectList:[],
  262. tabTypeList:[],
  263. };
  264. },
  265. created () {
  266. this.getTabTypeList()
  267. this.getWbsList()
  268. this.getProjectList()
  269. },
  270. computed: {
  271. ...mapGetters(["permission"]),
  272. permissionList () {
  273. return {
  274. addBtn: this.vaildData(this.permission.wbsinfo_add, false),
  275. viewBtn: this.vaildData(this.permission.wbsinfo_view, false),
  276. delBtn: this.vaildData(this.permission.wbsinfo_delete, false),
  277. editBtn: this.vaildData(this.permission.wbsinfo_edit, false)
  278. };
  279. },
  280. ids () {
  281. let ids = [];
  282. this.selectionList.forEach(ele => {
  283. ids.push(ele.id);
  284. });
  285. return ids.join(",");
  286. }
  287. },
  288. methods: {
  289. getProjectList () {
  290. getProjectListPage({
  291. current:1,
  292. size:999,
  293. ...this.searchForm
  294. }).then((res) => {
  295. this.projectList = res.data.data.records;
  296. })
  297. },
  298. generateTagItems(wbsTypes){
  299. const typeToLabelMap = {
  300. 1: '质检',
  301. 2: '试验',
  302. 3: '日志',
  303. 4: '计量',
  304. 5: '征拆',
  305. 6: '底层节点',
  306. };
  307. let tagItems = [];
  308. // 如果 wbsTypes 不是数组,则将其转换为数组
  309. if (!Array.isArray(wbsTypes)) {
  310. wbsTypes = [wbsTypes];
  311. }
  312. wbsTypes.forEach(type => {
  313. // 检查type是否在映射关系中存在
  314. if (typeToLabelMap.hasOwnProperty(type)) {
  315. // 如果存在,则创建一个新的对象并添加到tagItems数组中
  316. tagItems.push({
  317. type: type,
  318. label: typeToLabelMap[type]
  319. });
  320. }
  321. });
  322. return tagItems;
  323. },
  324. getTabTypeList(){
  325. let code = "wbs_type";
  326. getDictionary({
  327. code,
  328. }).then((res) => {
  329. this.tabTypeList = res.data.data;
  330. });
  331. },
  332. //点击元素库
  333. handleElement(){
  334. console.log('元素库');
  335. this.$router.push({
  336. path: '/wbs/element',
  337. })
  338. },
  339. rowSave (row, done, loading) {
  340. add(row).then(() => {
  341. this.onLoad(this.page);
  342. this.$message({
  343. type: "success",
  344. message: "操作成功!"
  345. });
  346. done();
  347. }, error => {
  348. loading();
  349. window.console.log(error);
  350. });
  351. },
  352. rowUpdate (row, index, done, loading) {
  353. update(row).then(() => {
  354. this.onLoad(this.page);
  355. this.$message({
  356. type: "success",
  357. message: "操作成功!"
  358. });
  359. done();
  360. }, error => {
  361. loading();
  362. console.log(error);
  363. });
  364. },
  365. rowDel (row) {
  366. this.$confirm("确定将选择数据删除?", {
  367. confirmButtonText: "确定",
  368. cancelButtonText: "取消",
  369. type: "warning"
  370. })
  371. .then(() => {
  372. return remove(row.id);
  373. })
  374. .then(() => {
  375. this.onLoad(this.page);
  376. this.$message({
  377. type: "success",
  378. message: "操作成功!"
  379. });
  380. });
  381. },
  382. handleAdd(row) {
  383. this.$refs.crud.rowAdd();
  384. },
  385. handleDelete () {
  386. if (this.selectionList.length === 0) {
  387. this.$message.warning("请选择至少一条数据");
  388. return;
  389. }
  390. this.$confirm("确定将选择数据删除?", {
  391. confirmButtonText: "确定",
  392. cancelButtonText: "取消",
  393. type: "warning"
  394. })
  395. .then(() => {
  396. return remove(this.ids);
  397. })
  398. .then(() => {
  399. this.onLoad(this.page);
  400. this.$message({
  401. type: "success",
  402. message: "操作成功!"
  403. });
  404. this.$refs.crud.toggleSelection();
  405. });
  406. },
  407. beforeOpen (done, type) {
  408. if (["edit", "view"].includes(type)) {
  409. getDetail(this.form.id).then(res => {
  410. this.form = res.data.data;
  411. });
  412. }
  413. done();
  414. },
  415. searchReset () {
  416. this.query = {};
  417. this.onLoad(this.page);
  418. },
  419. searchChange (params, done) {
  420. this.query = params;
  421. this.page.currentPage = 1;
  422. this.onLoad(this.page, params);
  423. done();
  424. },
  425. selectionChange (list) {
  426. this.selectionList = list;
  427. },
  428. selectionClear () {
  429. this.selectionList = [];
  430. this.$refs.crud.toggleSelection();
  431. },
  432. currentChange (currentPage) {
  433. this.page.currentPage = currentPage;
  434. },
  435. sizeChange (pageSize) {
  436. this.page.pageSize = pageSize;
  437. },
  438. refreshChange () {
  439. this.onLoad(this.page, this.query);
  440. },
  441. onLoad (page, params = {}) {
  442. this.loading = true;
  443. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  444. const data = res.data.data;
  445. this.page.total = data.total;
  446. this.data = data.records;
  447. this.loading = false;
  448. this.selectionClear();
  449. });
  450. },
  451. toEdit (row) {
  452. console.log(row);
  453. this.$router.push({
  454. path: '/wbs/edit',
  455. query: {
  456. id: row.id,
  457. type: row.wbsType
  458. }
  459. })
  460. //this.$router.push('/wbs/edit/' + row.id);
  461. },
  462. //点击参数库
  463. handleParameter(){
  464. this.$router.push('/wbs/parameter');
  465. },
  466. getWbsList(){
  467. getList(1, 1000).then(res => {
  468. const data = res.data.data;
  469. this.wbsList=data['records']
  470. });
  471. },
  472. //排序
  473. handleSort(){
  474. this.sortWbsList = JSON.parse(JSON.stringify(this.wbsList));
  475. this.sortTitle = '合同段排序';
  476. this.$nextTick(() => {
  477. this.$refs.contractSortRef.show(this.sortWbsList);
  478. });
  479. },
  480. handleSortConfirm(sortedList) {
  481. // 这里处理排序后的数据
  482. console.log('排序后的列表:', sortedList);
  483. // TODO: 调用接口保存排序结果
  484. this.wbsList = [...sortedList];
  485. const ids = this.wbsList.map(item => item.id);
  486. this. saveSort(ids);
  487. },
  488. saveSort(ids){
  489. sortWbs(ids).then((res) => {
  490. this.sortProLoad= false;
  491. if(res.data.code==200){
  492. this.$message.success(res.data.msg)
  493. this.onLoad(this.page);
  494. }else{
  495. this.$message.error(res.data.msg)
  496. }
  497. })
  498. },
  499. searchClick(){
  500. this.onLoad(this.page,this.query);
  501. },
  502. clearSearch(){
  503. this.query = {};
  504. this.onLoad(this.page,this.searchParams);
  505. }
  506. }
  507. };
  508. </script>
  509. <style scoped lang="scss">
  510. .search-box{
  511. display: flex;
  512. justify-content: space-between;
  513. .search-item{
  514. margin-right: 10px;
  515. margin-left: 10px;
  516. }
  517. }
  518. .filter-item{
  519. margin-right: 10px;
  520. }
  521. </style>