index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. let picUrlArr = item.picUrl.split(',')
  109. item.picUrl = env.filePublic + picUrlArr[0]
  110. })
  111. item.status = JSON.parse(item.status)
  112. })
  113. this.total = res.total
  114. this.list = this.list.concat(res.rows)
  115. }
  116. }).catch(() => {
  117. uni.hideLoading();
  118. this.loading = false
  119. })
  120. },
  121. pageList() {
  122. this.pageNum = 1
  123. this.list = []
  124. this.getList()
  125. },
  126. cancelOrder(id) {
  127. let _this = this
  128. uni.showModal({
  129. title: '提示',
  130. content: '您确认要取消订单吗?',
  131. success(res) {
  132. if (res.confirm) {
  133. $http.post('/api/v1/mp/user/deliver/order/cancel', {
  134. orderId: id
  135. }).then(res => {
  136. if (res.code == 0) {
  137. uni.$u.toast('订单取消成功');
  138. _this.pageList()
  139. }
  140. })
  141. }
  142. }
  143. })
  144. },
  145. payOrder(item) {
  146. let _this = this
  147. let payIng = false
  148. if (payIng) return
  149. uni.showLoading();
  150. $http.post('/api/v1/mp/user/deliver/order/pay', {
  151. orderId: item.orderId,
  152. payType: 2
  153. }).then(ele => {
  154. uni.hideLoading();
  155. payIng = true
  156. if (ele.code == 0) {
  157. uni.requestPayment({
  158. timeStamp: ele.data.timeStamp,
  159. nonceStr: ele.data.nonceStr,
  160. package: ele.data.package,
  161. signType: ele.data.signType,
  162. paySign: ele.data.paySign,
  163. success() {
  164. uni.showToast({
  165. title: '支付成功',
  166. icon: 'success',
  167. duration: 2000
  168. })
  169. _this.pageList()
  170. },
  171. fail() {
  172. payIng = false
  173. }
  174. })
  175. } else {
  176. payIng = false
  177. uni.$u.toast('支付失败!');
  178. }
  179. }).catch(() => {
  180. payIng = false
  181. uni.$u.toast('支付失败!');
  182. uni.hideLoading();
  183. })
  184. },
  185. changeTab(e) {
  186. if (e.index == 0) {
  187. this.status = null
  188. } else if (e.index == 1) {
  189. this.status = 0
  190. } else if (e.index == 2) {
  191. this.status = 1
  192. } else if (e.index == 3) {
  193. this.status = 2
  194. } else if (e.index == 4) {
  195. this.status = -1
  196. }
  197. this.pageList()
  198. },
  199. },
  200. onReachBottom() {
  201. // 判断是否有数据
  202. if (this.total > this.pageNum * 20) {
  203. setTimeout(() => {
  204. ++this.pageNum
  205. this.getList()
  206. }, 500)
  207. } else {
  208. uni.$u.toast('没有更多数据了')
  209. }
  210. },
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .order {
  215. padding-bottom: 40rpx;
  216. &-state-search {
  217. position: relative;
  218. width: 100%;
  219. position: fixed;
  220. z-index: 100;
  221. background-color: #FFFFFF;
  222. box-shadow: 0 5rpx 5rpx #ececec;
  223. }
  224. &-list {
  225. background-color: #F8F8F8;
  226. margin: 0rpx 10rpx 0;
  227. padding-top: 100rpx;
  228. &-data {
  229. navigator {
  230. margin-bottom: 10rpx;
  231. }
  232. navigator:last-child {
  233. margin-bottom: 0;
  234. }
  235. &-item {
  236. margin-bottom: 10rpx;
  237. padding: 20rpx 30rpx;
  238. background-color: #FFFFFF;
  239. justify-content: space-between;
  240. background-color: #FFFFFF;
  241. }
  242. &-item {
  243. &__info {
  244. &__title {
  245. justify-content: space-between;
  246. .number {
  247. line-height: 40rpx;
  248. }
  249. .success {
  250. color: $uni-text-color;
  251. }
  252. }
  253. &__detail {
  254. padding: 20rpx 0;
  255. justify-content: space-between;
  256. border-bottom: 1px solid rgba(236, 236, 236, 100);
  257. &__left {
  258. display: flex;
  259. height: 170rpx;
  260. .img {
  261. image {
  262. width: 134rpx;
  263. height: 170rpx;
  264. margin-right: 20rpx;
  265. }
  266. }
  267. }
  268. &__right {
  269. flex: 1;
  270. display: flex;
  271. height: 170rpx;
  272. flex-direction: column;
  273. justify-content: space-between;
  274. align-items: flex-end;
  275. }
  276. }
  277. &__detail:last-child {
  278. border: none;
  279. }
  280. &__total {
  281. display: flex;
  282. align-items: center;
  283. justify-content: flex-end;
  284. padding: 10rpx 0;
  285. .money {
  286. font-weight: bold;
  287. margin-left: 54rpx;
  288. }
  289. }
  290. &__btn {
  291. display: flex;
  292. align-items: center;
  293. justify-content: flex-end;
  294. padding-top: 10rpx;
  295. border-top: 1px solid rgba(236, 236, 236, 100);
  296. text {
  297. display: block;
  298. box-sizing: border-box;
  299. margin: 0 0 0 40rpx;
  300. width: 160rpx;
  301. height: 60rpx;
  302. line-height: 60rpx;
  303. text-align: center;
  304. font-size: 24rpx;
  305. border-radius: 8rpx;
  306. border: none;
  307. }
  308. text:first-child {
  309. background-color: #fff;
  310. line-height: 56rpx;
  311. border: 2rpx solid $uni-bg-color;
  312. }
  313. text:last-child {
  314. background-color: $uni-bg-color;
  315. color: #FFFFFF;
  316. }
  317. }
  318. }
  319. }
  320. }
  321. }
  322. .empty {
  323. height: 60vh;
  324. }
  325. }
  326. </style>