subscribe.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view style="background-color: #f3f4f5;">
  3. <u-navbar :back-text="i18n('Back')" :back-text-style="backStyle"
  4. back-icon-color="#fff" title-color="#fff"
  5. :title="i18n('MySubscription')"
  6. :background="background">
  7. </u-navbar>
  8. <view class="" style="margin:0 30upx;">
  9. <view class="sub-item">
  10. {{i18n('Project')}}
  11. </view>
  12. <view>
  13. <text v-for="(item,index) in subscribeList[0]" :class="item.ifTrue?'sub-text-click':'sub-text'" @click="pushSubscribe(item,index)">
  14. {{item.label}}
  15. </text>
  16. </view>
  17. <view class="sub-item">
  18. {{i18n('Periodical')}}
  19. </view>
  20. <view>
  21. <text v-for="(item,index) in subscribeList[1]" :class="item.ifTrue?'sub-text-click':'sub-text'" @click="pushSubscribe(item,index)">
  22. {{item.label}}
  23. </text>
  24. </view>
  25. <view class="sub-item">
  26. {{i18n('Information')}}
  27. </view>
  28. <view>
  29. <text v-for="(item,index) in subscribeList[2]" :class="item.ifTrue?'sub-text-click':'sub-text'" @click="pushSubscribe(item,index)">
  30. {{item.label}}
  31. </text>
  32. </view>
  33. <view style="margin:35upx 0 35upx 0;">
  34. <text style="margin-right: 20upx;">{{i18n('SetFrequency')}}:</text>
  35. <u-radio-group v-model="current" >
  36. <u-radio
  37. v-for="(item, index) in taberSendRate" :key="index"
  38. :name="item.value"
  39. >
  40. {{$i18n.locale == 'zh'?item.label:item.labelEN}}
  41. </u-radio>
  42. </u-radio-group>
  43. </view>
  44. <view style="margin-bottom: 55upx;">
  45. {{i18n('SendWay')}}:{{i18n('emailInfo')}}
  46. </view>
  47. <view style="margin-bottom: 55upx;">
  48. <button type="primary" @click="sveSubscript">{{i18n('OK')}}</button>
  49. </view>
  50. </view>
  51. <u-toast ref="uToast" />
  52. </view>
  53. </template>
  54. <script>
  55. import listCell from '@/components/JumpBox';
  56. // import {
  57. // getDicts
  58. // } from '@/api/dict';
  59. export default {
  60. components: {
  61. listCell
  62. },
  63. data() {
  64. return {
  65. background:{
  66. backgroundImage: 'linear-gradient(270deg, #4BC0E2 0%, #538BE7 100%)',
  67. },
  68. backStyle:{
  69. color:'#fff'
  70. },
  71. subscribeList: [],
  72. getTrueList: [],
  73. taberSendRate: [{
  74. label: "周",
  75. labelEN:'Weekly',
  76. value: '1'
  77. }, {
  78. label: "月",
  79. labelEN:'Monthly',
  80. value: '2'
  81. }],
  82. current: 1,
  83. checkList1:[],
  84. checkList2:[],
  85. checkList3:[],
  86. };
  87. },
  88. onShow() {
  89. this.getData() // 获取字典值
  90. },
  91. methods: {
  92. i18n (data) {
  93. return this.$t('common.'+data);
  94. },
  95. async getData() {
  96. let type = this.$i18n.locale == 'en'?'TECHNICAL_SCOPE_DICT_EN,JOURNAL_DICT_EN,CMS_INFORMATION_TYPE_DICT_EN':'TECHNICAL_SCOPE_DICT,JOURNAL_DICT,CMS_INFORMATION_TYPE_DICT';
  97. const res = await this.$myRequest({
  98. url: '/sys/sysDicts',
  99. data: {
  100. type: type
  101. }
  102. });
  103. if (res.data) {
  104. res.data.forEach((item, index) => {
  105. item.forEach((i, j) => {
  106. i.ifTrue = false;
  107. })
  108. });
  109. }
  110. this.subscribeList = res.data || [];
  111. this.getSubscriptionList();// 数据回显
  112. },
  113. async getSubscriptionList(){
  114. const result = await this.$myRequest({
  115. url: '/uc/sysSubscription/getSubscriptionData',
  116. data: {
  117. }
  118. });
  119. const that = this;
  120. if (result.data) {
  121. for (var i=0;i<result.data.length;i++) {
  122. var section =result.data[i].subscriptionSectionDict;
  123. var type=result.data[i].subscriptionTypeDict;
  124. if(section == 'project'){
  125. that.checkList1.push(type);
  126. } else if(section == 'journal'){
  127. that.checkList2.push(type);
  128. }else if(section == 'news'){
  129. that.checkList3.push(type);
  130. }
  131. that.current = result.data[i].subscriptionSendRateDict;
  132. }
  133. }
  134. that.subscribeList[0].forEach(j=>{
  135. that.checkList1.forEach(i=>{
  136. if(j.value == i){
  137. j.ifTrue = true;
  138. }
  139. })
  140. })
  141. that.subscribeList[1].forEach(j=>{
  142. that.checkList2.forEach(i=>{
  143. if(j.value == i){
  144. j.ifTrue = true;
  145. }
  146. })
  147. })
  148. that.subscribeList[2].forEach(j=>{
  149. that.checkList3.forEach(i=>{
  150. if(j.value == i){
  151. j.ifTrue = true;
  152. }
  153. })
  154. })
  155. },
  156. // 保存
  157. async sveSubscript(){
  158. let data ={},project={},journal={},information={},isProject =false,isJournal =false,isInformation =false;
  159. let checkList1List = this.subscribeList[0].filter(item=>{
  160. return item.ifTrue ==true;
  161. })
  162. let checkList2List = this.subscribeList[1].filter(item=>{
  163. return item.ifTrue ==true;
  164. })
  165. let checkList3List = this.subscribeList[2].filter(item=>{
  166. return item.ifTrue ==true;
  167. })
  168. const that = this;
  169. that.checkList1 = [];
  170. that.checkList2 = [];
  171. that.checkList3 = [];
  172. if(checkList1List){
  173. checkList1List.forEach(item=>{
  174. that.checkList1.push(item.value);
  175. })
  176. }
  177. if(checkList2List){
  178. checkList2List.forEach(item=>{
  179. that.checkList2.push(item.value);
  180. })
  181. }
  182. if(checkList3List){
  183. checkList3List.forEach(item=>{
  184. that.checkList3.push(item.value);
  185. })
  186. }
  187. if(this.checkList1.length>0){
  188. project.subscriptionTypeDict = this.checkList1.toString();
  189. project.subscriptionSectionDict = 'project';
  190. project.subscriptionSection = "项目";
  191. project.subscriptionSendRateDict = this.current;
  192. project.subscriptionSendRate = this.taberSendRate[this.current-1].label;
  193. isProject = true;
  194. }
  195. if(this.checkList2.length>0){
  196. journal.subscriptionTypeDict = this.checkList2.toString();
  197. journal.subscriptionSectionDict = 'journal';
  198. journal.subscriptionSection = "期刊";
  199. journal.subscriptionSendRateDict = this.current;
  200. journal.subscriptionSendRate = this.taberSendRate[this.current-1].label;
  201. isJournal = true;
  202. }
  203. if(this.checkList3.length>0){
  204. information.subscriptionTypeDict = this.checkList3.toString();
  205. information.subscriptionSectionDict = 'news';
  206. information.subscriptionSection = "资讯";
  207. information.subscriptionSendRateDict = this.current;
  208. information.subscriptionSendRate = this.taberSendRate[this.current-1].label;
  209. isInformation = true;
  210. }
  211. const res = await this.$myRequest({
  212. url: '/uc/sysSubscription/updataSubscript',
  213. data: {
  214. isProject,
  215. isJournal,
  216. isInformation,
  217. project:JSON.stringify(project),
  218. journal:JSON.stringify(journal),
  219. information:JSON.stringify(information)
  220. },
  221. method:'post'
  222. });
  223. if(res.status && res.data.length != 0){
  224. uni.showToast({
  225. title: this.$i18n.locale == 'zh'?'修改成功':'success',
  226. duration: 2000
  227. });
  228. setTimeout(()=>{
  229. uni.navigateBack({
  230. delta:1,
  231. success: function() {
  232. let page = getCurrentPages().pop(); //跳转页面成功之后
  233. if (!page) return;
  234. page.onLoad(); //如果页面存在,则重新刷新页面
  235. }
  236. });
  237. },2000)
  238. }else {
  239. this.$refs.uToast.show({
  240. title: this.$i18n.locale == 'zh'?'修改失败!':'Modification failed!',
  241. type: 'error'
  242. });
  243. }
  244. },
  245. navTo(route) {
  246. this.$mRouter.push({
  247. route
  248. });
  249. },
  250. pushSubscribe(item, index) {
  251. item.ifTrue = !item.ifTrue;
  252. // if(index==0) return this.getCheckList1(item);
  253. // else if(index==1) return this.getCheckList2(item);
  254. // else if(index==1) return this.getCheckList3(item);
  255. },
  256. // getCheckList1(item){
  257. // if(item.ifTrue){
  258. // this.checkList1.push(item.value);
  259. // }else {
  260. // if (this.checkList1.indexOf(item.value) >= 0) {
  261. // this.checkList1.splice(this.checkList1.indexOf(item.value), 1);
  262. // }
  263. // }
  264. // },
  265. // getCheckList2(){
  266. // },
  267. // getCheckList3(){
  268. // },
  269. }
  270. }
  271. </script>
  272. <style lang="scss" scoped>
  273. page {
  274. background-color: #f3f4f5 !important;
  275. .sub-item {
  276. line-height: 80upx;
  277. margin-top: 15upx;
  278. color: #666;
  279. font-size: 32upx;
  280. margin-left: 0upx;
  281. font-weight: 700;
  282. }
  283. .sub-text {
  284. display: inline-block;
  285. padding: 20upx 30upx;
  286. margin-right: 40upx;
  287. margin-top: 20upx;
  288. background-color: #fff;
  289. color: #666;
  290. }
  291. .sub-text-click {
  292. display: inline-block;
  293. padding: 20upx 30upx;
  294. margin-right: 40upx;
  295. margin-top: 20upx;
  296. background-color: #1777FE;
  297. color: #fff;
  298. }
  299. }
  300. </style>