goods-service.php 8.5 KB

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