peng
5 小时以前 b2ab3de804425caf06d49f0eeb743b2e703bf311
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
<template>
  <div>
    <!--微信模板-->
    <Modal v-model="wechatModal" width="530">
      <p slot="header">
        <Icon type="edit"></Icon>
        <span>微信设置</span>
      </p>
      <div>
        <Form ref="wechatFormData" :model="wechatFormData" label-position="left" :label-width="100">
          <FormItem v-if="tab === 'WECHAT'" label="模板名称">
            <Input v-model="wechatFormData.name" size="large" maxlength="9" disabled></Input>
          </FormItem>
          <FormItem v-if="tab === 'WECHAT'" label="头部信息" prop="first">
            <Input v-model="wechatFormData.first" size="large" maxlength="50"></Input>
          </FormItem>
          <FormItem v-if="tab === 'WECHAT'" label="备注" prop="remark">
            <Input class='textarea' :rows="5" :autosize="{maxRows:5,minRows: 5}" v-model="wechatFormData.remark"
                   type="textarea" maxlength="150"/>
          </FormItem>
          <FormItem label="是否开启" prop="enable">
            <i-switch v-model="wechatFormData.enable" size="large">
              <span slot="open">开启</span>
              <span slot="close">关闭</span>
            </i-switch>
          </FormItem>
        </Form>
 
      </div>
      <div slot="footer" style="text-align: right">
        <Button v-if="tab === 'WECHAT'"  type="primary"  @click="wechatFormDataEdit">保存</Button>
 
        <Button v-else  type="primary" @click="wechatMPFormDataEdit">保存</Button>
      </div>
    </Modal>
 
  <Card>
    <Tabs @on-click="tabPaneChange" v-model="tab">
      <TabPane label="微信消息" name="WECHAT">
        <div class="search">
            <Row class="operation mt_10">
              <Button @click="weChatSync" type="primary">初始化微信消息</Button>
            </Row>
            <Table
              :loading="loading"
              border
              :columns="weChatColumns"
              :data="weChatData"
              ref="weChatTable"
            ></Table>
            <Row type="flex" justify="end" class="mt_10">
              <Page
                :current="weChatSearchForm.pageNumber"
                :total="weChatTotal"
                :page-size="weChatSearchForm.pageSize"
                @on-change="changePage"
                @on-page-size-change="changePageSize"
                :page-size-opts="[10,20,50]"
                size="small"
              ></Page>
            </Row>
        </div>
      </TabPane>
 
      <TabPane label="微信小程序订阅消息" name="WECHATMP">
        <div class="search">
            <Row class="operation mt_10">
              <Button @click="weChatSync('mp')" type="primary">初始化微信小程序订阅消息</Button>
            </Row>
            <Table
              :loading="loading"
              border
              :columns="weChatColumns"
              :data="weChatMPData"
              sortable="custom"
              ref="weChatMPTable"
            ></Table>
            <Row type="flex" justify="end" class="mt_10">
              <Page
                :current="weChatMPSearchForm.pageNumber"
                :total="weChatMPTotal"
                :page-size="weChatMPSearchForm.pageSize"
                @on-change="changePage"
                @on-page-size-change="changePageSize"
                :page-size-opts="[10,20,50]"
                size="small"
              ></Page>
            </Row>
        </div>
      </TabPane>
    </Tabs>
     </Card>
  </div>
 
 
</template>
 
<script>
import {
  wechatMessageSync,
  getWechatMessagePage,
  editWechatMessageTemplate,
  delWechatMessageTemplate,
 
  wechatMPMessageSync,
  getWechatMPMessagePage,
  editWechatMPMessageTemplate,
  delWechatMPMessageTemplate
} from "@/api/setting";
 
export default {
  title: "wechat-message-manage",
  data() {
    return {
 
      wechatModal: false,// modal展示
      wechatFormData: {}, // 微信数据
      wechatMPFormData: {}, // 微信订阅消息
      tab: "WECHAT", // tab栏分类
      searchForm: { // 请求参数
        type: "WECHAT"
      },
      loading: true, // 表单加载状态
      id: '', // 模板id
      //微信消息查询
      weChatSearchForm: {
        // 搜索框对应data对象
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
      },
      weChatMPSearchForm: {
        // 搜索框对应data对象
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
      },
      weChatColumns: [
        {
          title: "模板编号",
          key: "code",
          width: 500,
          sortable: true
        },
        {
          title: "是否开启",
          key: "enable",
          sortable: true,
          width: 150,
          render: (h, params) => {
            if (params.row.enable == true) {
              return h('div', [
                h('span', {}, '开启'),
              ]);
            } else {
              return h('div', [
                h('span', {}, '关闭'),
              ]);
            }
          },
        },
        {
          title: "模板名称",
          key: "name",
          width: 200,
          sortable: true
        },
        {
          title: "创建时间",
          key: "createTime",
          sortable: true,
          sortType: "desc",
        },
        {
          title: "操作",
          key: "action",
          width: 200,
          align: "center",
          fixed: "right",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.wechatSettingAlert(params.row);
                    }
                  }
                },
                "编辑"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.delWeChat(params.row);
                    }
                  }
                },
                "删除"
              )
            ]);
          }
        }
      ],
      weChatData: [], // 表单数据
      weChatMPData: [], // 表单数据
      weChatTotal: 0, // 表单数据总数
      weChatMPTotal: 0, // 表单数据总数
    };
  },
  methods: {
    // 初始化数据
    init() {
      this.getDataList();
    },
    changePage(v) {
      this.searchForm.type = this.tab;
      this.getDataList();
    },
    changePageSize(v) {
      this.searchForm.type = this.tab;
      this.getDataList();
    },
    //微信弹出框
    wechatSettingAlert(v) {
      this.wechatFormData = v
      this.id = v.id
      this.wechatModal = true
    },
 
    //同步微信消息
    weChatSync(mp) {
      this.$Modal.confirm({
        title: "提示",
        // 记得确认修改此处
        content: "确认要初始化微信小程序消息订阅?",
        loading: true,
        onOk: () => {
          // 同步微信消息模板
 
          if (mp === "mp") {
            wechatMPMessageSync().then(res => {
              this.$Modal.remove();
              if (res.success) {
                this.$Message.success('微信小程序消息订阅初始化');
              }
            });
          } else {
            // 同步微信消息模板
            wechatMessageSync().then(res => {
              this.$Modal.remove();
              if (res.success) {
                this.$Message.success('微信消息模板初始化成功');
              }
            });
          }
        }
      });
    },
    //微信设置保存
    wechatFormDataEdit() {
      this.$refs['wechatFormData'].validate((valid) => {
        if (valid) {
          if(!this.wechatFormData.updateTime){
            this.wechatFormData.updateTime = ''
          }
          editWechatMessageTemplate(this.id, this.wechatFormData).then(res => {
            if (res.message === 'success') {
              this.$Message.success('微信模板修改成功');
              this.wechatModal = false;
              this.getWechatMessagePage();
            }
          });
        }
      })
    },
    wechatMPFormDataEdit() {
      this.$refs['wechatFormData'].validate((valid) => {
        if (valid) {
          editWechatMPMessageTemplate(this.id, this.wechatMPFormData).then(res => {
            if (res.message === 'success') {
              this.$Message.success('微信消息订阅模板修改成功');
              this.wechatModal = false;
              this.getWechatMessagePage();
            }
          });
        }
      })
    },
 
    //删除微信模消息
    delWeChat(v) {
      this.$Modal.confirm({
        title: "提示",
        content: "确定删除此模板?",
        loading: true,
        onOk: () => {
          // 删除微信消息模板
          if (this.tab === "WECHAT") {
            delWechatMessageTemplate(v.id).then(res => {
              if (res.success) {
                this.$Modal.remove();
                this.$Message.success('微信模板删除成功');
                this.getWechatMessagePage()
              }
            });
          } else {
            delWechatMPMessageTemplate(v.id).then(res => {
              if (res.success) {
                this.$Modal.remove();
                this.$Message.success('微信消息订阅删除成功');
                this.getWechatMessagePage()
              }
            });
          }
        }
      });
 
    },
    selectDateRange(v) {
      if (v) {
        this.searchForm.startDate = v[0];
        this.searchForm.endDate = v[1];
      }
    },
    getDataList() {
      this.loading = true;
      getWechatMessagePage(this.searchWe).then(res => {
        this.loading = false;
        if (res.success) {
          this.weChatData = res.result.records;
          this.weChatTotal = res.result.total;
        }
      });
    },
    //分页获取微信消息
    getWechatMessagePage() {
      getWechatMessagePage(this.weChatSearchForm).then(res => {
        this.loading = false;
        if (res.success) {
          this.weChatData = res.result.records;
          this.weChatTotal = res.result.total;
        }
      });
    },
    //分页获取微信小程序消息订阅
    getWechatMPMessagePage() {
      getWechatMPMessagePage(this.weChatMPSearchForm).then(res => {
        this.loading = false;
        if (res.success) {
          this.weChatMPData = res.result.records;
          this.weChatMPTotal = res.result.total;
        }
      });
    },
    //tab切换事件
    tabPaneChange(v) {
      this.searchForm.type = v;
      //如果是微信消息则走单独的接口
      if (v === "WECHAT") {
        this.getWechatMessagePage();
      } else if (v === "WECHATMP") {
        this.getWechatMPMessagePage();
      }
 
    }
  },
  mounted() {
    this.init();
  }
};
</script>