index.vue 12 KB

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