sms_send.vue 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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. this.sms_content = resp.data.default_content
  139. } else {
  140. this.$message.error(resp.msg)
  141. }
  142. }).catch(err => {
  143. this.$message.error(err)
  144. })
  145. },
  146. getTagCustomerCount: function() {
  147. var tag_ids = []
  148. for (let index = 0; index < this.selecting_tags.length; index++) {
  149. tag_ids.push(this.selecting_tags[index].id)
  150. }
  151. if (tag_ids.length == 0) {
  152. this.tag_filtered_count = 0
  153. return
  154. }
  155. tagFilterCustomerCount(tag_ids.join(",")).then(rs => {
  156. var resp = rs.data
  157. if (resp.state == 1) {
  158. this.tag_filtered_count = resp.data.count
  159. } else {
  160. console.log(resp.msg)
  161. }
  162. }).catch(err => {
  163. console.log(err)
  164. })
  165. },
  166. tagEffect: function(tag) {
  167. if (this.isTagSelected(tag)) {
  168. return "dark"
  169. } else {
  170. return "plain"
  171. }
  172. },
  173. isTagSelected: function(tag) {
  174. for (let index = 0; index < this.selecting_tags.length; index++) {
  175. if (this.selecting_tags[index].id == tag.id) {
  176. return true
  177. }
  178. }
  179. return false
  180. },
  181. selectTagAction: function(tag) {
  182. if (!this.isTagSelected(tag)) {
  183. this.selecting_tags.push(tag)
  184. this.getTagCustomerCount()
  185. }
  186. },
  187. cancelSelectTagAction: function(tag) {
  188. for (let index = 0; index < this.selecting_tags.length; index++) {
  189. if (this.selecting_tags[index].id == tag.id) {
  190. this.selecting_tags.splice(index, 1)
  191. this.getTagCustomerCount()
  192. break
  193. }
  194. }
  195. },
  196. isSMSContentValid: function() {
  197. if (this.sms_content.length == 0) {
  198. this.$message.error("请编辑短信内容")
  199. return false
  200. }
  201. if (this.sms_content.indexOf("【") >= 0 || this.sms_content.indexOf("】") >= 0) {
  202. this.$message.error("短信内容不得包含【】")
  203. return false
  204. }
  205. return true
  206. },
  207. sendToAllCustomersAction: function() {
  208. if (!this.isSMSContentValid()) {
  209. return
  210. }
  211. this.sending = true
  212. send2AllCustomers(this.sms_content).then(rs => {
  213. this.sending = false
  214. var resp = rs.data
  215. if (resp.state == 1) {
  216. this.$message.success("发送成功")
  217. } else {
  218. this.$message.error(resp.msg)
  219. }
  220. }).catch(err => {
  221. this.sending = false
  222. this.$message.error(err)
  223. })
  224. },
  225. sendToTagCustomersAction: function() {
  226. if (!this.isSMSContentValid()) {
  227. return
  228. }
  229. if (this.selecting_tags.length == 0) {
  230. this.$message.error("请选择标签")
  231. return
  232. }
  233. var tag_ids = []
  234. for (let index = 0; index < this.selecting_tags.length; index++) {
  235. tag_ids.push(this.selecting_tags[index].id)
  236. }
  237. this.sending = true
  238. send2TagCustomers(this.sms_content, tag_ids.join(",")).then(rs => {
  239. this.sending = false
  240. var resp = rs.data
  241. if (resp.state == 1) {
  242. this.$message.success("发送成功")
  243. } else {
  244. this.$message.error(resp.msg)
  245. }
  246. }).catch(err => {
  247. this.sending = false
  248. this.$message.error(err)
  249. })
  250. },
  251. sendToDesignatedCustomersAction: function() {
  252. if (!this.isSMSContentValid()) {
  253. return
  254. }
  255. var customer_ids = []
  256. for (let index = 0; index < this.designated_targets.length; index++) {
  257. customer_ids.push(this.designated_targets[index].id)
  258. }
  259. this.sending = true
  260. send2SpecificCustomers(this.sms_content, customer_ids.join(",")).then(rs => {
  261. this.sending = false
  262. var resp = rs.data
  263. if (resp.state == 1) {
  264. this.$message.success("发送成功")
  265. } else {
  266. this.$message.error(resp.msg)
  267. }
  268. }).catch(err => {
  269. this.sending = false
  270. this.$message.error(err)
  271. })
  272. },
  273. },
  274. }
  275. </script>
  276. <style lang="scss" scoped>
  277. .main-panel {
  278. width: 100%;
  279. display: flex;
  280. min-height: 600px;
  281. height: auto;
  282. box-sizing: border-box;
  283. .preview-panel {
  284. flex: 3;
  285. margin-right: 1rem;
  286. background-color: #fff;
  287. .form-content {
  288. width: 100%;
  289. padding: 14px 30px 14px 30px;
  290. .preview {
  291. width: 320px;
  292. height: 568px;
  293. background: #fff;
  294. position: relative;
  295. margin: 0 auto;
  296. .bg {
  297. position: relative;
  298. padding-top: 85px;
  299. padding-bottom: 40px;
  300. width: 320px;
  301. height: 568px;
  302. background: url(../../assets/img/message_preview_bg.png) 50% no-repeat;
  303. background-image: -webkit-image-set(url(../../assets/img/message_preview_bg.png) 1x,url(../../assets/img/message_preview_bg@2x.png) 2x);
  304. -webkit-box-sizing: border-box;
  305. -moz-box-sizing: border-box;
  306. box-sizing: border-box;
  307. .scroll {
  308. height: 430px;
  309. overflow-x: hidden;
  310. overflow-y: auto;
  311. .fake-time {
  312. margin: auto;
  313. width: 310px;
  314. line-height: 40px;
  315. font-size: 12px;
  316. text-align: center;
  317. color: #999;
  318. background: #fff;
  319. }
  320. .content {
  321. display: inline-block;
  322. position: relative;
  323. left: 20px;
  324. margin-bottom: 12px;
  325. padding: 8px 15px;
  326. max-width: 260px;
  327. word-break: break-all;
  328. font-size: 16px;
  329. line-height: 1.25;
  330. color: #000;
  331. background: #e5e5ea;
  332. border-radius: 17px;
  333. -webkit-box-sizing: border-box;
  334. -moz-box-sizing: border-box;
  335. box-sizing: border-box;
  336. }
  337. .content::before {
  338. content: "";
  339. position: absolute;
  340. bottom: -2px;
  341. left: -7px;
  342. height: 20px;
  343. border-left: 20px solid #e5e5ea;
  344. border-bottom-right-radius: 16px 14px;
  345. -webkit-transform: translateY(-2px);
  346. -moz-transform: translateY(-2px);
  347. -ms-transform: translateY(-2px);
  348. transform: translateY(-2px);
  349. }
  350. .content::after {
  351. content: "";
  352. position: absolute;
  353. bottom: -2px;
  354. left: 20px;
  355. width: 10px;
  356. height: 20px;
  357. background: #fff;
  358. border-bottom-right-radius: 10px;
  359. -webkit-transform: translate(-30px,-2px);
  360. -moz-transform: translate(-30px,-2px);
  361. -ms-transform: translate(-30px,-2px);
  362. transform: translate(-30px,-2px);
  363. }
  364. }
  365. .scroll::-webkit-scrollbar {
  366. width: 5px;
  367. }
  368. }
  369. }
  370. }
  371. }
  372. .edit-panel {
  373. flex: 4;
  374. padding-bottom: 80px;
  375. background-color: #fff;
  376. .form-content {
  377. width: 100%;
  378. padding: 14px 30px 14px 30px;
  379. .input-panel {
  380. padding-top: 10px;
  381. .hint-text {
  382. margin-top: 5px;
  383. font-size: 12px;
  384. color: #a8b3ba;
  385. line-height: 30px;
  386. }
  387. }
  388. .filters-panel {
  389. margin-top: 50px;
  390. .send-all-panel {
  391. display: flex;
  392. justify-content: space-between;
  393. align-items: center;
  394. .text {
  395. flex: 1;
  396. .title {
  397. font-size: 16px;
  398. color: #485b6d;
  399. font-weight: bold;
  400. height: 30px;
  401. display: -webkit-box;
  402. -webkit-box-orient: vertical;
  403. -webkit-line-clamp: 2;
  404. overflow: hidden;
  405. }
  406. .desc {
  407. font-size: 14px;
  408. color: #7b8a97;
  409. }
  410. }
  411. .btn {
  412. text-align: right;
  413. }
  414. }
  415. .tag-filter-panel {
  416. margin-top: 50px;
  417. .title {
  418. font-size: 16px;
  419. color: #485b6d;
  420. font-weight: bold;
  421. height: 30px;
  422. display: -webkit-box;
  423. -webkit-box-orient: vertical;
  424. -webkit-line-clamp: 2;
  425. overflow: hidden;
  426. }
  427. .desc {
  428. font-size: 14px;
  429. color: #7b8a97;
  430. }
  431. .tag-panel {
  432. margin-top: 15px;
  433. padding: 10px 15px 5px;
  434. background: #f4f7fa;
  435. .item-panel {
  436. display: inline-block;
  437. margin-bottom: 5px;
  438. margin-right: 5px;
  439. }
  440. }
  441. .hint-text {
  442. font-size: 12px;
  443. color: #a8b3ba;
  444. line-height: 30px;
  445. margin-top: 10px;
  446. }
  447. .send {
  448. display: flex;
  449. justify-content: space-between;
  450. align-items: center;
  451. margin-top: 15px;
  452. .text {
  453. flex: 1;
  454. color: #7b8a97;
  455. font-size: 14px;
  456. }
  457. .btn {
  458. text-align: right;
  459. }
  460. }
  461. }
  462. }
  463. .designated-targets-panel {
  464. margin-top: 20px;
  465. .send-panel {
  466. display: flex;
  467. justify-content: space-between;
  468. align-items: center;
  469. padding-bottom: 10px;
  470. .title {
  471. flex: 1;
  472. font-size: 16px;
  473. color: #485b6d;
  474. font-weight: bold;
  475. height: 100%;
  476. }
  477. .btn {
  478. text-align: right;
  479. }
  480. }
  481. }
  482. }
  483. }
  484. }
  485. </style>
  486. <style lang="scss" scoped>
  487. .form-title {
  488. width: 100%;
  489. height: 60px;
  490. padding: 20px 0 20px 30px;
  491. border-bottom: 1px #dee2e5 solid;
  492. .icon {
  493. margin-top: -4px;
  494. vertical-align: middle;
  495. }
  496. span {
  497. font-size: 18px;
  498. font-weight: 500;
  499. color: #485b6d;
  500. margin-left: 10px;
  501. }
  502. }
  503. </style>