my-order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <view class="my-order">
  3. <custom-nav noback="noback" transparent="transparent" ref="ltm" title=" " />
  4. <view class="content">
  5. <view class="swiper-nav">
  6. <view v-for="(item, index) in typeList" :key="index" class="item" :class="{ active: MIXIN_ActiveIndex === index }" @tap="switchSwiper(index)">{{ item }}</view>
  7. <view class="moveBar" :style="{ left: MIXIN_MoveBarLeft + 'px', width: 100 / typeList.length + '%' }"><text></text></view>
  8. </view>
  9. <view class="swiper-area">
  10. <swiper class="swiper" :current="MIXIN_NowIndex" :duration="234" @transition="MIXIN_transition" @change="MIXIN_change" @animationfinish="MIXIN_animationfinish">
  11. <swiper-item v-for="(typeValue, typeKey) in lists" :key="typeKey">
  12. <scroll-view scroll-y :style="{ height: MIXIN_ScrollViewHeight + 'px' }" @scrolltolower="MIXIN_scrolltolower">
  13. <view class="order-item" v-for="(orderItem) in lists[typeKey]" :key="orderItem.order_num" @click="toDetail(orderItem)">
  14. <view class="order-num">
  15. <text>订单编号:{{ orderItem.order_num }}</text>
  16. <text class="fsdfsd" :class="orderItem | orderStatus | orderStatusClass">{{ orderItem | orderStatus }}</text>
  17. </view>
  18. <view class="good-item">
  19. <view class="imgs">
  20. <image v-for="(item, index) in orderItem.order" :key="index" :src="item.main_img"></image>
  21. </view>
  22. <view class="info">
  23. <text class="name">种类:{{ orderItem.type }}{{ ', ' }}</text>
  24. <text class="num">数量:{{ orderItem.total }}{{ ', ' }}</text>
  25. <text class="price">共计金额:<text class="basecolor">¥{{ orderItem.money }}</text></text>
  26. </view>
  27. </view>
  28. <view class="bottom-bar">
  29. <text class="time">{{ orderItem.created_at }}</text>
  30. <!-- <view class="btn" v-if="!orderItem.is_deleted && !orderItem.pay_status" @click.stop="changeOrder(orderItem)">修改订单</view> -->
  31. <view class="btns">
  32. <view class="btn" @click.stop="buyAgain(orderItem)">再次购买</view>
  33. <view v-if="orderItem.express_num && orderItem.express_code" class="btn" @click.stop="express(orderItem.express_num, orderItem.express_code)">查看物流</view>
  34. <view class="btn bg" v-if="!orderItem.is_deleted && !orderItem.pay_status" @click.stop="payNow(orderItem)">立即付款</view>
  35. <view class="btn border" v-if="!orderItem.is_deleted && orderItem.pay_status && orderItem.status == 3" @click.stop="received(orderItem)">确认收货</view>
  36. </view>
  37. </view>
  38. </view>
  39. <custom-reach-bottom v-if="lists[typeKey].length" :nomore="page[typeKey] === 0" />
  40. <swiper-status v-else :page="page[typeKey]" />
  41. </scroll-view>
  42. </swiper-item>
  43. </swiper>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import { _API_GoodList } from '@/apis/good.js'
  50. import { deepClone } from '@/common/util/index.js'
  51. import MIXIN from '@/mixin/swiper-list.js'
  52. import swiperStatus from '@/components/public/swiper-status.vue'
  53. import pulldownRefresher from '@/components/public/pulldown-refresher.vue'
  54. import customReachBottom from '@/components/public/custom-reach-bottom.vue'
  55. // import { _API_OrderMyExamine, _API_OrderMySended, _API_OrderMyCompleted, _API_OrderReceiveGoods } from '@/apis/order.js'
  56. import { _API_OrderMy1, _API_OrderMy2, _API_OrderMy3, _API_OrderMy4, _API_OrderMy5, _API_OrderAgain, _API_OrderDel, _API_OrderDetail1, _API_OrderCancel, _API_OrderReceiveGoods1 } from '@/apis/order.js'
  57. export default {
  58. mixins: [MIXIN],
  59. components: { swiperStatus, customReachBottom, pulldownRefresher },
  60. data() {
  61. return {
  62. title: '我的订单',
  63. page: [1, 1, 1, 1, 1], // 每种类型的页数 当页数为 0 时表示当前类型没有更多了 -1 表示请求失败
  64. lists: { 0: [], 1: [], 2: [], 3: [], 4: {} }, // 数据
  65. typeList: ['全部', '待付款', '待审核', '待收货', '已完成'],
  66. apis: [_API_OrderMy1, _API_OrderMy2, _API_OrderMy3, _API_OrderMy4, _API_OrderMy5]
  67. }
  68. },
  69. filters: {
  70. orderStatus(orderItem) { // 计算订单总金额过滤器
  71. if (orderItem.is_deleted) {
  72. return '已作废'
  73. } else if (!orderItem.pay_status) {
  74. return '待支付订单'
  75. } else if (orderItem.status == 3) {
  76. return '待收货'
  77. } else if (orderItem.status == 4) {
  78. return '已完成'
  79. } else {
  80. return '待审核订单'
  81. }
  82. },
  83. orderStatusClass(status) {
  84. if (status == '已完成') {
  85. return ''
  86. } else {
  87. return 'basecolor'
  88. }
  89. }
  90. },
  91. onLoad(opt) {
  92. if (this.$store.state.userinfo.level !== '代理公司') {
  93. uni.navigateBack()
  94. setTimeout(() => uni.$emit('noopening'))
  95. return
  96. }
  97. if (opt.type === '1') {
  98. this.MIXIN_NowIndex = this.MIXIN_ActiveIndex = this.MIXIN_FinishedIndex = 1
  99. this.MIXIN_MoveBarLeft = this.MIXIN_NowIndex * (this.MIXIN_ScreenWidth / this.typeList.length)
  100. } else if (opt.type === '2') {
  101. this.MIXIN_NowIndex = this.MIXIN_ActiveIndex = this.MIXIN_FinishedIndex = 2
  102. this.MIXIN_MoveBarLeft = this.MIXIN_NowIndex * (this.MIXIN_ScreenWidth / this.typeList.length)
  103. } else if (opt.type === '3') {
  104. this.MIXIN_NowIndex = this.MIXIN_ActiveIndex = this.MIXIN_FinishedIndex = 3
  105. this.MIXIN_MoveBarLeft = this.MIXIN_NowIndex * (this.MIXIN_ScreenWidth / this.typeList.length)
  106. } else if (opt.type === '4') {
  107. this.MIXIN_NowIndex = this.MIXIN_ActiveIndex = this.MIXIN_FinishedIndex = 4
  108. this.MIXIN_MoveBarLeft = this.MIXIN_NowIndex * (this.MIXIN_ScreenWidth / this.typeList.length)
  109. }
  110. this.MIXIN_request()
  111. },
  112. onPullDownRefresh() {
  113. this.page[this.MIXIN_NowIndex] = 1
  114. this.MIXIN_request()
  115. },
  116. created() {
  117. uni.$on('PAYSUCCESS', (order_num) => {
  118. this.lists[0].splice(this.lists[0].findIndex(e => e.order_num == order_num), 1)
  119. this.lists[1].splice(this.lists[1].findIndex(e => e.order_num == order_num), 1)
  120. })
  121. },
  122. methods: {
  123. confirmReceive(order_num, index) { // 点击确认收货
  124. this.$refs.ltm.modal('提示', ['确定收到商品?']).then(() => {
  125. uni.showLoading({ mask: true })
  126. _API_OrderReceiveGoods({ order_num }).then(res => {
  127. if (res.code === 200) {
  128. const list1 = deepClone(this.lists[1])
  129. list1.splice(index, 1) // 把当前订单从待收货列表删除
  130. this.$set(this.lists, 1, list1)
  131. uni.toast('收货成功')
  132. } else {
  133. uni.toast('收货失败,请稍后重试')
  134. }
  135. })
  136. }).catch(() => {
  137. uni.toast('取消确认')
  138. })
  139. },
  140. MIXIN_requestHandle(res) { // 请求 handler
  141. console.log(res)
  142. uni.stopPullDownRefresh()
  143. },
  144. toDetail(goodItem) { // 点击查看订单
  145. const { order_num, order_id, is_deleted, pay_status, money, created_at } = goodItem
  146. let str = ''
  147. if (!is_deleted && !pay_status) {
  148. str = '&nopay=1'
  149. }
  150. uni.navigateTo({ url: `../order-detail1/order-detail1?created_at=${created_at}&status=${this.$options.filters.orderStatus(goodItem)}&order_id=${order_id}&order_num=${order_num}${str}&money=${money}` })
  151. },
  152. changeOrder({ order_num }) { // 取消订单
  153. uni.showModal({
  154. title: '',
  155. content: '修改订单后会作废此订单,然后复制此订单的商品到购物车中重新下单,确定作废?',
  156. success: (res) => {
  157. if (res.confirm) {
  158. uni.loading()
  159. _API_OrderCancel({ order_num }).then(({ code, message }) => {
  160. if (code != 200) {
  161. uni.toast(message)
  162. } else {
  163. uni.loading()
  164. _API_GoodList().then(({ data: { list: list1 } }) => {
  165. uni.loading()
  166. list1.forEach(e => e.cart = Array(e.size.length).fill(0))
  167. _API_OrderDetail1({ order_num }).then(({ data: { list: list2 } }) => {
  168. uni.loading()
  169. this.$store.commit('cart/CLEAR')
  170. list1.forEach((item, index) => {
  171. const findRes = list2.find(e => e.attr_id == item.attr_id)
  172. if (findRes) {
  173. findRes.size.forEach((size, sizeIndex) => {
  174. const goodItemSizeIndex = list1[index].size.findIndex(e => e === size)
  175. list1[index].cart[goodItemSizeIndex] = findRes.num[sizeIndex]
  176. })
  177. item.choosed = true
  178. item.sizeChoosed = Array(item.size.length).fill(true)
  179. this.$store.commit('cart/ADD', item)
  180. uni.switchTab({ url: '../shop-car1/shop-car1' })
  181. }
  182. })
  183. })
  184. })
  185. }
  186. })
  187. }
  188. }
  189. })
  190. },
  191. buyAgain({ order_num }) { // 点击再次购买
  192. uni.showModal({
  193. title: '提示',
  194. content: '确定要再次购买?',
  195. success: (res) => {
  196. if (res.confirm) {
  197. uni.loading()
  198. _API_GoodList().then(({ data: { list: list1 } }) => {
  199. uni.loading()
  200. list1.forEach(e => e.cart = Array(e.size.length).fill(0))
  201. _API_OrderDetail1({ order_num }).then(({ data: { list: list2 } }) => {
  202. this.$store.commit('cart/CLEAR')
  203. list1.forEach((item, index) => {
  204. const findRes = list2.find(e => e.attr_id == item.attr_id)
  205. if (findRes) {
  206. findRes.size.forEach((size, sizeIndex) => {
  207. const goodItemSizeIndex = list1[index].size.findIndex(e => e === size)
  208. list1[index].cart[goodItemSizeIndex] = findRes.num[sizeIndex]
  209. })
  210. item.choosed = true
  211. item.sizeChoosed = Array(item.size.length).fill(true)
  212. this.$store.commit('cart/ADD', item)
  213. uni.switchTab({ url: '../shop-car1/shop-car1' })
  214. }
  215. })
  216. })
  217. })
  218. }
  219. }
  220. })
  221. },
  222. express(expCode, expNo) {
  223. KDNWidget.run({ serviceType: "A", expCode, expNo })
  224. },
  225. payNow({ order_num, money, order_id }) { // 点击立即付款
  226. // console.log(order_id)
  227. uni.navigateTo({ url: `../pay-order/pay-order?order_num=${order_num}&money=${money}&order_id=${order_id}` })
  228. },
  229. received({ order_num }) { // 点击确认收货
  230. uni.showModal({
  231. title: '提示',
  232. content: '确认收到货物?',
  233. success: (res) => {
  234. if (res.confirm) {
  235. uni.loading()
  236. _API_OrderReceiveGoods1({ order_num }).then(() => {
  237. uni.startPullDownRefresh()
  238. })
  239. }
  240. }
  241. })
  242. }
  243. }
  244. }
  245. </script>
  246. <style lang="scss">
  247. .my-order {
  248. @include page();
  249. .content {
  250. @include flex(column);
  251. .swiper-area {
  252. scroll-view {
  253. .order-item {
  254. background: #FFFFFF;
  255. > view {
  256. padding: 0 30rpx;
  257. box-sizing: border-box;
  258. }
  259. .order-num {
  260. @include flex();
  261. height: 90rpx;
  262. font-size: 28rpx;
  263. font-weight: bold;
  264. justify-content: space-between;
  265. border-top: 20rpx solid $app-base-bg;
  266. border-bottom: 1rpx solid $app-base-bg;
  267. }
  268. .good-item {
  269. min-height: 240rpx;
  270. padding: 0 30rpx;
  271. background: #FFFFFF;
  272. box-sizing: border-box;
  273. border-bottom: 1rpx solid $app-base-bg;
  274. .imgs {
  275. min-height: 140rpx;
  276. width: 100%;
  277. margin-top: 28rpx;
  278. image {
  279. width: 140rpx;
  280. height: 140rpx;
  281. margin-right: 10rpx;
  282. border-radius: 6rpx;
  283. }
  284. }
  285. .info {
  286. margin-top: 4rpx;
  287. text-align: right;
  288. height: 64rpx;
  289. line-height: 64rpx;
  290. font-size: 24rpx;
  291. font-weight: bold;
  292. }
  293. }
  294. .bottom-bar {
  295. @include flex();
  296. height: 90rpx;
  297. font-size: 26rpx;
  298. justify-content: space-between;
  299. background: #FFFFFF;
  300. > text {
  301. font-size: 12rpx;
  302. font-weight: bold;
  303. }
  304. .btns {
  305. @include flex();
  306. .btn {
  307. @include flex();
  308. width: 140rpx;
  309. height: 54rpx;
  310. font-size: 28rpx;
  311. margin-left: 10rpx;
  312. color: #181818;
  313. border-radius: 54rpx;
  314. border: 1px solid rgba(24,24,24,1);
  315. &.bg {
  316. color: #FFFFFF;
  317. border-color: $app-base-color;
  318. background: $app-base-color;
  319. }
  320. &.border {
  321. color: $app-base-color;
  322. border-color: $app-base-color;
  323. }
  324. }
  325. }
  326. }
  327. }
  328. }
  329. }
  330. }
  331. }
  332. </style>