推广小程序前端代码
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.

235 lines
6.8 KiB

2 months ago
  1. <template>
  2. <view class="travelList">
  3. <view class="head-box"></view>
  4. <Navbar title="旅行列表" :autoBack="true" :bgColor="bgColor" leftIconSize="18px" height="100rpx" :leftIconColor="leftIconColor" :titleStyle="{color:fontColor}" />
  5. <view class="content contentPosition_">
  6. <view class="drop">
  7. <uv-drop-down
  8. ref="dropDown"
  9. text-color="#fff"
  10. text-size="30rpx"
  11. sign="dropDown_1"
  12. text-active-color="#fff"
  13. :extra-icon="{name:'arrow-down-fill',color:'#666',size:'26rpx'}"
  14. :extra-active-icon="{name:'arrow-up-fill',color:'#fff',size:'26rpx'}"
  15. :defaultValue="defaultValue"
  16. :custom-style="{padding: '0 30rpx'}"
  17. @click="selectMenu"
  18. >
  19. <uv-drop-down-item
  20. name="order"
  21. type="2"
  22. :label="dropItem('order').label"
  23. :value="dropItem('order').value">
  24. </uv-drop-down-item>
  25. <uv-drop-down-item
  26. name="type"
  27. type="2"
  28. :label="dropItem('type').label"
  29. :value="dropItem('type').value">
  30. </uv-drop-down-item>
  31. </uv-drop-down>
  32. <uv-drop-down-popup
  33. sign="dropDown_1"
  34. :click-overlay-on-close="true"
  35. :currentDropItem="currentDropItem"
  36. @clickItem="clickItem"
  37. @popupChange="change"
  38. ></uv-drop-down-popup>
  39. </view>
  40. <view class="info cardStyle_">
  41. <view class="left">
  42. <image src="https://img0.baidu.com/it/u=4274003247,920124130&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1031" alt="">
  43. </view>
  44. <view class="right">
  45. <view class="detailed">
  46. <view class="title">夏日去撒野旅游计划</view>
  47. <view class="date">2024.10.28 10:00</view>
  48. <view class="address">成都市东丽湖露营地32号</view>
  49. </view>
  50. <view class="data">
  51. <text>¥233.00</text>
  52. <text>11/40</text>
  53. <text class="btn">已开票</text>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import Navbar from '@/pages/components/Navbar.vue'
  62. import { globalMixin } from '../pages/mixins/globalMixin';
  63. export default{
  64. onPageScroll() {
  65. // 滚动后及时更新位置
  66. this.$refs.dropDown.init();
  67. },
  68. mixins: [globalMixin],
  69. components:{
  70. Navbar
  71. },
  72. computed: {
  73. dropItem(name) {
  74. return (name) => {
  75. const result = {};
  76. const find = this.result.find(item => item.name === name);
  77. if (find) {
  78. result.label = find.label;
  79. result.value = find.value;
  80. } else {
  81. result.label = this[name].label;
  82. result.value = this[name].value;
  83. }
  84. return result;
  85. }
  86. },
  87. // 获取当前下拉筛选项
  88. currentDropItem() {
  89. return this[this.activeName];
  90. }
  91. },
  92. data() {
  93. return {
  94. // 表示value等于这些值,就属于默认值
  95. defaultValue: [0, 'all', '0'],
  96. // 筛选结果
  97. result: [{ name: 'order', label: '全部', value: 'new' }],
  98. // { name: 'order', label: '最新发布', value: 'new' }
  99. activeName: 'order',
  100. order: {
  101. label: '全部',
  102. value: 'all',
  103. activeIndex: 0,
  104. color: '#333',
  105. activeColor: '#FF4546',
  106. child: [{
  107. label: '综合排序',
  108. value: 'all'
  109. }, {
  110. label: '最新发布',
  111. value: 'new'
  112. }, {
  113. label: '低价优先',
  114. value: 'money'
  115. }]
  116. },
  117. type: {
  118. label: '时间',
  119. value: 'all',
  120. activeIndex: 0,
  121. color: '#333',
  122. activeColor: '#FF4546',
  123. child: [{
  124. label: '全部',
  125. value: 'all'
  126. }, {
  127. label: 'PDF',
  128. value: 'pdf'
  129. }, {
  130. label: 'WROD',
  131. value: 'word'
  132. }, {
  133. label: 'PPT',
  134. value: 'ppt'
  135. }]
  136. }
  137. }
  138. },
  139. methods: {
  140. change(e) {
  141. console.log('弹窗打开状态:',e);
  142. },
  143. /**
  144. * 点击每个筛选项回调
  145. * @param {Object} e { name, active, type } = e
  146. */
  147. selectMenu(e) {
  148. const { name, active, type } = e;
  149. this.activeName = name;
  150. // type 等于1 的需要特殊处理:type不等于1可以忽略
  151. if (type == 1) {
  152. this.clickItem({
  153. name: 'vip_type',
  154. label: 'VIP文档',
  155. value: e.active ? 1 : 0
  156. });
  157. } else {
  158. const find = this.result.find(item => item.name == this.activeName);
  159. if (find) {
  160. const findIndex = this[this.activeName].child.findIndex(item => item.label == find.label && item.value == find.value);
  161. this[this.activeName].activeIndex = findIndex;
  162. } else {
  163. this[this.activeName].activeIndex = 0;
  164. }
  165. }
  166. },
  167. /**
  168. * 点击菜单回调处理
  169. * @param {Object} item 选中项 { label,value } = e
  170. */
  171. clickItem(e) {
  172. // 下面有重新赋值,所以用let
  173. let { label, value } = e;
  174. const findIndex = this.result.findIndex(item => item.name == this.activeName);
  175. if (this.defaultValue.indexOf(value) > -1 && this[this.activeName].label) {
  176. label = this[this.activeName].label;
  177. }
  178. // 已经存在筛选项
  179. if (findIndex > -1) {
  180. this.$set(this.result, findIndex, {
  181. name: this.activeName,
  182. label,
  183. value
  184. })
  185. } else {
  186. this.result.push({
  187. name: this.activeName,
  188. label,
  189. value
  190. });
  191. }
  192. this.result = this.result.filter(item => this.defaultValue.indexOf(item.value) == -1);
  193. uni.showModal({
  194. content: `筛选的值:${JSON.stringify(this.result)}`
  195. })
  196. }
  197. }
  198. }
  199. </script>
  200. <style scoped lang="scss">
  201. /deep/.uv-sticky__content{
  202. .uv-drop-down {
  203. justify-content: normal;
  204. border: 0;
  205. background: transparent;
  206. }
  207. }
  208. .travelList {
  209. margin-bottom: 500rpx;
  210. .content {
  211. .info {
  212. position: relative;
  213. margin: 10rpx 32rpx 36rpx;;
  214. padding: 35rpx 0 35rpx 24rpx;
  215. border-radius: 26rpx;
  216. .right {
  217. .data {
  218. display: flex;
  219. justify-content: space-between;
  220. align-items: center;
  221. .btn {
  222. background: #381615;
  223. color: $uni-color-primary;
  224. padding: 10rpx 40rpx;
  225. border-radius: 30rpx 0px 0px 30rpx;
  226. }
  227. }
  228. }
  229. }
  230. }
  231. }
  232. </style>