index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <view>
  3. <u-navbar title="我的订单" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
  4. <view class="order">
  5. <!-- 订单导航 -->
  6. <view class="flex order-state-search">
  7. <u-tabs @change="changeTab" :scrollable="false" :list="statusArr" lineWidth="20" lineHeight="4"
  8. lineColor="#E96737" :activeStyle="{
  9. color: '#333',
  10. transform: 'scale(1.1)',
  11. width: '50px',
  12. }" :inactiveStyle="{
  13. color: '#666666',
  14. transform: 'scale(1)',
  15. width: '50px'
  16. }" itemStyle="padding-left: 15px; padding-right: 15px; height: 44px;text-align: center;">
  17. </u-tabs>
  18. </view>
  19. <!-- 订单列表 -->
  20. <view class="order-list">
  21. <view class="order-list-item" v-for="(item, index) in list" :key="index">
  22. <view class="order-list-item__state">
  23. <text class="success" v-if="!status">{{ item.status && item.status.desc }}</text>
  24. </view>
  25. <view class="order-list-item__goods" @click="toDetail(item)">
  26. <view class="order-list-item__goods-item" v-for="(items, indexs) in item.items" :key="indexs">
  27. <image :src="items.picUrl" mode="aspectFit"></image>
  28. <view class="info">
  29. <view class="info-title ells">{{ items.title }}</view>
  30. <view class="info-num flex">
  31. <view class="info-num-price">¥{{ $numberFormat(items.price) }}</view>
  32. <view class="info-num-goods">x{{ items.goodsNum }}</view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="order-list-item-price flex">
  38. <view class="order-list-item-price__num">共计<text>{{ item.orderNum }}</text>商品,</view>
  39. <view class="order-list-item-price__total">总金额:<text>¥{{ $numberFormat(item.payAmt) }}</text></view>
  40. </view>
  41. <view class="order-list-item-btn flex">
  42. <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>
  43. <view class="order-list-item-btn-item flex cancel" v-if="item.status.value == 0" @click="cancelOrder(item.orderId)"><text>取消订单</text></view>
  44. <view class="order-list-item-btn-item flex detail" @click="toDetail(item)"><text>查看详情</text></view>
  45. <view class="order-list-item-btn-item flex pay"v-if="item.status.value == 0" @click="payOrder(item)"><text>去支付</text></view>
  46. </view>
  47. </view>
  48. </view>
  49. <view class="flex empty" v-if="!list.length && !loading">
  50. <view class="center">
  51. <image class="center-img" src="https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/v2/nodata_4.png" mode=""></image>
  52. <view class="center-font">暂无相关订单...</view>
  53. </view>
  54. <!-- <u-empty text="还没有订单" mode="order" /> -->
  55. </view>
  56. </view>
  57. <auth :auth-show="authShow" @close="authShow = false" />
  58. </view>
  59. </template>
  60. <script>
  61. import env from '../../config/env.js'
  62. import $http from '@/utils/request.js'
  63. import Auth from '../../components/auth/auth.vue'
  64. export default {
  65. components: {
  66. Auth
  67. },
  68. data() {
  69. return {
  70. loading: false,
  71. pageNum: 1,
  72. total: 100,
  73. list: [],
  74. status: null,
  75. statusArr: [{
  76. name: '全部'
  77. }, {
  78. name: '待付款',
  79. }, {
  80. name: '待发货'
  81. }, {
  82. name: '待收货'
  83. }, {
  84. name: '已完成'
  85. }, ],
  86. authShow: false,
  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] + '?imageView2/2/w/170'
  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. toDetail(item) {
  146. uni.navigateTo({
  147. url: `/packageGoods/order/detail?id=${ item.orderId }`
  148. })
  149. },
  150. // 查看物流
  151. toLogistics(item) {
  152. uni.navigateTo({
  153. url: `/packageGoods/order/logistics?id=${ item.orderId }`
  154. });
  155. },
  156. payOrder(item) {
  157. let _this = this
  158. let payIng = false
  159. if (payIng) return
  160. uni.showLoading({
  161. title: '加载中'
  162. });
  163. $http.post('/api/v1/mp/user/deliver/order/pay', {
  164. orderId: item.orderId,
  165. payType: 2
  166. }).then(ele => {
  167. uni.hideLoading();
  168. payIng = true
  169. if (ele.code == 0) {
  170. uni.requestPayment({
  171. timeStamp: ele.data.timeStamp,
  172. nonceStr: ele.data.nonceStr,
  173. package: ele.data.package,
  174. signType: ele.data.signType,
  175. paySign: ele.data.paySign,
  176. success() {
  177. uni.showToast({
  178. title: '支付成功',
  179. icon: 'success',
  180. duration: 2000
  181. })
  182. _this.pageList()
  183. },
  184. fail() {
  185. payIng = false
  186. }
  187. })
  188. } else if (ele.code == 1005) {
  189. _this.authShow = true
  190. } else {
  191. payIng = false
  192. uni.$u.toast('支付失败!');
  193. }
  194. }).catch(() => {
  195. payIng = false
  196. uni.$u.toast('支付失败!');
  197. uni.hideLoading();
  198. })
  199. },
  200. changeTab(e) {
  201. if (e.index == 0) {
  202. this.status = null
  203. } else if (e.index == 1) {
  204. this.status = '0'
  205. } else if (e.index == 2) {
  206. this.status = '1,4'
  207. } else if (e.index == 3) {
  208. this.status = '2'
  209. } else if (e.index == 4) {
  210. this.status = '3'
  211. }
  212. this.pageList()
  213. },
  214. },
  215. onReachBottom() {
  216. // 判断是否有数据
  217. if (this.total > this.pageNum * 20) {
  218. setTimeout(() => {
  219. ++this.pageNum
  220. this.getList()
  221. }, 500)
  222. } else {
  223. uni.$u.toast('已经到底了')
  224. }
  225. },
  226. }
  227. </script>
  228. <style lang="scss" scoped>
  229. .order {
  230. padding-bottom: 40rpx;
  231. // 订单导航
  232. &-state-search {
  233. position: relative;
  234. width: 100%;
  235. position: fixed;
  236. z-index: 100;
  237. background-color: #FFFFFF;
  238. box-shadow: 0 5rpx 5rpx #ececec;
  239. }
  240. // 订单列表
  241. &-list {
  242. margin: 0rpx 34rpx 0;
  243. padding-top: 110rpx;
  244. &-item {
  245. background: #FFFFFF;
  246. border-radius: 6rpx;
  247. margin-bottom: 22rpx;
  248. padding: 20rpx 34rpx;
  249. // 订单状态
  250. &__state {
  251. font-size: 30rpx;
  252. line-height: 30rpx;
  253. margin-bottom: 22rpx;
  254. .success {
  255. color: #FF1818;
  256. }
  257. }
  258. // 商品列表
  259. &__goods {
  260. margin-bottom: 20rpx;
  261. &-item{
  262. display: flex;
  263. padding: 22rpx;
  264. box-shadow: 0px 0px 8px 0px rgba(26, 35, 113, 0.08);
  265. border-radius: 4rpx;
  266. margin-bottom: 20rpx;
  267. image {
  268. width: 220rpx;
  269. height: 200rpx;
  270. border-radius: 12rpx;
  271. margin-right: 24rpx;
  272. }
  273. .info {
  274. display: flex;
  275. flex-direction: column;
  276. justify-content: space-between;
  277. flex: 1;
  278. padding-bottom: 34rpx;
  279. &-title {
  280. font-weight: bold;
  281. line-height: 40rpx;
  282. }
  283. &-num {
  284. justify-content: space-between;
  285. &-price {
  286. font-size: 24rpx;
  287. }
  288. &-goods {
  289. color: #999999;
  290. }
  291. }
  292. }
  293. }
  294. &-item:last-child {
  295. margin-bottom: 0;
  296. }
  297. }
  298. // 订单价格
  299. &-price {
  300. justify-content: flex-end;
  301. padding-bottom: 18rpx;
  302. border-bottom: 1px solid #E5E5E5;
  303. margin-bottom: 22rpx;
  304. &__num {
  305. text {
  306. color: #F9822C;
  307. }
  308. }
  309. &__total {
  310. text {
  311. color: #F24E4E;
  312. }
  313. }
  314. }
  315. // 操作按钮
  316. &-btn {
  317. justify-content: flex-end;
  318. &-item {
  319. width: 200rpx;
  320. height: 66rpx;
  321. font-size: 30rpx;
  322. border-radius: 33rpx;
  323. margin-left: 44rpx;
  324. text {
  325. line-height: 30rpx;
  326. }
  327. }
  328. .logistics {
  329. border: 1px solid #F9822C;
  330. color: #F9822C;
  331. }
  332. .detail {
  333. background-color: rgb(249, 130, 44);
  334. color: #FFFFFF;
  335. }
  336. .cancel {
  337. border: 1px solid #c4c6c9;
  338. color: #c4c6c9;
  339. }
  340. .pay {
  341. background-color: #5ac725;
  342. color: #fff;
  343. }
  344. &-item:first-child {
  345. margin-left: 0;
  346. }
  347. }
  348. }
  349. &-item:last-child {
  350. margin-bottom: 0;
  351. }
  352. }
  353. // 空状态
  354. .empty {
  355. height: 60vh;
  356. .center {
  357. text-align: center;
  358. &-img {
  359. width: 228rpx;
  360. height: 320rpx;
  361. }
  362. &-font {
  363. font-size: 30rpx;
  364. font-weight: 400;
  365. color: #999999;
  366. margin-bottom: 250rpx;
  367. }
  368. }
  369. }
  370. }
  371. </style>