service.php 8.3 KB

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