index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. <template>
  2. <view class="container">
  3. <mescroll-body ref="mescrollRef" :sticky="true" @init="mescrollInit" :down="{ native: true }" @down="downCallback"
  4. :up="upOption" @up="upCallback">
  5. <!-- tab栏 -->
  6. <u-tabs :list="tabs" :is-scroll="false" :current="curTab" active-color="#FA2209" :duration="0.2"
  7. @change="onChangeTab" />
  8. <!-- 订单列表 -->
  9. <view class="order-list">
  10. <view class="order-item" v-for="(item, index) in list.data" :key="index">
  11. <view class="item-top">
  12. <view class="item-top-left">
  13. <text class="order-time">{{ item.create_time }}</text>
  14. </view>
  15. <view class="item-top-right">
  16. <text class="state-text">{{ item.state_text }}</text>
  17. </view>
  18. </view>
  19. <!-- 商品列表 -->
  20. <view class="goods-list" @click="handleTargetDetail(item.order_id)">
  21. <view class="goods-item" v-for="(goods, idx) in item.goods" :key="idx">
  22. <!-- 商品图片 -->
  23. <view class="goods-image">
  24. <image class="image" :src="goods.goods_image" mode="widthFix"></image>
  25. </view>
  26. <!-- 商品信息 -->
  27. <view class="goods-content">
  28. <view class="goods-title twolist-hidden"><text>{{ goods.goods_name }}</text></view>
  29. <view class="goods-props clearfix">
  30. <view class="goods-props-item" v-for="(props, idx) in goods.goods_props" :key="idx">
  31. <text>{{ props.value.name }}</text>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 交易信息 -->
  36. <view class="goods-trade">
  37. <view class="goods-price">
  38. <text class="unit">¥</text>
  39. <text class="value">{{ goods.goods_price }}</text>
  40. </view>
  41. <view class="goods-num">
  42. <text>×{{ goods.total_num }}</text>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 订单合计 -->
  48. <view class="order-total">
  49. <text>共{{ item.total_num }}件商品,总金额</text>
  50. <text class="unit">¥</text>
  51. <text class="money">{{ item.pay_price }}</text>
  52. </view>
  53. <!-- 订单操作 -->
  54. <view v-if="item.order_status != 20" class="order-handle">
  55. <view class="btn-group clearfix">
  56. <!-- 未支付取消订单 -->
  57. <view v-if="item.pay_status.value == 10">
  58. <view class="btn-item" @click="onCancel(item.order_id)">取消</view>
  59. </view>
  60. <!-- 已支付取消订单 -->
  61. <block v-if="item.order_status != OrderStatusEnum.APPLY_CANCEL.value">
  62. <view v-if="item.pay_status == PayStatusEnum.SUCCESS.value && item.delivery_status == DeliveryStatusEnum.NOT_DELIVERED.value">
  63. <view class="btn-item" @click="onCancel(item.order_id)">申请取消</view>
  64. </view>
  65. </block>
  66. <view v-else class="f-28 col-8">取消申请中</view>
  67. <!-- 订单支付 -->
  68. <view v-if="item.pay_status == 10">
  69. <view class="btn-item active" @click="onPay(item.order_id)">去支付</view>
  70. </view>
  71. <!-- 确认收货 -->
  72. <view v-if="item.delivery_status == DeliveryStatusEnum.DELIVERED.value && item.receipt_status == ReceiptStatusEnum.NOT_RECEIVED.value">
  73. <view class="btn-item active" @click="onReceipt(item.order_id)">确认收货</view>
  74. </view>
  75. <!-- 订单评价 -->
  76. <view v-if="item.order_status == OrderStatusEnum.COMPLETED.value && item.is_comment == 0">
  77. <view class="btn-item" @click="handleTargetComment(item.order_id)">评价</view>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </mescroll-body>
  84. <!-- 支付方式弹窗 -->
  85. <u-popup v-model="showPayPopup" mode="bottom" border-radius="26" :closeable="true">
  86. <view class="pay-popup">
  87. <view class="title">请选择支付方式</view>
  88. <view class="pop-content">
  89. <!-- 微信支付 -->
  90. <!-- #ifdef MP-WEIXIN -->
  91. <view class="pay-item dis-flex flex-x-between" @click="onSelectPayType(PayTypeEnum.WECHAT.value)">
  92. <view class="item-left dis-flex flex-y-center">
  93. <view class="item-left_icon wechat">
  94. <text class="iconfont icon-wxpay"></text>
  95. </view>
  96. <view class="item-left_text">
  97. <text>{{ PayTypeEnum.WECHAT.name }}</text>
  98. </view>
  99. </view>
  100. </view>
  101. <!-- #endif -->
  102. <!-- 余额支付 -->
  103. <view class="pay-item dis-flex flex-x-between" @click="onSelectPayType(PayTypeEnum.BALANCE.value)">
  104. <view class="item-left dis-flex flex-y-center">
  105. <view class="item-left_icon balance">
  106. <text class="iconfont icon-qiandai"></text>
  107. </view>
  108. <view class="item-left_text">
  109. <text>{{ PayTypeEnum.BALANCE.name }}</text>
  110. </view>
  111. </view>
  112. </view>
  113. </view>
  114. </view>
  115. </u-popup>
  116. </view>
  117. </template>
  118. <script>
  119. import {
  120. DeliveryStatusEnum,
  121. DeliveryTypeEnum,
  122. OrderStatusEnum,
  123. PayStatusEnum,
  124. PayTypeEnum,
  125. ReceiptStatusEnum
  126. } from '@/common/enum/order'
  127. import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
  128. import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
  129. import { getEmptyPaginateObj, getMoreListData } from '@/utils/app'
  130. import * as OrderApi from '@/api/order'
  131. import { wxPayment } from '@/utils/app'
  132. // 每页记录数量
  133. const pageSize = 15
  134. // tab栏数据
  135. const tabs = [{
  136. name: `全部`,
  137. value: 'all'
  138. }, {
  139. name: `待支付`,
  140. value: 'payment'
  141. }, {
  142. name: `待发货`,
  143. value: 'delivery'
  144. }, {
  145. name: `待收货`,
  146. value: 'received'
  147. }, {
  148. name: `待评价`,
  149. value: 'comment'
  150. }]
  151. export default {
  152. components: {
  153. MescrollBody
  154. },
  155. mixins: [MescrollMixin],
  156. data() {
  157. return {
  158. // 枚举类
  159. DeliveryStatusEnum,
  160. DeliveryTypeEnum,
  161. OrderStatusEnum,
  162. PayStatusEnum,
  163. PayTypeEnum,
  164. ReceiptStatusEnum,
  165. // 当前页面参数
  166. options: { dataType: 'all' },
  167. // tab栏数据
  168. tabs,
  169. // 当前标签索引
  170. curTab: 0,
  171. // 订单列表数据
  172. list: getEmptyPaginateObj(),
  173. // 上拉加载配置
  174. upOption: {
  175. // 首次自动执行
  176. auto: true,
  177. // 每页数据的数量; 默认10
  178. page: { size: pageSize },
  179. // 数量要大于4条才显示无更多数据
  180. noMoreSize: 4,
  181. // 空布局
  182. empty: {
  183. tip: '亲,暂无订单记录'
  184. }
  185. },
  186. // 控制首次触发onShow事件时不刷新列表
  187. canReset: false,
  188. // 支付方式弹窗
  189. showPayPopup: false
  190. }
  191. },
  192. /**
  193. * 生命周期函数--监听页面加载
  194. */
  195. onLoad(options) {
  196. // 初始化当前选中的标签
  197. this.initCurTab(options)
  198. },
  199. /**
  200. * 生命周期函数--监听页面显示
  201. */
  202. onShow() {
  203. this.canReset && this.onRefreshList()
  204. this.canReset = true
  205. },
  206. methods: {
  207. // 初始化当前选中的标签
  208. initCurTab(options) {
  209. const app = this
  210. if (options.dataType) {
  211. const index = app.tabs.findIndex(item => item.value == options.dataType)
  212. app.curTab = index > -1 ? index : 0
  213. }
  214. },
  215. /**
  216. * 上拉加载的回调 (页面初始化时也会执行一次)
  217. * 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
  218. * @param {Object} page
  219. */
  220. upCallback(page) {
  221. const app = this
  222. // 设置列表数据
  223. app.getOrderList(page.num)
  224. .then(list => {
  225. const curPageLen = list.data.length
  226. const totalSize = list.data.total
  227. app.mescroll.endBySize(curPageLen, totalSize)
  228. })
  229. .catch(() => app.mescroll.endErr())
  230. },
  231. // 获取订单列表
  232. getOrderList(pageNo = 1) {
  233. const app = this
  234. return new Promise((resolve, reject) => {
  235. OrderApi.list({ dataType: app.getTabValue(), page: pageNo }, { load: false })
  236. .then(result => {
  237. // 合并新数据
  238. const newList = app.initList(result.data.list)
  239. app.list.data = getMoreListData(newList, app.list, pageNo)
  240. resolve(newList)
  241. })
  242. })
  243. },
  244. // 初始化订单列表数据
  245. initList(newList) {
  246. newList.data.forEach(item => {
  247. item.total_num = 0
  248. item.goods.forEach(goods => {
  249. item.total_num += goods.total_num
  250. })
  251. })
  252. return newList
  253. },
  254. // 获取当前标签项的值
  255. getTabValue() {
  256. return this.tabs[this.curTab].value
  257. },
  258. // 切换标签项
  259. onChangeTab(index) {
  260. const app = this
  261. // 设置当前选中的标签
  262. app.curTab = index
  263. // 刷新订单列表
  264. app.onRefreshList()
  265. },
  266. // 刷新订单列表
  267. onRefreshList() {
  268. this.list = getEmptyPaginateObj()
  269. setTimeout(() => {
  270. this.mescroll.resetUpScroll()
  271. }, 120)
  272. },
  273. // 取消订单
  274. onCancel(orderId) {
  275. const app = this
  276. uni.showModal({
  277. title: '友情提示',
  278. content: '确认要取消该订单吗?',
  279. success(o) {
  280. if (o.confirm) {
  281. OrderApi.cancel(orderId)
  282. .then(result => {
  283. // 显示成功信息
  284. app.$success(result.message)
  285. // 刷新订单列表
  286. app.onRefreshList()
  287. })
  288. }
  289. }
  290. });
  291. },
  292. // 确认收货
  293. onReceipt(orderId) {
  294. const app = this
  295. uni.showModal({
  296. title: '友情提示',
  297. content: '确认收到商品了吗?',
  298. success(o) {
  299. if (o.confirm) {
  300. OrderApi.receipt(orderId)
  301. .then(result => {
  302. // 显示成功信息
  303. app.$success(result.message)
  304. // 刷新订单列表
  305. app.onRefreshList()
  306. })
  307. }
  308. }
  309. });
  310. },
  311. // 点击去支付
  312. onPay(orderId) {
  313. // 记录订单id
  314. this.payOrderId = orderId
  315. // 显示支付方式弹窗
  316. this.showPayPopup = true
  317. },
  318. // 选择支付方式
  319. onSelectPayType(payType) {
  320. const app = this
  321. // 隐藏支付方式弹窗
  322. this.showPayPopup = false
  323. // 发起支付请求
  324. OrderApi.pay(app.payOrderId, payType)
  325. .then(result => app.onSubmitCallback(result))
  326. },
  327. // 订单提交成功后回调
  328. onSubmitCallback(result) {
  329. const app = this
  330. // 发起微信支付
  331. if (result.data.pay_type == PayTypeEnum.WECHAT.value) {
  332. wxPayment(result.data.payment)
  333. .then(() => {
  334. app.$success('支付成功')
  335. setTimeout(() => {
  336. app.onRefreshList()
  337. }, 1500)
  338. })
  339. .catch(err => {
  340. app.$error('订单未支付')
  341. })
  342. .finally(() => {
  343. app.disabled = false
  344. })
  345. }
  346. // 余额支付
  347. if (result.data.pay_type == PayTypeEnum.BALANCE.value) {
  348. app.$success('支付成功')
  349. app.disabled = false
  350. setTimeout(() => {
  351. app.onRefreshList()
  352. }, 1500)
  353. }
  354. },
  355. // 跳转到订单详情页
  356. handleTargetDetail(orderId) {
  357. this.$navTo('pages/order/detail', { orderId })
  358. },
  359. // 跳转到订单评价页
  360. handleTargetComment(orderId) {
  361. this.$navTo('pages/order/comment/index', { orderId })
  362. }
  363. },
  364. }
  365. </script>
  366. <style lang="scss" scoped>
  367. // 项目内容
  368. .order-item {
  369. margin: 20rpx auto 20rpx auto;
  370. padding: 30rpx 30rpx;
  371. width: 94%;
  372. box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
  373. border-radius: 16rpx;
  374. background: #fff;
  375. }
  376. // 项目顶部
  377. .item-top {
  378. display: flex;
  379. justify-content: space-between;
  380. font-size: 26rpx;
  381. margin-bottom: 40rpx;
  382. .order-time {
  383. color: #777;
  384. }
  385. .state-text {
  386. color: $uni-text-color-active;
  387. }
  388. }
  389. // 商品列表
  390. .goods-list {
  391. // 商品项
  392. .goods-item {
  393. display: flex;
  394. margin-bottom: 40rpx;
  395. // 商品图片
  396. .goods-image {
  397. width: 180rpx;
  398. height: 180rpx;
  399. .image {
  400. display: block;
  401. width: 100%;
  402. height: 100%;
  403. border-radius: 8rpx;
  404. }
  405. }
  406. // 商品内容
  407. .goods-content {
  408. flex: 1;
  409. padding-left: 16rpx;
  410. padding-top: 16rpx;
  411. .goods-title {
  412. font-size: 26rpx;
  413. max-height: 76rpx;
  414. }
  415. .goods-props {
  416. margin-top: 14rpx;
  417. height: 40rpx;
  418. color: #ababab;
  419. font-size: 24rpx;
  420. overflow: hidden;
  421. .goods-props-item {
  422. display: inline-block;
  423. margin-right: 14rpx;
  424. padding: 4rpx 16rpx;
  425. border-radius: 12rpx;
  426. background-color: #F5F5F5;
  427. width: auto;
  428. }
  429. }
  430. }
  431. // 交易信息
  432. .goods-trade {
  433. padding-top: 16rpx;
  434. width: 150rpx;
  435. text-align: right;
  436. color: $uni-text-color-grey;
  437. font-size: 26rpx;
  438. .goods-price {
  439. vertical-align: bottom;
  440. margin-bottom: 16rpx;
  441. .unit {
  442. margin-right: -2rpx;
  443. font-size: 24rpx;
  444. }
  445. }
  446. }
  447. }
  448. }
  449. // 订单合计
  450. .order-total {
  451. font-size: 26rpx;
  452. vertical-align: bottom;
  453. text-align: right;
  454. height: 40rpx;
  455. margin-bottom: 30rpx;
  456. .unit {
  457. margin-left: 8rpx;
  458. margin-right: -2rpx;
  459. font-size: 26rpx;
  460. }
  461. .money {
  462. font-size: 28rpx;
  463. }
  464. }
  465. // 订单操作
  466. .order-handle {
  467. .btn-group {
  468. .btn-item {
  469. border-radius: 10rpx;
  470. padding: 6rpx 20rpx;
  471. font-size: 28rpx;
  472. float: right;
  473. color: #383838;
  474. border: 1rpx solid #a8a8a8;
  475. &.active {
  476. color: $uni-text-color-active;
  477. border: 1rpx solid $uni-text-color-active;
  478. }
  479. }
  480. }
  481. }
  482. // 弹出层-支付方式
  483. .pay-popup {
  484. padding: 24rpx;
  485. .title {
  486. font-size: 30rpx;
  487. margin-bottom: 40rpx;
  488. font-weight: bold;
  489. text-align: center;
  490. }
  491. .pop-content {
  492. min-height: 260rpx;
  493. padding: 0 10rpx;
  494. .pay-item {
  495. padding: 24rpx 35rpx;
  496. font-size: 28rpx;
  497. border-bottom: 1rpx solid #f1f1f1;
  498. &:last-child {
  499. border-bottom: none;
  500. }
  501. .item-left_icon {
  502. margin-right: 20rpx;
  503. font-size: 32rpx;
  504. &.wechat {
  505. color: #00c800;
  506. }
  507. &.balance {
  508. color: #ff9700;
  509. }
  510. }
  511. }
  512. }
  513. }
  514. </style>