index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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 && item.type === 1" @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. this.loading = true
  105. $http.post(`/api/v1/mp/user/deliver/order/list?pageNum=${ this.pageNum }&pageSize=20`, {
  106. status: this.status
  107. }).then(res => {
  108. this.loading = false
  109. if (res.code == 0) {
  110. res.rows.forEach(item => {
  111. let items = item.items
  112. items.forEach(item => {
  113. let picUrlArr = item.picUrl.split(',')
  114. item.picUrl = env.filePublic + picUrlArr[0] + '?imageView2/2/w/170'
  115. })
  116. item.status = JSON.parse(item.status)
  117. })
  118. this.total = res.total
  119. this.list = this.list.concat(res.rows)
  120. }
  121. }).catch(() => {
  122. this.loading = false
  123. })
  124. },
  125. pageList() {
  126. this.pageNum = 1
  127. this.list = []
  128. this.getList()
  129. },
  130. cancelOrder(id) {
  131. let _this = this
  132. uni.showModal({
  133. title: '提示',
  134. content: '您确认要取消订单吗?',
  135. success(res) {
  136. if (res.confirm) {
  137. $http.post('/api/v1/mp/user/deliver/order/cancel', {
  138. orderId: id
  139. }).then(res => {
  140. if (res.code == 0) {
  141. uni.$u.toast('订单取消成功');
  142. _this.pageList()
  143. }
  144. })
  145. }
  146. }
  147. })
  148. },
  149. toDetail(item) {
  150. uni.navigateTo({
  151. url: `/packageGoods/order/detail?id=${ item.orderId }`
  152. })
  153. },
  154. // 查看物流
  155. toLogistics(item) {
  156. uni.navigateTo({
  157. url: `/packageGoods/order/logistics?id=${ item.orderId }`
  158. });
  159. },
  160. payOrder(item) {
  161. let _this = this
  162. let payIng = false
  163. if (payIng) return
  164. uni.showLoading({
  165. title: '加载中'
  166. });
  167. // #ifdef MP-ALIPAY
  168. let data = {
  169. orderId: item.orderId,
  170. payType: 1,
  171. appSource: appId
  172. }
  173. // #endif
  174. // #ifndef MP-ALIPAY
  175. let data = {
  176. orderId: item.orderId,
  177. payType: 2,
  178. appSource: appId
  179. }
  180. // #endif
  181. $http.post('/api/v1/mp/user/deliver/order/pay', data).then(ele => {
  182. uni.hideLoading();
  183. payIng = true
  184. if (ele.code == 0) {
  185. // #ifdef MP-ALIPAY
  186. my.tradePay({
  187. tradeNO: ele.data.pay_info,
  188. success(resu) {
  189. if(resu.resultCode == '9000'){
  190. uni.showToast({
  191. title: '支付成功',
  192. icon: 'success',
  193. duration: 2000
  194. })
  195. _this.pageList()
  196. }else {
  197. payIng = false
  198. }
  199. },
  200. fail() {
  201. payIng = false
  202. }
  203. })
  204. // #endif
  205. // #ifndef MP-ALIPAY
  206. uni.requestPayment({
  207. timeStamp: ele.data.timeStamp,
  208. nonceStr: ele.data.nonceStr,
  209. package: ele.data.package,
  210. signType: ele.data.signType,
  211. paySign: ele.data.paySign,
  212. success() {
  213. uni.showToast({
  214. title: '支付成功',
  215. icon: 'success',
  216. duration: 2000
  217. })
  218. _this.pageList()
  219. },
  220. fail() {
  221. payIng = false
  222. }
  223. })
  224. // #endif
  225. } else if (ele.code == 1005) {
  226. _this.authShow = true
  227. } else if (ele.code == 1026) {
  228. _this.authShow = true
  229. } else {
  230. payIng = false
  231. uni.$u.toast(res.msg);
  232. }
  233. }).catch(() => {
  234. payIng = false
  235. uni.$u.toast('订单创建失败');
  236. uni.hideLoading();
  237. })
  238. },
  239. changeTab(e) {
  240. if (e.index == 0) {
  241. this.status = null
  242. } else if (e.index == 1) {
  243. this.status = '0'
  244. } else if (e.index == 2) {
  245. this.status = '1,4'
  246. } else if (e.index == 3) {
  247. this.status = '2'
  248. } else if (e.index == 4) {
  249. this.status = '3'
  250. }
  251. this.pageList()
  252. },
  253. },
  254. onReachBottom() {
  255. if(this.total < this.pageNum * 20) return ;
  256. this.statusNomore = 'loading';
  257. ++this.pageNum
  258. if(this.total < this.pageNum * 20) this.statusNomore = 'nomore';
  259. else this.statusNomore = 'loading';
  260. this.getList()
  261. },
  262. }
  263. </script>
  264. <style lang="scss" scoped>
  265. .order {
  266. padding-bottom: 40rpx;
  267. // 订单导航
  268. &-state-search {
  269. position: relative;
  270. width: 100%;
  271. position: fixed;
  272. z-index: 100;
  273. background-color: #FFFFFF;
  274. box-shadow: 0 5rpx 5rpx #ececec;
  275. }
  276. // 订单列表
  277. &-list {
  278. margin: 0rpx 34rpx 0;
  279. padding-top: 110rpx;
  280. &-item {
  281. background: #FFFFFF;
  282. border-radius: 6rpx;
  283. margin-bottom: 22rpx;
  284. padding: 20rpx 34rpx;
  285. // 订单状态
  286. &__state {
  287. font-size: 30rpx;
  288. line-height: 30rpx;
  289. margin-bottom: 22rpx;
  290. color: #F9822C;
  291. .success {
  292. color: #999;
  293. }
  294. }
  295. // 商品列表
  296. &__goods {
  297. &-item{
  298. display: flex;
  299. padding: 20rpx 20rpx;
  300. border-radius: 4rpx;
  301. border-bottom: 1px solid rgba(102, 102, 102, 0.12);
  302. image {
  303. width: 220rpx;
  304. height: 200rpx;
  305. border-radius: 12rpx;
  306. margin-right: 24rpx;
  307. }
  308. .info {
  309. display: flex;
  310. flex-direction: column;
  311. justify-content: space-between;
  312. flex: 1;
  313. padding-bottom: 34rpx;
  314. &-title {
  315. font-weight: bold;
  316. line-height: 40rpx;
  317. }
  318. &-num {
  319. justify-content: space-between;
  320. &-price {
  321. font-size: 24rpx;
  322. }
  323. &-goods {
  324. color: #999999;
  325. }
  326. }
  327. }
  328. }
  329. &-item:last-child {
  330. margin-bottom: 0;
  331. border: none;
  332. }
  333. }
  334. // 订单价格
  335. &-price {
  336. justify-content: flex-end;
  337. padding-bottom: 18rpx;
  338. border-bottom: 1px solid #E5E5E5;
  339. margin-bottom: 22rpx;
  340. &__total {
  341. text:first-child {
  342. font-size: 24rpx;
  343. font-weight: normal;
  344. }
  345. text {
  346. font-size: 30rpx;
  347. font-weight: bold;
  348. color: #F9822C;
  349. }
  350. }
  351. }
  352. // 操作按钮
  353. &-btn {
  354. justify-content: flex-end;
  355. &-item {
  356. width: 200rpx;
  357. height: 66rpx;
  358. font-size: 30rpx;
  359. border-radius: 33rpx;
  360. margin-left: 44rpx;
  361. text {
  362. line-height: 30rpx;
  363. }
  364. }
  365. .logistics {
  366. border: 1px solid #F9822C;
  367. color: #F9822C;
  368. }
  369. .detail {
  370. background-color: rgb(249, 130, 44);
  371. color: #FFFFFF;
  372. }
  373. .cancel {
  374. border: 1px solid #c4c6c9;
  375. color: #c4c6c9;
  376. }
  377. .pay {
  378. background-color: #5ac725;
  379. color: #fff;
  380. }
  381. &-item:first-child {
  382. margin-left: 0;
  383. }
  384. }
  385. }
  386. &-item:last-child {
  387. margin-bottom: 0;
  388. }
  389. }
  390. // 空状态
  391. .empty {
  392. height: 60vh;
  393. .center {
  394. text-align: center;
  395. &-img {
  396. width: 228rpx;
  397. height: 320rpx;
  398. }
  399. &-font {
  400. font-size: 30rpx;
  401. font-weight: 400;
  402. color: #999999;
  403. margin-bottom: 250rpx;
  404. }
  405. }
  406. }
  407. }
  408. </style>