index.vue 16 KB

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