sms_send.vue 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. <template>
  2. <div class="main-contain" v-loading="sending">
  3. <div class="position">
  4. <bread-crumb :crumbs="crumbs"></bread-crumb>
  5. </div>
  6. <div class="app-container" style="padding: 0 5px; background-color: #f6f8f9;">
  7. <div class="main-panel">
  8. <div class="preview-panel">
  9. <div class="form-title">
  10. <img class="icon" src="@/assets/img/sa_06.png" />
  11. <span>预览</span>
  12. </div>
  13. <div class="form-content">
  14. <div class="preview">
  15. <div class="bg">
  16. <div class="scroll">
  17. <div class="fake-time">9:41</div>
  18. <div class="content">
  19. {{ content_preview }}
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. <div class="edit-panel">
  27. <div class="form-title">
  28. <img class="icon" src="@/assets/img/sa_7.png" />
  29. <span>短信编辑</span>
  30. </div>
  31. <div class="form-content">
  32. <div class="input-panel">
  33. <el-input v-model="sms_content" type="textarea" :rows="4" resize="none" maxlength="500"></el-input>
  34. <div class="hint-text">已输入{{ total_content_length }}字(含签名和尾缀)按{{ sms_charge_count }}条短信计费</div>
  35. </div>
  36. <div v-if="designated_targets.length == 0" class="filters-panel">
  37. <div class="send-all-panel">
  38. <div class="text">
  39. <p class="title">推送全部客户</p>
  40. <p class="desc">将该短信推送给系统里的所有客户</p>
  41. </div>
  42. <div class="btn">
  43. <el-button type="primary" @click="sendToAllCustomersAction()">发送</el-button>
  44. </div>
  45. </div>
  46. <div class="tag-filter-panel">
  47. <p class="title">按标签推送</p>
  48. <p class="desc">将该短信推送给相应标签客户</p>
  49. <div class="tag-panel">
  50. <div v-for="(tag, index) in tags" class="item-panel" :key="index">
  51. <el-tag :effect="tagEffect(tag)" @click="selectTagAction(tag)" @close="cancelSelectTagAction(tag)" :closable="isTagSelected(tag)">{{ tag.tag_name }}</el-tag>
  52. </div>
  53. </div>
  54. <p class="hint-text">*选择标签发送可以帮助您精准营销</p>
  55. <div class="send">
  56. <p class="text">已为您筛选 {{ tag_filtered_count }} 位客户</p>
  57. <div class="btn">
  58. <el-button type="primary" @click="sendToTagCustomersAction">发送</el-button>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. <div class="designated-targets-panel" v-else>
  64. <div class="send-panel">
  65. <div class="title">
  66. 推送指定客户
  67. </div>
  68. <div class="btn">
  69. <el-button type="primary" @click="sendToDesignatedCustomersAction">发送</el-button>
  70. </div>
  71. </div>
  72. <el-table :data="designated_targets" border max-height="500px">
  73. <el-table-column label="客户" prop="name" align="center"></el-table-column>
  74. <el-table-column label="手机号" prop="mobile" align="center"></el-table-column>
  75. </el-table>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. </template>
  83. <script>
  84. import BreadCrumb from "@/scrm_pages/components/bread-crumb"
  85. import { sendsInitData, tagFilterCustomerCount, send2AllCustomers, send2TagCustomers, send2SpecificCustomers } from "@/api/sms"
  86. export default {
  87. name: "SMSSend",
  88. components: {
  89. BreadCrumb,
  90. },
  91. data() {
  92. return {
  93. crumbs: [
  94. { path: false, name: "短信管理" },
  95. { path: false, name: "群发短信" },
  96. ],
  97. sending: false,
  98. sms_content: "",
  99. tags: [],
  100. selecting_tags: [],
  101. tag_filtered_count: 0,
  102. action: 0,
  103. id: 0,
  104. designated_targets: [],
  105. }
  106. },
  107. computed: {
  108. content_preview: function() {
  109. return "【酷医聚客】" + this.sms_content + "退订回TD"
  110. },
  111. total_content_length: function() {
  112. return this.content_preview.length
  113. },
  114. sms_charge_count: function() {
  115. return parseInt(Math.ceil(this.total_content_length / 67.0))
  116. },
  117. },
  118. mounted() {
  119. this.designated_targets = this.$store.getters.sms_designated_targets.targets
  120. if (this.designated_targets.length > 0) {
  121. this.$store.dispatch("SMSClearTargets")
  122. } else {
  123. var action = this.$route.query.action
  124. var id = this.$route.query.id
  125. if (action != undefined && id != undefined) {
  126. this.action = action
  127. this.id = id
  128. }
  129. this.getInitData()
  130. }
  131. },
  132. methods: {
  133. getInitData: function() {
  134. sendsInitData(this.action, this.id).then(rs => {
  135. var resp = rs.data
  136. if (resp.state == 1) {
  137. this.tags = resp.data.tags;
  138. // console.log("this.tags是什么",this.tags)
  139. this.sms_content = resp.data.default_content
  140. } else {
  141. this.$message.error(resp.msg)
  142. }
  143. }).catch(err => {
  144. this.$message.error(err)
  145. })
  146. },
  147. getTagCustomerCount: function() {
  148. var tag_ids = []
  149. for (let index = 0; index < this.selecting_tags.length; index++) {
  150. tag_ids.push(this.selecting_tags[index].id)
  151. }
  152. if (tag_ids.length == 0) {
  153. this.tag_filtered_count = 0
  154. return
  155. }
  156. tagFilterCustomerCount(tag_ids.join(",")).then(rs => {
  157. var resp = rs.data
  158. if (resp.state == 1) {
  159. console.log("这个数据是什么呢?",resp.data.count)
  160. this.tag_filtered_count = resp.data.count
  161. } else {
  162. console.log(resp.msg)
  163. }
  164. }).catch(err => {
  165. console.log(err)
  166. })
  167. },
  168. tagEffect: function(tag) {
  169. if (this.isTagSelected(tag)) {
  170. return "dark"
  171. } else {
  172. return "plain"
  173. }
  174. },
  175. isTagSelected: function(tag) {
  176. for (let index = 0; index < this.selecting_tags.length; index++) {
  177. if (this.selecting_tags[index].id == tag.id) {
  178. return true
  179. }
  180. }
  181. return false
  182. },
  183. selectTagAction: function(tag) {
  184. console.log("tag是什么",tag)
  185. if (!this.isTagSelected(tag)) {
  186. this.selecting_tags.push(tag)
  187. this.getTagCustomerCount()
  188. }
  189. },
  190. cancelSelectTagAction: function(tag) {
  191. for (let index = 0; index < this.selecting_tags.length; index++) {
  192. if (this.selecting_tags[index].id == tag.id) {
  193. this.selecting_tags.splice(index, 1)
  194. this.getTagCustomerCount()
  195. break
  196. }
  197. }
  198. },
  199. isSMSContentValid: function() {
  200. if (this.sms_content.length == 0) {
  201. this.$message.error("请编辑短信内容")
  202. return false
  203. }
  204. if (this.sms_content.indexOf("【") >= 0 || this.sms_content.indexOf("】") >= 0) {
  205. this.$message.error("短信内容不得包含【】")
  206. return false
  207. }
  208. return true
  209. },
  210. sendToAllCustomersAction: function() {
  211. if (!this.isSMSContentValid()) {
  212. return
  213. }
  214. this.sending = true
  215. send2AllCustomers(this.sms_content).then(rs => {
  216. this.sending = false
  217. var resp = rs.data
  218. if (resp.state == 1) {
  219. this.$message.success("发送成功")
  220. } else {
  221. // this.$message.error(resp.msg)
  222. this.$message.success("短信发送过于频繁,请稍后发送")
  223. }
  224. }).catch(err => {
  225. this.sending = false
  226. // this.$message.error(err)
  227. this.$message.success("短信发送过于频繁,请稍后发送")
  228. })
  229. },
  230. sendToTagCustomersAction: function() {
  231. if (!this.isSMSContentValid()) {
  232. return
  233. }
  234. if (this.selecting_tags.length == 0) {
  235. this.$message.error("请选择标签")
  236. return
  237. }
  238. var tag_ids = []
  239. for (let index = 0; index < this.selecting_tags.length; index++) {
  240. tag_ids.push(this.selecting_tags[index].id)
  241. }
  242. console.log("数据",tag_ids)
  243. this.sending = true
  244. send2TagCustomers(this.sms_content, tag_ids.join(",")).then(rs => {
  245. this.sending = false
  246. var resp = rs.data
  247. if (resp.state == 1) {
  248. this.$message.success("发送成功")
  249. } else {
  250. // this.$message.error(resp.msg)
  251. this.$message.success("短信发送过于频繁,请稍后发送")
  252. }
  253. }).catch(err => {
  254. this.sending = false
  255. // this.$message.error(err)
  256. this.$message.success("短信发送过于频繁,请稍后发送")
  257. })
  258. },
  259. sendToDesignatedCustomersAction: function() {
  260. if (!this.isSMSContentValid()) {
  261. return
  262. }
  263. var customer_ids = []
  264. for (let index = 0; index < this.designated_targets.length; index++) {
  265. customer_ids.push(this.designated_targets[index].id)
  266. }
  267. this.sending = true
  268. send2SpecificCustomers(this.sms_content, customer_ids.join(",")).then(rs => {
  269. this.sending = false
  270. var resp = rs.data
  271. if (resp.state == 1) {
  272. this.$message.success("发送成功")
  273. } else {
  274. // this.$message.error(resp.msg)
  275. this.$message.success("短信发送过于频繁,请稍后发送")
  276. }
  277. }).catch(err => {
  278. this.sending = false
  279. // this.$message.error(err)
  280. this.$message.success("短信发送过于频繁,请稍后发送")
  281. })
  282. },
  283. },
  284. }
  285. </script>
  286. <style lang="scss" scoped>
  287. .main-panel {
  288. width: 100%;
  289. display: flex;
  290. min-height: 600px;
  291. height: auto;
  292. box-sizing: border-box;
  293. .preview-panel {
  294. flex: 3;
  295. margin-right: 1rem;
  296. background-color: #fff;
  297. .form-content {
  298. width: 100%;
  299. padding: 14px 30px 14px 30px;
  300. .preview {
  301. width: 320px;
  302. height: 568px;
  303. background: #fff;
  304. position: relative;
  305. margin: 0 auto;
  306. .bg {
  307. position: relative;
  308. padding-top: 85px;
  309. padding-bottom: 40px;
  310. width: 320px;
  311. height: 568px;
  312. background: url(../../assets/img/message_preview_bg.png) 50% no-repeat;
  313. background-image: -webkit-image-set(url(../../assets/img/message_preview_bg.png) 1x,url(../../assets/img/message_preview_bg@2x.png) 2x);
  314. -webkit-box-sizing: border-box;
  315. -moz-box-sizing: border-box;
  316. box-sizing: border-box;
  317. .scroll {
  318. height: 430px;
  319. overflow-x: hidden;
  320. overflow-y: auto;
  321. .fake-time {
  322. margin: auto;
  323. width: 310px;
  324. line-height: 40px;
  325. font-size: 12px;
  326. text-align: center;
  327. color: #999;
  328. background: #fff;
  329. }
  330. .content {
  331. display: inline-block;
  332. position: relative;
  333. left: 20px;
  334. margin-bottom: 12px;
  335. padding: 8px 15px;
  336. max-width: 260px;
  337. word-break: break-all;
  338. font-size: 16px;
  339. line-height: 1.25;
  340. color: #000;
  341. background: #e5e5ea;
  342. border-radius: 17px;
  343. -webkit-box-sizing: border-box;
  344. -moz-box-sizing: border-box;
  345. box-sizing: border-box;
  346. }
  347. .content::before {
  348. content: "";
  349. position: absolute;
  350. bottom: -2px;
  351. left: -7px;
  352. height: 20px;
  353. border-left: 20px solid #e5e5ea;
  354. border-bottom-right-radius: 16px 14px;
  355. -webkit-transform: translateY(-2px);
  356. -moz-transform: translateY(-2px);
  357. -ms-transform: translateY(-2px);
  358. transform: translateY(-2px);
  359. }
  360. .content::after {
  361. content: "";
  362. position: absolute;
  363. bottom: -2px;
  364. left: 20px;
  365. width: 10px;
  366. height: 20px;
  367. background: #fff;
  368. border-bottom-right-radius: 10px;
  369. -webkit-transform: translate(-30px,-2px);
  370. -moz-transform: translate(-30px,-2px);
  371. -ms-transform: translate(-30px,-2px);
  372. transform: translate(-30px,-2px);
  373. }
  374. }
  375. .scroll::-webkit-scrollbar {
  376. width: 5px;
  377. }
  378. }
  379. }
  380. }
  381. }
  382. .edit-panel {
  383. flex: 4;
  384. padding-bottom: 80px;
  385. background-color: #fff;
  386. .form-content {
  387. width: 100%;
  388. padding: 14px 30px 14px 30px;
  389. .input-panel {
  390. padding-top: 10px;
  391. .hint-text {
  392. margin-top: 5px;
  393. font-size: 12px;
  394. color: #a8b3ba;
  395. line-height: 30px;
  396. }
  397. }
  398. .filters-panel {
  399. margin-top: 50px;
  400. .send-all-panel {
  401. display: flex;
  402. justify-content: space-between;
  403. align-items: center;
  404. .text {
  405. flex: 1;
  406. .title {
  407. font-size: 16px;
  408. color: #485b6d;
  409. font-weight: bold;
  410. height: 30px;
  411. display: -webkit-box;
  412. -webkit-box-orient: vertical;
  413. -webkit-line-clamp: 2;
  414. overflow: hidden;
  415. }
  416. .desc {
  417. font-size: 14px;
  418. color: #7b8a97;
  419. }
  420. }
  421. .btn {
  422. text-align: right;
  423. }
  424. }
  425. .tag-filter-panel {
  426. margin-top: 50px;
  427. .title {
  428. font-size: 16px;
  429. color: #485b6d;
  430. font-weight: bold;
  431. height: 30px;
  432. display: -webkit-box;
  433. -webkit-box-orient: vertical;
  434. -webkit-line-clamp: 2;
  435. overflow: hidden;
  436. }
  437. .desc {
  438. font-size: 14px;
  439. color: #7b8a97;
  440. }
  441. .tag-panel {
  442. margin-top: 15px;
  443. padding: 10px 15px 5px;
  444. background: #f4f7fa;
  445. .item-panel {
  446. display: inline-block;
  447. margin-bottom: 5px;
  448. margin-right: 5px;
  449. }
  450. }
  451. .hint-text {
  452. font-size: 12px;
  453. color: #a8b3ba;
  454. line-height: 30px;
  455. margin-top: 10px;
  456. }
  457. .send {
  458. display: flex;
  459. justify-content: space-between;
  460. align-items: center;
  461. margin-top: 15px;
  462. .text {
  463. flex: 1;
  464. color: #7b8a97;
  465. font-size: 14px;
  466. }
  467. .btn {
  468. text-align: right;
  469. }
  470. }
  471. }
  472. }
  473. .designated-targets-panel {
  474. margin-top: 20px;
  475. .send-panel {
  476. display: flex;
  477. justify-content: space-between;
  478. align-items: center;
  479. padding-bottom: 10px;
  480. .title {
  481. flex: 1;
  482. font-size: 16px;
  483. color: #485b6d;
  484. font-weight: bold;
  485. height: 100%;
  486. }
  487. .btn {
  488. text-align: right;
  489. }
  490. }
  491. }
  492. }
  493. }
  494. }
  495. </style>
  496. <style lang="scss" scoped>
  497. .form-title {
  498. width: 100%;
  499. height: 60px;
  500. padding: 20px 0 20px 30px;
  501. border-bottom: 1px #dee2e5 solid;
  502. .icon {
  503. margin-top: -4px;
  504. vertical-align: middle;
  505. }
  506. span {
  507. font-size: 18px;
  508. font-weight: 500;
  509. color: #485b6d;
  510. margin-left: 10px;
  511. }
  512. }
  513. </style>