Bladeren bron

短信发送

庄逸洲 5 jaren geleden
bovenliggende
commit
4bb02d1605

+ 57 - 0
src/api/sms/index.js Bestand weergeven

@@ -8,4 +8,61 @@ export function fetchBatchSendRecords(page) {
8 8
             page: page,
9 9
         }
10 10
     })
11
+}
12
+
13
+export function sendsInitData(action, id) {
14
+    var param = {}
15
+    if (action != null && action != undefined) {
16
+        param.action = action
17
+    }
18
+    if (id != null && id != undefined) {
19
+        param.id = id
20
+    }
21
+    return request({
22
+        url: "/api/sms/sendinit",
23
+        method: "get",
24
+        params: param,
25
+    })
26
+}
27
+
28
+export function tagFilterCustomerCount(tag_ids_str) {
29
+    return request({
30
+        url: "/api/sms/tagfiltercount",
31
+        method: "get",
32
+        params: {
33
+            tags: tag_ids_str,
34
+        },
35
+    })
36
+}
37
+
38
+export function send2AllCustomers(content) {
39
+    return request({
40
+        url: "/api/sms/send2all",
41
+        method: "post",
42
+        param: {
43
+            content: content,
44
+        }
45
+    })
46
+}
47
+
48
+export function send2TagCustomers(content, tag_ids) {
49
+    return request({
50
+        url: "/api/sms/send2tag",
51
+        method: "post",
52
+        param: {
53
+            content: content,
54
+            tags: tag_ids,
55
+        }
56
+    })
57
+}
58
+
59
+export function send2SpecificCustomers(content, customer_ids) {
60
+    return request({
61
+        url: "/api/sms/send2specific",
62
+        method: "post",
63
+        param: {
64
+            content: content,
65
+            ids: customer_ids,
66
+        }
67
+    })
11 68
 }

+ 4 - 1
src/scrm_pages/marketing_tool/activity_share.vue Bestand weergeven

@@ -24,7 +24,7 @@
24 24
                     <p class="desc">以短信方式推送给客户</p>
25 25
                 </div>
26 26
                 <div class="btn-panel">
27
-                    <el-button type="primary">短信推送</el-button>
27
+                    <el-button type="primary" @click="smsAction">短信推送</el-button>
28 28
                 </div>
29 29
             </div>
30 30
             <div class="link-share-panel">
@@ -114,6 +114,9 @@ export default {
114 114
             document.body.removeChild(input);
115 115
 
116 116
             this.$message.success("已复制链接")
117
+        },
118
+        smsAction: function() {
119
+            this.$router.push({ path: "/sms/send", query: { action: 1, id: this.activity_id } })
117 120
         }
118 121
     },
119 122
 }

+ 0 - 8
src/scrm_pages/sms/sms_manage.vue Bestand weergeven

@@ -81,14 +81,6 @@ export default {
81 81
             })
82 82
         },
83 83
         sendAction: function() {
84
-            // var targets = [
85
-            //     { id: 1, name: "会员1", mobile: "12346789098" },
86
-            //     { id: 2, name: "会员2", mobile: "12346789098" },
87
-            //     { id: 3, name: "会员3", mobile: "12346789098" },
88
-            //     { id: 4, name: "会员4", mobile: "12346789098" },
89
-            //     { id: 5, name: "会员5", mobile: "12346789098" },
90
-            // ]
91
-            // this.$store.dispatch("SMSSetTargets", targets)
92 84
             this.$router.push({path:'/sms/send'})
93 85
         },
94 86
 

+ 177 - 10
src/scrm_pages/sms/sms_send.vue Bestand weergeven

@@ -1,5 +1,5 @@
1 1
 <template>
2
-    <div class="main-contain">
2
+    <div class="main-contain" v-loading="sending">
3 3
         <div class="position">
4 4
             <bread-crumb :crumbs="crumbs"></bread-crumb>
5 5
         </div>
@@ -30,7 +30,7 @@
30 30
                     </div>
31 31
                     <div class="form-content">
32 32
                         <div class="input-panel">
33
-                            <el-input v-model="sms_content" type="textarea" :rows="4" resize="none"></el-input>
33
+                            <el-input v-model="sms_content" type="textarea" :rows="4" resize="none" maxlength="500"></el-input>
34 34
                             <div class="hint-text">已输入{{ total_content_length }}字(含签名和尾缀)按{{ sms_charge_count }}条短信计费</div>
35 35
                         </div>
36 36
                         <div v-if="designated_targets.length == 0" class="filters-panel">
@@ -40,7 +40,7 @@
40 40
                                     <p class="desc">将该短信推送给系统里的所有客户</p>
41 41
                                 </div>
42 42
                                 <div class="btn">
43
-                                    <el-button type="primary">发送</el-button>
43
+                                    <el-button type="primary" @click="sendToAllCustomersAction">发送</el-button>
44 44
                                 </div>
45 45
                             </div>
46 46
                             <div class="tag-filter-panel">
@@ -48,14 +48,14 @@
48 48
                                 <p class="desc">将该短信推送给相应标签客户</p>
49 49
                                 <div class="tag-panel">
50 50
                                     <div v-for="(tag, index) in tags" class="item-panel" :key="index">
51
-                                        <el-tag effect="plain">{{ tag.name }}</el-tag>
51
+                                        <el-tag :effect="tagEffect(tag)" @click="selectTagAction(tag)" @close="cancelSelectTagAction(tag)" :closable="isTagSelected(tag)">{{ tag.tag_name }}</el-tag>
52 52
                                     </div>
53 53
                                 </div>
54 54
                                 <p class="hint-text">*选择标签发送可以帮助您精准营销</p>
55 55
                                 <div class="send">
56 56
                                     <p class="text">已为您筛选 {{ tag_filtered_count }} 位客户</p>
57 57
                                     <div class="btn">
58
-                                        <el-button type="primary">发送</el-button>
58
+                                        <el-button type="primary" @click="sendToTagCustomersAction">发送</el-button>
59 59
                                     </div>
60 60
                                 </div>
61 61
                             </div>
@@ -66,7 +66,7 @@
66 66
                                     推送指定客户
67 67
                                 </div>
68 68
                                 <div class="btn">
69
-                                    <el-button type="primary">发送</el-button>
69
+                                    <el-button type="primary" @click="sendToDesignatedCustomersAction">发送</el-button>
70 70
                                 </div>
71 71
                             </div>
72 72
                             <el-table :data="designated_targets" border max-height="500px">
@@ -83,6 +83,7 @@
83 83
 
84 84
 <script>
85 85
 import BreadCrumb from "@/scrm_pages/components/bread-crumb"
86
+import { sendsInitData, tagFilterCustomerCount, send2AllCustomers, send2TagCustomers, send2SpecificCustomers } from "@/api/sms"
86 87
 
87 88
 export default {
88 89
     name: "SMSSend",
@@ -96,9 +97,14 @@ export default {
96 97
                 { path: false, name: "群发短信" },
97 98
             ],
98 99
 
100
+            sending: false,
99 101
             sms_content: "",
100 102
             tags: [],
103
+            selecting_tags: [],
104
+            tag_filtered_count: 0,
101 105
 
106
+            action: 0,
107
+            id: 0,
102 108
             designated_targets: [],
103 109
         }
104 110
     },
@@ -112,13 +118,173 @@ export default {
112 118
         sms_charge_count: function() {
113 119
             return parseInt(Math.ceil(this.total_content_length / 67.0))
114 120
         },
115
-        tag_filtered_count: function() {
116
-            return 0
117
-        },
118 121
     },
119 122
     mounted() {
120 123
         this.designated_targets = this.$store.getters.sms_designated_targets.targets
121
-        this.$store.dispatch("SMSClearTargets")
124
+        if (this.designated_targets.length > 0) {
125
+            this.$store.dispatch("SMSClearTargets")
126
+        } else {
127
+            var action = this.$route.query.action
128
+            var id = this.$route.query.id
129
+            if (action != undefined && id != undefined) {
130
+                this.action = action
131
+                this.id = id
132
+            }
133
+
134
+            this.getInitData()
135
+        }
136
+    },
137
+    methods: {
138
+        getInitData: function() {
139
+            sendsInitData(this.action, this.id).then(rs => {
140
+                var resp = rs.data
141
+                if (resp.state == 1) {
142
+                    this.tags = resp.data.tags
143
+                    this.sms_content = resp.data.default_content
144
+
145
+                } else {
146
+                    this.$message.error(resp.msg)
147
+                }
148
+
149
+            }).catch(err => {
150
+                this.$message.error(err)
151
+            })
152
+        },
153
+        getTagCustomerCount: function() {
154
+            var tag_ids = []
155
+            for (let index = 0; index < this.selecting_tags.length; index++) {
156
+                tag_ids.push(this.selecting_tags[index].id)
157
+            }
158
+            if (tag_ids.length == 0) {
159
+                this.tag_filtered_count = 0
160
+                return
161
+            }
162
+            tagFilterCustomerCount(tag_ids.join(",")).then(rs => {
163
+                var resp = rs.data
164
+                if (resp.state == 1) {
165
+                    this.tag_filtered_count = resp.data.count
166
+                } else {
167
+                    console.log(resp.msg)
168
+                }
169
+            }).catch(err => {
170
+                console.log(err)
171
+            })
172
+        },
173
+
174
+        tagEffect: function(tag) {
175
+            if (this.isTagSelected(tag)) {
176
+                return "dark"
177
+            } else {
178
+                return "plain"
179
+            }
180
+        },
181
+        isTagSelected: function(tag) {
182
+            for (let index = 0; index < this.selecting_tags.length; index++) {
183
+                if (this.selecting_tags[index].id == tag.id) {
184
+                    return true
185
+                }
186
+            }
187
+            return false
188
+        },
189
+        selectTagAction: function(tag) {
190
+            if (!this.isTagSelected(tag)) {
191
+                this.selecting_tags.push(tag)
192
+                this.getTagCustomerCount()
193
+            }
194
+        },
195
+        cancelSelectTagAction: function(tag) {
196
+            for (let index = 0; index < this.selecting_tags.length; index++) {
197
+                if (this.selecting_tags[index].id == tag.id) {
198
+                    this.selecting_tags.splice(index, 1)
199
+                    this.getTagCustomerCount()
200
+                    break
201
+                }
202
+            }
203
+        },
204
+
205
+        isSMSContentValid: function() {
206
+            if (this.sms_content.length == 0) {
207
+                this.$message.error("请编辑短信内容")
208
+                return false
209
+            }
210
+            if (this.sms_content.indexOf("【") >= 0 || this.sms_content.indexOf("】") >= 0) {
211
+                this.$message.error("短信内容不得包含【】")
212
+                return false
213
+            }
214
+            return true
215
+        },
216
+        sendToAllCustomersAction: function() {
217
+            if (!this.isSMSContentValid()) {
218
+                return
219
+            }
220
+            this.sending = true
221
+            send2AllCustomers(this.sms_content).then(rs => {
222
+                this.sending = false
223
+                var resp = rs.data
224
+                if (resp.state == 1) {
225
+                    this.$message.success("发送成功")
226
+                } else {
227
+                    this.$message.error(resp.msg)
228
+                }
229
+
230
+            }).catch(err => {
231
+                this.sending = false
232
+                this.$message.error(err)
233
+            })
234
+        },
235
+        sendToTagCustomersAction: function() {
236
+            if (!this.isSMSContentValid()) {
237
+                return
238
+            }
239
+            if (this.selecting_tags.length == 0) {
240
+                this.$message.error("请选择标签")
241
+                return
242
+            }
243
+
244
+            var tag_ids = []
245
+            for (let index = 0; index < this.selecting_tags.length; index++) {
246
+                tag_ids.push(this.selecting_tags[index].id)
247
+            }
248
+
249
+            this.sending = true
250
+            send2TagCustomers(this.sms_content, tag_ids.join(",")).then(rs => {
251
+                this.sending = false
252
+                var resp = rs.data
253
+                if (resp.state == 1) {
254
+                    this.$message.success("发送成功")
255
+                } else {
256
+                    this.$message.error(resp.msg)
257
+                }
258
+
259
+            }).catch(err => {
260
+                this.sending = false
261
+                this.$message.error(err)
262
+            })
263
+        },
264
+        sendToDesignatedCustomersAction: function() {
265
+            if (!this.isSMSContentValid()) {
266
+                return
267
+            }
268
+            var customer_ids = []
269
+            for (let index = 0; index < this.designated_targets.length; index++) {
270
+                customer_ids.push(this.designated_targets[index].id)
271
+            }
272
+
273
+            this.sending = true
274
+            send2SpecificCustomers(this.sms_content, customer_ids.join(",")).then(rs => {
275
+                this.sending = false
276
+                var resp = rs.data
277
+                if (resp.state == 1) {
278
+                    this.$message.success("发送成功")
279
+                } else {
280
+                    this.$message.error(resp.msg)
281
+                }
282
+
283
+            }).catch(err => {
284
+                this.sending = false
285
+                this.$message.error(err)
286
+            })
287
+        },
122 288
     },
123 289
 }
124 290
 </script>
@@ -302,6 +468,7 @@ export default {
302 468
                         .item-panel {
303 469
                             display: inline-block;
304 470
                             margin-bottom: 5px;
471
+                            margin-right: 5px;
305 472
                         }
306 473
                     }
307 474
                     .hint-text {

+ 1 - 1
src/store/modules/sms_designated_targets.js Bestand weergeven

@@ -1,6 +1,6 @@
1 1
 const sms_designated_targets = {
2 2
     state: {
3
-        targets: [],
3
+        targets: [ /* { id, name, mobile } */ ],
4 4
     },
5 5
     mutations: {
6 6
         SET_TARGETS: (state, targets) => {