index.vue 8.6 KB

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