index.vue 16 KB

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