goodsclassification.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <view>
  3. <ly-tree @edit="editCate" @deldata="delCate" :tree-data="treeData" :props="props" node-key="id"></ly-tree>
  4. <addBtn @click="goPage(`/pagesT/goods/AddGoodsclassification`)"></addBtn>
  5. <u-modal v-model="model_show" :show-cancel-button="true" content="确定删除此分类?" @confirm="modelConfirm"
  6. @cancel="modelCancel"></u-modal>
  7. </view>
  8. </template>
  9. <script>
  10. import LyTree from '@/components/ly-tree/ly-tree.vue';
  11. export default {
  12. components: {
  13. LyTree
  14. },
  15. onShow() {
  16. this.treeData = []
  17. this.getAllCategory();
  18. },
  19. data() {
  20. return {
  21. treeData: [],
  22. ready: false,
  23. props: {
  24. label: 'title', // label: 'personName', // 指把数据中的‘personName’当做label也就是节点名称
  25. children: 'children'
  26. },
  27. model_show: false,
  28. id: ''
  29. };
  30. },
  31. methods: {
  32. // 编辑
  33. editCate(node) {
  34. this.goPage(`/pagesT/goods/AddGoodsclassification?id=${node.data.id}`)
  35. },
  36. // 删除
  37. delCate(node) {
  38. this.id = node.data.id
  39. this.model_show = true
  40. },
  41. // 如果不需要不用到这个方法,需要删除相应代码,打印大量日志会造成性能损耗
  42. handleNodeClick(obj) {
  43. console.log('handleNodeClick', JSON.stringify(obj));
  44. },
  45. // 获取所有商品分类
  46. getAllCategory() {
  47. this.$u.api.getAllCategory().then(res => {
  48. this.treeData = res.data;
  49. });
  50. },
  51. modelConfirm() {
  52. this.$u.api.delCategory(this.id).then(res => {
  53. this.treeData = []
  54. this.getAllCategory();
  55. this.$u.toast('删除成功')
  56. })
  57. },
  58. modelCancel() {}
  59. }
  60. };
  61. </script>
  62. <style>
  63. .ly-search {
  64. margin: 0 30rpx;
  65. margin-top: 40rpx;
  66. padding-bottom: 15rpx;
  67. border-bottom: 1px solid #ededed;
  68. }
  69. </style>