fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<template>
  <div class="addActivity">
    <el-button type="success" size="mini" @click="addActivity">添加活动</el-button>
    <el-button size="mini" @click="clearTable">清空</el-button>
    <el-table :data="tableData" border>
      <el-table-column label="活动名称" prop="promotionName" show-overflow-tooltip></el-table-column>
      <el-table-column label="活动类型" prop="promotionType" width="120px" show-overflow-tooltip>
        <template slot-scope="scope">
          {{scope.row.promotionType?getArrayLable(promotionTypeList,scope.row.promotionType):'限时抢购'}}
        </template>
      </el-table-column>
      <el-table-column label="活动状态" width="120px" show-overflow-tooltip>
        <template slot-scope="scope">
          {{getStatusText(scope.row.promotionStatus)}}
        </template>
      </el-table-column>
      <el-table-column label="活动时间" width="300px">
        <template slot-scope="scope">
          <span>{{scope.row.promotionStartTime}} ~ {{scope.row.promotionEndTime}}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" prop="createTime" width="180px"></el-table-column>
      <slot name="activityTableRow"></slot>
      <el-table-column width="100px" label="操作">
        <template slot-scope="scope">
          <el-form-item>
            <el-button type="danger" size="mini" @click="deleteItem(scope.row,scope.$index)">删除
            </el-button>
          </el-form-item>
        </template>
      </el-table-column>
    </el-table>
    <proActivity-selected :show.sync='selectedActivityDialog.show'
                          :title="selectedActivityDialog.title"
                          @hand-selected-row-data="handSelectedRowData"
                          :isShowPromotionStatus="true" :promotionStatusList="promotionStatusList">
    </proActivity-selected>
  </div>
</template>
<script>
import proActivitySelected from '@/views/proActivity/components/proActivitySelected.vue'
import { getArrayLable } from '@/utils/getArrayLable'
export default {
  components: { proActivitySelected },
  props: {
    activityData: {
      type: Array,
      default: function () {
        return []
      }
    },
    formRules: {
      type: Object,
      default: function () {
        return {}
      }
    },
    // 查询指定活动状态的数据
    promotionStatusList: {
      type: Array,
      default: function () {
        return []
      }
    },
  },
  data() {
    return {
      selectedActivityDialog: {
        show: false,
        title: '选择活动'
      },
      tableData: [],
      promotionTypeList: [
        {
          id: '1',
          name: '满减'
        },
        {
          id: '2',
          name: '满赠'
        },
        {
          id: '3',
          name: '盲盒抽奖'
        },
        {
          id: '4',
          name: '限时抢购'
        },
        {
          id: '6',
          name: '拼团活动'
        }
      ]
    }
  },
  watch: {
    activityData: {
      immediate: true, // immediate选项可以开启首次赋值监听
      handler: function (newValue, oldValue) {
        this.tableData = newValue
      }
    },
    tableData(newValue, oldValue) {
      this.$emit('update:activityData', newValue)
    }
  },
  methods: {
    /**
    * 获取活动状态
    */
    getStatusText(promotionStatus) {
      switch (promotionStatus) {
        case '00':
          return '未开始'
        case '02':
          return '进行中'
        case '06':
          return '已结束'
        case '07':
          return '已停用'
        case '08':
          return '已暂停'
        default:
          break
      }
    },
    /**
    * 获取数组的label
    */
    getArrayLable,
    /**
       * 清空表格数据
       */
    clearTable() {
      this.tableData = []
    },
    /**
       * 删除表格数据
       */
    deleteItem(row, index) {
      this.tableData.splice(index, 1)
    },
    /**
       * 打开添加活动弹窗
       */
    addActivity() {
      this.selectedActivityDialog.show = true
    },
    /**
     * 获取弹出框返回的数据
     */
    handSelectedRowData(rows) {
      rows.forEach(rowItem => {
        if (!this.tableData.find(item => {
          return rowItem.promotionId === item.promotionId
        })) {
          this.tableData.push(rowItem)
        }
      })
      this.$emit('hand-selected', rows)
    }
  }
}
</script>
<style>
.addActivity .el-table {
  margin-top: 20px;
}
</style>