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

  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. console.log(item3)
  91. if(item3 == item2.id) {
  92. this.activaItem(item2,index2,index,item,1)
  93. }
  94. })
  95. })
  96. })
  97. }).catch(err => {
  98. })
  99. },
  100. // 添加频道
  101. activaItem(item2, index2, index, item,type){
  102. let select_list = this.select_list;
  103. if(!select_list[item2.name]){
  104. if(Object.keys(select_list).length > 11){
  105. this.$msg('最多只能添加12个频道哦')
  106. }else{
  107. this.select_list[item2.name] = {p_index: index, c_index: index2};
  108. this.chanel_id.push(item2.id);
  109. this.channel_list[index].content[index2].checked = true;
  110. console.log('频道',this.select_list)
  111. }
  112. }
  113. if(type != 1) {
  114. this.updateChannel(1);
  115. }
  116. },
  117. // 移除频道
  118. cancelItem(key){
  119. // 源数据状态改变
  120. let item = this.select_list[key];
  121. let list = this.channel_list[item.p_index].content[item.c_index];
  122. let id = this.channel_list[item.p_index].content[item.c_index].id;
  123. list.checked = false;
  124. // this.chanel_id.filter(t => t != id)
  125. this.chanel_id.forEach((item,index) => {
  126. if(this.chanel_id[index] == id) {
  127. this.chanel_id.splice(index, 1)
  128. }
  129. });
  130. // 清除选中的对象
  131. delete this.select_list[key];
  132. this.updateChannel(2);
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped="scoped">
  138. .content{
  139. padding: 30rpx 32rpx;
  140. }
  141. .title{
  142. color: #222222;
  143. font-size: 32rpx;
  144. margin-bottom: 20rpx;
  145. display: flex;
  146. align-items: center;
  147. }
  148. .select-item{
  149. width: max-content;
  150. padding: 0 40rpx 0 20rpx;
  151. height: 82rpx;
  152. border: 1rpx solid #999999;
  153. font-size: 28rpx;
  154. color: #333333;
  155. text-align: center;
  156. line-height: 82rpx;
  157. background-color: #FFFFFF;
  158. margin-right: -2rpx;
  159. margin-top: -2rpx;
  160. box-sizing: border-box;
  161. }
  162. .select-item1{
  163. width: max-content;
  164. padding: 0 20rpx;
  165. height: 82rpx;
  166. border: 1rpx solid #999999;
  167. font-size: 28rpx;
  168. color: #333333;
  169. text-align: center;
  170. line-height: 82rpx;
  171. background-color: #FFFFFF;
  172. margin-right: -2rpx;
  173. margin-top: -2rpx;
  174. box-sizing: border-box;
  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>