cloudroam
2024-12-31 701392dda8429b164e180e3004c235eea58604ca
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
<template>
  <el-bus-crud ref="curd" v-bind="tableConfig" />
</template>
 
<script>
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'
import SelectAllUser from '@/components/sms/select-all-user'
import CopyTextarea from '@/components/sms/copy-textarea'
import TemplateDownload from '@/components/sms/template-download'
export default {
  data() {
    const defaultDate = `${dayjs().format('YYYY-MM-DD')} 00:00:00`
    return {
      tableConfig: {
        url: 'flower/v2/sms-task/list',
        newUrl: 'flower/v2/sms-task/new',
        editUrl: 'flower/v2/sms-task/edit',
        viewUrl: 'flower/v2/sms-task',
        viewOnPath: true,
        deleteUrl: 'flower/v2/sms-task/delete',
        hasNew: true,
        newText: '添加发送任务',
        dialogNeedRequest: true,
        canEdit: (row) => row.status === 'wait_publish',
        canDelete: (row) => row.status === 'wait_publish',
        extraButtons: [
          {
            text: '发布',
            show: (row) => {
              return row.status === 'wait_publish';
            },
            atClick: async (row) => {
              try {
                await this.$elBusUtil.confirm('确定要发布吗?')
                const { code } = await this.$elBusHttp.request(
                  `flower/v2/sms-task/publish`,
                  {
                    method: 'post',
                    data: {
                      id: row.id,
                    }
                  }
                )
                if (code === 0) {
                  this.$message.success('发布成功')
                }
              } catch (e) {
                return false
              }
            },
          },
        ],
        onResetView: (row) => {
          // this.$router.push(`${this.$route.path}/${row.id}`)
          this.$router.push(`${this.$route.path}/${row.id}`)
         
          // const url = this.$router.resolve(
          //   `/sms/send-batch/${row.id}`
          // ).href
          // window.open(url, '_blank')
 
        },
        columns: [
          { label: '任务名称', prop: 'name' },
          { label: '模板名称', prop: 'smsTemplateName' },
          { label: '模板描述', prop: 'smsTemplateDesc' },
          { label: '任务状态', prop: 'statusStr' },
          { label: '创建时间', prop: 'createTime' },
        ],
        searchForm: [
          {
            type: 'row',
            items: [
              { label: '任务名称', id: 'name', type: 'input' },
              { label: '模板名称', id: 'smsTemplateName', type: 'input' },
              {
                label: '任务状态',
                id: 'status',
                type: 'bus-select-dict',
                el: {
                  code: 'SMS_TASK_STATUS',
                  multiple: false,
                  style: 'width:100%',
                },
              },
              {
                label: '创建时间',
                id: 'startDate',
                component: 'el-bus-date-range',
                el: {
                  clearable: true,
                },
                // commonFormat: true,
                // commonFormatProps: ['startDate', 'endDate'],
                inputFormat: (row) => {
                  if ('startDate' in row || 'endDate' in row) {
                    return [
                      this.$elBusUtil.toDate(row.startDate),
                      this.$elBusUtil.toDate(row.endDate),
                    ]
                  }
                },
                outputFormat: (val) => {
                  return {
                    startDate: val[0] ? `${this.$elBusUtil.toDate(val[0])} 00:00:00` : undefined,
                    endDate: val[1] ? `${this.$elBusUtil.toDate(val[1])} 23:59:59` : undefined,
                  }
                },
                customClass: 'in-bus-form',
                // commonRules: true,
                // default: [defaultDate, defaultDate],
              },
 
            ],
          },
        ],
        form: [
          {
            label: '任务名称',
            id: 'name',
            type: 'input',
            rules: {
              required: true,
              message: '请输入任务名称',
              trigger: 'blur',
            },
          },
          {
            label: '短信模板:',
            id: 'smsTemplateId',
            type: 'bus-select',
            el: {
              interfaceUri: 'flower/v2/sms-template/templateName/all',
              extraQuery: {
                current: 1,
                size: 2000,
              },
              props: {
                label: 'name',
                value: 'id',
                // dataPath: 'data',
              },
              filterable: true,
              multiple: false,
              style: 'width:100%',
            },
            rules: {
              required: true,
              message: '请选择短信模板',
              trigger: 'change',
            },
          },
          {
            label: '接收号码:',
            id: 'type',
            type: 'bus-radio',
            el: {
              code: 'SMS_RECEIVE_TYPE',
              // hasAll: false,
              // childType: 'el-radio-button',
            },
            str: true,
            on: {
              change: (e, updateForm, obj) => {
                // updateForm({
                //   // fileUrl: undefined,
                //   // fileUrlDesc: undefined,
                //   // pointCostomIdList: undefined,
                //   // input: undefined,
                // })
              },
            },
            default: this.$route.query.status || '',
            span: 24,
            searchImmediately: true,
            rules: {
              required: true,
              message: '请输入接收号码',
              trigger: 'change',
            },
          },
          {
            label: '导入接收文件',
            id: 'fileUrl',
            component: 'el-bus-upload',
            el: {
              // listType: 'text',
              accept: ".xls,.xlsx",
              limit: 1
            },
            commonFormat: true,
            forceDisabled: true,
            hidden: (row) => {
              return row.type !== 'IMPORT'
            },
            readonly: false,
            rules: [
              { required: true, message: '请上传文件' },
              {
                validator: (rule, value, callback) => {
                  if (!value || value.length > 1) {
                    callback(new Error('只能上传一个文件'));
                  } else {
                    callback();
                  }
                },
                trigger: 'change',
              },
            ],
            // outputFormat: (val) => {
            //   console.log(val)
            //   return '';
            // },
          },
          {
            label: '',
            id: 'fileUrlDesc',
            component: TemplateDownload,
            hidden: (row) => row.type !== 'IMPORT',
          },
          {
            label: '手动输入:',
            id: 'phones',
            component: CopyTextarea,
            el: {
              type: 'textarea',
            },
            // hidden: (row) => row.discountType !== 'ratio',
            hidden: (row) => row.type !== 'INPUT',
            readonly: false,
            span: 24,
            rules: [
              { required: true, message: '请输入号码', trigger: 'blur,change', },
              // {
              //   validator: (rule, value, callback) => {
              //     // 如果值为空,直接返回错误
              //     if (!value || value.trim() === '') {
              //       callback(new Error('请输入电话号码,每个号码后跟换行符'));
              //       return;
              //     }
 
              //     // 正则表达式:只匹配中国大陆手机号格式
              //     const phoneRegex = /^1[3-9]\d{9}$/;
              //     const lines = value.split('\n'); // 按换行符分割文本
 
              //     // 遍历每一行并校验
              //     for (let i = 0; i < lines.length; i++) {
              //       const line = lines[i]; // 每一行去除空格
              //       if (line && !phoneRegex.test(line)) {
              //         // 如果当前行的电话号码格式不正确,提示出错的行号
              //         callback(new Error(`第 ${i + 1} 行电话号码格式不正确,请检查输入, 如 电话号码后面有空格等`));
              //         return; // 一旦发现不符合的号码格式,就终止校验
              //       }
              //     }
 
              //     if(lines.length>100){
              //       callback(new Error(`手动输入最多支持100个号码`));
              //     }
 
              //     // 所有行都符合格式,执行 callback()
              //     callback();
              //   },
              //   trigger: 'blur',
              // }
              {
                validator: (rule, value, callback) => {
                  // 如果值为空,直接返回错误
                  if (!value || value.trim() === '') {
                    callback(new Error('请输入电话号码,每个号码后跟换行符'));
                    return;
                  }
 
 
 
                  const phoneRegex = /^1[3-9]\d{9}$/; // 校验手机号格式
                  const lines = value.split('\n'); // 按换行符分割文本
                  const phoneCount = {}; // 用来统计电话号码出现次数
 
                  if (lines.length > 100) {
                    callback(new Error(`手动输入最多支持100个号码`));
                  }
 
                  // 校验每一行的电话号码
                  for (let i = 0; i < lines.length; i++) {
                    const line = lines[i].trim();
                    if (line) {
                      // 如果当前行不是空的,校验其格式
                      if (!phoneRegex.test(line)) {
                        callback(new Error(`第 ${i + 1} 行电话号码格式不正确,请检查输入`));
                        return;
                      }
 
                      // 统计号码出现的次数
                      phoneCount[line] = (phoneCount[line] || 0) + 1;
                    }
                  }
 
 
                  // 收集所有重复的电话号码
                  const duplicates = [];
                  for (const phone in phoneCount) {
                    if (phoneCount[phone] > 1) {
                      duplicates.push(`${phone} 重复了 ${phoneCount[phone]} 次`);
                    }
                  }
 
 
                  // 如果有重复号码,返回错误并列出所有重复的号码
                  if (duplicates.length > 0) {
                    callback(new Error(`以下电话号码重复:\n${duplicates.join('\n')}`));
                    return;
                  }
 
                  // 校验通过
                  callback();
                },
                trigger: 'blur',
              }
 
            ],
 
          },
 
          {
            label: '选择用户列表',
            id: 'smsUserDTOS',
            component: SelectAllUser,
            hidden: (row) => row.type !== 'SELECT',
            rules: { required: true, message: '请选择领取用户' },
            inputFormat: (row) => {
              if ('smsUserDTOS' in row && row.smsUserDTOS && row.smsUserDTOS.length>0) {
                return row.smsUserDTOS.filter((i) => i)
              }
            },
            outputFormat: (val) => {
             return val?.length ? val.map((i) => {return {userId:i.userId,userPhone:i.tel} }) : []
 
            },
            forceDisabled: true,
          },
        ],
      },
    }
  },
  head() {
    return {
      title: '批量发送短信',
    }
  },
 
}
</script>