index.vue 15 KB

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