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

221 lines
5.2 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">
  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. methods: {
  45. //我的频道列表
  46. getMyChancel(){
  47. this.$http(this.API.API_MYCHANNEL).then(res => {
  48. this.my_list = res.data;
  49. if(this.my_list) {
  50. this.getChannel()
  51. }
  52. })
  53. },
  54. updateChannel(type) {
  55. this.$http(this.API.API_EDITCHANNEL,{channels: this.chanel_id},{showLoading:false}).then(res => {
  56. // if(type == 1) {
  57. // this.$msg('添加频道成功')
  58. // }else {
  59. // this.$msg('取消频道成功')
  60. // }
  61. }).catch(err => {
  62. })
  63. },
  64. //全部频道列表
  65. getChannel() {
  66. this.$http(this.API.API_CHANNEL).then(res => {
  67. let list = [];
  68. res.data.forEach(item => {
  69. if(item.pid == 0) {
  70. item.content = [];
  71. list.push(item);
  72. }else {
  73. this.content_list.push(item)
  74. }
  75. })
  76. this.channel_list = list;
  77. res.data.forEach(item => {
  78. this.channel_list.forEach((item2,index) => {
  79. if(item.pid == item2.id) {
  80. this.channel_list[index].content.push(item);
  81. this.channel_list[index].content.forEach((item3,index3) => {
  82. this.$set(this.channel_list[index].content[index3],'checked',false)
  83. })
  84. }
  85. })
  86. })
  87. this.channel_list.forEach((item,index) => {
  88. item.content.forEach((item2,index2) => {
  89. this.my_list.forEach((item3,index3) => {
  90. if(item3 == item2.id) {
  91. this.activaItem(item2,index2,index,item,1)
  92. }
  93. })
  94. })
  95. })
  96. }).catch(err => {
  97. })
  98. },
  99. // 添加频道
  100. activaItem(item2, index2, index, item,type){
  101. let select_list = this.select_list;
  102. if(!select_list[item2.name]){
  103. if(Object.keys(select_list).length > 11){
  104. this.$msg('最多只能添加12个频道哦')
  105. }else{
  106. this.select_list[item2.name] = {p_index: index, c_index: index2};
  107. this.chanel_id.push(item2.id);
  108. this.channel_list[index].content[index2].checked = true;
  109. }
  110. }
  111. if(type != 1) {
  112. this.updateChannel(1);
  113. }
  114. },
  115. // 移除频道
  116. cancelItem(key){
  117. // 源数据状态改变
  118. let item = this.select_list[key];
  119. let list = this.channel_list[item.p_index].content[item.c_index];
  120. let id = this.channel_list[item.p_index].content[item.c_index].id;
  121. list.checked = false;
  122. // this.chanel_id.filter(t => t != id)
  123. this.chanel_id.forEach((item,index) => {
  124. if(this.chanel_id[index] == id) {
  125. this.chanel_id.splice(index, 1)
  126. }
  127. });
  128. // 清除选中的对象
  129. delete this.select_list[key];
  130. this.updateChannel(2);
  131. }
  132. }
  133. }
  134. </script>
  135. <style lang="scss" scoped="scoped">
  136. .content{
  137. padding: 30rpx 32rpx;
  138. }
  139. .title{
  140. color: #222222;
  141. font-size: 32rpx;
  142. margin-bottom: 20rpx;
  143. display: flex;
  144. align-items: center;
  145. }
  146. .select-item{
  147. width: max-content;
  148. padding: 0 40rpx 0 20rpx;
  149. height: 82rpx;
  150. border: 1rpx solid #999999;
  151. font-size: 28rpx;
  152. color: #333333;
  153. text-align: center;
  154. line-height: 82rpx;
  155. background-color: #FFFFFF;
  156. margin-right: -2rpx;
  157. margin-top: -2rpx;
  158. box-sizing: border-box;
  159. }
  160. .select-item1{
  161. width: max-content;
  162. padding: 0 20rpx;
  163. height: 82rpx;
  164. border: 1rpx solid #999999;
  165. font-size: 28rpx;
  166. color: #333333;
  167. text-align: center;
  168. line-height: 82rpx;
  169. background-color: #FFFFFF;
  170. // margin-right: -2rpx;
  171. // margin-top: -2rpx;
  172. box-sizing: border-box;
  173. margin: 6rpx;
  174. border-radius: 20rpx;
  175. }
  176. .active{
  177. border: 1rpx solid #FF0000;
  178. color: #FF0000;
  179. background-color: #FFF8F8;
  180. position: relative;
  181. border-radius: 5rpx;
  182. margin-right: 10rpx;
  183. margin-bottom: 10rpx;
  184. // text-align: left;
  185. // display: flex;
  186. // justify-content: space-between;
  187. // box-sizing: border-box;
  188. // padding: 0 10rpx;
  189. .remove-icon{
  190. position: absolute;
  191. right: 22rpx;
  192. top: 0;
  193. color: #FF0000;
  194. font-size: 24rpx;
  195. }
  196. }
  197. .lf-p-l-5{
  198. padding-left: 5rpx;
  199. }
  200. // .select-box{
  201. // overflow: hidden;
  202. // padding-top: 1rpx;
  203. // width: 100%;
  204. // height: max-content;
  205. // border-radius: 5rpx;
  206. // }
  207. .icon-img{
  208. width: 41rpx;
  209. height: 40rpx;
  210. }
  211. </style>