service.php 8.4 KB

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