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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<template>
  <div class="msgNotificationDialog-style">
    <el-dialog :visible.sync="isShow" :title="title" width="1050px" :modal-append-to-body="false"
               :close-on-click-modal="false">
      <div class="msg-list">
        <span>消息类型:</span>
        <el-select v-model="messageType" placeholder="请选择" size="small" @change="queryData">
          <el-option v-for="item in msgTypeArr" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
        <div v-if="msgList.length" style="overflow-y: hidden;">
          <div v-infinite-scroll="load" infinite-scroll-disabled="disabled"
               infinite-scroll-distance="10">
            <msg-notification-module :list="msgList" @clickInfo="getDetails" @del="handleDel">
            </msg-notification-module>
          </div>
          <p v-if="loading" class="loading-s">加载中...</p>
          <p v-if="noMore" class="loading-s">没有更多了</p>
        </div>
        <el-empty v-if="!msgList.length" description="暂无数据"></el-empty>
      </div>
    </el-dialog>
    <msg-info-dialog ref="msgInfoDialog" :dialogVisible.sync="msgInfoDialogVisible" title="消息详情"
                     @handleInventory="handleInventory" :operItem="operItem">
    </msg-info-dialog>
  </div>
</template>
 
<script>
import msgNotificationModule from '@/views/layout/module/msgNotificationModule.vue'
import msgInfoDialog from '@/views/layout/components/msgInfoDialog.vue'
import msgApi from '@/api/messages'
import msgTypeArr from '@/utils/constant/msgTypeArr'
export default {
  name: "msgNotificationDialog",
  components: {
    msgNotificationModule,
    msgInfoDialog
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      isShow: false,
      messageType: null,
      pages: 1,
      pageNum: 1,
      pageSize: 10,
      total: 0,
      msgList: [],//消息列表
      loading: false,
      operItem: {},//当前操作项
      msgInfoDialogVisible: false,//消息详情弹窗状态
      msgTypeArr: msgTypeArr,
    }
  },
  watch: {
    /**
     * 监控外部显示变量变化
     * 传递到dialog组件
     */
    dialogVisible: function (newShow, oldShow) {
      this.isShow = newShow
      if (this.isShow) {
        //获取站内消息列表
        this.queryData();
      }
    },
    /**
     * 监控内部显示属性变化
     * 传递到外部调用变量
     */
    isShow: function (newDialogShow, oldDialogShow) {
      this.$emit('update:dialogVisible', newDialogShow)
      if (!newDialogShow) {
        this.initData();
      }
    },
  },
  computed: {
    noMore() {
      return this.pageNum >= this.pages;
    },
    disabled() {
      return this.loading || this.noMore
    }
  },
  methods: {
    /**
     * 初始化数据
     */
    initData() {
      this.messageType = null;
      this.pageDataReset();
    },
    /**
      * 获取消息列表
      */
    async getMsgList() {
      const params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        messageType: this.messageType,
      }
      try {
        const res = await msgApi.getMsgList(params)
        const _data = res.data
        console.log(res)
        if (res.code === '0' && _data.list) {
          this.msgList = this.msgList.concat(_data.list)
          this.total = _data.total
          this.pages = _data.total > 0 ? Math.ceil(_data.total / this.pageSize) : 1
        }
      } catch (error) {
        this.isShow = false
        this.loading = false
      }
    },
    /**
     * 加载更多
     */
    load() {
      this.loading = true
      setTimeout(() => {
        this.pageNum += 1;
        this.getMsgList();
        this.loading = false
      }, 500)
    },
    /**
     * 查看详情
     */
    async getDetails(data) {
      this.operItem = data;
      console.log(this.getMenuIsExist('orderMgtList'));
      //消息状态为未读的情况下
      if (data.readFlag === '0') {
        this.setMsgStatus(data);
      }
      this.goPage(data);
    },
    /**
     * 根据消息类型实现不同页面跳转
     * 消息类型:1 商品推送,2 文章推送,3 系统消息,4 活动消息,5 账号通知 6 物流消息 7任务 8预警
     */
    goPage(obj) {
      const { messageType, promotionId, prodNo } = obj;
      switch (messageType) {
        case '6':
          if (this.getMenuIsExist('orderMgtList').length) {
            this.$router.push({ name: 'orderMgtList', query: { prodNo: prodNo } })
            this.updateDialogStatus(false);
          } else {
            this.$message.warning('您当前暂无分配权限,请联系管理员!')
          }
          break;
        case '7':
          this.msgInfoDialogVisible = true;
          break;
        case '8':
          if (this.getMenuIsExist('channelInventory').length) {
            this.$router.push({ name: 'channelInventory', query: { promotionId: promotionId } })
            this.updateDialogStatus(false);
          } else {
            this.$message.warning('您当前暂无分配权限,请联系管理员!')
          }
          break;
 
      }
    },
    /**
     * 更改消息状态为已读状态
     */
    getMenuIsExist(name) {
      return this.$store.state.userTreeFlat.filter(v => {
        return v.code === name
      })
    },
    /**
     * 更改消息状态为已读状态
     */
    async setMsgStatus(obj) {
      let params = {
        id: obj.id,
        promotionId: obj.promotionId
      }
      const res = await msgApi.updateMsgStatus(params)
      if (res.code === '0') {
        obj.readFlag = '1';
      }
    },
    /**
     * 删除消息
     */
    async handleDel(id) {
      let params = {
        id: id
      }
      const res = await msgApi.deleteRecord(params)
      if (res.code === '0') {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
        this.queryData();
      }
    },
    /**
     * 查询条件改变数据获取
     */
    queryData() {
      this.pageDataReset();
      this.getMsgList();
    },
    /**
      * 分页数据重置
      */
    pageDataReset() {
      this.total = 0;
      this.pageNum = 1;
      this.loading = false;
      this.msgList = [];
    },
    /**
      * 显示/隐藏loadding
      */
    updateDialogStatus(bool) {
      this.isShow = bool;
    },
    /**
      * 消息详情页----点击【去分配】
      */
    handleInventory() {
      if (this.getMenuIsExist('commodityStocks').length) {
        this.$router.push({ name: 'commodityStocks' })
        this.updateDialogStatus(false);
        this.msgInfoDialogVisible = false;
      } else {
        this.$message.warning('您当前暂无分配权限,请联系管理员!')
      }
    },
  },
}
</script>
 
<style lang="scss">
.msg-list {
  max-height: 500px;
  overflow: auto;
  padding: 0 15px;
  > span {
    font-size: 16px;
  }
}
.loading-s {
  text-align: center;
}
.msgNotificationDialog-style {
  .el-dialog__body {
    padding: 30px 10px !important;
  }
}
</style>