project.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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/projectOption.json";
  59. import {getServiceProjectList, remove, submit,detail, getServiceTypeTree,getDeptTree,getDicData} from "@/api/workManagement/serviceProject";
  60. import reportDialog from "@/components/report-dialog/main";
  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. getServiceTypeTree(parentId).then(res => {
  84. resolve(
  85. res.data.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: "title",
  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 - 350 ;
  113. //查询服务类别字典项
  114. getDeptTree().then(res => {
  115. this.findObject(this.tableOption.column, "goodsTypeId").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. getServiceProjectList(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=='goodsTypeId'){
  143. this.$set(this.tableOption.column,2,{...e,value:this.treeDeptId})
  144. }
  145. })
  146. }
  147. if (["edit"].includes(type)) {
  148. detail(this.form.id).then(res => {
  149. this.form = res.data.data;
  150. });
  151. }
  152. done();
  153. },
  154. searchChange(params, done) {
  155. this.getList(this.page, params);
  156. done();
  157. },
  158. sizeChange(val) {
  159. this.page.pageSize = val;
  160. this.getList();
  161. },
  162. currentChange(val) {
  163. this.page.currentPage = val;
  164. this.getList();
  165. },
  166. refreshChange() {
  167. this.getList(this.page,this.search);
  168. },
  169. rowSave(row, done, loading) {
  170. row.sort = 1;
  171. row.goodsTypeId = Array.isArray(row.goodsTypeId) ? row.goodsTypeId.join(',') : row.goodsTypeId;
  172. submit(row).then(() => {
  173. this.page.currentPage = 1;
  174. this.getList(this.page);
  175. this.$message.success("保存成功");
  176. done()
  177. }, error => {
  178. window.console.log(error);
  179. loading();
  180. });
  181. },
  182. rowUpdate(row, index, done, loading) {
  183. submit(row).then(() => {
  184. this.getList(this.page);
  185. this.$message({
  186. type: "success",
  187. message: "操作成功!"
  188. });
  189. // 数据回调进行刷新
  190. done(row);
  191. }, error => {
  192. window.console.log(error);
  193. loading();
  194. });
  195. },
  196. rowDel(row, index,done) {
  197. this.$confirm("确定将选择数据删除?", {
  198. confirmButtonText: "确定",
  199. cancelButtonText: "取消",
  200. type: "warning"
  201. }).then(() => {
  202. return remove(row.id);
  203. }).then(() => {
  204. this.$message({
  205. type: "success",
  206. message: "操作成功!"
  207. });
  208. this.getList(this.page);
  209. done(row);
  210. });
  211. },
  212. cellDblclick(row, column, cell, event) {
  213. this.$refs.crud.rowEdit(row);
  214. },
  215. saveColumn(row, column) {
  216. console.log(row, column);
  217. },
  218. //展开主页左边类型
  219. nodeClick(data) {
  220. this.treeDeptName = data.cname;
  221. this.treeDeptId = data.id;
  222. this.page.currentPage = 1;
  223. this.getList(this.page);
  224. },
  225. //列表内展开树节点
  226. treeLoad(tree, treeNode, resolve) {
  227. const parentId = tree.id;
  228. getList({parentId:parentId}).then(res => {
  229. resolve(res.data.data.records);
  230. });
  231. },
  232. }
  233. };
  234. </script>
  235. <style scoped lang="scss">
  236. </style>