index.vue 8.6 KB

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