index.vue 12 KB

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