order.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <template>
  2. <view class="container">
  3. <!-- #ifdef MP-ALIPAY -->
  4. <!-- 订单状态区 -->
  5. <view class="pos-f w-full state-area dflex navbar-area bg-main">
  6. <view class="nav-item dflex-c pos-r fs h-full" :class="{ active: tabCurrentIndex === index }"
  7. v-for="(item, index) in navList" :key="index" @click="tabClick(index)">
  8. {{ item.state }}
  9. </view>
  10. </view>
  11. <!-- 订单轮播区 -->
  12. <view class="order-area w-full" style="margin-top: 7vh;">
  13. <!-- 空白页 -->
  14. <use-empty v-if="navData.orderList.length === 0 && navData.loaded" e-style="round" e-type="cart"
  15. tip="订单数据为空" height="93vh"></use-empty>
  16. <!-- 订单列表区 -->
  17. <view class="padding-lr margin-bottom-sm" :class="index === 0 ? 'padding-top-sm' : ''"
  18. v-for="(item, index) in navData.orderList" :key="index">
  19. <!-- 订单项 -->
  20. <view class="order-item padding bg-main border-radius">
  21. <view @click="todetail(item)">
  22. <!-- 订单商品明细 -->
  23. <view class="goods-area" :class="{ 'margin-top': goodsIndex > 0 }"
  24. v-for="(goodsItem, goodsIndex) in item.orderDetails" :key="goodsIndex">
  25. <image :src="goodsItem.goodsMasterImg" mode="aspectFill"></image>
  26. <view class="right flex1">
  27. <text class="clamp-2">{{ goodsItem.goodsName }}</text>
  28. <view class="ft-dark fs-xs padding-top-xs">
  29. <text class="margin-right">× {{goodsItem.goodsCount}}</text>
  30. {{ goodsItem.goodsAttr || '&nbsp;&nbsp;' }}
  31. </view>
  32. <view class="margin-top-sm">
  33. <text class="price ft-main fs-sm">{{ goodsItem.goodsActualPrice }}</text>
  34. </view>
  35. </view>
  36. <!-- 实付款 -->
  37. <view class="dflex-e" style="padding-top: 70px;">
  38. <text class="fs-xs margin-right-xs">实付款</text>
  39. <text class="price ft-main">{{ item.totalPrice }}</text>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- 订单操作区 -->
  44. <view class="dflex-b margin-top-sm">
  45. <view>
  46. <!-- 当前状态 -->
  47. <!-- <text class="ft-dark" v-if="item.order.order_refund_state == '处理中'">退款处理中</text>
  48. <text class="ft-dark"
  49. v-else-if="item.order.order_refund_state">{{ item.order.order_refund_state }}</text>
  50. <text class="ft-dark" v-else-if="item.order.state == '待评价'">已发货</text>
  51. <text class="ft-dark" v-else>{{ item.order.state }}</text> -->
  52. </view>
  53. <view class="dflex-e">
  54. <view class="dflex" v-if="item.state == '1'">
  55. <button class="action-btn border-radius-big bg-main"
  56. @click="cancelOrder(item)">取消订单</button>
  57. <button v-if="item.state == '1'"
  58. class="action-btn border-radius-big bg-main main-btn"
  59. @click="payment(item)">立即支付</button>
  60. <!-- <button v-if="item.order.state == '待核实'"
  61. class="action-btn border-radius-big bg-main main-btn"
  62. @click="payment(item.order)">待核实</button> -->
  63. </view>
  64. <view class="dflex" v-if="item.state == '2'">
  65. <button
  66. class="action-btn border-radius-big bg-main" @click="torefund(item)">申请退款</button>
  67. <!-- <button v-if="!item.order.order_refund_state"
  68. class="action-btn border-radius-big bg-main" @click="torefund(item)">申请退款</button> -->
  69. </view>
  70. <button v-if="['3',].includes(item.state)"
  71. class="action-btn border-radius-big bg-main" @click="toexpress(item)">查看物流</button>
  72. <!-- <button v-if="!item.order.order_refund_state &&
  73. ['待收货', '待评价', '已完成'].includes(item.order.state)"
  74. class="action-btn border-radius-big bg-main" @click="toexpress(item)">查看物流</button> -->
  75. <view class="dflex" v-if="item.state == '3'">
  76. <button
  77. class="action-btn border-radius-big bg-main main-btn"
  78. @click="toreceipt(item)">确认收货</button>
  79. <!-- <button v-if="!item.order.order_refund_state"
  80. class="action-btn border-radius-big bg-main main-btn"
  81. @click="toreceipt(item)">确认收货</button> -->
  82. </view>
  83. <view class="dflex" v-if="item.state == '4'">
  84. <button class="action-btn border-radius-big bg-main main-btn"
  85. @click="toevaluate(item)">我要评价</button>
  86. </view>
  87. <view class="dflex" v-if="['6'].includes(item.state)">
  88. <button class="action-btn border-radius-big bg-main main-btn"
  89. @click="delOrder(item)">删除订单</button>
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. <!-- 上拉加载更多 -->
  96. <use-loadmore v-if="navData.orderList.length > 0 && navData.loaded && navData.hasmore"
  97. :type="navData.loadingType"></use-loadmore>
  98. </view>
  99. <!-- #endif -->
  100. <!-- #ifndef MP-ALIPAY -->
  101. <!-- 订单状态区 -->
  102. <!-- <scroll-view scroll-x="true" class="navbar-area bg-main" :scroll-left="scrollLeft"> -->
  103. <view class="state-area dflex navbar-area bg-main">
  104. <view class="nav-item dflex-c pos-r fs h-full" :class="{ active: tabCurrentIndex === index }"
  105. v-for="(item, index) in navList" :key="index" @click="tabClick(index)">
  106. {{ item.state }}
  107. </view>
  108. </view>
  109. <!-- </scroll-view> -->
  110. <!-- 订单轮播区 -->
  111. <swiper class="swiper-area w-full" :duration="0" :current="tabCurrentIndex" @change="changeTab">
  112. <!-- 轮播项对应订单状态 -->
  113. <swiper-item class="tab-content wh-full" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
  114. <!-- 滚动区 -->
  115. <scroll-view class="h-full" scroll-y @scrolltolower="loadData">
  116. <!-- 空白页 -->
  117. <use-empty v-if="tabItem.orderList.length === 0 && tabItem.loaded" e-style="round" e-type="cart"
  118. tip="订单数据为空" height="93vh"></use-empty>
  119. <!-- 订单列表区 -->
  120. <view class="padding-lr margin-bottom-sm" :class="index === 0 ? 'padding-top-sm' : ''"
  121. v-for="(item, index) in tabItem.orderList" :key="index">
  122. <!-- 订单项 -->
  123. <view class="order-item padding bg-main border-radius">
  124. <view @click="todetail(item)">
  125. <!-- 订单商品明细 -->
  126. <view class="goods-area" :class="{ 'margin-top': goodsIndex > 0 }"
  127. v-for="(goodsItem, goodsIndex) in item.orderDetails" :key="goodsIndex">
  128. <image :src="goodsItem.goodsMasterImg" mode="aspectFill"></image>
  129. <view class="right flex1">
  130. <text class="clamp-2">{{ goodsItem.goodsName }}
  131. </text>
  132. <view class="ft-dark fs-xs padding-top-xs">
  133. <text class="margin-right">× {{goodsItem.goodsCount}}</text>
  134. {{ goodsItem.goodsAttr || '&nbsp;&nbsp;' }}
  135. </view>
  136. <view class="margin-top-sm">
  137. <text class="price ft-main fs-sm">{{ goodsItem.goodsActualPrice}}</text>
  138. </view>
  139. </view>
  140. <!-- 实付款 -->
  141. <view class="dflex-e" style="padding-top: 70px;">
  142. <text class="fs-xs margin-right-xs">实付款</text>
  143. <text class="price ft-main">{{ item.totalPrice}}</text>
  144. </view>
  145. </view>
  146. </view>
  147. <!-- 订单操作区 -->
  148. <view class="dflex-b margin-top-sm">
  149. <view>
  150. <!-- 当前状态 -->
  151. <!-- <text class="ft-dark" v-if="item.order.order_refund_state == '处理中'">退款处理中</text>
  152. <text class="ft-dark"
  153. v-else-if="item.order.order_refund_state">{{ item.order.order_refund_state }}</text>
  154. <text class="ft-dark" v-else-if="item.order.state == '待评价'">已发货</text>
  155. <text class="ft-dark" v-else>{{ item.order.state }}</text> -->
  156. </view>
  157. <view class="dflex-e">
  158. <view class="dflex" v-if="item.state == '1'">
  159. <button class="action-btn border-radius-big bg-main"
  160. @click="cancelOrder(item)">取消订单</button>
  161. <button v-if="item.state == '1'"
  162. class="action-btn border-radius-big bg-main main-btn"
  163. @click="payment(item)">立即支付</button>
  164. <!-- <button v-if="item.order.state == '待核实'"
  165. class="action-btn border-radius-big bg-main main-btn"
  166. @click="payment(item.order)">待核实</button> -->
  167. </view>
  168. <view class="dflex" v-if="item.state == '2'">
  169. <button
  170. class="action-btn border-radius-big bg-main" @click="torefund(item)">申请退款</button>
  171. <!-- <button v-if="!item.order.order_refund_state"
  172. class="action-btn border-radius-big bg-main" @click="torefund(item)">申请退款</button> -->
  173. </view>
  174. <button v-if="['3',].includes(item.state)"
  175. class="action-btn border-radius-big bg-main" @click="toexpress(item)">查看物流</button>
  176. <!-- <button v-if="!item.order.order_refund_state &&
  177. ['待收货', '待评价', '已完成'].includes(item.order.state)"
  178. class="action-btn border-radius-big bg-main" @click="toexpress(item)">查看物流</button> -->
  179. <view class="dflex" v-if="item.state == '3'">
  180. <button
  181. class="action-btn border-radius-big bg-main main-btn"
  182. @click="toreceipt(item)">确认收货</button>
  183. <!-- <button v-if="!item.order.order_refund_state"
  184. class="action-btn border-radius-big bg-main main-btn"
  185. @click="toreceipt(item)">确认收货</button> -->
  186. </view>
  187. <view class="dflex" v-if="item.state == '4'">
  188. <button class="action-btn border-radius-big bg-main main-btn"
  189. @click="toevaluate(item)">我要评价</button>
  190. </view>
  191. <view class="dflex" v-if="['6'].includes(item.state)">
  192. <button class="action-btn border-radius-big bg-main main-btn"
  193. @click="delOrder(item)">删除订单</button>
  194. </view>
  195. </view>
  196. </view>
  197. </view>
  198. </view>
  199. <!-- 上拉加载更多 -->
  200. <use-loadmore v-if="tabItem.orderList.length > 0 && tabItem.loaded && tabItem.hasmore"
  201. :type="tabItem.loadingType"></use-loadmore>
  202. </scroll-view>
  203. </swiper-item>
  204. </swiper>
  205. <!-- #endif -->
  206. </view>
  207. </template>
  208. <script>
  209. import {
  210. orserlist,
  211. orserdelete,
  212. orserclear,
  213. shouhuo
  214. } from '../../../utils/api_order.js'
  215. const _order = 'usemall-order'
  216. import {
  217. mapState
  218. } from 'vuex';
  219. export default {
  220. data() {
  221. return {
  222. tabCurrentIndex: 0,
  223. navData: {},
  224. navList: [{
  225. id: 0,
  226. state: '全部',
  227. orderState:7,
  228. loadingType: 'more',
  229. orderList: []
  230. },
  231. {
  232. id: 1,
  233. state: '待付款',
  234. orderState:1,
  235. loadingType: 'more',
  236. orderList: []
  237. },
  238. {
  239. id: 2,
  240. state: '待发货',
  241. orderState:2,
  242. loadingType: 'more',
  243. orderList: []
  244. },
  245. {
  246. id: 3,
  247. state: '待收货',
  248. orderState:3,
  249. loadingType: 'more',
  250. orderList: []
  251. },
  252. {
  253. id: 4,
  254. state: '待评价',
  255. orderState:4,
  256. loadingType: 'more',
  257. orderList: []
  258. },
  259. {
  260. id: 5,
  261. state: '已完成',
  262. orderState:5,
  263. loadingType: 'more',
  264. orderList: []
  265. },
  266. {
  267. id: 6,
  268. state: '已取消',
  269. orderState:6,
  270. loadingType: 'more',
  271. orderList: []
  272. },
  273. ],
  274. reqdata: {
  275. page: 1,
  276. rows: 10
  277. },
  278. scrollLeft: 0,
  279. title: '全部'
  280. };
  281. },
  282. watch: {
  283. tabCurrentIndex(nv, ov) {
  284. this.loadData('tab_change', 1);
  285. }
  286. },
  287. onShow(options) {
  288. let _this = this;
  289. let state = '';
  290. uni.getStorage({
  291. key: '__order_state',
  292. success(res) {
  293. state = res.data;
  294. let cur_nav = _this.navList.find(x => x.state == state);
  295. if (cur_nav) {
  296. _this.tabCurrentIndex = cur_nav.id;
  297. }
  298. uni.removeStorage({
  299. key: '__order_state'
  300. });
  301. },
  302. complete() {
  303. _this.loadData('refresh');
  304. }
  305. });
  306. },
  307. onLoad(options) {
  308. uni.$on('__event_order', res => {
  309. if (res == 'refresh') {
  310. this.loadData('refresh');
  311. }
  312. });
  313. },
  314. // 下拉刷新
  315. onPullDownRefresh() {
  316. this.loadData('refresh');
  317. },
  318. // 上拉加载更多
  319. onReachBottom() {
  320. this.loadData();
  321. },
  322. methods: {
  323. // 获取订单列表
  324. loadData(source = 'add', loading) {
  325. // 获取当前 nav
  326. let cur_nav = this.navList[this.tabCurrentIndex];
  327. this.title = cur_nav.state;
  328. console.log(this.title);
  329. console.log('loadData cur_nav', cur_nav);
  330. if (cur_nav.loadingType === 'loading') {
  331. //防止重复加载
  332. return;
  333. }
  334. this.reqdata.state = cur_nav.state;
  335. var orderState=cur_nav.orderState
  336. if (loading == 1 || source == 'refresh') {
  337. this.reqdata.page = 1;
  338. }
  339. if (source.type) {
  340. source.type = source.type.toLowerCase();
  341. }
  342. if (source === 'add' || source.type == 'scrolltolower') {
  343. if (cur_nav.loadingType == 'nomore') {
  344. return;
  345. }
  346. cur_nav.loadingType = 'loading';
  347. } else {
  348. cur_nav.loadingType = 'more';
  349. }
  350. var _self=this
  351. // 1等待付款、2等待发货、3等待收货、4等待评论、5完成、7全部
  352. var data='?curPage='+_self.reqdata.page+'&pageSize='+_self.reqdata.rows+'&orderState='+orderState
  353. orserlist(data).then((res) => {
  354. if(res.success){
  355. cur_nav.loaded = true;
  356. if (loading == 1 || source == 'refresh') {
  357. cur_nav.orderList = [];
  358. cur_nav.hasmore = 0;
  359. }
  360. if (res.data.list.length > 0) {
  361. let __datas = [];
  362. res.data.list.forEach(row => {
  363. __datas.push(row);
  364. });
  365. cur_nav.orderList = [...cur_nav.orderList, ...__datas];
  366. if (res.data.list.length >= _self.reqdata.rows) {
  367. if (_self.reqdata.page == 1) {
  368. cur_nav.hasmore = !0;
  369. }
  370. _self.reqdata.page++;
  371. cur_nav.loadingType = 'more';
  372. } else {
  373. cur_nav.loadingType = 'nomore';
  374. }
  375. } else {
  376. cur_nav.loadingType = 'nomore';
  377. }
  378. if (loading == 1) {
  379. uni.hideLoading();
  380. } else if (source == 'refresh') {
  381. uni.stopPullDownRefresh();
  382. }
  383. _self.navData = cur_nav;
  384. return
  385. }
  386. _self.$api.msg(res.msg);
  387. })
  388. },
  389. // swiper 切换
  390. changeTab(e) {
  391. this.tabCurrentIndex = e.target.current;
  392. },
  393. //顶部tab点击
  394. tabClick(index) {
  395. this.tabCurrentIndex = index;
  396. },
  397. // 点击跳转详情页面
  398. todetail(order) {
  399. uni.navigateTo({
  400. url: `/packageShang/pages/user/order/order-detail?order_id=${order.orderId}`
  401. });
  402. },
  403. // 立即支付
  404. payment(item) {
  405. if (item.order_pay_state == '待核实') {
  406. this.$api.msg('订单已支付待核实状态');
  407. return;
  408. }
  409. this.$api.topay({
  410. order_id: item.orderId,
  411. money: item.totalPrice
  412. });
  413. },
  414. // 删除订单
  415. delOrder(item) {
  416. let _this = this;
  417. uni.showModal({
  418. title: '提示',
  419. content: '删除订单',
  420. success: function(res) {
  421. if (res.confirm) {
  422. uni.showLoading({
  423. title: '请稍后'
  424. });
  425. var data=item.orderId
  426. orserdelete(data).then((res) => {
  427. if(res.success){
  428. _this.loadData('tab_change', 1);
  429. return
  430. }
  431. _this.$api.msg(res.msg);
  432. })
  433. } else if (res.cancel) {
  434. console.log('点击取消');
  435. }
  436. },
  437. complete() {
  438. uni.hideLoading();
  439. }
  440. });
  441. },
  442. // 取消订单
  443. cancelOrder(item) {
  444. let _this = this;
  445. uni.showModal({
  446. title: '提示',
  447. content: '取消订单',
  448. success: function(res) {
  449. if (res.confirm) {
  450. uni.showLoading({
  451. title: '请稍后'
  452. });
  453. var data=item.orderId
  454. orserclear(data).then((res) => {
  455. if(res.success){
  456. _this.loadData('tab_change', 1);
  457. return
  458. }
  459. _this.$api.msg(res.msg);
  460. })
  461. } else if (res.cancel) {
  462. console.log('用户点击取消');
  463. }
  464. },
  465. complete() {
  466. uni.hideLoading();
  467. }
  468. });
  469. },
  470. // 查看物流
  471. toexpress(item) {
  472. // this.$api.msg('查看物流开发中');
  473. uni.navigateTo({
  474. url: `/packageShang/pages/user/order/order-express?order_id=${item.orderId}`
  475. });
  476. },
  477. // 收货
  478. toreceipt(item) {
  479. let _this = this;
  480. uni.showModal({
  481. title: '提示',
  482. content: '确认收货',
  483. success: function(res) {
  484. if (res.confirm) {
  485. uni.showLoading({
  486. title: '请稍后'
  487. });
  488. var data=item.orderId
  489. shouhuo(data).then((res) => {
  490. if(res.success){
  491. _this.loadData('tab_change', 1);
  492. return
  493. }
  494. _this.$api.msg(res.msg);
  495. })
  496. } else if (res.cancel) {
  497. console.log('用户点击取消');
  498. }
  499. },
  500. complete() {
  501. uni.hideLoading();
  502. }
  503. });
  504. },
  505. // 申请退款
  506. torefund(data) {
  507. uni.navigateTo({
  508. url: `/packageShang/pages/user/order/order-refund?order_id=${data.orderId}`
  509. });
  510. },
  511. // 评价
  512. toevaluate(item) {
  513. uni.navigateTo({
  514. url: `/packageShang/pages/user/order/order-evaluate?id=${item.orderId}`
  515. });
  516. }
  517. }
  518. };
  519. </script>
  520. <style lang="scss">
  521. page,
  522. .container {
  523. min-height: 100%;
  524. background: $page-color-base;
  525. }
  526. @import url('/packageShang/components/iconfont/iconfont.css');
  527. @import url('/packageShang/common/common.scss');
  528. /* 订单状态区 */
  529. .navbar-area {
  530. white-space: nowrap;
  531. }
  532. .state-area {
  533. height: 7vh;
  534. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  535. z-index: 10;
  536. top: 0;
  537. }
  538. .nav-item {
  539. flex: 1;
  540. &.active {
  541. &:after {
  542. content: '';
  543. position: absolute;
  544. left: 50%;
  545. transform: translate(-50%);
  546. bottom: 0;
  547. width: 44px;
  548. height: 0;
  549. border-bottom: 2px solid $base-color;
  550. }
  551. }
  552. }
  553. /* 订单轮播区 */
  554. .swiper-area {
  555. height: 93vh;
  556. }
  557. /* 订单区 */
  558. .order-area {}
  559. /* 订单项 */
  560. .order-item {
  561. /* 订单商品明细区 */
  562. .goods-area {
  563. display: flex;
  564. image {
  565. width: 180rpx;
  566. height: 180rpx;
  567. }
  568. .right {
  569. padding: 0 30upx 0 24upx;
  570. overflow: hidden;
  571. .attr-box {
  572. font-size: $font-sm + 2upx;
  573. color: $font-color-light;
  574. padding: 10upx 12upx;
  575. }
  576. }
  577. }
  578. /* 操作按钮 */
  579. .action-btn {
  580. width: 156rpx;
  581. height: inherit;
  582. line-height: inherit;
  583. margin: 0;
  584. margin-left: 20rpx;
  585. padding: 12rpx 0;
  586. font-size: $font-sm + 2upx;
  587. /* #ifdef MP-QQ || MP-ALIPAY */
  588. border: 1px solid;
  589. /* #endif */
  590. &:after {
  591. border-radius: 100px;
  592. }
  593. &.main-btn {
  594. background: #fff9f9;
  595. color: $base-color;
  596. &:after {
  597. border-color: #f7bcc8;
  598. }
  599. }
  600. }
  601. }
  602. </style>