cate-index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. .el-table th > .cell {
  42. color: #333;
  43. font-weight: bold;
  44. font-size: 14px;
  45. }
  46. .el-table__footer-wrapper, .el-table__header-wrapper {
  47. border-bottom: 1.4px solid #D6D6D6;
  48. }
  49. .el-button--primary2 {
  50. color: #FFF;
  51. background-color: #03C5FF;
  52. border-color: #03C5FF;
  53. }
  54. </style>
  55. <div id="app" v-cloak>
  56. <el-card shadow="never" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  57. <div slot="header">
  58. <div>
  59. <span>文章分类</span>
  60. </div>
  61. </template>
  62. </div>
  63. <div class="table-body">
  64. <el-button class="el-button--primary2" style="padding: 9px 15px!important; float: right;" type="primary"
  65. @click="addgsForm()" size="small">新增分类
  66. </el-button>
  67. <div class="input-item" style="float: left;">
  68. <el-input @keyup.enter.native="search" size="small"
  69. placeholder="搜索分类名称"
  70. v-model="keyword"
  71. clearable
  72. @clear="search">
  73. <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
  74. </el-input>
  75. </div>
  76. <el-table v-loading="listLoading" :data="list" stripe style="width: 100%">
  77. <el-table-column prop="id" label="ID" min-width="80" align="center"></el-table-column>
  78. <el-table-column
  79. label="分类"
  80. min-width="150"
  81. align="center">
  82. <template slot-scope="scope">
  83. <com-ellipsis :line="1">{{scope.row.name}}</com-ellipsis>
  84. </template>
  85. </el-table-column>
  86. <el-table-column label="启用状态" min-width="100" align="center">
  87. <template slot-scope="scope">
  88. <el-switch active-value="1" inactive-value="0" @change="handle('enable',scope.row)"
  89. v-model="scope.row.status + ''">
  90. </el-switch>
  91. </template>
  92. </el-table-column>
  93. <el-table-column prop="scope" width="180" label="排序">
  94. <template slot-scope="scope">
  95. <div v-if="id != scope.row.id">
  96. <el-tooltip class="item" effect="dark" content="排序" placement="top">
  97. <span>{{scope.row.sort}}</span>
  98. </el-tooltip>
  99. <el-button class="edit-sort" type="text" @click="editSort(scope.row)">
  100. <img src="resources/img/mall/order/edit.png" alt="">
  101. </el-button>
  102. </div>
  103. <div style="display: flex;align-items: center" v-else>
  104. <el-input style="min-width: 70px" type="number" @input="sortChange" size="mini" class="change" v-model="sort" autocomplete="off"></el-input>
  105. <el-button class="change-quit" type="text" style="color: #F56C6C;padding: 0 5px" icon="el-icon-error" circle @click="quit()"></el-button>
  106. <el-button class="change-success" type="text" style="margin-left: 0;color: #67C23A;padding: 0 5px" icon="el-icon-success" circle @click="handle('sort','')">
  107. </el-button>
  108. </div>
  109. </template>
  110. </el-table-column>
  111. <el-table-column prop="scope" width="180" label="创建时间">
  112. <template slot-scope="scope">
  113. {{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}
  114. </template>
  115. </el-table-column>
  116. <el-table-column prop="scope" width="180" label="修改时间">
  117. <template slot-scope="scope">
  118. {{scope.row.updated_at|dateTimeFormat('Y-m-d H:i:s')}}
  119. </template>
  120. </el-table-column>
  121. <el-table-column
  122. label="操作"
  123. min-width="180"
  124. align="center">
  125. <template slot-scope="scope">
  126. <el-button circle size="mini" type="text" @click="getEdit(scope.row)">
  127. 编辑
  128. </el-button>
  129. <el-button circle size="mini" type="text" @click="handle('delete',scope.row)">
  130. 删除
  131. </el-button>
  132. </template>
  133. </el-table-column>
  134. </el-table>
  135. <div style="text-align: right;margin: 20px 0;">
  136. <el-pagination v-if="pagination" :page-size="pagination.pageSize"
  137. style="display: inline-block;float: right;" background @current-change="pageChange"
  138. layout="prev, pager, next" :total="pagination.total_count">
  139. </el-pagination>
  140. </div>
  141. </div>
  142. <!-- 弹框添加分类开始-->
  143. <el-dialog :title="title" width="30%" :visible.sync="dialogAddgsVisible"
  144. @close="closeDialogAddgsVisible" :modal-append-to-body="false">
  145. <el-form :model="addForm" ref="addForm" :rules="addRule" :inline="true" @submit.native.prevent label-width="100px">
  146. <el-form-item label="分类名称" prop="name">
  147. <el-input v-model="addForm.name" placeholder="请填写标题"></el-input>
  148. </el-form-item>
  149. <el-form-item label="排序" prop="sort">
  150. <el-input v-model="addForm.sort" type = "number" onkeyup="value=value.replace(/[^\d]/g,'')" @input="sortChange" placeholder="请填写排序"></el-input>
  151. </el-form-item>
  152. </el-form>
  153. <span slot="footer" class="dialog-footer">
  154. <el-button @click="dialogAddgsVisible = false">取 消</el-button>
  155. <el-button type="primary" :loading="btnLoading" @click="handle('edit','addForm')">确 定</el-button>
  156. </span>
  157. </el-dialog>
  158. <!-- 弹框添加分类结束-->
  159. </el-card>
  160. </div>
  161. <script>
  162. const app = new Vue({
  163. el: '#app',
  164. data() {
  165. var validatePass = (rule, value, callback) => {
  166. var reg = /^[\u4e00-\u9fa5\w]+$/;
  167. if (reg.test(value)) {
  168. callback();
  169. }else{
  170. callback(new Error('规则名不能含有特殊字符'));
  171. }
  172. };
  173. return {
  174. list: [],
  175. id: null,
  176. sort: 0,
  177. keyword: '',
  178. listLoading: false,
  179. btnLoading: false,
  180. pagination:null,
  181. page: 1,
  182. pageCount: 0,
  183. //弹框配置
  184. addForm: {
  185. id : '',
  186. name : '',
  187. status : 1,
  188. sort:99,
  189. },
  190. addRule: {
  191. name: [
  192. {required: true, message: '请填写分类名称', trigger: 'change'},
  193. {
  194. validator: (rule, value, callback) => {
  195. if(value.length>8||value.length<0){
  196. callback('最大长度在1-8个字内');
  197. }
  198. callback();
  199. }
  200. },
  201. {
  202. validator:validatePass,
  203. trigger: 'blur'
  204. },
  205. ],
  206. },
  207. ptypeList: [
  208. {key: "0", value: "成功"},
  209. {key: "1", value: "失败"},
  210. ],
  211. title:'',
  212. dialogAddgsVisible: false,
  213. dataList: [],
  214. // 对话框显示与否
  215. dialogVisible: false,
  216. dataloading: false,
  217. addGroupVisible: false,
  218. };
  219. },
  220. methods: {
  221. sortChange(){
  222. this.$forceUpdate();
  223. },
  224. editSort(row) {
  225. this.id = row.id;
  226. this.sort = row.sort;
  227. },
  228. quit() {
  229. this.id = null;
  230. },
  231. search() {
  232. this.page = 1;
  233. this.getList();
  234. },
  235. pageChange(currentPage) {
  236. let self = this;
  237. self.page = currentPage; //console.log(currentPage,999999);
  238. self.getList();
  239. },
  240. getList() {
  241. let self = this;
  242. self.listLoading = true;
  243. request({
  244. params: {
  245. r: 'xhs/cate/index',
  246. page: self.page,
  247. keyword: this.keyword
  248. },
  249. method: 'get',
  250. }).then(e => {
  251. self.listLoading = false;
  252. self.list = e.data.data.list;
  253. this.pagination = e.data.data.pagination;
  254. this.pagination.pageSize = e.data.data.page_size;
  255. this.pagination.total_count = e.data.data.count;
  256. }).catch(e => {
  257. console.log(e);
  258. });
  259. },
  260. getEdit(data) {
  261. this.dialogAddgsVisible = true;
  262. this.title = "编辑分类";
  263. this.addForm.id = data.id;
  264. this.addForm.name = data.name;
  265. this.addForm.sort = data.sort;
  266. },
  267. handle(type,data = null){
  268. switch (type) {
  269. case 'delete':// 删除
  270. this.$confirm('删除该条数据后不可以恢复, 是否继续?', '警告', {type: 'warning'}).then(() => {this.send({id: data.id,status:-1,type:'1'});})
  271. break;
  272. case 'enable':
  273. var status = 0;
  274. if(data.status=='0') status = 1;
  275. this.send({id: data.id,status: status,type:'1'});
  276. break;
  277. case 'sort':
  278. this.send({sort:this.sort,id:this.id});
  279. this.id = '';
  280. break;
  281. case 'edit':
  282. this.$refs[data].validate((valid) => {
  283. let self = this;
  284. if (valid) {
  285. if(this.addForm.id){
  286. this.send({name : self.addForm.name,id:this.addForm.id,sort:this.addForm.sort});
  287. }else{
  288. this.send({name : self.addForm.name,sort:this.addForm.sort});
  289. }
  290. } else {
  291. console.log('error submit!!');
  292. return false;
  293. }
  294. });
  295. break;
  296. }
  297. },
  298. send(data){
  299. let self = this;
  300. self.btnLoading = true;
  301. request({
  302. params: {
  303. r: 'xhs/cate/edit',
  304. },
  305. method: 'post',
  306. data:data,
  307. }).then(e => {
  308. this.dialogAddgsVisible = false;
  309. this.btnLoading = false;
  310. if (e.data.code == 0) {
  311. self.$message.success(e.data.msg);
  312. self.getList();
  313. } else {
  314. self.$message.error(e.data.msg);
  315. }
  316. }).catch(e => {
  317. console.log(e);
  318. });
  319. },
  320. /**
  321. *点击新增按钮,弹出新增模态框
  322. * @param
  323. */
  324. addgsForm() {
  325. this.dialogAddgsVisible = true;
  326. this.title = "新增分类";
  327. this.addForm.id = '';
  328. this.addForm.sort = 99;
  329. },
  330. /**
  331. *关闭或取消模态框,清空值
  332. * @param
  333. */
  334. closeDialogAddgsVisible() {
  335. this.$refs.addForm.resetFields();//element封装的方法,清空模态框的值
  336. this.title = "" //初始化title的值
  337. this.addForm = {//初始化addForm中的值
  338. name: "",
  339. }
  340. },
  341. },
  342. mounted: function () {
  343. this.getList();
  344. }
  345. });
  346. </script>