label.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <style>
  2. @media screen and (max-width: 1500px) {
  3. #app {
  4. min-width: 1270px;
  5. }
  6. }
  7. </style>
  8. <div id="app" v-cloak>
  9. <el-card shadow="never" style="border:0" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  10. <div slot="header">
  11. <div>
  12. <span>标签列表</span>
  13. <div style="float: right;margin-top: -5px">
  14. <el-button type="primary" @click="edit" size="small">添加标签</el-button>
  15. </div>
  16. </div>
  17. </div>
  18. <div class="table-body">
  19. <el-form :inline="true" size="small" class="demo-form-inline">
  20. <el-form-item>
  21. <el-input @keyup.enter.native="search" size="small" placeholder="请输入搜索内容" v-model="keyword" clearable @clear="getList">
  22. <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
  23. </el-input>
  24. </el-form-item>
  25. </el-form>
  26. <el-table v-loading="listLoading" :data="list" stripe style="width: 100%">
  27. <el-table-column prop="id" label="ID" width="100">
  28. </el-table-column>
  29. <el-table-column label="标签名称" width="350px">
  30. <template slot-scope="scope">
  31. <com-ellipsis :line="1">{{scope.row.title}}</com-ellipsis>
  32. </template>
  33. </el-table-column>
  34. <el-table-column label="副标题">
  35. <template slot-scope="scope">
  36. <com-ellipsis :line="1">{{scope.row.sub_title}}</com-ellipsis>
  37. </template>
  38. </el-table-column>
  39. <el-table-column label="是否默认" width="100">
  40. <template slot-scope="scope">
  41. <el-switch @change="operate('default',scope.row)" v-model="scope.row.is_default" :active-value="1" :inactive-value="0" active-color="#3399ff">
  42. </el-switch>
  43. </template>
  44. </el-table-column>
  45. <el-table-column prop="sort" label="排序" width="150">
  46. <template slot-scope="scope">
  47. <div v-if="id != scope.row.id">
  48. <el-tooltip class="item" effect="dark" content="排序" placement="top">
  49. <span>{{scope.row.sort}}</span>
  50. </el-tooltip>
  51. <el-button class="edit-sort" type="text" @click="editSort(scope.row)">
  52. <img src="resources/img/mall/order/edit.png" alt="">
  53. </el-button>
  54. </div>
  55. <div style="display: flex;align-items: center" v-else>
  56. <el-input style="min-width: 70px" type="number" size="mini" class="change" v-model="sort" autocomplete="off"></el-input>
  57. <el-button class="change-quit" type="text" style="color: #F56C6C;padding: 0 5px" icon="el-icon-error" circle @click="quit()"></el-button>
  58. <el-button class="change-success" type="text" style="margin-left: 0;color: #67C23A;padding: 0 5px" icon="el-icon-success" circle @click="operate('sort',scope.row)">
  59. </el-button>
  60. </div>
  61. </template>
  62. </el-table-column>
  63. <el-table-column prop="created_at" width="220" label="添加日期">
  64. <template slot-scope="scope">
  65. <div>{{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}</div>
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="操作" width="220">
  69. <template slot-scope="scope">
  70. <el-button type="text" @click="edit(scope.row.id)">编辑</el-button>
  71. <el-button type="text" @click="operate('destroy',scope.row)">删除</el-button>
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. <div style="text-align: right;margin: 20px 0;">
  76. <el-pagination @current-change="pagination" background layout="prev, pager, next" :page-count="pageCount"></el-pagination>
  77. </div>
  78. </div>
  79. </el-card>
  80. </div>
  81. <script>
  82. const app = new Vue({
  83. el: '#app',
  84. data() {
  85. return {
  86. list: [],
  87. listLoading: false,
  88. page: 1,
  89. keyword: '',
  90. pageCount: 0,
  91. sort: 0,
  92. id: null,
  93. };
  94. },
  95. mounted: function() {
  96. this.getList();
  97. },
  98. methods: {
  99. search(){
  100. this.page = 1;
  101. this.getList();
  102. },
  103. editSort(row) {
  104. this.id = row.id;
  105. this.sort = row.sort;
  106. },
  107. quit() {
  108. this.id = null;
  109. },
  110. pagination(currentPage) {
  111. let self = this;
  112. self.page = currentPage;
  113. self.getList();
  114. },
  115. getList() {
  116. let self = this;
  117. self.listLoading = true;
  118. let keyword = this.keyword;
  119. let params = {
  120. r: 'mall/goods/label',
  121. page: self.page
  122. }
  123. if (keyword) params.keyword = keyword;
  124. request({
  125. params: params,
  126. method: 'get',
  127. }).then(e => {
  128. self.listLoading = false;
  129. if (e.data.code == 0) {
  130. self.list = e.data.data.list;
  131. self.pageCount = e.data.data.page_count;
  132. } else {
  133. self.$message.error(e.data.msg);
  134. }
  135. }).catch(e => {
  136. self.$message.error(e.data.msg);
  137. self.listLoading = false;
  138. });
  139. },
  140. // 跳转编辑页
  141. edit(id) {
  142. id = parseInt(id);
  143. let params = {
  144. r: 'mall/goods/label-edit'
  145. };
  146. if (id) params = Object.assign(params, {
  147. id: id
  148. });
  149. navigateTo(params);
  150. },
  151. operate(type, data = null) {
  152. let param = { id: data.id, type: type };
  153. switch (type) {
  154. case 'sort':
  155. param.sort = this.sort;
  156. this.send(param);
  157. break;
  158. case 'destroy':
  159. this.$confirm('删除该条数据后不可以恢复, 是否继续?', '警告', {
  160. type: 'warning'
  161. }).then(() => {
  162. this.send(param)
  163. })
  164. break;
  165. case 'default':
  166. param = {
  167. id: data.id,
  168. is_default: data.is_default,
  169. type: type
  170. };
  171. this.send(param);
  172. break;
  173. }
  174. },
  175. send(params) {
  176. let self = this;
  177. request({
  178. params: {
  179. r: 'mall/goods/label',
  180. },
  181. method: 'post',
  182. data: params
  183. }).then(e => {
  184. if (e.data.code == 0) {
  185. self.$message.success(e.data.msg);
  186. self.getList();
  187. } else {
  188. self.$message.error(e.data.msg);
  189. }
  190. }).catch(e => {
  191. console.log(e);
  192. });
  193. }
  194. }
  195. });
  196. </script>