wbsinfo.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <basic-container>
  3. <avue-crud
  4. :option="option"
  5. :table-loading="loading"
  6. :data="data"
  7. :page.sync="page"
  8. :permission="permissionList"
  9. :before-open="beforeOpen"
  10. v-model="form"
  11. ref="crud"
  12. @row-update="rowUpdate"
  13. @row-save="rowSave"
  14. @row-del="rowDel"
  15. @search-change="searchChange"
  16. @search-reset="searchReset"
  17. @selection-change="selectionChange"
  18. @current-change="currentChange"
  19. @size-change="sizeChange"
  20. @refresh-change="refreshChange"
  21. @on-load="onLoad"
  22. >
  23. <template slot="menuLeft">
  24. <el-button
  25. type="danger"
  26. size="small"
  27. icon="el-icon-delete"
  28. plain
  29. v-if="permission.wbsinfo_delete"
  30. @click="handleDelete"
  31. >删 除
  32. </el-button>
  33. </template>
  34. <template slot="menuRight">
  35. <!-- 新增元素按钮 -->
  36. <el-button
  37. size="small"
  38. style="background-color:#FFA042;color:white;font-weight:bold"
  39. plain
  40. v-if="permission.wbsinfo_delete"
  41. @click="handleElement"
  42. >元素库
  43. </el-button>
  44. </template>
  45. <template
  46. slot-scope="{row,index}"
  47. slot="menu"
  48. >
  49. <el-button
  50. type="text"
  51. icon="el-icon-edit"
  52. size="mini"
  53. v-if="permission.wbsinfo_tree_edit"
  54. @click="toEdit(row,index)"
  55. >编辑wbs库</el-button>
  56. </template>
  57. </avue-crud>
  58. </basic-container>
  59. </template>
  60. <script>
  61. import { getList, getDetail, add, update, remove } from "@/api/manager/wbsinfo";
  62. import { mapGetters } from "vuex";
  63. export default {
  64. data () {
  65. return {
  66. form: {},
  67. query: {},
  68. loading: true,
  69. page: {
  70. pageSize: 20,
  71. currentPage: 1,
  72. total: 0
  73. },
  74. selectionList: [],
  75. option: {
  76. menuWidth: 300,
  77. height: 'auto',
  78. calcHeight: 30,
  79. tip: false,
  80. searchShow: true,
  81. searchMenuSpan: 6,
  82. border: true,
  83. index: true,
  84. viewBtn: true,
  85. selection: true,
  86. dialogClickModal: false,
  87. column: [
  88. {
  89. label: "创建时间",
  90. prop: "createTime",
  91. editDetail: true,
  92. addDisabled: true,
  93. },
  94. {
  95. label: "wbs名称",
  96. prop: "wbsName",
  97. rules: [{
  98. required: true,
  99. message: "请输入wbs名称",
  100. trigger: "blur"
  101. }]
  102. },
  103. {
  104. label: "划分类型",
  105. type: "select",
  106. dicUrl: "/api/blade-system/dict/dictionary?code=wbs_type",
  107. props: {
  108. label: "dictValue",
  109. value: "dictKey"
  110. },
  111. dataType: "number",
  112. prop: "wbsType",
  113. rules: [{
  114. required: true,
  115. message: "请选择划分类型",
  116. trigger: "blur"
  117. }]
  118. },
  119. {
  120. label: "是否启用",
  121. prop: "status",
  122. rules: [{
  123. required: true,
  124. message: "是否启用",
  125. trigger: "blur"
  126. }],
  127. type: "radio",
  128. dicData: [
  129. {
  130. label: "否",
  131. value: 0
  132. },
  133. {
  134. label: "是",
  135. value: 1
  136. }
  137. ],
  138. },
  139. ]
  140. },
  141. data: [],
  142. };
  143. },
  144. computed: {
  145. ...mapGetters(["permission"]),
  146. permissionList () {
  147. return {
  148. addBtn: this.vaildData(this.permission.wbsinfo_add, false),
  149. viewBtn: this.vaildData(this.permission.wbsinfo_view, false),
  150. delBtn: this.vaildData(this.permission.wbsinfo_delete, false),
  151. editBtn: this.vaildData(this.permission.wbsinfo_edit, false)
  152. };
  153. },
  154. ids () {
  155. let ids = [];
  156. this.selectionList.forEach(ele => {
  157. ids.push(ele.id);
  158. });
  159. return ids.join(",");
  160. }
  161. },
  162. methods: {
  163. //点击元素库
  164. handleElement(){
  165. console.log('元素库');
  166. this.$router.push({
  167. path: '/wbs/element',
  168. })
  169. },
  170. rowSave (row, done, loading) {
  171. add(row).then(() => {
  172. this.onLoad(this.page);
  173. this.$message({
  174. type: "success",
  175. message: "操作成功!"
  176. });
  177. done();
  178. }, error => {
  179. loading();
  180. window.console.log(error);
  181. });
  182. },
  183. rowUpdate (row, index, done, loading) {
  184. update(row).then(() => {
  185. this.onLoad(this.page);
  186. this.$message({
  187. type: "success",
  188. message: "操作成功!"
  189. });
  190. done();
  191. }, error => {
  192. loading();
  193. console.log(error);
  194. });
  195. },
  196. rowDel (row) {
  197. this.$confirm("确定将选择数据删除?", {
  198. confirmButtonText: "确定",
  199. cancelButtonText: "取消",
  200. type: "warning"
  201. })
  202. .then(() => {
  203. return remove(row.id);
  204. })
  205. .then(() => {
  206. this.onLoad(this.page);
  207. this.$message({
  208. type: "success",
  209. message: "操作成功!"
  210. });
  211. });
  212. },
  213. handleDelete () {
  214. if (this.selectionList.length === 0) {
  215. this.$message.warning("请选择至少一条数据");
  216. return;
  217. }
  218. this.$confirm("确定将选择数据删除?", {
  219. confirmButtonText: "确定",
  220. cancelButtonText: "取消",
  221. type: "warning"
  222. })
  223. .then(() => {
  224. return remove(this.ids);
  225. })
  226. .then(() => {
  227. this.onLoad(this.page);
  228. this.$message({
  229. type: "success",
  230. message: "操作成功!"
  231. });
  232. this.$refs.crud.toggleSelection();
  233. });
  234. },
  235. beforeOpen (done, type) {
  236. if (["edit", "view"].includes(type)) {
  237. getDetail(this.form.id).then(res => {
  238. this.form = res.data.data;
  239. });
  240. }
  241. done();
  242. },
  243. searchReset () {
  244. this.query = {};
  245. this.onLoad(this.page);
  246. },
  247. searchChange (params, done) {
  248. this.query = params;
  249. this.page.currentPage = 1;
  250. this.onLoad(this.page, params);
  251. done();
  252. },
  253. selectionChange (list) {
  254. this.selectionList = list;
  255. },
  256. selectionClear () {
  257. this.selectionList = [];
  258. this.$refs.crud.toggleSelection();
  259. },
  260. currentChange (currentPage) {
  261. this.page.currentPage = currentPage;
  262. },
  263. sizeChange (pageSize) {
  264. this.page.pageSize = pageSize;
  265. },
  266. refreshChange () {
  267. this.onLoad(this.page, this.query);
  268. },
  269. onLoad (page, params = {}) {
  270. this.loading = true;
  271. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  272. const data = res.data.data;
  273. this.page.total = data.total;
  274. this.data = data.records;
  275. this.loading = false;
  276. this.selectionClear();
  277. });
  278. },
  279. toEdit (row) {
  280. console.log(row);
  281. this.$router.push({
  282. path: '/wbs/edit',
  283. query: {
  284. id: row.id,
  285. type: row.wbsType
  286. }
  287. })
  288. //this.$router.push('/wbs/edit/' + row.id);
  289. }
  290. }
  291. };
  292. </script>
  293. <style>
  294. </style>