index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <el-row>
  3. <el-col :span="4">
  4. <div class="box">
  5. <el-scrollbar>
  6. <basic-container>
  7. <avue-tree
  8. :option="treeOption"
  9. :data="treeData"
  10. @node-click="nodeClick"
  11. />
  12. </basic-container>
  13. </el-scrollbar>
  14. </div>
  15. </el-col>
  16. <el-col :span="20">
  17. <basic-container>
  18. <avue-crud
  19. ref="crud"
  20. :data="data"
  21. :option="tableOption"
  22. :page.sync="page"
  23. :table-loading="loading"
  24. v-model='form'
  25. :search.sync="search"
  26. :before-open="beforeOpen"
  27. @size-change="sizeChange"
  28. @current-change="currentChange"
  29. @search-change="searchChange"
  30. @refresh-change="refreshChange"
  31. @row-save="rowSave"
  32. @row-del="rowDel"
  33. @row-update="rowUpdate"
  34. @cell-dblclick="cellDblclick"
  35. @on-load="getList"
  36. @saveColumn="saveColumn"
  37. @tree-load="treeLoad"
  38. >
  39. <template slot="menuLeft">
  40. <el-button
  41. icon="el-icon-printer"
  42. size="small"
  43. type="primary"
  44. @click.stop="openReport()"
  45. >报 表
  46. </el-button>
  47. </template>
  48. <report-dialog
  49. :switchDialog="switchDialog"
  50. @onClose="onClose()"
  51. ></report-dialog>
  52. </avue-crud>
  53. </basic-container>
  54. </el-col>
  55. </el-row>
  56. </template>
  57. <script>
  58. import option from "./configuration/mainList.json";
  59. import reportDialog from "@/components/report-dialog/main";
  60. import {getList , add ,update ,remove ,getPortTypeTree , getTypeTree} from "@/api/basicData/portinformation"
  61. export default {
  62. data() {
  63. return {
  64. switchDialog:false,//报表
  65. loading: true,
  66. data: [],
  67. tableOption: option,
  68. form:{},
  69. search:{},
  70. treeDeptId:"",
  71. treeDeptName:'',
  72. height: window.innerHeight - 350,
  73. page: {
  74. currentPage: 1,
  75. total: 0,
  76. pageSize: 10
  77. },
  78. treeOption: {
  79. nodeKey: "id",
  80. lazy: true,
  81. treeLoad: function(node, resolve) {
  82. const parentId = node.level === 0 ? 0 : node.data.id;
  83. getPortTypeTree(parentId).then(res => {
  84. resolve(
  85. res.data.map(item => {
  86. return {
  87. ...item,
  88. leaf: !item.hasChildren
  89. };
  90. })
  91. );
  92. });
  93. },
  94. addBtn: false,
  95. menu: false,
  96. size: "small",
  97. props: {
  98. labelText: "标题",
  99. label: "name",
  100. value: "id",
  101. children: "children"
  102. }
  103. }
  104. };
  105. },
  106. created() {
  107. },
  108. components: {
  109. reportDialog
  110. },
  111. mounted() {
  112. option.height = window.innerHeight - 235 ;
  113. //查询服务类别字典项
  114. getTypeTree().then(res => {
  115. this.findObject(this.tableOption.column, "typeId").dicData = res.data.data;
  116. });
  117. },
  118. methods: {
  119. //打印
  120. openReport() {
  121. this.switchDialog =! this.switchDialog;
  122. },
  123. //关闭打印
  124. onClose(val) {
  125. this.switchDialog = val;
  126. },
  127. getList(page, params = {}) {
  128. this.loading = true
  129. getList(page.currentPage, page.pageSize, params, this.treeDeptId).then(res => {
  130. this.data = res.data.data.records
  131. this.page.total = res.data.data.total
  132. this.loading = false
  133. })
  134. },
  135. //点击新增打开的窗口 取消时触发
  136. // beforeClose(){
  137. // },
  138. //点击新增或修改时
  139. beforeOpen(done, type){
  140. if (["add"].includes(type)) {
  141. this.tableOption.column.forEach(e=>{
  142. if(e.prop=='typeId'){
  143. this.$set(this.tableOption.column,3,{...e,value:this.treeDeptId})
  144. }
  145. })
  146. }
  147. done();
  148. },
  149. searchChange(params, done) {
  150. this.getList(this.page, params);
  151. done();
  152. },
  153. sizeChange(val) {
  154. this.page.pageSize = val;
  155. this.getList();
  156. },
  157. currentChange(val) {
  158. this.page.currentPage = val;
  159. this.getList();
  160. },
  161. refreshChange() {
  162. this.getList(this.page,this.search);
  163. },
  164. rowSave(row, done, loading) {
  165. add(row).then(() => {
  166. this.page.currentPage = 1;
  167. this.getList(this.page);
  168. this.$message.success("保存成功");
  169. done()
  170. }, error => {
  171. window.console.log(error);
  172. loading();
  173. });
  174. },
  175. rowUpdate(row, index, done, loading) {
  176. row.createTime = '';
  177. update(row).then(() => {
  178. this.getList(this.page);
  179. this.$message({
  180. type: "success",
  181. message: "操作成功!"
  182. });
  183. // 数据回调进行刷新
  184. done(row);
  185. }, error => {
  186. window.console.log(error);
  187. loading();
  188. });
  189. },
  190. rowDel(row, index,done) {
  191. this.$confirm("确定将选择数据删除?", {
  192. confirmButtonText: "确定",
  193. cancelButtonText: "取消",
  194. type: "warning"
  195. }).then(() => {
  196. return remove(row.id);
  197. }).then(() => {
  198. this.$message({
  199. type: "success",
  200. message: "操作成功!"
  201. });
  202. this.getList(this.page);
  203. done(row);
  204. });
  205. },
  206. cellDblclick(row, column, cell, event) {
  207. this.$refs.crud.rowEdit(row);
  208. },
  209. saveColumn(row, column) {
  210. console.log(row, column);
  211. },
  212. //展开主页左边类型
  213. nodeClick(data) {
  214. this.treeDeptName = data.cname;
  215. this.treeDeptId = data.id;
  216. this.page.currentPage = 1;
  217. this.getList(this.page);
  218. },
  219. //列表内展开树节点
  220. treeLoad(tree, treeNode, resolve) {
  221. const parentId = tree.id;
  222. getList({parentId:parentId}).then(res => {
  223. resolve(res.data.data.records);
  224. });
  225. },
  226. }
  227. };
  228. </script>
  229. <style scoped lang="scss">
  230. </style>