sendingMsg.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <template>
  2. <div class="send-msg">
  3. <h1>群发消息</h1>
  4. <Form ref="send" :model="send" :rules="ruleValidate" :label-width="112">
  5. <FormItem label="用户:" prop="sendway">
  6. <RadioGroup v-model="send.sendway">
  7. <Radio label="1">
  8. <span>全部用户</span>
  9. </Radio>
  10. <Radio label="2" style="margin-left:20px">
  11. <span>convertlab用户分组</span>
  12. </Radio>
  13. </RadioGroup>
  14. </FormItem>
  15. <FormItem label="发送用户:" prop="userGroupName" v-if="send.sendway==2">
  16. convertlab用户分组同步
  17. <Button type="primary" size="small" @click="refreshed" style="margin: 0 40px">刷新分组</Button>
  18. <!-- <RadioGroup v-model="msgRadio">
  19. <Radio label="1">
  20. <span>后台群组</span>
  21. </Radio>
  22. <Radio label="2" style="margin-left:20px">
  23. <span>新用户</span>
  24. </Radio>
  25. </RadioGroup> -->
  26. <!-- <div v-show="groupData.length" style="border-bottom: 1px solid #e9e9e9;padding-bottom:6px;margin-bottom:6px;">
  27. <Checkbox
  28. :indeterminate="indeterminate"
  29. :value="checkAll"
  30. @click.prevent.native="handleCheckAll">全部用户</Checkbox>
  31. </div> -->
  32. <CheckboxGroup v-model="send.userGroupName" @on-change="checkGroup" v-show="groupData.length">
  33. <Checkbox v-for="item in groupData" :key="item.id" :label="item.name">
  34. <span>{{item.name}}</span>
  35. </Checkbox>
  36. </CheckboxGroup>
  37. </FormItem>
  38. <FormItem label="消息类型:" prop="msgType" style="width:300px">
  39. <Select v-model="send.msgType" placeholder="请选择消息类型">
  40. <Option v-for="item in filterMessageTypeList" :value="item.msg_type" :key="item.msg_type">{{ item.name }}</Option>
  41. </Select>
  42. </FormItem>
  43. <FormItem label="消息标题:" prop="title">
  44. <Input
  45. v-model="send.title"
  46. type="text"
  47. :maxlength="30"
  48. placeholder="请输入消息标题(最多30个字)"
  49. ></Input>
  50. </FormItem>
  51. <FormItem label="消息内容:" prop="content">
  52. <Input v-model="send.content" type="textarea" :autosize="{minRows: 3,maxRows: 5}" placeholder="请输入消息内容(最多200个字)" :maxlength="200"></Input>
  53. </FormItem>
  54. <FormItem label="内容链接:"><br />
  55. <div class="link-url">
  56. <span>PC</span>
  57. <Input
  58. v-model="send.link"
  59. type="text"
  60. placeholder="请输入PC端内容链接"
  61. ></Input>
  62. </div>
  63. <div class="link-url">
  64. <span>安卓</span>
  65. <Input
  66. v-model="send.androidUrl"
  67. type="text"
  68. placeholder="请输入安卓端内容链接"
  69. ></Input>
  70. </div>
  71. <div class="link-url">
  72. <span>苹果</span>
  73. <Input
  74. v-model="send.iosUrl"
  75. type="text"
  76. placeholder="请输入苹果端内容链接"
  77. ></Input>
  78. </div>
  79. <div class="link-url">
  80. <span>微信</span>
  81. <Input
  82. v-model="send.weChatUrl"
  83. type="text"
  84. placeholder="请输入微信端内容链接"
  85. ></Input>
  86. </div>
  87. </FormItem>
  88. <!-- <FormItem label="展示样式:" style="width:440px"><br/>-->
  89. <!-- <div class="show_style">-->
  90. <!-- <div class="show_top show_common">-->
  91. <!-- <div class="show_label">在前端是否展示为浮标</div>-->
  92. <!-- <Select v-model="send.showBuoy" placeholder="请选择是否展示为浮标">-->
  93. <!-- <Option v-for="item in showSelect" :value="item.v" :key="item.v">{{ item.n }}</Option>-->
  94. <!-- </Select>-->
  95. <!-- </div>-->
  96. <!-- <div class="show_bot show_common">-->
  97. <!-- <div class="show_label">展示文案为</div>-->
  98. <!-- <Input-->
  99. <!-- v-model="send.showContent"-->
  100. <!-- type="text"-->
  101. <!-- class="show_text"-->
  102. <!-- placeholder="请输入展示文案"-->
  103. <!-- ></Input>-->
  104. <!-- </div>-->
  105. <!-- </div>-->
  106. <!-- </FormItem>-->
  107. <FormItem label="发送时效:" prop="sendMode">
  108. <RadioGroup v-model="send.sendMode">
  109. <Radio label="1">
  110. <span>定时</span>
  111. </Radio>
  112. <Radio label="2" style="margin-left:20px">
  113. <span>实时</span>
  114. </Radio>
  115. </RadioGroup>
  116. </FormItem>
  117. <FormItem label="发送时间:" prop="sendTime" style="width:600px" v-show="send.sendMode=='1'">
  118. <date-sigle ref="sigleRef3" :dateType="'datetime'" :formated="'yyyy-MM-dd HH:mm'" :placeholderd="'请选择发送时间'" @startDate="sendDate" :overTime="0"></date-sigle>
  119. </FormItem>
  120. <FormItem label="App端打开菜单:" prop="menuname" style="width:300px">
  121. <Select v-model="send.menuname" placeholder="APP端消息进入展示所属菜单" filterable clearable>
  122. <Option v-for="item in menuList" :value="item.key" :key="item.key">{{ item.label }}</Option>
  123. </Select>
  124. </FormItem>
  125. <FormItem>
  126. <Button type="primary" :class="{'is-active':isDis}" @click="sendSub('send')" style="width:100px">保存</Button>
  127. <Button @click="sendCancel('send')" style="width: 100px;margin-left: 8px">取消</Button>
  128. </FormItem>
  129. </Form>
  130. </div>
  131. </template>
  132. <script>
  133. import dateSigle from '@/components/dateSigle'
  134. import { mapGetters } from 'vuex'
  135. export default {
  136. components: {
  137. dateSigle
  138. },
  139. computed: {
  140. ...mapGetters(['messageTypeList', 'filterMessageTypeList'])
  141. },
  142. created() {
  143. this.refreshed()
  144. if(this.messageTypeList.length === 0) {
  145. this.$store.dispatch('getMessageType')
  146. }
  147. },
  148. methods: {
  149. msgBack() {
  150. this.$request('/message/messageDetails').data({
  151. id: this.$route.query.id
  152. }).success((res) => {
  153. if (res.status == 'success') {
  154. Object.keys(this.send).forEach(key => {
  155. this.send[key] = res.data[key]
  156. })
  157. // if(res.data.send_usergroup_id === 'all_user'){ //全选
  158. // this.checkAll = true
  159. // let arrs = [], arrs1 = []
  160. // this.groupData.forEach(v => {
  161. // arrs.push(v.name)
  162. // arrs1.push(v.id)
  163. // })
  164. // this.send.userGroupId = arrs1
  165. // this.send.userGroupName = arrs
  166. // } else {
  167. // this.indeterminate = true
  168. // this.send.userGroupId = res.data.send_usergroup_id?res.data.send_usergroup_id.split(','):[]
  169. // this.send.userGroupName = res.data.send_usergroup_name?res.data.send_usergroup_name.split(','):[]
  170. // }
  171. if(res.data.send_usergroup_id === 'all_user'){
  172. this.send.sendway = '1'
  173. } else {
  174. this.send.sendway = '2'
  175. this.send.userGroupId = res.data.send_usergroup_id?res.data.send_usergroup_id.split(','):[]
  176. this.send.userGroupName = res.data.send_usergroup_name?res.data.send_usergroup_name.split(','):[]
  177. }
  178. this.send.msgType = res.data?.msg_type?.toString()
  179. this.send.sendMode = String(res.data.send_mode)
  180. this.send.sendTime = res.data.send_time
  181. this.$refs.sigleRef3.dataVals = res.data.send_time
  182. }
  183. }).get()
  184. },
  185. inited() {
  186. this.$refs.sigleRef3.initd()
  187. this.isDis = false
  188. // this.checkAll = false
  189. // this.indeterminate = false
  190. Object.keys(this.send).forEach( key => {
  191. if (key == 'userGroupName') {
  192. this.send[key] = []
  193. } else {
  194. this.send[key] = ''
  195. }
  196. })
  197. },
  198. refreshed() {
  199. this.$request('/message/getGroup').data().success((res) => {
  200. if (res.status == 'success') {
  201. this.groupData = res.data
  202. if (this.$route.query.id) {
  203. this.msgBack()
  204. }
  205. }
  206. }).get()
  207. },
  208. handleCheckAll () {
  209. if (this.indeterminate) {
  210. this.checkAll = false
  211. } else {
  212. this.checkAll = !this.checkAll
  213. this.send.userGroupId = []
  214. }
  215. this.indeterminate = false
  216. if (this.checkAll) {
  217. const arrs = [], arrs1 = []
  218. this.groupData.forEach(v => {
  219. arrs.push(v.name)
  220. arrs1.push(v.id)
  221. })
  222. this.send.userGroupId = arrs1
  223. this.send.userGroupName = arrs
  224. } else {
  225. this.send.userGroupId = []
  226. this.send.userGroupName = []
  227. }
  228. this.$refs.send.validateField('userGroupName')
  229. },
  230. checkGroup(data) {
  231. const arrs = []
  232. this.groupData.forEach(v => {
  233. data.forEach(i => {
  234. if (i == v.name) {
  235. arrs.push(v.id)
  236. }
  237. })
  238. })
  239. this.send.userGroupId = arrs
  240. if (data.length === this.groupData.length) {
  241. this.indeterminate = false
  242. this.checkAll = true
  243. } else if (data.length > 0) {
  244. this.indeterminate = true
  245. this.checkAll = false
  246. } else {
  247. this.indeterminate = false
  248. this.checkAll = false
  249. }
  250. },
  251. sendDate(val) {
  252. this.send.sendTime = val
  253. },
  254. sendSub(name) {
  255. let rout = this.$route.query.id
  256. let obj = {
  257. id: rout ? rout : '',
  258. userGroupId: this.send.sendway == 1 ? 'all_user' : String(this.send.userGroupId),
  259. userGroupName:this.send.sendway == 1 ? '全部用户' : String(this.send.userGroupName),
  260. msgType: Number(this.send.msgType),
  261. title: this.send.title,
  262. content: this.send.content,
  263. link: this.send.link,
  264. androidUrl: this.send.androidUrl,
  265. iosUrl: this.send.iosUrl,
  266. weChatUrl: this.send.weChatUrl,
  267. sendMode: this.send.sendMode,
  268. showBuoy: this.send.showBuoy,
  269. showContent: this.send.showContent,
  270. sendTime: this.send.sendMode=='1'?this.send.sendTime:'',
  271. menuname: this.send.menuname
  272. }
  273. console.log(obj)
  274. this.$refs[name].validate((valid) => {
  275. if (valid) {
  276. this.isDis = true
  277. setTimeout(() => {
  278. if (rout) {
  279. this.inited()
  280. this.$refs[name].resetFields()
  281. this.$Message.success('修改成功!')
  282. // dataManage
  283. this.$router.push('/msgManage/sentList')
  284. }
  285. }, 600)
  286. setTimeout(() => {
  287. this.isDis = false
  288. }, 1000)
  289. this.$request('/message/messageSave').data(obj).success((res) => {
  290. if (res.status === 'success') {
  291. this.inited()
  292. this.$refs[name].resetFields()
  293. }
  294. }).error(() => {
  295. this.isDis = false
  296. }).post()
  297. this.$Message.success('发送成功!')
  298. }
  299. })
  300. },
  301. sendCancel(name) {
  302. let rout = this.$route.query.id
  303. if (rout) {
  304. this.$router.push('/msgManage/sentList')
  305. } else {
  306. this.inited()
  307. this.$refs[name].resetFields()
  308. }
  309. }
  310. },
  311. data () {
  312. return {
  313. isDis: false,
  314. // msgRadio: 1,
  315. // showSelect: [
  316. // {v: 1, n: '是'},
  317. // {v: 0, n: '否'}
  318. // ],
  319. indeterminate: false, //半选
  320. checkAll: false, // 全选
  321. groupData: [],
  322. menuList: [
  323. {
  324. key: 'search',
  325. label: '首页'
  326. },
  327. {
  328. key: 'subscribe',
  329. label: '订阅'
  330. },
  331. {
  332. key: 'message',
  333. label: '消息'
  334. },
  335. {
  336. key: 'box',
  337. label: '百宝箱'
  338. },
  339. {
  340. key: 'me',
  341. label: '我的'
  342. },
  343. {
  344. key: 'other',
  345. label: '新的 webview'
  346. }
  347. ],
  348. send: {
  349. userGroupId: [],
  350. userGroupName: [],
  351. msgType: '',
  352. title: '',
  353. content: '',
  354. link: '',
  355. androidUrl: '',
  356. iosUrl: '',
  357. weChatUrl: '',
  358. showBuoy: 0,
  359. sendMode: '',
  360. sendway:'',
  361. showContent: '',
  362. sendTime: '',
  363. menuname: 'message'
  364. },
  365. ruleValidate: {
  366. sendway: [{ required: true, message: '请选择用户类型', trigger: 'change'}],
  367. userGroupName: [
  368. { required: true, type: 'array', min: 1, message: '请选择发送用户', trigger: 'change' }
  369. ],
  370. msgType: [
  371. { required: true, message: '请选择消息类型', trigger: 'change'}
  372. ],
  373. title: [
  374. { required: true, message: '消息标题不能为空', trigger: 'blur'},
  375. { type: 'string', max: 30, message: '最多30个字', trigger: 'blur'}
  376. ],
  377. content: [
  378. { required: true, message: '请输入消息内容', trigger: 'blur'},
  379. { type: 'string', max: 200, message: '最多200个字', trigger: 'blur'}
  380. ],
  381. sendMode: [
  382. { required: true, message: '请选择发送时效', trigger: 'change'}
  383. ]
  384. }
  385. }
  386. }
  387. }
  388. </script>
  389. <style lang="scss" scoped>
  390. .send-msg {
  391. display: flex;
  392. flex-direction: column;
  393. align-items: center;
  394. h1 {
  395. width: 90%;
  396. font-size:24px;
  397. color:#3f4047;
  398. padding: 10px 0 20px 10px;
  399. }
  400. .ivu-form {
  401. width: 90%;
  402. background: #fff;
  403. padding: 20px;
  404. :v-deep .ivu-form-item-label {
  405. text-align: right;
  406. }
  407. ::v-deep .ivu-input{
  408. width: 660px;
  409. }
  410. ::v-deep {
  411. .show_text{
  412. .ivu-input{
  413. width: 620px;
  414. }
  415. }
  416. }
  417. }
  418. .link-url {
  419. display: flex;
  420. margin-bottom: 15px;
  421. span {
  422. width: 30px;
  423. margin-right: 10px;
  424. }
  425. }
  426. .el-radio-group{
  427. margin-left: 40px;
  428. }
  429. .show_style{
  430. display: flex;
  431. flex-direction: column;
  432. .show_common {
  433. display: flex;
  434. }
  435. .show_top{
  436. margin-bottom: 15px;
  437. }
  438. .show_label{
  439. white-space: nowrap;
  440. margin-right: 10px;
  441. }
  442. }
  443. .is-active {
  444. pointer-events: none;
  445. }
  446. }
  447. </style>