index.php 14 KB

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