index.vue 8.0 KB

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