index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <div id="meteringManagement">
  3. <div class="mian">
  4. <div class="tree_box">
  5. <div class="control">
  6. <el-button icon="el-icon-plus" type="primary" @click="addType('新增')"
  7. v-if="$hasPermission('main:categorymeasure:save')"
  8. >新增</el-button
  9. >
  10. <el-button
  11. v-if="currentObj.id&&$hasPermission('main:categorymeasure:update')"
  12. icon="el-icon-edit"
  13. type="success"
  14. @click="addType('修改')"
  15. >修改</el-button
  16. >
  17. <!-- <el-button icon="el-icon-delete" type="danger" @click="deleted()"
  18. >删除</el-button
  19. > -->
  20. </div>
  21. <el-tree
  22. class="tree"
  23. ref="tree"
  24. highlight-current
  25. node-key="id"
  26. :expand-on-click-node="false"
  27. :default-expand-all="true"
  28. :data="typeList"
  29. :props="defaultProps"
  30. @node-click="handleNodeClick"
  31. ></el-tree>
  32. </div>
  33. <div class="list">
  34. <div class="search_bar">
  35. <el-input
  36. placeholder="请输入编码或名称关键词"
  37. v-model="name"
  38. clearable
  39. class="input-with-select"
  40. >
  41. <el-button slot="append" icon="el-icon-search" @click="search"
  42. >搜索</el-button
  43. >
  44. </el-input>
  45. </div>
  46. <div class="table_box">
  47. <ele-pro-table
  48. ref="table"
  49. :columns="columns"
  50. :initLoad="false"
  51. :needPage="false"
  52. :datasource="datasource"
  53. >
  54. <!-- 表头工具栏 -->
  55. <template v-slot:toolbar>
  56. <el-button
  57. v-if="currentObj.id&&$hasPermission('main:categorymeasure:save')"
  58. size="small"
  59. type="primary"
  60. icon="el-icon-plus"
  61. class="ele-btn-icon"
  62. @click="openEdit('新增')"
  63. >
  64. 新增
  65. </el-button>
  66. </template>
  67. <template v-slot:action="{ row }">
  68. <el-link
  69. type="primary"
  70. :underline="false"
  71. icon="el-icon-edit"
  72. @click="openEdit('修改', row)"
  73. v-if="$hasPermission('main:categorymeasure:update')"
  74. >
  75. 修改
  76. </el-link>
  77. </template>
  78. </ele-pro-table>
  79. </div>
  80. </div>
  81. </div>
  82. <baseDialog ref="baseDialogRef" @reload="getPages"></baseDialog>
  83. <typeDialog ref="typeDialogRef" @reload="getTypeList"></typeDialog>
  84. </div>
  85. </template>
  86. <script>
  87. import { getCategorymeasureList } from '@/api/ruleManagement/meteringManagement.js';
  88. import baseDialog from './baseDialog.vue';
  89. import typeDialog from './typeDialog.vue';
  90. export default {
  91. components: { baseDialog, typeDialog },
  92. data() {
  93. return {
  94. currentObj: {
  95. id: '',
  96. name: ''
  97. },
  98. // 表格列配置
  99. columns: [
  100. {
  101. columnKey: 'index',
  102. type: 'index',
  103. label: '序号',
  104. width: 50,
  105. align: 'center',
  106. showOverflowTooltip: true
  107. },
  108. {
  109. prop: 'code',
  110. label: '编码',
  111. showOverflowTooltip: true
  112. },
  113. {
  114. prop: 'name',
  115. label: '名称',
  116. showOverflowTooltip: true
  117. },
  118. {
  119. prop: 'parentName',
  120. label: '分组',
  121. showOverflowTooltip: true
  122. },
  123. {
  124. columnKey: 'action',
  125. label: '操作',
  126. width: 200,
  127. align: 'center',
  128. resizable: false,
  129. slot: 'action',
  130. showOverflowTooltip: true
  131. }
  132. ],
  133. name: '',
  134. tableData: [
  135. {
  136. name: '包',
  137. code: 'bao'
  138. },
  139. {
  140. name: '包',
  141. code: 'bao'
  142. }
  143. ],
  144. typeList: [
  145. {
  146. label: '长度(length)',
  147. children: []
  148. },
  149. {
  150. label: '数量(quantity)',
  151. children: []
  152. },
  153. {
  154. label: '重量(weight)',
  155. children: []
  156. }
  157. ],
  158. defaultProps: {
  159. children: 'children',
  160. label: 'name'
  161. }
  162. };
  163. },
  164. async mounted() {
  165. this.getTypeList(); // 获取侧边栏分类列表
  166. },
  167. methods: {
  168. search() {
  169. this.getPages({
  170. name: this.name,
  171. parentId: this.currentObj.id ? this.currentObj.id : ''
  172. });
  173. },
  174. async getTypeList() {
  175. this.currentObj = {};
  176. this.typeList = await getCategorymeasureList({ parentId: 0 });
  177. this.getPages();
  178. },
  179. addType(type) {
  180. // if (!this.currentObj.id) {
  181. // return this.$message.warning('请选择分类');
  182. // }
  183. if (type == '新增') {
  184. this.$refs.typeDialogRef.open(type);
  185. } else {
  186. this.$refs.typeDialogRef.open(type, this.currentObj.id);
  187. }
  188. },
  189. deleted() {
  190. this.$confirm('是否确认删除?', '提示', {
  191. confirmButtonText: '确定',
  192. cancelButtonText: '取消',
  193. type: 'warning'
  194. })
  195. .then(() => {
  196. this.$message({
  197. type: 'success',
  198. message: '删除成功!'
  199. });
  200. })
  201. .catch(() => {});
  202. },
  203. getPages(where) {
  204. this.$refs.table.reload({ where });
  205. },
  206. datasource({ page, limit, where, order }) {
  207. console.log('where', where);
  208. return getCategorymeasureList({
  209. ...where
  210. });
  211. },
  212. handleNodeClick(data) {
  213. this.currentObj = data;
  214. this.getPages({ parentId: data.id });
  215. console.log(data);
  216. },
  217. openEdit(type, row) {
  218. if (type == '新增') {
  219. this.$refs.baseDialogRef.open(type, this.currentObj);
  220. } else {
  221. this.$refs.baseDialogRef.open(type, this.currentObj, row.id);
  222. }
  223. }
  224. }
  225. };
  226. </script>
  227. <style lang="scss" scoped>
  228. #meteringManagement {
  229. height: calc(100vh - 96px);
  230. width: 100%;
  231. padding: 10px;
  232. box-sizing: border-box;
  233. .mian {
  234. height: 100%;
  235. width: 100%;
  236. border-radius: 4px;
  237. display: flex;
  238. .tree_box {
  239. flex: 0 0 240px;
  240. background-color: #fff;
  241. margin-right: 10px;
  242. display: flex;
  243. flex-direction: column;
  244. border: 1px solid #ddd;
  245. .control {
  246. flex: 0 0 50px;
  247. padding: 10px;
  248. box-sizing: border-box;
  249. display: flex;
  250. align-items: center;
  251. background-color: #fafafa;
  252. border-bottom: 1px solid #ddd;
  253. }
  254. .tree {
  255. flex: 1 0 auto;
  256. height: 0;
  257. padding: 10px;
  258. box-sizing: border-box;
  259. overflow: auto;
  260. }
  261. }
  262. .list {
  263. flex: 1;
  264. padding: 10px;
  265. box-sizing: border-box;
  266. border: 1px solid #ddd;
  267. background-color: #fff;
  268. display: flex;
  269. flex-direction: column;
  270. .search_bar {
  271. height: 50px;
  272. box-sizing: border-box;
  273. display: flex;
  274. align-items: center;
  275. > div {
  276. width: 300px;
  277. }
  278. }
  279. .table_box {
  280. flex: 1 0 auto;
  281. height: 0;
  282. overflow: hidden;
  283. > div {
  284. height: 100%;
  285. display: flex;
  286. flex-direction: column;
  287. }
  288. }
  289. }
  290. }
  291. }
  292. </style>