index.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <style>
  2. .table-body {
  3. padding: 20px;
  4. background-color: #fff;
  5. }
  6. .input-item {
  7. display: inline-block;
  8. width: 250px;
  9. margin: 0 0 20px;
  10. }
  11. .input-item .el-input__inner {
  12. border-right: 0;
  13. }
  14. .input-item .el-input__inner:hover {
  15. border: 1px solid #dcdfe6;
  16. border-right: 0;
  17. outline: 0;
  18. }
  19. .input-item .el-input__inner:focus {
  20. border: 1px solid #dcdfe6;
  21. border-right: 0;
  22. outline: 0;
  23. }
  24. .input-item .el-input-group__append {
  25. background-color: #fff;
  26. border-left: 0;
  27. width: 10%;
  28. padding: 0;
  29. }
  30. .input-item .el-input-group__append .el-button {
  31. padding: 0;
  32. }
  33. .input-item .el-input-group__append .el-button {
  34. margin: 0;
  35. }
  36. .table-body .el-button {
  37. padding: 0 !important;
  38. border: 0;
  39. margin: 0 5px;
  40. }
  41. .form-body {
  42. background-color: #fff;
  43. margin-bottom: 20px;
  44. }
  45. .el-tabs__header {
  46. background-color: #fff;
  47. }
  48. .el-tabs__item {
  49. width: 100px;
  50. text-align: center;
  51. }
  52. .el-table th>.cell {
  53. color: #333;
  54. font-weight: bold;
  55. font-size: 14px;
  56. }
  57. .el-table__footer-wrapper,
  58. .el-table__header-wrapper {
  59. border-bottom: 1.4px solid #D6D6D6;
  60. }
  61. </style>
  62. <div id="app" v-cloak>
  63. <el-card shadow="never" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  64. <div slot="header">
  65. <div>
  66. <span>分类列表</span>
  67. <div style="float: right">
  68. <el-button type="primary" size="small" style="padding: 9px 15px !important;" @click="storage">创建分类
  69. </el-button>
  70. </div>
  71. </div>
  72. </div>
  73. <div class="table-body">
  74. <!-- <template>
  75. <el-tabs v-model="activeName" @tab-click="handleClick">
  76. <el-tab-pane label="轮播图" name="carousel">轮播图</el-tab-pane>
  77. <el-tab-pane label="分类栏" name="category">分类栏</el-tab-pane>
  78. </el-tabs>
  79. </template>
  80. <div class="input-item">
  81. <el-input @keyup.enter.native="search" size="small"
  82. placeholder="请输入广告名称"
  83. v-model="keyword"
  84. clearable
  85. @clear="search">
  86. <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
  87. </el-input>
  88. </div>
  89. -->
  90. <el-table v-loading="listLoading" :data="list" stripe style="width: 100%">
  91. <el-table-column label="ID" prop="id" min-width="80" align="center"></el-table-column>
  92. <el-table-column label="序号" prop="sort" min-width="80" align="center">
  93. <template slot-scope="scope">
  94. <div size="small">{{scope.row.sort}}</div>
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="名称" prop="title" min-width="80" align="center">
  98. <template slot-scope="scope">
  99. <div size="small">{{scope.row.title}}</div>
  100. </template>
  101. </el-table-column>
  102. <el-table-column label="图片" prop="pic_path" min-width="80" align="center">
  103. <template slot-scope="scope">
  104. <div size="small" align="center">
  105. <com-image width='50px' height='50px' :src=scope.row.pic_path></com-image>
  106. </div>
  107. </template>
  108. </el-table-column>
  109. <el-table-column label="是否启用" prop="content" min-width="100" align="center">
  110. <template slot-scope="scope">
  111. <el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0" active-text="启用" inactive-text="不启用" @change="isUse(scope.row.status, scope.row.id)"> </el-switch>
  112. </template>
  113. </el-table-column>
  114. <el-table-column label="创建时间" prop="created_at" min-width="100" align="center">
  115. <template slot-scope="scope">
  116. <div size="small">{{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}</div>
  117. </template>
  118. </el-table-column>
  119. <el-table-column label="操作" min-width="100" align="center">
  120. <template slot-scope="scope">
  121. <el-button circle type="text" size="mini" @click="storage(scope.row.id)">编辑</el-button>
  122. <el-button circle type="text" size="mini" @click="categoryDelete(scope.row.id, scope.$index)">删除</el-button>
  123. </template>
  124. </el-table-column>
  125. </el-table>
  126. <div style="text-align: right;margin: 20px 0;">
  127. <el-pagination @current-change="pagination" background layout="prev, pager, next" :page-count="pageCount"></el-pagination>
  128. </div>
  129. </div>
  130. </el-card>
  131. </div>
  132. <script>
  133. const app = new Vue({
  134. el: '#app',
  135. data() {
  136. return {
  137. activeName: 'category',
  138. status: 0,
  139. list: [],
  140. keyword: '',
  141. listLoading: false,
  142. page: 1,
  143. pageCount: 0,
  144. form: {
  145. sort: null,
  146. title: '',
  147. created_at: null,
  148. }
  149. };
  150. },
  151. methods: {
  152. handleClick(tab, event) {
  153. console.log(tab.name, 111111111111);
  154. if (tab.name === 'carousel') {
  155. let request_url = {
  156. r: 'lucky-group/banner/index'
  157. };
  158. } else if (tab.name === 'category') {
  159. let request_url = {
  160. r: 'lucky-group/category/index'
  161. };
  162. }
  163. navigateTo(this.path);
  164. },
  165. search() {
  166. this.page = 1;
  167. this.getList();
  168. },
  169. pagination(currentPage) {
  170. let self = this;
  171. self.page = currentPage;
  172. self.getList();
  173. },
  174. // 获取广告列表
  175. getList() {
  176. let self = this;
  177. self.listLoading = true;
  178. request({
  179. params: {
  180. r: 'lucky-group/group-category/index',
  181. page: self.page,
  182. keyword: this.keyword
  183. },
  184. method: 'get',
  185. }).then(e => {
  186. self.listLoading = false;
  187. self.list = e.data.data.list;
  188. self.pageCount = e.data.data.page_count;
  189. }).catch(e => {
  190. console.log(e);
  191. });
  192. },
  193. // 新建 or 编辑
  194. storage(id = null) {
  195. if (!id) {
  196. navigateTo({
  197. r: 'lucky-group/group-category/storage',
  198. });
  199. } else {
  200. navigateTo({
  201. r: 'lucky-group/group-category/storage',
  202. id: id,
  203. });
  204. }
  205. },
  206. // 屏蔽状态切换
  207. isUse(event, id) {
  208. let self = this;
  209. self.listLoading = true;
  210. request({
  211. params: {
  212. r: 'lucky-group/group-category/switch-status'
  213. },
  214. method: 'post',
  215. data: {
  216. id: id,
  217. status: event
  218. }
  219. }).then(e => {
  220. self.listLoading = false;
  221. if (e.data.code === 0) {
  222. self.$message.success(e.data.msg);
  223. } else {
  224. self.$message.error(e.data.msg);
  225. }
  226. }).catch(e => {
  227. console.log(e);
  228. });
  229. },
  230. categoryDelete(id, index) {
  231. let self = this;
  232. self.$confirm('是否删除广告?', '提示', {
  233. confirmButtonText: '确定',
  234. cancelButtonText: '取消',
  235. type: 'warning'
  236. }).then(() => {
  237. self.listLoading = true;
  238. // console.log(id,'1111')
  239. request({
  240. params: {
  241. r: 'lucky-group/group-category/delete',
  242. },
  243. method: 'post',
  244. data: {
  245. id: id,
  246. }
  247. }).then(e => {
  248. self.listLoading = false;
  249. if (e.data.code === 0) {
  250. self.$message.success(e.data.msg);
  251. self.list.splice(index, 1);
  252. } else {
  253. self.$message.error(e.data.msg);
  254. }
  255. }).catch(e => {
  256. console.log(e);
  257. });
  258. }).catch(() => {
  259. self.$message.info('已取消删除')
  260. });
  261. }
  262. },
  263. mounted: function() {
  264. this.getList();
  265. }
  266. });
  267. </script>