index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <view>
  3. <view class="order_status_list">
  4. <view class="order_status_item" :class="requestParam.status == 0 ? 'active' : ''" @click="setStatus(0)"> 全部 </view>
  5. <view class="order_status_item" :class="requestParam.status == 1 ? 'active' : ''" @click="setStatus(1)"> 待付款 </view>
  6. <view class="order_status_item" :class="requestParam.status == 4 ? 'active' : ''" @click="setStatus(4)"> 已取消 </view>
  7. <view class="order_status_item" :class="requestParam.status == 8 ? 'active' : ''" @click="setStatus(8)"> 已完成 </view>
  8. </view>
  9. <view class="order_list" v-if="orderList.length">
  10. <view class="order_item" v-for="(item, index) in orderList" :key="index">
  11. <view @click.stop="goDetail(item.id)">
  12. <view class="order_title">
  13. <view class="business_name">{{ item.business_name }}</view>
  14. <view class="order_status">{{ item.state }}</view>
  15. </view>
  16. <view class="product_list" :class="item.contents_class ? 'active' : ''">
  17. <view class="product_item" v-for="(product_info, k) in item.product_list" :key="k">
  18. <image class="product_img" :src="product_info.product_thumb" mode=""></image>
  19. <view class="product_info">
  20. <view class="product_name"> <text v-if="product_info.is_rebate">【赠】</text> {{ product_info.product_name }} </view>
  21. <view class="product_spec">
  22. {{ product_info.product_spec }}
  23. </view>
  24. </view>
  25. <view class="buy_num"> x{{ product_info.buy_num }} </view>
  26. </view>
  27. </view>
  28. <view class="show_more" v-if="item.product_list.length > 1" @click.stop="changeHeight(index)">
  29. <uni-icons :type="item.contents_class ? 'up' : 'down'"></uni-icons>
  30. </view>
  31. <view class="order_price">
  32. <view class="pay_total">¥{{ item.pay_total }}</view>
  33. </view>
  34. </view>
  35. <view class="order_btn" v-if="item.status == 0">
  36. <button v-if="item.regiment_id > 0" class="order_cancel" @click="cancelOrderRegiment(index)">取消拼团</button>
  37. <button v-else class="order_cancel" @click="cancelOrder(index)">取消订单</button>
  38. <button class="order_share" @click="toPay(item)">去付款</button>
  39. </view>
  40. <view class="order_btn" v-if="item.status == 2 || item.status == 3">
  41. <button class="order_share" @click="toReceipt(item)">我已收货</button>
  42. </view>
  43. <view class="order_btn" v-if="item.status == 1">
  44. <button class="order_cancel" @click="cancelOrder(index)">取消订单</button>
  45. <button class="order_share" @click="toReceipt(item)">我已收货</button>
  46. </view>
  47. <view class="order_btn" v-if="item.status == 10 && item.is_pay == 0">
  48. <button class="order_cancel" @click="cancelOrderRegiment(index)">取消拼团</button>
  49. </view>
  50. </view>
  51. </view>
  52. <Empty text="----- 还没有订单 -----" v-if="!orderList.length" />
  53. <view class="to_bottom" v-if="isLast && orderList.length"> -----到底啦-----</view>
  54. </view>
  55. </template>
  56. <script>
  57. import Empty from '@/components/Empty/Empty.vue';
  58. export default {
  59. components: {
  60. Empty,
  61. },
  62. data() {
  63. return {
  64. // 产品列表
  65. orderList: [],
  66. // 请求参数
  67. requestParam: {
  68. page: 1,
  69. status: 0,
  70. },
  71. // 是否最后一页
  72. isLast: false,
  73. // 是否请求中
  74. isReqing: false,
  75. };
  76. },
  77. onLoad(param) {
  78. if (param.status) {
  79. this.requestParam.status = param.status;
  80. }
  81. },
  82. onShow() {
  83. // 登录提示
  84. if (!this.$checkAccess.alterLogin()) return;
  85. // 没有数据的话,或者请求中,不允许刷新
  86. if (this.isReqing) return;
  87. // 初始化页码为1
  88. this.requestParam.page = 1;
  89. // 是否是最后一页
  90. this.isLast = false;
  91. // 设置请求中
  92. this.isReqing = true;
  93. // 请求列表
  94. this.$http.request('api/orders/get_list', this.requestParam).then((re) => {
  95. // 设置非请求中
  96. this.isReqing = false;
  97. // 成功结果
  98. if (re.code == 'success') {
  99. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  100. this.orderList = re.data.data;
  101. }
  102. });
  103. },
  104. onPullDownRefresh() {
  105. // 登录提示
  106. if (!this.$checkAccess.alterLogin()) return;
  107. // 如果请求中,不允许请求,
  108. if (this.isReqing) return false;
  109. // 初始化页码为1
  110. this.requestParam.page = 1;
  111. // 是否是最后一页
  112. this.isLast = false;
  113. // 设置请求中
  114. this.isReqing = true;
  115. // 请求列表
  116. this.$http.request('api/orders/get_list', this.requestParam).then((re) => {
  117. // 设置非请求中
  118. this.isReqing = false;
  119. // 成功结果
  120. if (re.code == 'success') {
  121. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  122. this.orderList = re.data.data;
  123. }
  124. });
  125. uni.stopPullDownRefresh();
  126. },
  127. onReachBottom() {
  128. // 登录提示
  129. if (!this.$checkAccess.alterLogin()) return;
  130. // 如果页码是0,避免第一页重复
  131. if (this.requestParam.page < 1) return;
  132. // 最后一页不请求
  133. if (this.isLast) return;
  134. // 请求中,不再请求
  135. if (this.isReqing) return;
  136. // 增加一页
  137. this.requestParam.page = this.requestParam.page + 1;
  138. // 设置请求中
  139. this.isReqing = true;
  140. // 请求列表
  141. this.$http.request('api/orders/get_list', this.requestParam).then((re) => {
  142. // 设置非请求中
  143. this.isReqing = false;
  144. // 成功结果
  145. if (re.code == 'success') {
  146. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  147. // 追加数据
  148. this.orderList.push(...re.data.data);
  149. }
  150. });
  151. },
  152. methods: {
  153. setStatus(status) {
  154. // 登录提示
  155. if (!this.$checkAccess.alterLogin()) return;
  156. // 请求中,不再请求
  157. if (this.isReqing) return;
  158. // 初始化页码为1
  159. this.requestParam.page = 1;
  160. // 是否是最后一页
  161. this.isLast = false;
  162. // 状态变更
  163. this.requestParam.status = status;
  164. // 设置请求中
  165. this.isReqing = true;
  166. // 请求列表
  167. this.$http.request('api/orders/get_list', this.requestParam).then((re) => {
  168. // 设置非请求中
  169. this.isReqing = false;
  170. // 成功结果
  171. if (re.code == 'success') {
  172. if (re.data.last_page >= this.requestParam.page) this.isLast = true;
  173. this.orderList = re.data.data;
  174. }
  175. });
  176. },
  177. changeHeight(index) {
  178. this.orderList[index].contents_class = this.orderList[index].contents_class ? 0 : 1;
  179. },
  180. // 取消订单
  181. cancelOrder(index) {
  182. uni.showModal({
  183. title: '确认取消该订单?',
  184. success: (res) => {
  185. if (res.confirm) {
  186. // 请求列表
  187. this.$http.request('api/orders/cancel', { id: this.orderList[index].id }).then((re) => {
  188. this.orderList[index].state = '已取消';
  189. this.orderList[index].status = 4;
  190. });
  191. }
  192. },
  193. });
  194. },
  195. toPay(item) {
  196. if (item) {
  197. let orderInfo = {
  198. snowflake_id: item.snowflake_id,
  199. pay_total: item.pay_total,
  200. order_id: item.id,
  201. };
  202. orderInfo = JSON.stringify(orderInfo);
  203. let params = encodeURIComponent(orderInfo);
  204. // 跳转到确认支付页面
  205. uni.navigateTo({ url: `/pages/orders/confirm?params=${params}` });
  206. } else {
  207. uni.showToast({
  208. title: '订单数据错误',
  209. icon: 'none',
  210. });
  211. return;
  212. }
  213. },
  214. // 取消拼团
  215. cancelOrderRegiment(index) {
  216. uni.showModal({
  217. title: '确认取消该订单?',
  218. success: (res) => {
  219. if (res.confirm) {
  220. // 请求列表
  221. this.$http.request('api/orders/cancel_regiment', { id: this.orderList[index].id }).then((re) => {
  222. this.orderList[index].state = '已取消';
  223. this.orderList[index].status = 4;
  224. });
  225. }
  226. },
  227. });
  228. },
  229. navToProduct(id) {
  230. if (id) {
  231. uni.navigateTo({
  232. url: '/pages/product/index?product_id=' + id,
  233. });
  234. }
  235. },
  236. toReceipt(item) {
  237. uni.navigateTo({
  238. url: '/pages/orders/receipt?order_id=' + item.id,
  239. });
  240. },
  241. goDetail(id) {
  242. uni.navigateTo({
  243. url: '/pages/orders/detail?order_id=' + id,
  244. });
  245. },
  246. },
  247. };
  248. </script>
  249. <style lang="less">
  250. .order_status_list {
  251. display: block;
  252. height: 60rpx;
  253. color: #666666;
  254. line-height: 60rpx;
  255. background: #ffffff;
  256. padding: 10rpx 35rpx;
  257. .order_status_item {
  258. float: left;
  259. font-size: 28rpx;
  260. padding: 0rpx 20rpx;
  261. }
  262. .order_status_item.active {
  263. color: #000000;
  264. font-weight: bold;
  265. }
  266. }
  267. .order_list {
  268. display: block;
  269. overflow: hidden;
  270. margin: 0rpx auto;
  271. .order_item {
  272. display: block;
  273. background: #ffffff;
  274. margin: 0rpx auto;
  275. padding: 0rpx 35rpx;
  276. margin-bottom: 10rpx;
  277. .order_title {
  278. width: 100%;
  279. height: 60rpx;
  280. display: block;
  281. overflow: hidden;
  282. line-height: 60rpx;
  283. display: flex;
  284. align-items: center;
  285. justify-content: space-between;
  286. .business_name {
  287. float: left;
  288. font-size: 32rpx;
  289. display: flex;
  290. align-items: center;
  291. .business_icon {
  292. width: 48rpx;
  293. height: 48rpx;
  294. margin-right: 10rpx;
  295. }
  296. }
  297. .order_status {
  298. float: right;
  299. color: #999999;
  300. font-size: 24rpx;
  301. }
  302. }
  303. .product_list {
  304. display: block;
  305. height: 100rpx;
  306. overflow: hidden;
  307. margin: 15rpx auto;
  308. transition: all 1s ease-out; /* 添加过渡效果 */
  309. .product_item {
  310. display: block;
  311. height: 100rpx;
  312. overflow: hidden;
  313. .product_img {
  314. float: left;
  315. width: 80rpx;
  316. height: 80rpx;
  317. display: block;
  318. margin-top: 10rpx;
  319. margin-right: 30rpx;
  320. }
  321. .product_info {
  322. float: left;
  323. width: 480rpx;
  324. height: 100rpx;
  325. display: block;
  326. overflow: hidden;
  327. .product_name {
  328. display: block;
  329. height: 60rpx;
  330. display: block;
  331. font-size: 28rpx;
  332. line-height: 60rpx;
  333. overflow: hidden;
  334. }
  335. .product_spec {
  336. color: #999999;
  337. height: 40rpx;
  338. display: block;
  339. font-size: 24rpx;
  340. line-height: 40rpx;
  341. overflow: hidden;
  342. }
  343. }
  344. .buy_num {
  345. float: right;
  346. height: 100rpx;
  347. color: #999999;
  348. font-size: 26rpx;
  349. text-align: right;
  350. position: relative;
  351. line-height: 100rpx;
  352. }
  353. }
  354. }
  355. .product_list.active {
  356. height: auto !important;
  357. }
  358. .order_price {
  359. display: block;
  360. height: 60rpx;
  361. overflow: hidden;
  362. line-height: 60rpx;
  363. .pay_total {
  364. float: right;
  365. height: 60rpx;
  366. color: #f89c33;
  367. font-size: 28rpx;
  368. line-height: 60rpx;
  369. }
  370. }
  371. .show_more {
  372. width: 100%;
  373. height: 30rpx;
  374. display: block;
  375. font-size: 20rpx !important;
  376. margin-top: -30rpx;
  377. text-align: center;
  378. position: relative;
  379. background-color: rgba(0, 0, 0, 0.05);
  380. }
  381. .order_btn {
  382. display: block;
  383. height: 60rpx;
  384. overflow: hidden;
  385. .order_cancel {
  386. float: left;
  387. height: 50rpx;
  388. color: #999999;
  389. font-size: 24rpx;
  390. padding: 0rpx 10rpx;
  391. line-height: 50rpx;
  392. margin-left: 10rpx;
  393. border-radius: 25rpx;
  394. border: 2rpx solid #999999;
  395. background-color: transparent;
  396. }
  397. .order_cancel::after {
  398. border: none;
  399. }
  400. .order_share {
  401. float: right;
  402. height: 50rpx;
  403. color: #f89c33;
  404. font-size: 24rpx;
  405. padding: 0rpx 10rpx;
  406. line-height: 50rpx;
  407. margin-left: 10rpx;
  408. border-radius: 25rpx;
  409. border: 2rpx solid #f89c33;
  410. background-color: transparent;
  411. }
  412. .order_share::after {
  413. border: none;
  414. }
  415. }
  416. }
  417. }
  418. </style>