order.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view class="order-main">
  3. <network-error />
  4. <u-sticky
  5. :enable="enable"
  6. offset-top="0"
  7. h5-nav-height="0"
  8. >
  9. <view class="order-tabs">
  10. <u-tabs
  11. :is-scroll="false"
  12. :list="tabList"
  13. :current="currentTab"
  14. height="72"
  15. font-size="28"
  16. active-color="#111111"
  17. inactive-color="#111111"
  18. :gutter="32"
  19. :bar-style="{
  20. bottom: '8rpx',
  21. marginLeft: '-8rpx',
  22. width: '56rpx',
  23. height: '10rpx',
  24. borderRadius: 0,
  25. backgroundColor: '#FD5B36',
  26. boxShadow: '0px 1px 1px 0px rgba(255, 102, 50, 0.3)'
  27. }"
  28. @change="changeTab"
  29. >
  30. </u-tabs>
  31. </view>
  32. </u-sticky>
  33. <view class="order-list">
  34. <block v-if="orderList.length !== 0">
  35. <view class="u-m-b-16" v-for="(item, index) in orderList" :key="index">
  36. <order-card
  37. :value="item"
  38. @click-card="toActivityDetail"
  39. @submit-result="toSubmitOrder"
  40. @cancel-sign-up="cancelSignUp"
  41. >
  42. </order-card>
  43. </view>
  44. <view class="touch-bottom u-font-22 line-32 u-text-center">{{isLoadMore ? '加载中...' : '到底了~'}}</view>
  45. </block>
  46. <block v-else>
  47. <view class="def-content">
  48. <def-content type="1"></def-content>
  49. </view>
  50. </block>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import defContent from '@/components/defContent'
  56. import orderCard from '@/components/orderCard'
  57. import { getOrderList, editJoinActivity } from '@/api/userApi'
  58. export default {
  59. components: { defContent, orderCard },
  60. data () {
  61. return {
  62. enable: true,
  63. tabList: [
  64. {
  65. status: -1,
  66. name: '全部'
  67. }, {
  68. status: 1,
  69. name: '已报名'
  70. }, {
  71. status: 2,
  72. name: '已提交'
  73. }, {
  74. status: 3,
  75. name: '已完成'
  76. }, {
  77. status: 4,
  78. name: '已取消'
  79. }
  80. ],
  81. currentTab: 0,
  82. isLoadMore: false,
  83. searchForm: {
  84. page_no: 1,
  85. page_size: 10,
  86. status: -1
  87. },
  88. orderList: [],
  89. total: -1
  90. }
  91. },
  92. computed: {
  93. userId () {
  94. return this.$store.state.userInfo.id
  95. }
  96. },
  97. watch: {
  98. userId (e) {
  99. if (!e) {
  100. uni.navigateTo({
  101. url: '/pagesSub/other/login'
  102. })
  103. }
  104. }
  105. },
  106. onShow () {
  107. if (!this.userId) {
  108. uni.navigateTo({
  109. url: '/pagesSub/other/login'
  110. })
  111. return
  112. }
  113. this.enable = true
  114. this.searchForm.page_no = 1
  115. this.total = -1
  116. this.orderList = []
  117. this.getOrderData()
  118. },
  119. onHide () {
  120. this.enable = true
  121. },
  122. onPullDownRefresh () {
  123. this.searchForm.page_no = 1
  124. this.total = -1
  125. this.activityList = []
  126. this.getOrderData()
  127. },
  128. onReachBottom () {
  129. if (this.isLoadMore) {
  130. this.searchForm.page_no += 1
  131. this.getOrderData()
  132. }
  133. },
  134. methods: {
  135. // 获取订单列表
  136. async getOrderData () {
  137. const params = {
  138. page_no: this.searchForm.page_no,
  139. page_size: this.searchForm.page_size,
  140. status: this.searchForm.status
  141. }
  142. const { code, data } = await getOrderList(params)
  143. if (code === 200) {
  144. this.orderList = this.orderList.concat(data.rows)
  145. this.total = data.total_count
  146. this.isLoadMore = this.total !== this.orderList.length
  147. }
  148. },
  149. // 取消报名
  150. async joinActivity (id) {
  151. const params = {
  152. id: id,
  153. type: 2
  154. }
  155. const { code, msg } = await editJoinActivity(params)
  156. if (code === 200) {
  157. this.searchForm.page_no = 1
  158. this.total = -1
  159. this.orderList = []
  160. this.getOrderData()
  161. uni.showToast({
  162. title: '取消成功',
  163. icon: 'none'
  164. })
  165. } else {
  166. uni.showToast({
  167. title: msg,
  168. icon: 'none'
  169. })
  170. }
  171. },
  172. changeTab (index) {
  173. this.currentTab = index
  174. this.searchForm.status = this.tabList[index].status
  175. this.searchForm.page_no = 1
  176. this.total = -1
  177. this.orderList = []
  178. this.getOrderData()
  179. },
  180. cancelSignUp (e) {
  181. uni.showModal({
  182. title: '提示',
  183. content: '确定取消报名',
  184. confirmColor: '#1677FF',
  185. cancelColor: '#1677FF',
  186. success: (res) => {
  187. if (res.confirm) {
  188. this.joinActivity(e.id)
  189. }
  190. }
  191. })
  192. },
  193. toActivityDetail (e) {
  194. uni.navigateTo({
  195. url: `/pagesSub/activity/activityDetail?id=${e.activity_id}`
  196. })
  197. },
  198. toSubmitOrder (e) {
  199. uni.navigateTo({
  200. url: `/pagesSub/order/submitOrder?activityId=${e.activity_id}&userActivityId=${e.user_activity_id}`
  201. })
  202. }
  203. }
  204. }
  205. </script>
  206. <style lang="scss" scoped>
  207. .order-main {
  208. .order-tabs {
  209. width: 100%;
  210. padding: 0;
  211. background-color: #fff;
  212. }
  213. .order-list {
  214. padding: 24px 16px 0 16px;
  215. }
  216. .def-content {
  217. padding-top: 252px;
  218. }
  219. .touch-bottom {
  220. padding: 16px 0;
  221. color: #BABBBC;
  222. }
  223. }
  224. </style>
  225. <style >
  226. .order-tabs >>> .u-tab-item {
  227. z-index: 10;
  228. }
  229. </style>