海南旅游项目 前端仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
5.7 KiB

4 years ago
4 years ago
  1. <template>
  2. <view class="content">
  3. <!-- 我的频道已选的 -->
  4. <view class="title lf-font-bold">
  5. <text>我的频道</text>
  6. </view>
  7. <view class="lf-flex-wrap lf-p-l-5">
  8. <view class="select-item active" hover-class="lf-opacity"
  9. v-for="(item, key, index) in select_list" :key="index"
  10. @click="cancelItem(key)">
  11. <text class="lf-m-r-24">{{ key }}</text>
  12. <text class="lf-iconfont lf-icon-cuo remove-icon"></text>
  13. </view>
  14. </view>
  15. <!-- 机票酒店 -->
  16. <view v-for="(item,index) of channel_list">
  17. <view class="title lf-m-t-40" v-if="!item.showTitle">
  18. <image src="../../static/images/plane_ticket.png" class="icon-img"></image>
  19. <text class="lf-m-l-10">{{item.name}}</text>
  20. </view>
  21. <view class="lf-flex-wrap lf-p-l-5 select-box">
  22. <view class="select-item1" hover-class="lf-opacity"
  23. v-for="(item2, index2) in item.content" :key="index2"
  24. v-if="!item2.checked" @click="activaItem(item2, index2, index, item)">{{ item2.name }}
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data(){
  33. return {
  34. select_list: {}, // 当前选中的频道
  35. channel_list: [],
  36. chanel_id: [],
  37. my_list: [],
  38. content_list: []
  39. }
  40. },
  41. onLoad(){
  42. this.getMyChancel()
  43. },
  44. computed: {
  45. },
  46. methods: {
  47. verfiyCheck(value) {
  48. return value.checked == true;
  49. },
  50. //我的频道列表
  51. getMyChancel(){
  52. this.$http(this.API.API_MYCHANNEL).then(res => {
  53. this.my_list = res.data;
  54. if(this.my_list) {
  55. this.getChannel()
  56. }
  57. })
  58. },
  59. updateChannel(type) {
  60. this.$http(this.API.API_EDITCHANNEL,{channels: this.chanel_id},{showLoading:false}).then(res => {
  61. // if(type == 1) {
  62. // this.$msg('添加频道成功')
  63. // }else {
  64. // this.$msg('取消频道成功')
  65. // }
  66. }).catch(err => {
  67. })
  68. },
  69. //全部频道列表
  70. getChannel() {
  71. this.$http(this.API.API_CHANNEL).then(res => {
  72. let list = [];
  73. res.data.forEach(item => {
  74. if(item.pid == 0) {
  75. item.content = [];
  76. list.push(item);
  77. }else {
  78. this.content_list.push(item)
  79. }
  80. })
  81. this.channel_list = list;
  82. res.data.forEach(item => {
  83. this.channel_list.forEach((item2,index) => {
  84. if(item.pid == item2.id) {
  85. this.channel_list[index].content.push(item);
  86. this.channel_list[index].content.forEach((item3,index3) => {
  87. this.$set(this.channel_list[index].content[index3],'checked',false)
  88. })
  89. }
  90. })
  91. })
  92. this.channel_list.forEach((item,index) => {
  93. item.content.forEach((item2,index2) => {
  94. this.my_list.forEach((item3,index3) => {
  95. if(item3 == item2.id) {
  96. this.activaItem(item2,index2,index,item,1)
  97. }
  98. })
  99. })
  100. })
  101. }).catch(err => {
  102. })
  103. },
  104. // 添加频道
  105. activaItem(item2, index2, index, item,type){
  106. let select_list = this.select_list;
  107. if(!select_list[item2.name]){
  108. if(Object.keys(select_list).length > 11){
  109. this.$msg('最多只能添加12个频道哦')
  110. }else{
  111. this.select_list[item2.name] = {p_index: index, c_index: index2};
  112. this.chanel_id.push(item2.id);
  113. this.channel_list[index].content[index2].checked = true;
  114. this.channel_list.forEach((item,index) => {
  115. var valueContent = item.content.every(this.verfiyCheck);
  116. if(valueContent) {
  117. this.$set(item,'showTitle',true)
  118. }else {
  119. this.$set(item,'showTitle',false)
  120. }
  121. })
  122. }
  123. }
  124. if(type != 1) {
  125. this.updateChannel(1);
  126. }
  127. },
  128. // 移除频道
  129. cancelItem(key){
  130. // 源数据状态改变
  131. let item = this.select_list[key];
  132. let list = this.channel_list[item.p_index].content[item.c_index];
  133. let id = this.channel_list[item.p_index].content[item.c_index].id;
  134. list.checked = false;
  135. // this.chanel_id.filter(t => t != id)
  136. this.chanel_id.forEach((item,index) => {
  137. if(this.chanel_id[index] == id) {
  138. this.chanel_id.splice(index, 1)
  139. }
  140. });
  141. // 清除选中的对象
  142. delete this.select_list[key];
  143. this.channel_list.forEach((item,index) => {
  144. var valueContent = item.content.every(this.verfiyCheck);
  145. if(valueContent) {
  146. this.$set(item,'showTitle',true)
  147. }else {
  148. this.$set(item,'showTitle',false)
  149. }
  150. })
  151. this.updateChannel(2);
  152. }
  153. }
  154. }
  155. </script>
  156. <style lang="scss" scoped="scoped">
  157. .content{
  158. padding: 30rpx 32rpx;
  159. }
  160. .title{
  161. color: #222222;
  162. font-size: 32rpx;
  163. margin-bottom: 20rpx;
  164. display: flex;
  165. align-items: center;
  166. }
  167. .select-item{
  168. width: max-content;
  169. padding: 0 40rpx 0 20rpx;
  170. height: 82rpx;
  171. border: 1rpx solid #999999;
  172. font-size: 28rpx;
  173. color: #333333;
  174. text-align: center;
  175. line-height: 82rpx;
  176. background-color: #FFFFFF;
  177. margin-right: -2rpx;
  178. margin-top: -2rpx;
  179. box-sizing: border-box;
  180. }
  181. .select-item1{
  182. width: max-content;
  183. padding: 0 20rpx;
  184. height: 82rpx;
  185. border: 1rpx solid #999999;
  186. font-size: 28rpx;
  187. color: #333333;
  188. text-align: center;
  189. line-height: 82rpx;
  190. background-color: #FFFFFF;
  191. // margin-right: -2rpx;
  192. // margin-top: -2rpx;
  193. box-sizing: border-box;
  194. margin: 6rpx;
  195. border-radius: 20rpx;
  196. }
  197. .active{
  198. border: 1rpx solid #FF0000;
  199. color: #FF0000;
  200. background-color: #FFF8F8;
  201. position: relative;
  202. border-radius: 20rpx;
  203. margin: 6rpx;
  204. // text-align: left;
  205. // display: flex;
  206. // justify-content: space-between;
  207. // box-sizing: border-box;
  208. // padding: 0 10rpx;
  209. .remove-icon{
  210. position: absolute;
  211. right: 22rpx;
  212. top: 0;
  213. color: #FF0000;
  214. font-size: 24rpx;
  215. }
  216. }
  217. .lf-p-l-5{
  218. padding-left: 5rpx;
  219. }
  220. // .select-box{
  221. // overflow: hidden;
  222. // padding-top: 1rpx;
  223. // width: 100%;
  224. // height: max-content;
  225. // border-radius: 5rpx;
  226. // }
  227. .icon-img{
  228. width: 41rpx;
  229. height: 40rpx;
  230. }
  231. </style>