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

251 lines
6.6 KiB

2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
2 months ago
1 month ago
2 months ago
2 months ago
1 month ago
2 months ago
2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
1 month ago
1 month ago
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="state"
  21. type="2"
  22. :label="dropItem('state').label"
  23. :value="dropItem('state').value">
  24. </uv-drop-down-item>
  25. <uv-drop-down-item
  26. name="timeStr"
  27. type="1"
  28. :label="dropItem('timeStr').label"
  29. :value="dropItem('timeStr').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=""
  41. style="padding: 0 20rpx;">
  42. <travelList :cardListData="cardListData"/>
  43. </view>
  44. </view>
  45. <uv-calendars ref="calendars"
  46. @close="closeCalendars"
  47. @confirm="confirmCalendars" />
  48. </view>
  49. </template>
  50. <script>
  51. import Navbar from '@/pages/components/Navbar.vue'
  52. import { globalMixin } from '../pages/mixins/globalMixin';
  53. import travelList from '@/components/travel/travelList.vue'
  54. export default{
  55. onPageScroll() {
  56. // 滚动后及时更新位置
  57. this.$refs.dropDown.init();
  58. },
  59. mixins: [globalMixin],
  60. components:{
  61. Navbar,
  62. travelList,
  63. },
  64. computed: {
  65. dropItem(name) {
  66. return (name) => {
  67. const result = {};
  68. const find = this.result.find(item => item.name === name);
  69. if (find) {
  70. result.label = find.label;
  71. result.value = find.value;
  72. } else {
  73. result.label = this[name].label;
  74. result.value = this[name].value;
  75. }
  76. return result;
  77. }
  78. },
  79. // 获取当前下拉筛选项
  80. currentDropItem() {
  81. return this[this.activeName];
  82. }
  83. },
  84. data() {
  85. return {
  86. params:{
  87. pageNo:1,
  88. pageSize:10
  89. },
  90. totalPage: '',
  91. cardListData: [],
  92. // 表示value等于这些值,就属于默认值
  93. defaultValue: ['all'],
  94. // 筛选结果
  95. result: [],
  96. // { name: 'state', label: '最新发布', value: 'new' }
  97. activeName: 'state',
  98. state: {
  99. label: '全部',
  100. value: 'all',
  101. activeIndex: 0,
  102. color: '#999',
  103. activeColor: '#FF4546',
  104. child: [{
  105. label: '全部',
  106. value: 'all'
  107. }, {
  108. label: '报名中',
  109. value: '0'
  110. }, {
  111. label: '已结束',
  112. value: '1'
  113. }]
  114. },
  115. timeStr: {
  116. label: '时间',
  117. value: 'all',
  118. activeIndex: 0,
  119. color: '#999',
  120. activeColor: '#FF4546',
  121. child: []
  122. },
  123. isC : false,
  124. }
  125. },
  126. onReachBottom() {
  127. if(this.params.pageNo >= this.totalPage) return
  128. this.params.pageNo ++
  129. this.travelPageList()
  130. },
  131. onLoad() {
  132. this.travelPageList()
  133. },
  134. onPullDownRefresh() {
  135. this.params.pageNo = 1
  136. this.cardListData = []
  137. this.travelPageList()
  138. },
  139. methods: {
  140. travelPageList() {
  141. let params = {
  142. ...this.params
  143. }
  144. this.result.forEach(n => {
  145. params[n.name] = n.value
  146. })
  147. this.$api('travelPageList',params, res=> {
  148. uni.stopPullDownRefresh()
  149. if(res.code == 200) {
  150. this.totalPage = res.result.pages
  151. this.cardListData = [...this.cardListData,...res.result.records]
  152. }
  153. })
  154. },
  155. change(e) {
  156. console.log('弹窗打开状态:',e);
  157. },
  158. /**
  159. * 点击每个筛选项回调
  160. * @param {Object} e { name, active, type } = e
  161. */
  162. selectMenu(e) {
  163. const { name, active, type } = e;
  164. this.activeName = name;
  165. // type 等于1 的需要特殊处理:type不等于1可以忽略
  166. if (type == 1) {
  167. this.$refs.calendars.open()
  168. } else {
  169. const find = this.result.find(item => item.name == this.activeName);
  170. if (find) {
  171. const findIndex = this[this.activeName].child.findIndex(item => item.label == find.label && item.value == find.value);
  172. this[this.activeName].activeIndex = findIndex;
  173. } else {
  174. this[this.activeName].activeIndex = 0;
  175. }
  176. }
  177. },
  178. /**
  179. * 点击菜单回调处理
  180. * @param {Object} item 选中项 { label,value } = e
  181. */
  182. clickItem(e) {
  183. // 下面有重新赋值,所以用let
  184. let { label, value } = e;
  185. const findIndex = this.result.findIndex(item => item.name == this.activeName);
  186. if (this.defaultValue.indexOf(value) > -1 && this[this.activeName].label) {
  187. label = this[this.activeName].label;
  188. }
  189. // 已经存在筛选项
  190. if (findIndex > -1) {
  191. this.$set(this.result, findIndex, {
  192. name: this.activeName,
  193. label,
  194. value
  195. })
  196. } else {
  197. this.result.push({
  198. name: this.activeName,
  199. label,
  200. value
  201. });
  202. }
  203. this.result = this.result.filter(item => this.defaultValue.indexOf(item.value) == -1);
  204. this.params.pageNo = 1
  205. this.cardListData = []
  206. this.travelPageList()
  207. },
  208. confirmCalendars(e){
  209. this.isC = true
  210. this.clickItem({
  211. name: 'timeStr',
  212. label: e.fulldate,
  213. value: e.fulldate
  214. });
  215. },
  216. closeCalendars(){
  217. if(this.isC) return this.isC = false
  218. this.clickItem({
  219. name: 'timeStr',
  220. label: 'all',
  221. value: 'all'
  222. });
  223. },
  224. }
  225. }
  226. </script>
  227. <style scoped lang="scss">
  228. /deep/.uv-sticky__content{
  229. .uv-drop-down {
  230. justify-content: normal;
  231. border: 0;
  232. background: transparent;
  233. }
  234. }
  235. .travelList {
  236. // margin-bottom: 500rpx;
  237. .content {
  238. margin-top: 40rpx;
  239. }
  240. }
  241. </style>