RulesManager.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div>
  3. <crumbs title="规则维护">
  4. <el-form :inline="true">
  5. <el-form-item label="id:">
  6. <el-input size="mini" v-model="filter.id" placeholder="请输入id" clearable></el-input>
  7. </el-form-item>
  8. <el-form-item label="规则名:">
  9. <el-input size="mini" v-model="filter.pubName" placeholder="请输入规则名" clearable></el-input>
  10. </el-form-item>
  11. <el-form-item>
  12. <el-button size="mini" @click="filterDatas">确认</el-button>
  13. <el-button size="mini" type="warning" @click="addRule">添加规则</el-button>
  14. </el-form-item>
  15. </el-form>
  16. </crumbs>
  17. <div class="contents">
  18. <el-table
  19. :data="list"
  20. border
  21. style="width: 100%">
  22. <el-table-column
  23. :resizable = "false"
  24. prop="id"
  25. label="id">
  26. </el-table-column>
  27. <el-table-column
  28. :resizable = "false"
  29. prop="pubName"
  30. label="规则名">
  31. </el-table-column>
  32. <el-table-column
  33. :resizable = "false"
  34. prop="minOperator"
  35. label="最小值操作符"
  36. width="180">
  37. </el-table-column>
  38. <el-table-column
  39. :resizable = "false"
  40. prop="minValue"
  41. label="最小值">
  42. </el-table-column>
  43. <el-table-column
  44. :resizable = "false"
  45. prop="minUnit"
  46. label="最小值单位">
  47. </el-table-column>
  48. <el-table-column
  49. :resizable = "false"
  50. prop="maxOperator"
  51. label="最大值操作符"
  52. width="80">
  53. </el-table-column>
  54. <el-table-column
  55. :resizable = "false"
  56. prop="maxValue"
  57. label="最大值">
  58. </el-table-column>
  59. <el-table-column
  60. :resizable = "false"
  61. prop="maxUnit"
  62. label="最大值单位">
  63. </el-table-column>
  64. <el-table-column
  65. :resizable = "false"
  66. prop="eqOperator"
  67. label="等于操作符">
  68. </el-table-column>
  69. <el-table-column
  70. :resizable = "false"
  71. prop="eqValue"
  72. label="等于值">
  73. </el-table-column>
  74. <el-table-column
  75. :resizable = "false"
  76. prop="eqUnit"
  77. label="等于值单位">
  78. </el-table-column>
  79. <el-table-column
  80. :resizable = "false"
  81. prop="remind"
  82. label="备注">
  83. </el-table-column>
  84. <el-table-column
  85. :resizable = "false"
  86. prop="suffixInfo"
  87. label="文本后缀">
  88. </el-table-column>
  89. <el-table-column
  90. :resizable = "false"
  91. prop="operate"
  92. label="操作"
  93. width="140">
  94. <template slot-scope="scope">
  95. <el-button @click="modifyRule(scope.row)" type="text" size="small">修改</el-button>
  96. <span style="margin:0 3px;">|</span>
  97. <el-button @click="showDelDialog(scope.row.id)" class="delete" type="text" size="small">删除</el-button>
  98. </template>
  99. </el-table-column>
  100. </el-table>
  101. <el-pagination :current-page.sync="currentPage"
  102. @current-change="currentChange"
  103. background
  104. :page-size="pageSize"
  105. :page-sizes="pageSizeArr"
  106. @size-change="handleSizeChange"
  107. :layout="pageLayout"
  108. :total="total">
  109. </el-pagination>
  110. </div>
  111. </div>
  112. </template>
  113. <script>
  114. import api from '@api/rulesManage.js';
  115. import config from '@api/config.js';
  116. import utils from '@api/utils.js';
  117. export default {
  118. name: 'RulesManager',
  119. data: function() {
  120. return {
  121. list: [],
  122. searched:false,
  123. filter: {
  124. pubName:'', //规则名
  125. id:''
  126. },
  127. currentPage: 1,
  128. pageSize: config.pageSize,
  129. pageSizeArr:config.pageSizeArr,
  130. pageLayout:config.pageLayout,
  131. total: 0,
  132. }
  133. },
  134. created() {
  135. this.getDataList();
  136. },
  137. watch:{
  138. 'filter':{
  139. handler:function(){
  140. this.searched = false;
  141. },
  142. deep:true
  143. }
  144. },
  145. beforeRouteEnter(to, from, next){
  146. next(vm => {
  147. //const pm = to.param;
  148. Object.assign(vm,to.params);
  149. vm.inCurrentPage=to.params.currentPage;
  150. })
  151. },
  152. methods: {
  153. handleSizeChange(val){
  154. this.pageSize = val;
  155. this.currentPage = utils.getCurrentPage(this.currentPage, this.total, this.pageSize);
  156. this.getDataList();
  157. },
  158. getDataList(isTurnPage) {
  159. const param = this.getFilterItems(isTurnPage);
  160. this.searched = true;
  161. const loading = this.$loading({
  162. lock: true,
  163. text: 'Loading',
  164. spinner: 'el-icon-loading',
  165. background: 'rgba(0, 0, 0, 0.7)'
  166. });
  167. api.getRulesList(param).then((res) => {
  168. loading.close()
  169. const list = [...res.data.data.records];
  170. this.list = list;
  171. this.total = res.data.data.total;
  172. if(this.inCurrentPage!==undefined){
  173. this.currentPage=this.inCurrentPage;
  174. this.inCurrentPage = undefined;
  175. }
  176. })
  177. },
  178. filterDatas() {
  179. this.currentPage = 1;
  180. this.getDataList();
  181. },
  182. addRule() {
  183. const pam = this.searched?{currentPage:this.currentPage,
  184. pageSize:this.pageSize,
  185. filter:this.filter}:{currentPage:this.currentPage,
  186. pageSize:this.pageSize};
  187. this.$router.push({name:'AddRule',
  188. params:pam})
  189. },
  190. modifyRule(row) {
  191. api.ruleDetail({id:row.id}).then((res)=>{
  192. const {code,data,msg} = res.data;
  193. if(code=='0'){
  194. const item = Object.assign({},row,data);
  195. const pam = this.searched?{currentPage:this.currentPage,
  196. pageSize:this.pageSize,
  197. filter:this.filter}:{currentPage:this.currentPage,
  198. pageSize:this.pageSize};
  199. this.$router.push({name:'AddRule',params:Object.assign(pam,{isEdit:true,data:item})});
  200. }else{
  201. this.$message({
  202. message: msg,
  203. type: 'warning'
  204. });
  205. }
  206. });
  207. //this.$router.push({name:'AddIndeptLabel',params:{isEdit:true,data:row}});
  208. },
  209. currentChange(next) {
  210. this.currentPage = next;
  211. this.getDataList(true);
  212. // if (this.cacheData[next]) { //如果已请求过该页数据,则使用缓存不重复请求
  213. // this.list = this.cacheData[next];
  214. // } else {
  215. // this.getDataList();
  216. // }
  217. },
  218. clearFilter(){
  219. this.filter = {
  220. pubName:'', //规则名
  221. id:''
  222. }
  223. },
  224. getFilterItems(isTurnPage) {
  225. //翻页时筛选条件没点确定则清空
  226. if(isTurnPage&&!this.searched){
  227. this.clearFilter();
  228. };
  229. const param = {
  230. current: this.inCurrentPage||this.currentPage,
  231. size: this.pageSize,
  232. pubName:this.filter.pubName.trim(),
  233. id:this.filter.id.trim(),
  234. };
  235. return param;
  236. },
  237. indexMethod(index) {
  238. return ((this.currentPage - 1) * this.pageSize) + index + 1;
  239. },
  240. getTagType(val) {
  241. return val
  242. },
  243. warning(msg,type){
  244. this.$message({
  245. showClose: true,
  246. message:msg,
  247. type:type||'warning'
  248. })
  249. },
  250. showConfirmDialog(msg,resolve){
  251. this.$alert(msg, '提示', {
  252. confirmButtonText: '确定',
  253. type: 'warning'
  254. }).then(() => {
  255. resolve();
  256. }).catch(() => {});
  257. },
  258. showDelDialog(id){
  259. const param = {
  260. "id": id
  261. };
  262. this.showConfirmDialog('是否删除该规则?',()=>{
  263. api.deleteRule(param).then((res)=>{
  264. if(res.data.code=='0'){
  265. if(!this.searched){
  266. //未点确认时清空搜索条件
  267. this.clearFilter();
  268. }
  269. if(this.list.length==1){
  270. //当前在最后一页且只有一条数据时,删除后跳到前一页
  271. this.currentPage = this.currentPage===1?1:this.currentPage-1;
  272. }
  273. this.getDataList();
  274. this.warning(res.data.msg || '操作成功','success');
  275. }else{
  276. this.warning(res.data.msg);
  277. }
  278. }).catch((error)=>{
  279. this.warning(error);
  280. })
  281. });
  282. }
  283. }
  284. }
  285. </script>
  286. <style lang="less">
  287. @import "../../less/admin.less";
  288. .delete{
  289. color: red
  290. }
  291. .delete:hover {
  292. color: red;
  293. }
  294. .el-select .el-input .el-icon-arrow-up{
  295. display: inline-block!important;
  296. }
  297. .el-select .el-input .el-icon-circle-close{
  298. float:left;
  299. }
  300. </style>