list.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. ?>
  3. <div id="app" v-cloak>
  4. <el-card shadow="never" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  5. <div slot="header">
  6. <span>列表</span>
  7. <el-button style="margin: -5px 0" type="primary" size="small" @click="$navigate({r:'mall/postage-rules/index'})">添加
  8. </el-button>
  9. </div>
  10. <div class="table-body">
  11. <el-form :inline="true" :model="search_data" size="small" class="demo-form-inline">
  12. <el-form-item>
  13. <el-input placeholder="请输入名称" v-model="search_data.title"></el-input>
  14. </el-form-item>
  15. <el-form-item>
  16. <el-input placeholder="请输入ID精准搜索" v-model="search_data.id"></el-input>
  17. </el-form-item>
  18. <el-form-item>
  19. <el-date-picker style="margin-top: 1px;" @change="changeTime" v-model="datetime" type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']"></el-date-picker>
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button size="small" type="primary" @click="search">搜索</el-button>
  23. <el-button size="small" type="danger" @click="clearSearch" v-if="show_clear_search_btn">清除条件</el-button>
  24. </el-form-item>
  25. </el-form>
  26. <el-table v-loading="listLoading" :data="list" stripe style="width: 100%">
  27. <el-table-column label="ID" prop="id" align="center"></el-table-column>
  28. <el-table-column label="标题" prop="title" align="center">
  29. <template slot-scope="scope">
  30. <div size="small">{{scope.row.title}}</div>
  31. </template>
  32. </el-table-column>
  33. <el-table-column label="操作" min-width="300" align="center">
  34. <template slot-scope="scope">
  35. <el-button type="text" @click="handle('edit',scope.row)">编辑</el-button>
  36. <el-button type="text" @click="handle('delete',scope.row)">删除</el-button>
  37. </template>
  38. </el-table-column>
  39. </el-table>
  40. <div style="text-align: right;margin: 20px 0;">
  41. <el-pagination @current-change="pagination" background layout="prev, pager, next" :page-count="pageCount"></el-pagination>
  42. </div>
  43. </div>
  44. </el-card>
  45. </div>
  46. <script>
  47. const app = new Vue({
  48. el: '#app',
  49. data() {
  50. return {
  51. list: [{
  52. title: "测试标题"
  53. }],
  54. listLoading: false,
  55. page: 1,
  56. pageCount: 0,
  57. search_data: { // 筛选条件
  58. start: null,
  59. end: null,
  60. id: null,
  61. name: null,
  62. },
  63. datetime:[]
  64. };
  65. },
  66. mounted: function() {
  67. this.getList();
  68. },
  69. computed: {
  70. show_clear_search_btn: function() {
  71. return !isEmpty(this.search_data.start) || !isEmpty(this.search_data.end)
  72. || !isEmpty(this.search_data.id) || !isEmpty(this.search_data.name);
  73. }
  74. },
  75. methods: {
  76. changeTime(e) {
  77. // console.log(e)
  78. this.search_data.start = e[0]
  79. this.search_data.end = e[1]
  80. },
  81. sortChange(row) {
  82. if (row.prop) {
  83. this.search_data.sort_field = row.prop;
  84. this.search_data.sort_type = row.order == "descending" ? 'desc' : 'asc';
  85. } else {
  86. this.search_data.sort_prop = null;
  87. this.search_data.sort_type = null;
  88. }
  89. this.getList(this.search_data);
  90. },
  91. search() {
  92. this.getList(this.search_data);
  93. },
  94. clearSearch() {
  95. this.search_data.start = null;
  96. this.search_data.end = null;
  97. this.search_data.id = null;
  98. this.search_data.name = null;
  99. this.datetime = [];
  100. this.getList();
  101. },
  102. handle(type, data = null) {
  103. let id = data ? parseInt(data.id) : '';
  104. switch (type) {
  105. case 'edit':
  106. let params = {
  107. //编辑页面路径
  108. r: ''
  109. };
  110. if (id) params = Object.assign(params, {id: id});
  111. navigateTo(params);
  112. break;
  113. }
  114. },
  115. pagination(currentPage) {
  116. let self = this;
  117. self.page = currentPage;
  118. self.getList();
  119. },
  120. // 获取广告列表
  121. getList() {
  122. let self = this;
  123. if (self.listLoading == false) {
  124. self.listLoading = true;
  125. request({
  126. params: {
  127. r: '',
  128. page: self.page,
  129. },
  130. method: 'get',
  131. }).then(e => {
  132. self.listLoading = false;
  133. if (e.data.code == 0) {
  134. self.list = e.data.data.list;
  135. self.pageCount = e.data.data.page_count;
  136. } else {
  137. self.$message.error(e.data.msg);
  138. }
  139. }).catch(e => {
  140. self.$message.error(e.data.msg);
  141. self.listLoading = false;
  142. });
  143. }
  144. },
  145. }
  146. });
  147. </script>