海南旅游项目 前端仓库
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.

168 lines
4.0 KiB

  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>{{ key }}</text>
  12. <text class="lf-iconfont lf-icon-cuowu 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">
  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-item" 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. }
  38. },
  39. onLoad(){
  40. this.getChannel()
  41. },
  42. methods: {
  43. updateChannel() {
  44. this.$http(this.API.API_EDITCHANNEL,{channels: this.chanel_id},{showLoading:false}).then(res => {
  45. console.log(res)
  46. }).catch(err => {
  47. })
  48. },
  49. //频道列表
  50. getChannel() {
  51. this.$http(this.API.API_CHANNEL).then(res => {
  52. let list = [];
  53. res.data.forEach(item => {
  54. if(item.pid == 0) {
  55. item.content = [];
  56. list.push(item);
  57. }
  58. })
  59. this.channel_list = list;
  60. res.data.forEach(item => {
  61. this.channel_list.forEach((item2,index) => {
  62. if(item.pid == item2.id) {
  63. this.channel_list[index].content.push(item);
  64. this.channel_list[index].content.forEach((item3,index3) => {
  65. this.$set(this.channel_list[index].content[index3],'checked',false)
  66. })
  67. }
  68. })
  69. })
  70. }).catch(err => {
  71. })
  72. },
  73. // 添加频道
  74. activaItem(item2, index2, index, item){
  75. let select_list = this.select_list;
  76. if(!select_list[item2.name]){
  77. if(Object.keys(select_list).length > 11){
  78. this.$msg('最多只能添加12个频道哦')
  79. }else{
  80. this.select_list[item2.name] = {p_index: index, c_index: index2};
  81. this.chanel_id.push(item2.id);
  82. this.channel_list[index].content[index2].checked = true;
  83. }
  84. }
  85. this.updateChannel();
  86. },
  87. // 移除频道
  88. cancelItem(key){
  89. // 源数据状态改变
  90. let item = this.select_list[key];
  91. let list = this.channel_list[item.p_index].content[item.c_index];
  92. let id = this.channel_list[item.p_index].content[item.c_index].id;
  93. list.checked = false;
  94. // this.chanel_id.filter(t => t != id)
  95. this.chanel_id.forEach((item,index) => {
  96. if(this.chanel_id[index] == id) {
  97. this.chanel_id.splice(index, 1)
  98. }
  99. });
  100. // 清除选中的对象
  101. delete this.select_list[key];
  102. this.updateChannel();
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang="scss" scoped="scoped">
  108. .content{
  109. padding: 30rpx 32rpx;
  110. }
  111. .title{
  112. color: #222222;
  113. font-size: 32rpx;
  114. margin-bottom: 20rpx;
  115. display: flex;
  116. align-items: center;
  117. }
  118. .select-item{
  119. width: 170rpx;
  120. height: 82rpx;
  121. border: 1rpx solid #999999;
  122. font-size: 28rpx;
  123. color: #333333;
  124. text-align: center;
  125. line-height: 82rpx;
  126. background-color: #FFFFFF;
  127. margin-right: -1rpx;
  128. margin-top: -1rpx;
  129. box-sizing: border-box;
  130. }
  131. .active{
  132. border: 1rpx solid #1998FE;
  133. color: #1998FE;
  134. position: relative;
  135. // text-align: left;
  136. // display: flex;
  137. // justify-content: space-between;
  138. // box-sizing: border-box;
  139. // padding: 0 10rpx;
  140. .remove-icon{
  141. position: absolute;
  142. right: 0rpx;
  143. top: -28rpx;
  144. color: #FF0000;
  145. font-size: 26rpx;
  146. }
  147. }
  148. .lf-p-l-5{
  149. padding-left: 5rpx;
  150. }
  151. // .select-box{
  152. // overflow: hidden;
  153. // padding-top: 1rpx;
  154. // width: 100%;
  155. // height: max-content;
  156. // border-radius: 5rpx;
  157. // }
  158. .icon-img{
  159. width: 41rpx;
  160. height: 40rpx;
  161. }
  162. </style>