index.vue 9.4 KB

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