index.vue 9.9 KB

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