index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <view>
  3. <u-navbar title="我的订单" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
  4. <view class="order">
  5. <view class="flex order-state-search">
  6. <u-tabs @change="changeTab" :scrollable="false" :list="statusArr" lineWidth="30" lineHeight="1"
  7. lineColor="#E96737" :activeStyle="{
  8. color: '#E96737',
  9. transform: 'scale(1)'
  10. }" :inactiveStyle="{
  11. color: '#333',
  12. transform: 'scale(1)'
  13. }" itemStyle="padding-left: 15px; padding-right: 15px; height: 44px;">
  14. </u-tabs>
  15. <view class="test"></view>
  16. </view>
  17. <view class="order-list">
  18. <view class="order-list-data">
  19. <view class="order-list-data-item" v-for="(item, index) in list" :key="index">
  20. <view class="order-list-data-item__info">
  21. <view class="flex order-list-data-item__info__title">
  22. <view class="number">
  23. <text>订单编号:</text>
  24. <text>{{ item.orderId }}</text>
  25. </view>
  26. <view class="success" v-if="item.status.value == 1">{{ item.status.desc }}</view>
  27. <view v-else>{{ item.status.desc }}</view>
  28. </view>
  29. <navigator :url="`/pages/order/detail?id=${ item.orderId }`" hover-class="navigator-hover">
  30. <view class="flex order-list-data-item__info__detail"
  31. v-for="(items, index) in item.items" :key="index">
  32. <view class="order-list-data-item__info__detail__left">
  33. <view class="img">
  34. <image class="img" :src="items.picUrl" mode="aspectFill">
  35. </image>
  36. </view>
  37. </view>
  38. <view class="order-list-data-item__info__detail__right">
  39. <view class="title">{{ items.title }}</view>
  40. <view class="num">x {{ items.goodsNum }}</view>
  41. </view>
  42. </view>
  43. </navigator>
  44. <view class="order-list-data-item__info__total">
  45. <view>共{{ item.orderNum }}个商品</view>
  46. <view class="money">
  47. <text>实付:</text>
  48. <text>¥{{ $numberFormat(item.payAmt) }}</text>
  49. </view>
  50. </view>
  51. <view class="order-list-data-item__info__btn" v-if="item.status.value == 0">
  52. <text @click="cancelOrder(item.orderId)">取消订单</text>
  53. <text @click="payOrder(item)">去支付</text>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="flex empty" v-if="!list.length && !loading">
  59. <u-empty text="订单为空" mode="order" />
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import env from '../../config/env.js'
  67. import $http from '@/utils/request.js'
  68. export default {
  69. data() {
  70. return {
  71. loading: false,
  72. pageNum: 1,
  73. total: 100,
  74. list: [],
  75. status: null,
  76. statusArr: [{
  77. name: '全部'
  78. }, {
  79. name: '待付款',
  80. }, {
  81. name: '待发货'
  82. }, {
  83. name: '已发货'
  84. }, {
  85. name: '已取消'
  86. }, ],
  87. };
  88. },
  89. onLoad(opthios) {},
  90. onShow() {
  91. this.pageList()
  92. },
  93. methods: {
  94. getList() {
  95. uni.showLoading({
  96. title: '加载中'
  97. });
  98. this.loading = true
  99. $http.post(`/api/v1/mp/user/deliver/order/list?pageNum=${ this.pageNum }&pageSize=20`, {
  100. status: this.status
  101. }).then(res => {
  102. uni.hideLoading();
  103. this.loading = false
  104. if (res.code == 0) {
  105. res.rows.forEach(item => {
  106. let items = item.items
  107. items.forEach(item => {
  108. item.picUrl = env.filePublic + item.picUrl
  109. })
  110. item.status = JSON.parse(item.status)
  111. })
  112. this.total = res.total
  113. this.list = this.list.concat(res.rows)
  114. }
  115. }).catch(() => {
  116. uni.hideLoading();
  117. this.loading = false
  118. })
  119. },
  120. pageList() {
  121. this.pageNum = 1
  122. this.list = []
  123. this.getList()
  124. },
  125. cancelOrder(id) {
  126. $http.post('/api/v1/mp/user/deliver/order/cancel', {
  127. orderId: id
  128. }).then(res => {
  129. if (res.code == 0) {
  130. uni.$u.toast('订单取消成功');
  131. this.pageList()
  132. }
  133. })
  134. },
  135. payOrder(item) {
  136. let _this = this
  137. let payIng = false
  138. if (payIng) return
  139. $http.post('/api/v1/mp/user/deliver/order/pay', {
  140. orderId: item.orderId,
  141. payType: 2
  142. }).then(ele => {
  143. payIng = true
  144. if (ele.code == 0) {
  145. uni.requestPayment({
  146. timeStamp: ele.data.timeStamp,
  147. nonceStr: ele.data.nonceStr,
  148. package: ele.data.package,
  149. signType: ele.data.signType,
  150. paySign: ele.data.paySign,
  151. success() {
  152. uni.showToast({
  153. title: '支付成功',
  154. icon: 'success',
  155. duration: 2000
  156. })
  157. _this.pageList()
  158. },
  159. fail() {
  160. payIng = false
  161. }
  162. })
  163. } else {
  164. payIng = false
  165. uni.$u.toast('支付失败!');
  166. }
  167. }).catch(() => {
  168. payIng = false
  169. uni.$u.toast('支付失败!');
  170. })
  171. },
  172. changeTab(e) {
  173. if (e.index == 0) {
  174. this.status = null
  175. } else if (e.index == 1) {
  176. this.status = 0
  177. } else if (e.index == 2) {
  178. this.status = 1
  179. } else if (e.index == 3) {
  180. this.status = 2
  181. } else if (e.index == 4) {
  182. this.status = -1
  183. }
  184. this.pageList()
  185. },
  186. },
  187. onReachBottom() {
  188. // 判断是否有数据
  189. if (this.total > this.pageNum * 20) {
  190. setTimeout(() => {
  191. ++this.pageNum
  192. this.getList()
  193. }, 500)
  194. } else {
  195. uni.$u.toast('没有更多数据了')
  196. }
  197. },
  198. }
  199. </script>
  200. <style lang="scss" scoped>
  201. .order {
  202. padding-bottom: 40rpx;
  203. &-state-search {
  204. position: relative;
  205. width: 100%;
  206. position: fixed;
  207. z-index: 100;
  208. background-color: #FFFFFF;
  209. box-shadow: 0 5rpx 5rpx #ececec;
  210. }
  211. &-list {
  212. background-color: #F8F8F8;
  213. margin: 0rpx 10rpx 0;
  214. padding-top: 100rpx;
  215. &-data {
  216. navigator {
  217. margin-bottom: 10rpx;
  218. }
  219. navigator:last-child {
  220. margin-bottom: 0;
  221. }
  222. &-item {
  223. margin-bottom: 10rpx;
  224. padding: 20rpx 30rpx;
  225. background-color: #FFFFFF;
  226. justify-content: space-between;
  227. background-color: #FFFFFF;
  228. }
  229. &-item {
  230. &__info {
  231. &__title {
  232. justify-content: space-between;
  233. .number {
  234. line-height: 40rpx;
  235. }
  236. .success {
  237. color: $uni-text-color;
  238. }
  239. }
  240. &__detail {
  241. padding: 20rpx 0;
  242. justify-content: space-between;
  243. border-bottom: 1px solid rgba(236, 236, 236, 100);
  244. &__left {
  245. display: flex;
  246. height: 170rpx;
  247. .img {
  248. image {
  249. width: 134rpx;
  250. height: 170rpx;
  251. margin-right: 20rpx;
  252. }
  253. }
  254. }
  255. &__right {
  256. flex: 1;
  257. display: flex;
  258. height: 170rpx;
  259. flex-direction: column;
  260. justify-content: space-between;
  261. align-items: flex-end;
  262. }
  263. }
  264. &__detail:last-child {
  265. border: none;
  266. }
  267. &__total {
  268. display: flex;
  269. align-items: center;
  270. justify-content: flex-end;
  271. padding: 10rpx 0;
  272. .money {
  273. font-weight: bold;
  274. margin-left: 54rpx;
  275. }
  276. }
  277. &__btn {
  278. display: flex;
  279. align-items: center;
  280. justify-content: flex-end;
  281. padding-top: 10rpx;
  282. border-top: 1px solid rgba(236, 236, 236, 100);
  283. text {
  284. display: block;
  285. box-sizing: border-box;
  286. margin: 0 0 0 40rpx;
  287. width: 160rpx;
  288. height: 60rpx;
  289. line-height: 60rpx;
  290. text-align: center;
  291. font-size: 24rpx;
  292. border-radius: 8rpx;
  293. border: none;
  294. }
  295. text:first-child {
  296. background-color: #fff;
  297. line-height: 56rpx;
  298. border: 2rpx solid $uni-bg-color;
  299. }
  300. text:last-child {
  301. background-color: $uni-bg-color;
  302. color: #FFFFFF;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. }
  309. .empty {
  310. height: 60vh;
  311. }
  312. }
  313. </style>