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

244 lines
5.8 KiB

5 years ago
5 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="item.icon" 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. console.log('shujushuju',this.channel_list)
  102. }).catch(err => {
  103. })
  104. },
  105. // 添加频道
  106. activaItem(item2, index2, index, item,type){
  107. let select_list = this.select_list;
  108. if(!select_list[item2.name]){
  109. if(Object.keys(select_list).length > 11){
  110. this.$msg('最多只能添加12个频道哦')
  111. }else{
  112. this.select_list[item2.name] = {p_index: index, c_index: index2};
  113. this.chanel_id.push(item2.id);
  114. this.channel_list[index].content[index2].checked = true;
  115. this.channel_list.forEach((item,index) => {
  116. var valueContent = item.content.every(this.verfiyCheck);
  117. if(valueContent) {
  118. this.$set(item,'showTitle',true)
  119. }else {
  120. this.$set(item,'showTitle',false)
  121. }
  122. })
  123. }
  124. }
  125. if(type != 1) {
  126. this.updateChannel(1);
  127. }
  128. },
  129. // 移除频道
  130. cancelItem(key){
  131. // 源数据状态改变
  132. let item = this.select_list[key];
  133. let list = this.channel_list[item.p_index].content[item.c_index];
  134. let id = this.channel_list[item.p_index].content[item.c_index].id;
  135. list.checked = false;
  136. // this.chanel_id.filter(t => t != id)
  137. this.chanel_id.forEach((item,index) => {
  138. if(this.chanel_id[index] == id) {
  139. this.chanel_id.splice(index, 1)
  140. }
  141. });
  142. // 清除选中的对象
  143. delete this.select_list[key];
  144. this.channel_list.forEach((item,index) => {
  145. var valueContent = item.content.every(this.verfiyCheck);
  146. if(valueContent) {
  147. this.$set(item,'showTitle',true)
  148. }else {
  149. this.$set(item,'showTitle',false)
  150. }
  151. })
  152. this.updateChannel(2);
  153. }
  154. }
  155. }
  156. </script>
  157. <style lang="scss" scoped="scoped">
  158. .content{
  159. padding: 30rpx 32rpx;
  160. }
  161. .title{
  162. color: #222222;
  163. font-size: 32rpx;
  164. margin-bottom: 20rpx;
  165. display: flex;
  166. align-items: center;
  167. }
  168. .select-item{
  169. width: max-content;
  170. padding: 0 40rpx 0 20rpx;
  171. height: 82rpx;
  172. border: 1rpx solid #999999;
  173. font-size: 28rpx;
  174. color: #333333;
  175. text-align: center;
  176. line-height: 82rpx;
  177. background-color: #FFFFFF;
  178. margin-right: -2rpx;
  179. margin-top: -2rpx;
  180. box-sizing: border-box;
  181. }
  182. .select-item1{
  183. width: max-content;
  184. padding: 0 20rpx;
  185. height: 82rpx;
  186. border: 1rpx solid #999999;
  187. font-size: 28rpx;
  188. color: #333333;
  189. text-align: center;
  190. line-height: 82rpx;
  191. background-color: #FFFFFF;
  192. // margin-right: -2rpx;
  193. // margin-top: -2rpx;
  194. box-sizing: border-box;
  195. margin: 6rpx;
  196. border-radius: 20rpx;
  197. }
  198. .active{
  199. border: 1rpx solid #FF0000;
  200. color: #FF0000;
  201. background-color: #FFF8F8;
  202. position: relative;
  203. border-radius: 20rpx;
  204. margin: 6rpx;
  205. // text-align: left;
  206. // display: flex;
  207. // justify-content: space-between;
  208. // box-sizing: border-box;
  209. // padding: 0 10rpx;
  210. .remove-icon{
  211. position: absolute;
  212. right: 22rpx;
  213. top: 0;
  214. color: #FF0000;
  215. font-size: 24rpx;
  216. }
  217. }
  218. .lf-p-l-5{
  219. padding-left: 5rpx;
  220. }
  221. // .select-box{
  222. // overflow: hidden;
  223. // padding-top: 1rpx;
  224. // width: 100%;
  225. // height: max-content;
  226. // border-radius: 5rpx;
  227. // }
  228. .icon-img{
  229. width: 41rpx;
  230. height: 40rpx;
  231. }
  232. </style>