list.blade.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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. <ul style="margin-bottom:10px;">
  29. <li style="margin-bottom:10px;">
  30. 服务提供:
  31. <el-button size="mini" @click="openService">
  32. 批量编辑
  33. </el-button>
  34. </li>
  35. <li>
  36. 一键显示:
  37. <el-button size="mini" @click="patchDisplayCategory(1)">
  38. 开启
  39. </el-button>
  40. <el-button size="mini" @click="patchDisplayCategory(0)">
  41. 关闭
  42. </el-button>
  43. </li>
  44. <li style="display:block;margin-top:5px;">
  45. 一键推荐:
  46. <el-button size="mini" @click="patchRecommendCategory(1)">
  47. 开启
  48. </el-button>
  49. <el-button size="mini" @click="patchRecommendCategory(0)">
  50. 关闭
  51. </el-button>
  52. <el-button size="mini" @click="batchDeleteCategory()">
  53. 批量删除
  54. </el-button>
  55. </el-switch>
  56. </li>
  57. </ul>
  58. <el-table
  59. v-if="show_table"
  60. :data="list"
  61. row-key="id"
  62. ref="table"
  63. default-expand-all
  64. :tree-props="{children: 'has_many_children'}"
  65. style="width: 100%"
  66. row-key="id" border @select="select" @select-all="selectAll"
  67. >
  68. <el-table-column type="selection" width="55"></el-table-column>
  69. <el-table-column prop="name" label="分类名称"></el-table-column>
  70. <el-table-column label="显示" width="100">
  71. <template slot-scope="scope">
  72. <el-switch v-model="scope.row.enabled" @change="displayCategory(scope.row)"></el-switch>
  73. </template>
  74. </el-table-column>
  75. <el-table-column label="推荐" width="100">
  76. <template slot-scope="scope">
  77. <el-switch v-model="scope.row.is_home" @change="recommendCateogry(scope.row)"></el-switch>
  78. </template>
  79. </el-table-column>
  80. <el-table-column prop="refund_time" label="操作" align="left" width="400">
  81. <template slot-scope="scope">
  82. <div style="text-align:left">
  83. <el-link title="创建子分类" :underline="false" v-if="scope.row.has_many_children && thirdShow && scope.row.level !== 3" @click="addChild(scope.row)" style="text-align: left;display: inline-block;font-size:26px;width:50px;">
  84. <i class="iconfont icon-ht_operation_add"></i>
  85. </el-link>
  86. <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;">
  87. <i class="iconfont icon-ht_operation_add"></i>
  88. </el-link>
  89. <el-link title="编辑分类" :underline="false" @click="editChild(scope.row)" style="text-align: left;display: inline-block;font-size:26px;width:50px;">
  90. <i class="iconfont icon-ht_operation_edit"></i>
  91. </el-link>
  92. <el-link title="删除分类" :underline="false" @click="del(scope.row.id,scope.$index)" style="text-align: left;display: inline-block;font-size:26px;width:50px;">
  93. <i class="iconfont icon-ht_operation_delete"></i>
  94. </el-link>
  95. </div>
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. </div>
  100. </div>
  101. <el-dialog title="服务提供" :visible.sync="dialogTableVisible" center width="730px">
  102. <div style="overflow:auto">
  103. <el-form ref="service_form" style="width: 100%;height:auto;overflow:auto">
  104. <el-form-item label="是否自动上下架">
  105. <el-radio v-model="service_form.is_automatic" :label="1">是</el-radio>
  106. <el-radio v-model="service_form.is_automatic" :label="0">否</el-radio>
  107. </el-form-item>
  108. <el-form-item label="时间方式">
  109. <el-radio v-model="service_form.time_type" :label="0">固定</el-radio>
  110. <el-radio v-model="service_form.time_type" :label="1">循环</el-radio>
  111. <span style="display: flex">
  112. <span class="tip" style="margin-right: 20px">固定:在设置的时间商品自动上下架时间</span>
  113. <span class="tip">循环:在循环日期内商品每天在设置的时间点自动循环上下架</span>
  114. </span>
  115. </el-form-item>
  116. <el-form-item label="上下架时间" v-if="service_form.time_type==0">
  117. <el-date-picker
  118. v-model="service_form.shelves_time"
  119. type="datetimerange"
  120. value-format="timestamp"
  121. align="right"
  122. unlink-panels
  123. range-separator="至"
  124. start-placeholder="开始日期"
  125. end-placeholder="结束日期"
  126. :picker-options="pickerOptions">
  127. </el-date-picker>
  128. </el-form-item>
  129. <el-form-item label="循环日期" v-if="service_form.time_type==1">
  130. <el-date-picker
  131. v-model="service_form.loop_date"
  132. type="daterange"
  133. value-format="timestamp"
  134. align="right"
  135. unlink-panels
  136. range-separator="至"
  137. start-placeholder="开始日期"
  138. end-placeholder="结束日期"
  139. :picker-options="pickerOptions"
  140. >
  141. </el-date-picker>
  142. </el-form-item>
  143. <el-form-item label="上架时间" v-if="service_form.time_type==1">
  144. <el-time-select
  145. v-model="service_form.loop_time_up"
  146. value-format="timestamp"
  147. :picker-options="{
  148. start: '00:00',
  149. step: '00:05',
  150. end: '24:00'
  151. }"
  152. placeholder="选择时间">
  153. </el-time-select>
  154. <span style="margin-left: 15px;margin-right: 8px">下架时间</span>
  155. <el-time-select
  156. v-model="service_form.loop_time_down"
  157. value-format="timestamp"
  158. :picker-options="{
  159. start: '00:00',
  160. step: '00:05',
  161. end: '24:00',
  162. minTime: service_form.loop_time_up
  163. }"
  164. placeholder="选择时间">
  165. </el-time-select>
  166. </el-form-item>
  167. <el-form-item label="库存自动刷新" v-if="service_form.time_type==1">
  168. <el-switch v-model="service_form.auth_refresh_stock" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0"></el-switch>
  169. <div class="tip">开启后,循环日期期间,每日重新上架时,库存商品数自动刷新为原始库存数</div>
  170. </el-form-item>
  171. <el-form-item label="原始库存" v-if="service_form.time_type==1">
  172. <el-input v-model="service_form.original_stock" style="width:30%;"></el-input>
  173. </el-form-item>
  174. <span style="">
  175. <el-button type="primary" @click="serviceSubmit">确 认</el-button>
  176. <el-button @click="closeService">取 消</el-button>
  177. </span>
  178. </el-form>
  179. </div>
  180. </el-dialog>
  181. <!-- 分页 -->
  182. <div class="vue-page">
  183. <el-row v-if="total>0">
  184. <el-col align="right">
  185. <el-pagination layout="prev, pager, next,jumper" @current-change="search" :total="total"
  186. :page-size="per_page" :current-page="current_page" background
  187. ></el-pagination>
  188. </el-col>
  189. </el-row>
  190. </div>
  191. </div>
  192. </div>
  193. <script>
  194. var app = new Vue({
  195. el: "#app",
  196. delimiters: ['[[', ']]'],
  197. name: 'test',
  198. data() {
  199. return {
  200. list:[],
  201. keyword:'',
  202. rules: {},
  203. thirdShow:true,
  204. show_table:true,
  205. current_page:1,
  206. total:1,
  207. per_page:1,
  208. selectedCategoies:[],
  209. batchDisplay:false,
  210. batchRecommend:false,
  211. // 保存页码状态
  212. page:1,
  213. dialogTableVisible:false,
  214. service_form: {
  215. is_automatic: 0,
  216. time_type: 1,
  217. auth_refresh_stock: 1,
  218. shelves_time:[],
  219. loop_date:[],
  220. },
  221. pickerOptions: {
  222. shortcuts: [{
  223. text: "最近一周",
  224. onClick(picker) {
  225. const end = new Date();
  226. const start = new Date();
  227. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  228. picker.$emit("pick", [start, end]);
  229. }
  230. }, {
  231. text: "最近一个月",
  232. onClick(picker) {
  233. const end = new Date();
  234. const start = new Date();
  235. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
  236. picker.$emit("pick", [start, end]);
  237. }
  238. }, {
  239. text: "最近三个月",
  240. onClick(picker) {
  241. const end = new Date();
  242. const start = new Date();
  243. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
  244. picker.$emit("pick", [start, end]);
  245. }
  246. }]
  247. },
  248. }
  249. },
  250. created() {
  251. },
  252. mounted() {
  253. if(this.getParam('page')){
  254. this.getData(this.getParam('page'));
  255. }else{
  256. this.getData(this.page);
  257. }
  258. },
  259. methods: {
  260. getParam(name) {
  261. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  262. var r = window.location.search.substr(1).match(reg);
  263. if (r != null) return unescape(r[2]);
  264. return null;
  265. },
  266. beforeunloadFn (e) {
  267. this.$http.post(`{!! yzWebFullUrl('goods.category.get-page') !!}`,{page:1}).then(response => {
  268. if (response.data.result) {
  269. console.log(response.data.msg);
  270. } else {
  271. console.log(response.data.msg);
  272. }
  273. },response => {
  274. console.log(response);
  275. });
  276. },
  277. setChildren(children, type) {
  278. // 编辑多个子层级
  279. children.map((j) => {
  280. this.toggleSelection(j, type)
  281. if (j.has_many_children) {
  282. this.setChildren(j.has_many_children, type)
  283. }
  284. })
  285. },
  286. // 选中父节点时,子节点一起选中取消
  287. select(selection, row) {
  288. this.selectedCategoies=selection;
  289. if (
  290. selection.some((el) => {
  291. return row.id === el.id
  292. })
  293. ) {
  294. if (row.has_many_children) {
  295. // 解决子组件没有被勾选到
  296. this.setChildren(row.has_many_children, true)
  297. }
  298. } else {
  299. if (row.has_many_children) {
  300. this.setChildren(row.has_many_children, false)
  301. }
  302. }
  303. },
  304. toggleSelection(row, select) {
  305. if (row) {
  306. this.$nextTick(() => {
  307. this.$refs.table && this.$refs.table.toggleRowSelection(row, select)
  308. })
  309. }
  310. },
  311. // 选择全部
  312. selectAll(selection) {
  313. this.selectedCategoies=selection;
  314. // tabledata第一层只要有在selection里面就是全选
  315. const isSelect = selection.some((el) => {
  316. const tableDataIds = this.list.map((j) => j.id)
  317. return tableDataIds.includes(el.id)
  318. })
  319. // tableDate第一层只要有不在selection里面就是全不选
  320. const isCancel = !this.list.every((el) => {
  321. const selectIds = selection.map((j) => j.id)
  322. return selectIds.includes(el.id)
  323. })
  324. if (isSelect) {
  325. selection.map((el) => {
  326. if (el.has_many_children) {
  327. // 解决子组件没有被勾选到
  328. this.setChildren(el.has_many_children, true)
  329. }
  330. })
  331. }
  332. if (isCancel) {
  333. this.list.map((el) => {
  334. if (el.has_many_children) {
  335. // 解决子组件没有被勾选到
  336. this.setChildren(el.has_many_children, false)
  337. }
  338. })
  339. }
  340. },
  341. recommendCateogry(row){
  342. this.$http.post("{!! yzWebFullUrl('goods.category.batch-recommend') !!}",{
  343. ids:[row.id],
  344. is_home:row.is_home?1:0
  345. }).then(res=>{
  346. if(res.result==0){
  347. this.$toast(res.msg);
  348. row.is_home=!Boolean(row.is_home);
  349. return;
  350. }
  351. })
  352. },
  353. patchRecommendCategory(flag){
  354. let ids=[];
  355. for (const item of this.selectedCategoies) {
  356. if (item.has_many_children && item.has_many_children.length > 0){
  357. for (const itemChildren of item.has_many_children) {
  358. ids.push(itemChildren.id)
  359. if (itemChildren.has_many_children && itemChildren.has_many_children.length > 0){
  360. for (const itemChildrenLower of itemChildren.has_many_children) {
  361. ids.push(itemChildrenLower.id)
  362. }
  363. }
  364. }
  365. }
  366. ids.push(item.id)
  367. }
  368. this.$http.post("{!! yzWebFullUrl('goods.category.batch-recommend') !!}",{
  369. ids,
  370. is_home:flag
  371. }).then(res=>{
  372. if(res.result==0){
  373. this.$toast(res.msg);
  374. return;
  375. }
  376. for (const item of this.selectedCategoies) {
  377. item.is_home=Boolean(flag);
  378. if (item.has_many_children && item.has_many_children.length > 0){
  379. for (const itemChildren of item.has_many_children) {
  380. itemChildren.is_home=Boolean(flag)
  381. if (itemChildren.has_many_children && itemChildren.has_many_children.length > 0){
  382. for (const itemChildrenLower of itemChildren.has_many_children) {
  383. itemChildrenLower.is_home=Boolean(flag)
  384. }
  385. }
  386. }
  387. }
  388. }
  389. })
  390. },
  391. batchDeleteCategory(){
  392. let ids=[];
  393. for (const item of this.selectedCategoies) {
  394. if (item.has_many_children && item.has_many_children.length > 0){
  395. for (const itemChildren of item.has_many_children) {
  396. ids.push(itemChildren.id)
  397. if (itemChildren.has_many_children && itemChildren.has_many_children.length > 0){
  398. for (const itemChildrenLower of itemChildren.has_many_children) {
  399. ids.push(itemChildrenLower.id)
  400. }
  401. }
  402. }
  403. }
  404. ids.push(item.id)
  405. }
  406. this.$confirm('确定删除吗', '提示', {confirmButtonText: '确定',cancelButtonText: '取消',type: 'warning'}).then(() => {
  407. let loading = this.$loading({target:document.querySelector(".content"),background: 'rgba(0, 0, 0, 0)'});
  408. this.$http.post('{!! yzWebFullUrl('goods.category.batchDeleteCategory') !!}',{ids}).then(function (response) {
  409. console.log(response.data);
  410. if (response.data.result) {
  411. // this.list.splice(index,1);
  412. this.$message({type: 'success',message: '删除成功!'});
  413. window.location.reload();
  414. }
  415. else{
  416. this.$message({type: 'error',message: response.data.msg});
  417. }
  418. loading.close();
  419. },function (response) {
  420. this.$message({type: 'error',message: response.data.msg});
  421. loading.close();
  422. }
  423. );
  424. }).catch(() => {
  425. this.$message({type: 'info',message: '已取消删除'});
  426. });
  427. },
  428. displayCategory(row){
  429. this.$http.post("{!! yzWebFullUrl('goods.category.batch-display') !!}",{
  430. ids:[row.id],
  431. enabled:row.enabled?1:0
  432. }).then(res=>{
  433. if(res.result==0){
  434. this.$toast(res.msg);
  435. row.enabled=!Boolean(row.enabled);
  436. return;
  437. }
  438. })
  439. },
  440. patchDisplayCategory(flag){
  441. let ids=[];
  442. for (const item of this.selectedCategoies) {
  443. if (item.has_many_children && item.has_many_children.length > 0){
  444. for (const itemChildren of item.has_many_children) {
  445. ids.push(itemChildren.id)
  446. if (itemChildren.has_many_children && itemChildren.has_many_children.length > 0){
  447. for (const itemChildrenLower of itemChildren.has_many_children) {
  448. ids.push(itemChildrenLower.id)
  449. }
  450. }
  451. }
  452. }
  453. ids.push(item.id)
  454. }
  455. this.$http.post("{!! yzWebFullUrl('goods.category.batch-display') !!}",{
  456. ids,
  457. enabled:flag
  458. }).then(res=>{
  459. if(res.result==0){
  460. this.$toast(res.msg);
  461. row.enabled=!Boolean(row.enabled);
  462. return;
  463. }
  464. for (const item of this.selectedCategoies) {
  465. item.enabled=Boolean(flag);
  466. if (item.has_many_children && item.has_many_children.length > 0) {
  467. for (const itemChildren of item.has_many_children) {
  468. itemChildren.enabled=Boolean(flag);
  469. if (itemChildren.has_many_children && itemChildren.has_many_children.length > 0) {
  470. for (const itemChildrenLower of itemChildren.has_many_children) {
  471. itemChildrenLower.enabled=Boolean(flag);
  472. }
  473. }
  474. }
  475. }
  476. }
  477. })
  478. },
  479. serviceSubmit(){
  480. let ids=[];
  481. for (const item of this.selectedCategoies) {
  482. if (item.has_many_children && item.has_many_children.length > 0){
  483. for (const itemChildren of item.has_many_children) {
  484. ids.push(itemChildren.id)
  485. if (itemChildren.has_many_children && itemChildren.has_many_children.length > 0){
  486. for (const itemChildrenLower of itemChildren.has_many_children) {
  487. ids.push(itemChildrenLower.id)
  488. }
  489. }
  490. }
  491. }
  492. ids.push(item.id)
  493. }
  494. if (this.service_form.time_type==0) {
  495. console.log(this.service_form)
  496. if (!this.service_form.shelves_time[0] || !this.service_form.shelves_time[1]) {
  497. this.$message({message: '上下架时间不能为空', type: 'error'});return;
  498. }
  499. this.service_form.on_shelf_time = this.service_form.shelves_time[0] / 1000;
  500. this.service_form.lower_shelf_time = this.service_form.shelves_time[1] / 1000;
  501. }
  502. if (this.service_form.time_type==1) {
  503. if (!this.service_form.loop_date[0] || !this.service_form.loop_date[1]) {
  504. this.$message({message: '循环时间不能为空', type: 'error'});return;
  505. }
  506. this.service_form.loop_date_start = this.service_form.loop_date[0] / 1000;
  507. this.service_form.loop_date_end = this.service_form.loop_date[1] / 1000;
  508. }
  509. if (this.service_form.time_type==1) {
  510. if (!this.service_form.loop_time_up || !this.service_form.loop_time_down) {
  511. this.$message({message: '循环上下架时间不能为空', type: 'error'});return;
  512. }
  513. }
  514. let json = {
  515. ids:ids,
  516. service_form:this.service_form,
  517. };
  518. this.$http.post("{!! yzWebFullUrl('goods.category.batchService') !!}",json).then(res=>{
  519. if (res.data.result) {
  520. this.$message({message: res.data.msg, type: 'success'});
  521. location.reload();
  522. } else {
  523. this.$message({message: res.data.msg, type: 'error'});
  524. }
  525. })
  526. },
  527. getData(page) {
  528. let loading = this.$loading({target:document.querySelector(".content"),background: 'rgba(0, 0, 0, 0)'});
  529. this.show_table = false;
  530. this.$http.post("{!! yzWebFullUrl('goods.category.index') !!}",{page:page,keyword:this.keyword}).then(function(response) {
  531. if (response.data.result) {
  532. for (const item of response.data.data.data.data) {
  533. if(item.has_many_children && item.has_many_children.length>0){
  534. for (const subItem of item.has_many_children) {
  535. subItem['is_home']=Boolean(subItem['is_home']);
  536. subItem['enabled']=Boolean(subItem['enabled']);
  537. if(subItem.has_many_children && subItem.has_many_children.length>0){
  538. for (const subItemChildren of subItem.has_many_children) {
  539. subItemChildren['is_home']=Boolean(subItemChildren['is_home']);
  540. subItemChildren['enabled']=Boolean(subItemChildren['enabled']);
  541. }
  542. }
  543. }
  544. }
  545. item['is_home']=Boolean(item['is_home']);
  546. item['enabled']=Boolean(item['enabled']);
  547. }
  548. this.list = response.data.data.data.data;
  549. this.current_page=response.data.data.data.current_page;
  550. this.total=response.data.data.data.total;
  551. this.per_page=response.data.data.data.per_page;
  552. this.thirdShow=response.data.data.thirdShow;
  553. loading.close();
  554. this.show_table = true;
  555. } else {
  556. this.$message({
  557. message: response.data.msg,
  558. type: 'error'
  559. });
  560. this.show_table = true;
  561. }
  562. loading.close();
  563. }, function(response) {
  564. this.$message({
  565. message: response.data.msg,
  566. type: 'error'
  567. });
  568. loading.close();
  569. this.show_table = true;
  570. });
  571. },
  572. search(val) {
  573. this.page = val
  574. if(this.keyword == "") {
  575. this.getData(val);
  576. return;
  577. }
  578. this.show_table = false;
  579. let loading = this.$loading({target:document.querySelector(".content"),background: 'rgba(0, 0, 0, 0)'});
  580. this.$http.post("{!! yzWebFullUrl('goods.category.index') !!}",{page:val,keyword:this.keyword}).then(function(response) {
  581. if (response.data.result) {
  582. for (const item of response.data.data.data.data) {
  583. if (item.has_many_children && item.has_many_children.length>0) {
  584. for (const subItem of item.has_many_children) {
  585. subItem['is_home']=Boolean(subItem['is_home']);
  586. subItem['enabled']=Boolean(subItem['enabled']);
  587. }
  588. }
  589. item['is_home']=Boolean(item['is_home']);
  590. item['enabled']=Boolean(item['enabled']);
  591. }
  592. this.list = response.data.data.data.data;
  593. this.current_page=response.data.data.current_page;
  594. this.total=response.data.data.data.total;
  595. this.per_page=response.data.data.data.per_page;
  596. this.show_table = true;
  597. this.thirdShow=response.data.data.thirdShow;
  598. this.$forceUpdate()
  599. // this.thirdShow=response.data.thirdShow;
  600. loading.close();
  601. } else {
  602. this.$message({
  603. message: response.data.msg,
  604. type: 'error'
  605. });
  606. this.show_table = false;
  607. }
  608. loading.close();
  609. }, function(response) {
  610. this.$message({
  611. message: response.data.msg,
  612. type: 'error'
  613. });
  614. loading.close();
  615. this.show_table = false;
  616. });
  617. },
  618. openAll() {
  619. this.list.forEach((item,index) => {
  620. // this.$refs.table.toggleRowExpansion(item, true)
  621. if(this.list[index].has_many_children && this.list[index].has_many_children.length>0) {
  622. this.$refs.table.toggleRowExpansion(item, true)
  623. }
  624. })
  625. },
  626. closeAll() {
  627. this.list.forEach((item,index) => {
  628. if(this.list[index].has_many_children && this.list[index].has_many_children.length>0) {
  629. this.$refs.table.toggleRowExpansion(item, false)
  630. }
  631. })
  632. },
  633. // 添加一级分类
  634. addFirst() {
  635. let link = `{!! yzWebFullUrl('goods.category.category-info') !!}`+`&level=1`;
  636. window.location.href = link;
  637. },
  638. // 添加子分类
  639. addChild(item) {
  640. let link = '';
  641. if(item.parent_id == 0) {
  642. link = `{!! yzWebFullUrl('goods.category.category-info') !!}`+`&parent_id=`+item.id+`&level=2`;
  643. }
  644. else {
  645. link = `{!! yzWebFullUrl('goods.category.category-info') !!}`+`&parent_id=`+item.id+`&level=3`;
  646. }
  647. window.location.href = link;
  648. },
  649. // 编辑子分类
  650. editChild(item) {
  651. let link = `{!! yzWebFullUrl('goods.category.category-info') !!}`+`&id=`+item.id+`&page=`+this.page;
  652. window.location.href = link;
  653. },
  654. del(id,index) {
  655. console.log(id,index)
  656. this.$confirm('确定删除吗', '提示', {confirmButtonText: '确定',cancelButtonText: '取消',type: 'warning'}).then(() => {
  657. let loading = this.$loading({target:document.querySelector(".content"),background: 'rgba(0, 0, 0, 0)'});
  658. this.$http.post('{!! yzWebFullUrl('goods.category.deleted-category') !!}',{id:id}).then(function (response) {
  659. console.log(response.data);
  660. if (response.data.result) {
  661. // this.list.splice(index,1);
  662. this.$message({type: 'success',message: '删除成功!'});
  663. window.location.reload();
  664. }
  665. else{
  666. this.$message({type: 'error',message: response.data.msg});
  667. }
  668. loading.close();
  669. },function (response) {
  670. this.$message({type: 'error',message: response.data.msg});
  671. loading.close();
  672. }
  673. );
  674. }).catch(() => {
  675. this.$message({type: 'info',message: '已取消删除'});
  676. });
  677. },
  678. openService() {
  679. this.dialogTableVisible = true;
  680. },
  681. closeService() {
  682. this.dialogTableVisible = false;
  683. },
  684. },
  685. })
  686. </script>
  687. @endsection