Blame view

src/components/scm/CouponRuleDiv.vue 3.2 KB
71def04c   wuxw   优化优惠
1
  <template>
f52d2b06   wuxw   积分功能开发中
2
3
4
5
6
7
8
    <div>
      <el-card class="coupon-rule-div">
        <div class="operation-buttons">
          <el-button type="primary" size="small" @click="openAddModal">{{ $t('common.add') }}</el-button>
          <el-button type="warning" size="small" @click="openEditModal">{{ $t('common.edit') }}</el-button>
          <el-button type="danger" size="small" @click="openDeleteModal">{{ $t('common.delete') }}</el-button>
        </div>
71def04c   wuxw   优化优惠
9
  
f52d2b06   wuxw   积分功能开发中
10
        <el-divider></el-divider>
71def04c   wuxw   优化优惠
11
  
f52d2b06   wuxw   积分功能开发中
12
13
14
15
16
17
18
19
20
21
22
        <el-tree :data="couponRules" :props="treeProps" node-key="ruleId" highlight-current @node-click="handleNodeClick"
          class="coupon-rule-tree">
          <span slot-scope="{ node }" class="custom-tree-node">
            <span>{{ node.label }}</span>
          </span>
        </el-tree>
      </el-card>
      <add-coupon-rule ref="addCouponRule" @success="handleSuccess" />
      <edit-coupon-rule ref="editCouponRule" @success="handleSuccess" />
      <delete-coupon-rule ref="deleteCouponRule" @success="handleSuccess" />
    </div>
71def04c   wuxw   优化优惠
23
24
25
26
27
  </template>
  
  <script>
  import { listCouponRule } from '@/api/scm/couponRuleApi'
  import { getCommunityId } from '@/api/community/communityApi'
f52d2b06   wuxw   积分功能开发中
28
29
30
  import AddCouponRule from '@/components/scm/AddCouponRule'
  import EditCouponRule from '@/components/scm/EditCouponRule'
  import DeleteCouponRule from '@/components/scm/DeleteCouponRule'
71def04c   wuxw   优化优惠
31
32
33
34
35
36
37
38
39
40
41
42
  export default {
    name: 'CouponRuleDiv',
    data() {
      return {
        couponRules: [],
        currentRule: {},
        treeProps: {
          label: 'ruleName',
          children: 'children'
        }
      }
    },
f52d2b06   wuxw   积分功能开发中
43
44
45
46
47
    components: {
      AddCouponRule,
      EditCouponRule,
      DeleteCouponRule
    },
71def04c   wuxw   优化优惠
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    created() {
      this.communityId = getCommunityId()
      this.getList()
    },
    methods: {
      async getList() {
        try {
          const params = {
            page: 1,
            row: 100,
            communityId: this.communityId
          }
          const { data } = await listCouponRule(params)
          this.couponRules = data
          if (this.couponRules.length > 0) {
            this.handleNodeClick(this.couponRules[0])
          }
        } catch (error) {
          console.error('Failed to get coupon rules:', error)
        }
      },
      handleNodeClick(data) {
        this.currentRule = data
f52d2b06   wuxw   积分功能开发中
71
        this.$emit('switch',this.currentRule);
71def04c   wuxw   优化优惠
72
73
      },
      openAddModal() {
f52d2b06   wuxw   积分功能开发中
74
        this.$refs.addCouponRule.open()
71def04c   wuxw   优化优惠
75
76
77
78
79
80
      },
      openEditModal() {
        if (!this.currentRule.ruleId) {
          this.$message.warning(this.$t('couponRule.selectRuleFirst'))
          return
        }
f52d2b06   wuxw   积分功能开发中
81
        this.$refs.editCouponRule.open(this.currentRule)
71def04c   wuxw   优化优惠
82
83
84
85
86
87
      },
      openDeleteModal() {
        if (!this.currentRule.ruleId) {
          this.$message.warning(this.$t('couponRule.selectRuleFirst'))
          return
        }
f52d2b06   wuxw   积分功能开发中
88
        this.$refs.deleteCouponRule.open(this.currentRule)
71def04c   wuxw   优化优惠
89
      },
f52d2b06   wuxw   积分功能开发中
90
      handleSuccess() {
71def04c   wuxw   优化优惠
91
        this.getList()
f52d2b06   wuxw   积分功能开发中
92
93
94
      },
      refreshList() {
      
71def04c   wuxw   优化优惠
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .coupon-rule-div {
    height: 100%;
  
    .operation-buttons {
      margin-bottom: 10px;
  
      .el-button {
        margin-right: 10px;
      }
    }
  
    .coupon-rule-tree {
      height: calc(100% - 60px);
      overflow-y: auto;
  
      .custom-tree-node {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 14px;
        padding-right: 8px;
      }
    }
  }
  </style>