index.vue 16 KB

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