index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <template>
  2. <view>
  3. <!-- #ifdef MP-ALIPAY -->
  4. <u-navbar title="我的订单" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" leftIconSize="0"/>
  5. <!-- #endif -->
  6. <!-- #ifndef MP-ALIPAY -->
  7. <u-navbar title="我的订单" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
  8. <!-- #endif -->
  9. <view class="order">
  10. <!-- 订单导航 -->
  11. <view class="flex order-state-search">
  12. <u-tabs @change="changeTab" :scrollable="false" :list="statusArr" lineWidth="20" lineHeight="4"
  13. lineColor="#E96737" :activeStyle="{
  14. color: '#333',
  15. transform: 'scale(1.1)',
  16. width: '50px',
  17. }" :inactiveStyle="{
  18. color: '#666666',
  19. transform: 'scale(1)',
  20. width: '50px'
  21. }" itemStyle="padding-left: 15px; padding-right: 15px; height: 44px;text-align: center;">
  22. </u-tabs>
  23. </view>
  24. <!-- 订单列表 -->
  25. <view class="order-list">
  26. <view class="order-list-item" v-for="(item, index) in list" :key="index">
  27. <view class="order-list-item__state">
  28. <text class="success" v-if="item.status.value == -1 || item.status.value == 3">{{ item.status && item.status.desc }}</text>
  29. <text v-else>{{ item.status && item.status.desc }}</text>
  30. </view>
  31. <view class="order-list-item__goods" @click="toDetail(item)">
  32. <view class="order-list-item__goods-item" v-for="(items, indexs) in item.items" :key="indexs">
  33. <image :src="items.picUrl" mode="aspectFit"></image>
  34. <view class="info">
  35. <view class="info-title ells">{{ items.title }}</view>
  36. <view class="info-num flex">
  37. <view class="info-num-price">¥{{ $numberFormat(items.price) }}</view>
  38. <view class="info-num-goods">x{{ items.goodsNum }}</view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="order-list-item-price flex">
  44. <view class="order-list-item-price__num">共计<text>{{ item.orderNum }}</text>商品,</view>
  45. <view class="order-list-item-price__total">总金额:<text>¥</text><text>{{ $numberFormat(item.payAmt) }}</text></view>
  46. </view>
  47. <view class="order-list-item-btn flex">
  48. <view class="order-list-item-btn-item flex logistics" v-if="item.status.value == 2 || item.status.value == 3" @click="toLogistics(item)"><text>查看物流</text></view>
  49. <view class="order-list-item-btn-item flex cancel" v-if="item.status.value == 0" @click="cancelOrder(item.orderId)"><text>取消订单</text></view>
  50. <view class="order-list-item-btn-item flex detail" @click="toDetail(item)"><text>查看详情</text></view>
  51. <view class="order-list-item-btn-item flex pay"v-if="item.status.value == 0" @click="payOrder(item)"><text>去支付</text></view>
  52. </view>
  53. </view>
  54. <u-loadmore :line="true" v-if="list.length>3" :status="statusNomore" :loading-text="'努力加载中'" :nomore-text="'已经到底了'" />
  55. </view>
  56. <view class="flex empty" v-if="!list.length && !loading">
  57. <view class="center">
  58. <image class="center-img" src="https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/v2/nodata_4.png" mode="scaleToFill"></image>
  59. <view class="center-font">暂无相关订单...</view>
  60. </view>
  61. <!-- <u-empty text="还没有订单" mode="order" /> -->
  62. </view>
  63. </view>
  64. <auth :auth-show="authShow" @close="authShow = false" />
  65. </view>
  66. </template>
  67. <script>
  68. import env from '../../config/env.js'
  69. import $http from '@/utils/request.js'
  70. import appId from '@/config/appId.js'
  71. import Auth from '../../components/auth/auth.vue'
  72. export default {
  73. components: {
  74. Auth
  75. },
  76. data() {
  77. return {
  78. statusNomore: 'nomore',//上拉刷新状态
  79. loading: false,
  80. pageNum: 1,
  81. total: 100,
  82. list: [],
  83. status: null,
  84. statusArr: [{
  85. name: '全部'
  86. }, {
  87. name: '待付款',
  88. }, {
  89. name: '待发货'
  90. }, {
  91. name: '待收货'
  92. }, {
  93. name: '已完成'
  94. }, ],
  95. authShow: false,
  96. };
  97. },
  98. onLoad(opthios) {},
  99. onShow() {
  100. this.pageList()
  101. },
  102. methods: {
  103. getList() {
  104. uni.showLoading({
  105. title: '加载中'
  106. });
  107. this.loading = true
  108. $http.post(`/api/v1/mp/user/deliver/order/list?pageNum=${ this.pageNum }&pageSize=20`, {
  109. status: this.status
  110. }).then(res => {
  111. uni.hideLoading();
  112. this.loading = false
  113. if (res.code == 0) {
  114. res.rows.forEach(item => {
  115. let items = item.items
  116. items.forEach(item => {
  117. let picUrlArr = item.picUrl.split(',')
  118. item.picUrl = env.filePublic + picUrlArr[0] + '?imageView2/2/w/170'
  119. })
  120. item.status = JSON.parse(item.status)
  121. })
  122. this.total = res.total
  123. this.list = this.list.concat(res.rows)
  124. }
  125. }).catch(() => {
  126. uni.hideLoading();
  127. this.loading = false
  128. })
  129. },
  130. pageList() {
  131. this.pageNum = 1
  132. this.list = []
  133. this.getList()
  134. },
  135. cancelOrder(id) {
  136. let _this = this
  137. uni.showModal({
  138. title: '提示',
  139. content: '您确认要取消订单吗?',
  140. success(res) {
  141. if (res.confirm) {
  142. $http.post('/api/v1/mp/user/deliver/order/cancel', {
  143. orderId: id
  144. }).then(res => {
  145. if (res.code == 0) {
  146. uni.$u.toast('订单取消成功');
  147. _this.pageList()
  148. }
  149. })
  150. }
  151. }
  152. })
  153. },
  154. toDetail(item) {
  155. uni.navigateTo({
  156. url: `/packageGoods/order/detail?id=${ item.orderId }`
  157. })
  158. },
  159. // 查看物流
  160. toLogistics(item) {
  161. uni.navigateTo({
  162. url: `/packageGoods/order/logistics?id=${ item.orderId }`
  163. });
  164. },
  165. payOrder(item) {
  166. let _this = this
  167. let payIng = false
  168. if (payIng) return
  169. uni.showLoading({
  170. title: '加载中'
  171. });
  172. // #ifdef MP-ALIPAY
  173. let data = {
  174. orderId: item.orderId,
  175. payType: 1,
  176. appSource: appId
  177. }
  178. // #endif
  179. // #ifndef MP-ALIPAY
  180. let data = {
  181. orderId: item.orderId,
  182. payType: 2,
  183. appSource: appId
  184. }
  185. // #endif
  186. $http.post('/api/v1/mp/user/deliver/order/pay', data).then(ele => {
  187. uni.hideLoading();
  188. payIng = true
  189. if (ele.code == 0) {
  190. // #ifdef MP-ALIPAY
  191. my.tradePay({
  192. tradeNO: ele.data.pay_info,
  193. success(resu) {
  194. if(resu.resultCode == '9000'){
  195. uni.showToast({
  196. title: '支付成功',
  197. icon: 'success',
  198. duration: 2000
  199. })
  200. _this.pageList()
  201. }else {
  202. payIng = false
  203. }
  204. },
  205. fail() {
  206. payIng = false
  207. }
  208. })
  209. // #endif
  210. // #ifndef MP-ALIPAY
  211. uni.requestPayment({
  212. timeStamp: ele.data.timeStamp,
  213. nonceStr: ele.data.nonceStr,
  214. package: ele.data.package,
  215. signType: ele.data.signType,
  216. paySign: ele.data.paySign,
  217. success() {
  218. uni.showToast({
  219. title: '支付成功',
  220. icon: 'success',
  221. duration: 2000
  222. })
  223. _this.pageList()
  224. },
  225. fail() {
  226. payIng = false
  227. }
  228. })
  229. // #endif
  230. } else if (ele.code == 1005) {
  231. _this.authShow = true
  232. } else if (ele.code == 1026) {
  233. _this.authShow = true
  234. } else {
  235. payIng = false
  236. uni.$u.toast(res.msg);
  237. }
  238. }).catch(() => {
  239. payIng = false
  240. uni.$u.toast('订单创建失败');
  241. uni.hideLoading();
  242. })
  243. },
  244. changeTab(e) {
  245. if (e.index == 0) {
  246. this.status = null
  247. } else if (e.index == 1) {
  248. this.status = '0'
  249. } else if (e.index == 2) {
  250. this.status = '1,4'
  251. } else if (e.index == 3) {
  252. this.status = '2'
  253. } else if (e.index == 4) {
  254. this.status = '3'
  255. }
  256. this.pageList()
  257. },
  258. },
  259. onReachBottom() {
  260. if(this.total < this.pageNum * 20) return ;
  261. this.statusNomore = 'loading';
  262. // setTimeout(() => {
  263. ++this.pageNum
  264. if(this.total < this.pageNum * 20) this.statusNomore = 'nomore';
  265. else this.statusNomore = 'loading';
  266. this.getList()
  267. // }, 2000)
  268. },
  269. }
  270. </script>
  271. <style lang="scss" scoped>
  272. .order {
  273. padding-bottom: 40rpx;
  274. // 订单导航
  275. &-state-search {
  276. position: relative;
  277. width: 100%;
  278. position: fixed;
  279. z-index: 100;
  280. background-color: #FFFFFF;
  281. box-shadow: 0 5rpx 5rpx #ececec;
  282. }
  283. // 订单列表
  284. &-list {
  285. margin: 0rpx 34rpx 0;
  286. padding-top: 110rpx;
  287. &-item {
  288. background: #FFFFFF;
  289. border-radius: 6rpx;
  290. margin-bottom: 22rpx;
  291. padding: 20rpx 34rpx;
  292. // 订单状态
  293. &__state {
  294. font-size: 30rpx;
  295. line-height: 30rpx;
  296. margin-bottom: 22rpx;
  297. color: #F9822C;
  298. .success {
  299. color: #999;
  300. }
  301. }
  302. // 商品列表
  303. &__goods {
  304. &-item{
  305. display: flex;
  306. padding: 20rpx 20rpx;
  307. border-radius: 4rpx;
  308. border-bottom: 1px solid rgba(102, 102, 102, 0.12);
  309. image {
  310. width: 220rpx;
  311. height: 200rpx;
  312. border-radius: 12rpx;
  313. margin-right: 24rpx;
  314. }
  315. .info {
  316. display: flex;
  317. flex-direction: column;
  318. justify-content: space-between;
  319. flex: 1;
  320. padding-bottom: 34rpx;
  321. &-title {
  322. font-weight: bold;
  323. line-height: 40rpx;
  324. }
  325. &-num {
  326. justify-content: space-between;
  327. &-price {
  328. font-size: 24rpx;
  329. }
  330. &-goods {
  331. color: #999999;
  332. }
  333. }
  334. }
  335. }
  336. &-item:last-child {
  337. margin-bottom: 0;
  338. border: none;
  339. }
  340. }
  341. // 订单价格
  342. &-price {
  343. justify-content: flex-end;
  344. padding-bottom: 18rpx;
  345. border-bottom: 1px solid #E5E5E5;
  346. margin-bottom: 22rpx;
  347. &__total {
  348. text:first-child {
  349. font-size: 24rpx;
  350. font-weight: normal;
  351. }
  352. text {
  353. font-size: 30rpx;
  354. font-weight: bold;
  355. color: #F9822C;
  356. }
  357. }
  358. }
  359. // 操作按钮
  360. &-btn {
  361. justify-content: flex-end;
  362. &-item {
  363. width: 200rpx;
  364. height: 66rpx;
  365. font-size: 30rpx;
  366. border-radius: 33rpx;
  367. margin-left: 44rpx;
  368. text {
  369. line-height: 30rpx;
  370. }
  371. }
  372. .logistics {
  373. border: 1px solid #F9822C;
  374. color: #F9822C;
  375. }
  376. .detail {
  377. background-color: rgb(249, 130, 44);
  378. color: #FFFFFF;
  379. }
  380. .cancel {
  381. border: 1px solid #c4c6c9;
  382. color: #c4c6c9;
  383. }
  384. .pay {
  385. background-color: #5ac725;
  386. color: #fff;
  387. }
  388. &-item:first-child {
  389. margin-left: 0;
  390. }
  391. }
  392. }
  393. &-item:last-child {
  394. margin-bottom: 0;
  395. }
  396. }
  397. // 空状态
  398. .empty {
  399. height: 60vh;
  400. .center {
  401. text-align: center;
  402. &-img {
  403. width: 228rpx;
  404. height: 320rpx;
  405. }
  406. &-font {
  407. font-size: 30rpx;
  408. font-weight: 400;
  409. color: #999999;
  410. margin-bottom: 250rpx;
  411. }
  412. }
  413. }
  414. }
  415. </style>