list.blade.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. @extends('layouts.base')
  2. @section('title', '素材中心分类管理')
  3. @section('content')
  4. <link rel="stylesheet" type="text/css" href="{{static_url('yunshop/goods/vue-goods1.css')}}"/>
  5. <div class="all">
  6. <div id="app" v-cloak>
  7. <div class="vue-head">
  8. <div class="vue-main-title" style="margin-bottom:20px">
  9. <div class="vue-main-title-left"></div>
  10. <div class="vue-main-title-content">素材分类</div>
  11. <div class="vue-main-title-button">
  12. <el-button type="primary" plain icon="el-icon-plus" size="small" @click="addFirst">添加一级分类</el-button>
  13. </div>
  14. </div>
  15. <div class="vue-search">
  16. <el-input v-model="keyword" style="width:40%"></el-input>
  17. <el-button type="primary" @click="search(1)">搜索</el-button>
  18. <el-link class="el-link-assist" :underline="false" @click="openAll">
  19. 全部展开
  20. </el-link>
  21. <el-link class="el-link-assist" :underline="false" @click="closeAll" style="margin-left:20px;">
  22. 全部折叠
  23. </el-link>
  24. </div>
  25. </div>
  26. <div class="vue-main">
  27. <div class="vue-main-form">
  28. <el-table
  29. v-if="show_table"
  30. :data="list"
  31. row-key="id"
  32. ref="table"
  33. default-expand-all
  34. :tree-props="{children: 'has_many_children'}"
  35. style="width: 100%"
  36. >
  37. <el-table-column prop="name" label="分类名称"></el-table-column>
  38. <el-table-column prop="refund_time" label="操作" align="left" width="400">
  39. <template slot-scope="scope">
  40. <div style="text-align:left">
  41. <el-link title="创建子分类" :underline="false" v-if="scope.row.has_many_children && thirdShow" @click="addChild(scope.row)" style="text-align: left;display: inline-block;font-size:26px;width:50px;">
  42. <i class="iconfont icon-ht_operation_add"></i>
  43. </el-link>
  44. <el-link title="创建子分类" :underline="false" v-else-if="!thirdShow &&scope.row.parent_id==0" @click="addChild(scope.row)" style="text-align: left;display: inline-block;font-size:26px;width:50px;">
  45. <i class="iconfont icon-ht_operation_add"></i>
  46. </el-link>
  47. <el-link title="编辑分类" :underline="false" @click="editChild(scope.row)" style="text-align: left;display: inline-block;font-size:26px;width:50px;">
  48. <i class="iconfont icon-ht_operation_edit"></i>
  49. </el-link>
  50. <el-link title="删除分类" :underline="false" @click="del(scope.row.id,scope.$index)" style="text-align: left;display: inline-block;font-size:26px;width:50px;">
  51. <i class="iconfont icon-ht_operation_delete"></i>
  52. </el-link>
  53. </div>
  54. </template>
  55. </el-table-column>
  56. </el-table>
  57. </div>
  58. </div>
  59. <!-- 分页 -->
  60. <div class="vue-page">
  61. <el-row v-if="total>0">
  62. <el-col align="right">
  63. <el-pagination layout="prev, pager, next,jumper" @current-change="search" :total="total"
  64. :page-size="per_page" :current-page="current_page" background
  65. ></el-pagination>
  66. </el-col>
  67. </el-row>
  68. </div>
  69. </div>
  70. </div>
  71. <script>
  72. var app = new Vue({
  73. el: "#app",
  74. delimiters: ['[[', ']]'],
  75. name: 'test',
  76. data() {
  77. return {
  78. list:[],
  79. keyword:'',
  80. rules: {},
  81. thirdShow:true,
  82. show_table:true,
  83. current_page:1,
  84. total:1,
  85. per_page:1,
  86. }
  87. },
  88. created() {
  89. },
  90. mounted() {
  91. this.getData(1);
  92. },
  93. methods: {
  94. getData(page) {
  95. let loading = this.$loading({target:document.querySelector(".content"),background: 'rgba(0, 0, 0, 0)'});
  96. this.show_table = false;
  97. this.$http.post('{!! yzWebFullUrl('plugin.material-center.admin.category.index') !!}',{page:page,keyword:this.keyword}).then(function(response) {
  98. if (response.data.result) {
  99. this.list = response.data.data.data.data;
  100. this.current_page=response.data.data.data.current_page;
  101. this.total=response.data.data.data.total;
  102. this.per_page=response.data.data.data.per_page;
  103. this.thirdShow=response.data.data.thirdShow;
  104. loading.close();
  105. this.show_table = true;
  106. } else {
  107. this.$message({
  108. message: response.data.msg,
  109. type: 'error'
  110. });
  111. this.show_table = true;
  112. }
  113. loading.close();
  114. }, function(response) {
  115. this.$message({
  116. message: response.data.msg,
  117. type: 'error'
  118. });
  119. loading.close();
  120. this.show_table = true;
  121. });
  122. },
  123. search(val) {
  124. if(this.keyword == "") {
  125. this.getData(val);
  126. return;
  127. }
  128. this.show_table = false;
  129. let loading = this.$loading({target:document.querySelector(".content"),background: 'rgba(0, 0, 0, 0)'});
  130. this.$http.post('{!! yzWebFullUrl('plugin.material-center.admin.category.index') !!}',{page:val,keyword:this.keyword}).then(function(response) {
  131. if (response.data.result) {
  132. this.list = response.data.data.data;
  133. this.list = response.data.data.data;
  134. this.current_page=response.data.data.current_page;
  135. this.total=response.data.data.total;
  136. this.per_page=response.data.data.per_page;
  137. this.show_table = true;
  138. this.$forceUpdate()
  139. // this.thirdShow=response.data.thirdShow;
  140. loading.close();
  141. } else {
  142. this.$message({
  143. message: response.data.msg,
  144. type: 'error'
  145. });
  146. this.show_table = false;
  147. }
  148. loading.close();
  149. }, function(response) {
  150. this.$message({
  151. message: response.data.msg,
  152. type: 'error'
  153. });
  154. loading.close();
  155. this.show_table = false;
  156. });
  157. },
  158. openAll() {
  159. this.list.forEach((item,index) => {
  160. // this.$refs.table.toggleRowExpansion(item, true)
  161. if(this.list[index].has_many_children && this.list[index].has_many_children.length>0) {
  162. this.$refs.table.toggleRowExpansion(item, true)
  163. }
  164. })
  165. },
  166. closeAll() {
  167. this.list.forEach((item,index) => {
  168. if(this.list[index].has_many_children && this.list[index].has_many_children.length>0) {
  169. this.$refs.table.toggleRowExpansion(item, false)
  170. }
  171. })
  172. },
  173. // 添加一级分类
  174. addFirst() {
  175. let link = `{!! yzWebFullUrl('plugin.material-center.admin.category.category-info') !!}`+`&level=1`;
  176. window.location.href = link;
  177. },
  178. // 添加子分类
  179. addChild(item) {
  180. let link = '';
  181. if(item.parent_id == 0) {
  182. link = `{!! yzWebFullUrl('plugin.material-center.admin.category.category-info') !!}`+`&parent_id=`+item.id+`&level=2`;
  183. }
  184. window.location.href = link;
  185. },
  186. // 编辑子分类
  187. editChild(item) {
  188. let link = `{!! yzWebFullUrl('plugin.material-center.admin.category.category-info') !!}`+`&id=`+item.id;
  189. window.location.href = link;
  190. },
  191. del(id,index) {
  192. console.log(id,index)
  193. this.$confirm('确定删除吗', '提示', {confirmButtonText: '确定',cancelButtonText: '取消',type: 'warning'}).then(() => {
  194. let loading = this.$loading({target:document.querySelector(".content"),background: 'rgba(0, 0, 0, 0)'});
  195. this.$http.post('{!! yzWebFullUrl('plugin.material-center.admin.category.deleted-category') !!}',{id:id}).then(function (response) {
  196. console.log(response.data);
  197. if (response.data.result) {
  198. // this.list.splice(index,1);
  199. this.$message({type: 'success',message: '删除成功!'});
  200. window.location.reload();
  201. }
  202. else{
  203. this.$message({type: 'error',message: response.data.msg});
  204. }
  205. loading.close();
  206. },function (response) {
  207. this.$message({type: 'error',message: response.data.msg});
  208. loading.close();
  209. }
  210. );
  211. }).catch(() => {
  212. this.$message({type: 'info',message: '已取消删除'});
  213. });
  214. },
  215. },
  216. })
  217. </script>
  218. @endsection