project.vue 6.1 KB

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