天波用户运营管理后台系统
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

400 行
12KB

  1. <!--
  2. * @Date: 2022-08-08 10:09:47
  3. * @LastEditors: JinxChen
  4. * @LastEditTime: 2022-09-20 09:20:19
  5. * @FilePath: \TelpoUserManageAdmin\src\views\message-manage\main\add-mass\index.vue
  6. * @description: 添加群发
  7. -->
  8. <template>
  9. <div class="home-container">
  10. <div class="form-container">
  11. <!-- 表单 -->
  12. <el-form ref="form" :model="form" label-width="100px" :rules="rules">
  13. <el-form-item label="消息主题:" size="small" prop="subject">
  14. <el-input v-model="form.subject" class="input-width-400" clearable ></el-input>
  15. </el-form-item>
  16. <el-form-item label="内容模板:" size="small" required>
  17. <el-form-item prop="first">
  18. <p>{{firstData}}</p>
  19. <el-input v-model="form.first" class="input-width-600" clearable prop="first"></el-input>
  20. </el-form-item>
  21. <el-form-item prop="keyword1">
  22. <p>消息类别{{keyword1Data}}</p>
  23. <el-input v-model="form.keyword1" class="input-width-400" clearable prop="keyword1"></el-input>
  24. </el-form-item>
  25. <el-form-item prop="keyword2">
  26. <p>通知用户{{keyword2Data}}</p>
  27. <el-input v-model="form.keyword2" class="input-width-400" clearable prop="keyword1"></el-input>
  28. </el-form-item>
  29. <el-form-item prop="keyword3">
  30. <p>通知内容{{keyword3Data}}</p>
  31. <el-input v-model="form.keyword3" class="input-width-600" clearable prop="keyword1"></el-input>
  32. </el-form-item>
  33. <el-form-item prop="remark">
  34. <p>{{remarkData}}</p>
  35. <el-input v-model="form.remark" class="input-width-600" clearable prop="remark"></el-input>
  36. </el-form-item>
  37. </el-form-item>
  38. <el-form-item label="内容链接:" size="small" class="inline-form-item" prop="articleContent" required>
  39. <el-form-item prop="remark">
  40. <el-input v-model="form.articleContent" placeholder="请选择文章或者输入外部URL" class="input-width-400"></el-input>
  41. <el-select v-model="article" placeholder="选择文章" clearable filterable @change="onSelectArt">
  42. <el-option :label="item.label" :value="item.value" v-for="(item, index) in articleList" :key="index"/>
  43. </el-select>
  44. </el-form-item>
  45. </el-form-item>
  46. <el-form-item label="群发对象:" size="small" prop="selfGroupId">
  47. <el-select v-model="form.selfGroupId" placeholder="选择分组" clearable filterable @change="onSelectMass">
  48. <el-option :label="item.label" :value="item.value" v-for="(item, index) in groupList" :key="index"/>
  49. </el-select>
  50. <el-button type="primary" @click="onCheckList" disabled>查看名单</el-button>
  51. </el-form-item>
  52. <div class="footer-container">
  53. <el-button type="primary" v-for="(item, index) in footBtnList" :key="index" @click="item.click">{{item.name}}</el-button>
  54. </div>
  55. </el-form>
  56. </div>
  57. <!-- 底部操作按钮 -->
  58. <!-- 预览dialog -->
  59. <el-dialog title="预览信息" :visible.sync="previewShow">
  60. <div class="preview-container">
  61. <div class="top">
  62. <p>{{form.first}}</p>
  63. <p>消息类别:{{form.keyword1}}</p>
  64. <p>通知用户:{{form.keyword2}}</p>
  65. <p>通知内容:{{form.keyword3}}</p>
  66. <p>更新时间:{{initUpdateTime}}</p>
  67. </div>
  68. <div class="fot">
  69. <p>{{form.remark}}</p>
  70. <p>></p>
  71. </div>
  72. </div>
  73. <div class="preview-btn">
  74. <el-button type="primary" @click="onConfirm">确认</el-button>
  75. </div>
  76. </el-dialog>
  77. </div>
  78. </template>
  79. <script>
  80. //import TopMenu from "@/components/TopMenu/index";
  81. import { initTime } from '@/utils/index.js';
  82. import { APIWechatFans } from '@/api/wechat-fans.js';
  83. /* import './index.scss' */
  84. export default {
  85. name: 'add-mass',
  86. components: { },
  87. data(){
  88. return {
  89. buttonList: [], // 头部按钮,例子: {name: '添加', type: 'primary', icon: 'el-icon-circle-plus', click: () => { this.AddDialog();}}
  90. firstData: '{{first.DATA}}:',
  91. keyword1Data: '{{keyword1DATA}}:',
  92. keyword2Data: '{{keyword2DATA}}:',
  93. keyword3Data: '{{keyword3DATA}}:',
  94. remarkData: '{{remarkDATA}}:',
  95. form: {
  96. subject: '' /* || '财商学习通知' */, //发送主题
  97. templateId: 1, //模板id
  98. articleContent: '', //文章内容
  99. articleId: '', //文章id
  100. selfGroupId: '', //分组id
  101. first: '' /* || '家长您好,您孩子所需的财商学习内容有更新' */, //内容模板标题
  102. keyword1: '' /* || 'csds' */, //学习账号
  103. keyword2: '' /* || '财商36问' */, //更新内容
  104. keyword3: '',
  105. remark: '' /* || '请点击内容查看详情' */, //内容详情
  106. },
  107. article: '', //选择文章
  108. // 文章列表
  109. articleList: [],
  110. // 用户分组
  111. groupList: [],
  112. // 底部操作按钮
  113. footBtnList: [
  114. { name: '立即发送', click: () => { this.onSend()}},
  115. { name: '保存', click: () => { this.onSave()} },
  116. { name: '预览', click: () => { this.onPreview()} },
  117. ],
  118. // 预览dialog
  119. previewShow: false,
  120. // form验证
  121. rules: {
  122. subject: [
  123. { required: true, message: '请输入消息主题', trigger: 'blur' },
  124. ],
  125. first: [
  126. { required: true, message: '请填写消息模板内容', trigger: 'blur' },
  127. ],
  128. keyword1: [
  129. { required: true, message: '请填写消息模板内容', trigger: 'blur' },
  130. ],
  131. keyword2: [
  132. { required: true, message: '请填写消息模板内容', trigger: 'blur' },
  133. ],
  134. keyword3: [
  135. { required: true, message: '请填写消息模板内容', trigger: 'blur' },
  136. ],
  137. remark: [
  138. { required: true, message: '请填写消息模板内容', trigger: 'blur' },
  139. ],
  140. messageSubject: [
  141. { required: true, message: '请填写消息模板内容', trigger: 'blur' },
  142. ],
  143. articleContent: [
  144. { required: true, message: '请选择文章获取填写外部URL', trigger: 'blur' },
  145. ],
  146. selfGroupId: [
  147. { required: true, message: '请选择群发分组', trigger: 'blur' },
  148. ],
  149. }
  150. }
  151. },
  152. computed: {
  153. // 初始弹窗更新时间
  154. initUpdateTime() {
  155. return initTime(new Date(), 'ymdhm'); //更新时间
  156. }
  157. },
  158. activated() {
  159. this.getSelfGroups();
  160. this.getArticlesGroup();
  161. },
  162. mounted() {
  163. },
  164. created() {
  165. this.getSelfGroups();
  166. this.getArticlesGroup();
  167. },
  168. methods: {
  169. // 获取自定义分组
  170. getSelfGroups() {
  171. let reqBody = {
  172. page_index: 1,
  173. page_size: 10
  174. }
  175. APIWechatFans.SelfGroups(reqBody)
  176. .then(res => {
  177. let data = res.data;
  178. this.groupList = data.rows.map(item => {
  179. return {
  180. label: item.name,
  181. value: item.id
  182. }
  183. })
  184. console.log("data", data);
  185. })
  186. },
  187. // 获取文章列表
  188. getArticlesGroup() {
  189. let reqBody = {
  190. page_index: 1,
  191. page_size: 100000
  192. }
  193. APIWechatFans.getArticlesGroup(reqBody)
  194. .then(res => {
  195. let data = res.data;
  196. console.log("文章data", data);
  197. this.articleList = data.rows.map(item => {
  198. return {
  199. label: item.title,
  200. value: item.id
  201. }
  202. })
  203. })
  204. },
  205. // 查看白名单
  206. onCheckList() {},
  207. // 立即发送
  208. onSend() {
  209. // 拼接所需字段
  210. let keywordStr = this.form.keyword1 + ',' + this.form.keyword2 + ',' + this.form.keyword3;
  211. let reqBody = {
  212. send_now: true, //true 是立即发送, false是保存
  213. subject: this.form.subject,
  214. template_id: '1',
  215. self_group_id: this.form.selfGroupId,
  216. article_id: this.form.articleId || 0,
  217. first: this.form.first,
  218. remark: this.form.remark,
  219. keyword: keywordStr,
  220. url: this.form.articleContent
  221. };
  222. this.$refs['form'].validate((valid) => {
  223. if(valid) {
  224. this.addGroupSender(reqBody, '群发');
  225. } else {
  226. this.$message({
  227. type: "error",
  228. message: "请完善群发消息"
  229. });
  230. }
  231. });
  232. //this.addGroupSender(reqBody);
  233. },
  234. // 保存
  235. onSave() {
  236. // 拼接所需字段
  237. let keywordStr = this.form.keyword1 + ',' + this.form.keyword2 + ',' + this.form.keyword3;
  238. let reqBody = {
  239. send_now: false, //true 是立即发送, false是保存
  240. subject: this.form.subject,
  241. template_id: '1',
  242. self_group_id: this.form.selfGroupId,
  243. article_id: this.form.articleId || 0,
  244. first: this.form.first,
  245. remark: this.form.remark,
  246. keyword: keywordStr,
  247. url: this.form.articleContent
  248. };
  249. this.$refs['form'].validate((valid) => {
  250. if(valid) {
  251. this.addGroupSender(reqBody, '保存');
  252. } else {
  253. this.$message({
  254. type: "error",
  255. message: "请完善群发消息"
  256. });
  257. }
  258. });
  259. },
  260. // 添加群发
  261. addGroupSender(reqBody, action) {
  262. const loading = this.$loading({
  263. text: `${action}中`
  264. });
  265. APIWechatFans.addGroupSender(reqBody)
  266. .then(res => {
  267. console.log("res", res);
  268. if(res.code === 20000) {
  269. this.$message({
  270. type: "success",
  271. message: `${action}成功!`
  272. });
  273. } else {
  274. this.$message({
  275. type: "error",
  276. message: `${action}失败!${res.message}`
  277. });
  278. }
  279. }).catch(error => {
  280. this.$message({
  281. type: "error",
  282. message: '出错了!请联系管理员。'
  283. });
  284. }).finally(() => {
  285. loading.close();
  286. })
  287. },
  288. // 预览
  289. onPreview() {
  290. this.previewShow = true;
  291. },
  292. // 预览确认
  293. onConfirm() {
  294. this.previewShow = false;
  295. },
  296. // 选择文章
  297. onSelectArt(value) {
  298. if(value) {
  299. this.form.articleId = value;
  300. this.form.articleContent = this.articleList.filter(item => {
  301. return item.value === value;
  302. }).map(item => {
  303. return item.label;
  304. }).toString();
  305. }
  306. },
  307. // 选择群发对象分组
  308. onSelectMass(value) {
  309. if(value) {
  310. this.form.selfGroupId = value;
  311. console.log("选择的对象分组", value);
  312. }
  313. }
  314. }
  315. }
  316. </script>
  317. <style scoped lang="scss">
  318. .home-container {
  319. height: 600px;
  320. padding: 0 20px;
  321. //overflow-y: scroll;
  322. overflow-x: hidden;
  323. border: none;
  324. box-shadow: none;
  325. overflow-y: scroll;
  326. .form-container {
  327. height: 600px;
  328. padding: 5px 0;
  329. border: 1px solid #d8dce5;
  330. display: flex;
  331. justify-content: center;
  332. //align-items: center;
  333. overflow: scroll;
  334. p {
  335. margin: 5px 0;
  336. }
  337. .input-width-400 {
  338. width: 400px;
  339. }
  340. .input-width-600 {
  341. width: 600px;
  342. }
  343. .inline-form-item {
  344. display: inline-block;
  345. }
  346. }
  347. .footer-container {
  348. height: 60px;
  349. display: flex;
  350. justify-content: center;
  351. align-items: center;
  352. .el-button {
  353. width: 120px;
  354. }
  355. }
  356. .preview-container {
  357. //height: 400px;
  358. display: flex;
  359. justify-content: flex-start;
  360. align-items: flex-start;
  361. flex-direction: column;
  362. margin: 20px;
  363. border: 1px solid #d8dce5;
  364. .top {
  365. width: 100%;
  366. display: flex;
  367. justify-content: flex-start;
  368. align-items: flex-start;
  369. flex-direction: column;
  370. padding: 0 40px;
  371. border-bottom: 1px solid #d8dce5 ;
  372. }
  373. .fot {
  374. width: 100%;
  375. padding: 0 40px;
  376. display: flex;
  377. justify-content: space-between;
  378. align-items: center;
  379. }
  380. }
  381. .preview-btn {
  382. display: flex;
  383. justify-content: center;
  384. align-items: center;
  385. }
  386. }
  387. </style>