order-search.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="order-search">
  3. <!-- 搜索区域 -->
  4. <view class="order-top sticky-top">
  5. <cm-search
  6. v-model="listQuery.searchWord"
  7. @search="handleSearch"
  8. placeholder="请输入搜索关键字"
  9. :keywordVisible="keywordVisible"
  10. :keywordList="keywordList"
  11. @focus="keywordVisible = true"
  12. @clear="keywordVisible = true"
  13. @remove="removeKeywordModal = true"
  14. ></cm-search>
  15. </view>
  16. <view class="order-list">
  17. <!-- 订单列表为空 -->
  18. <template v-if="orderList.length <= 0 && !isLoading">
  19. <tui-no-data :imgUrl="emptyInfo.image" :imgHeight="230" :imgWidth="290">
  20. <view class="empty-tip" v-text="emptyInfo.message"></view>
  21. </tui-no-data>
  22. </template>
  23. <template v-else>
  24. <view
  25. class="section"
  26. v-for="orderInfo in orderList"
  27. :key="orderInfo.orderId"
  28. @click="handleToDetail(orderInfo)"
  29. >
  30. <!-- 订单信息 -->
  31. <view class="order-info">
  32. <view class="order-no">
  33. <text class="label">订单编号:</text> <text>{{ orderInfo.orderNo }}</text>
  34. </view>
  35. <view class="order-time">
  36. <text class="label">下单时间:</text> <text>{{ orderInfo.orderTime }}</text>
  37. </view>
  38. <view class="order-status">{{ stateExpFormat(orderInfo.status) }}</view>
  39. </view>
  40. <tui-divider :height="48"></tui-divider>
  41. <!-- 商品列表 -->
  42. <view class="shop-list">
  43. <view
  44. class="shop-section"
  45. v-for="shopInfo in orderInfo.shopOrderList"
  46. :key="shopInfo.shopOrderId"
  47. >
  48. <order-supplier-area :shopInfo="shopInfo"></order-supplier-area>
  49. </view>
  50. </view>
  51. <!-- 商品统计 -->
  52. <view class="total">
  53. <view class="count">共{{ orderInfo.productCount }}件商品</view>
  54. <view class="price">
  55. <template v-if="['31', '32', '33', '81', '82', '83'].includes(orderInfo.status)">
  56. <text class="label">已支付:</text>
  57. <text>¥{{ orderInfo.receiptAmount | priceFormat }}</text>
  58. </template>
  59. <template v-else>
  60. <text class="label">待付总额:</text>
  61. <text>¥{{ orderInfo.pendingPayments | priceFormat }}</text>
  62. </template>
  63. </view>
  64. </view>
  65. <!-- 操作订单 -->
  66. <view class="control">
  67. <order-contror
  68. v-if="orderInfo.userId == userId"
  69. :orderInfo="orderInfo"
  70. @confirm="handleConfirmClick"
  71. ></order-contror>
  72. </view>
  73. </view>
  74. <cm-loadmore :hasMore="hasNextPage" :isLoading="isLoading" :visiable="visiable"></cm-loadmore>
  75. </template>
  76. </view>
  77. <!-- 失效商品列表 -->
  78. <order-invalid-modal
  79. :goodsList="invalidList"
  80. :visible="buyAgainModal"
  81. @confirm="buyAgainModalClick"
  82. @cancel="buyAgainModalHide"
  83. ></order-invalid-modal>
  84. <!-- 操作弹窗 -->
  85. <tui-modal :show="removeKeywordModal" content="确认清空搜索历史记录?" @click="clearSearchRecord"></tui-modal>
  86. </view>
  87. </template>
  88. <script>
  89. import { searchOrderList, fetchOrderSearchHistory, clearOrderSearchHistory } from '@/services/api/order.js'
  90. import { debounce } from '@/common/utils.js'
  91. import { mapGetters } from 'vuex'
  92. import orderList from '@/pages/views/order/mixins/orderList.js'
  93. import wechatPay from '@/pages/views/order/mixins/wechatPay.js'
  94. export default {
  95. mixins: [orderList, wechatPay],
  96. data() {
  97. return {
  98. isLoading: false,
  99. keywordVisible: true,
  100. removeKeywordModal: false,
  101. keywordList: [],
  102. listQuery: {
  103. searchWord: '',
  104. userId: 0,
  105. pageNum: 1,
  106. pageSize: 10
  107. },
  108. orderList: [],
  109. total: 0,
  110. hasNextPage: true,
  111. isRefresh: true
  112. }
  113. },
  114. watch: {
  115. keywordVisible(nVal) {
  116. if (!nVal) return
  117. this.fetchSearchHistory()
  118. this.orderList = []
  119. }
  120. },
  121. computed: {
  122. ...mapGetters(['userId']),
  123. // 列表为空
  124. emptyInfo() {
  125. const info = {}
  126. info.image = `${this.staticUrl}icon-empty-address.png`
  127. info.message = '未找到相关订单~_~'
  128. if (this.keywordList.length <= 0) {
  129. info.message = '暂无任何搜索历史记录~_~'
  130. }
  131. return info
  132. },
  133. visiable() {
  134. return this.orderList.length > this.listQuery.pageSize
  135. }
  136. },
  137. onReachBottom() {
  138. this.fetchOrderList()
  139. },
  140. onLoad() {
  141. this.fetchSearchHistory()
  142. },
  143. methods: {
  144. handleSearch() {
  145. this.keywordVisible = false
  146. this.isRefresh = true
  147. this.hasNextPage = true
  148. this.listQuery.pageNum = 1
  149. this.listQuery.userId = this.userId
  150. this.fetchOrderList()
  151. },
  152. // 获取订单列表
  153. fetchOrderList: debounce(async function() {
  154. if (!this.hasNextPage) return
  155. this.isLoading = true
  156. try {
  157. const res = await searchOrderList(this.listQuery)
  158. if (this.isRefresh) {
  159. this.orderList = res.data.list
  160. } else {
  161. this.orderList = [...this.orderList, ...res.data.list]
  162. }
  163. this.total = res.data.total
  164. this.hasNextPage = res.data.hasNextPage
  165. this.listQuery.pageNum++
  166. } catch (e) {
  167. console.log(e)
  168. } finally {
  169. this.isLoading = false
  170. this.isRefresh = false
  171. }
  172. }),
  173. // 获取搜索历史记录
  174. async fetchSearchHistory() {
  175. try {
  176. const res = await fetchOrderSearchHistory({ userId: this.userId })
  177. this.keywordList = res.data
  178. return res
  179. } catch (e) {
  180. console.log(e)
  181. }
  182. },
  183. // 清空搜索历史记录
  184. async clearSearchRecord(e) {
  185. if (!e.index) return (this.removeKeywordModal = false)
  186. try {
  187. await clearOrderSearchHistory({ userId: this.userId })
  188. await this.fetchSearchHistory()
  189. this.removeKeywordModal = false
  190. this.$toast('已清空搜索历史记录')
  191. } catch (e) {
  192. console.log(e)
  193. }
  194. },
  195. // 订单详情
  196. handleToDetail(order) {
  197. this.$router.navigateTo('order/order-detail?orderId=' + order.orderId)
  198. }
  199. }
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. .order-list {
  204. .section {
  205. padding: 24rpx;
  206. margin-bottom: 24rpx;
  207. background-color: #fff;
  208. .order-info {
  209. position: relative;
  210. line-height: 1.6;
  211. .order-no,
  212. .order-time {
  213. font-size: 26rpx;
  214. color: #333333;
  215. .label {
  216. color: #999999;
  217. }
  218. }
  219. .order-status {
  220. position: absolute;
  221. font-size: 26rpx;
  222. color: #ff457b;
  223. right: 0;
  224. bottom: 0;
  225. }
  226. }
  227. .shop-list {
  228. .shop-section {
  229. margin-bottom: 24rpx;
  230. &:last-child {
  231. margin-bottom: 0;
  232. }
  233. }
  234. }
  235. .total {
  236. display: flex;
  237. justify-content: space-between;
  238. align-items: center;
  239. margin-top: 24rpx;
  240. font-size: 26rpx;
  241. color: #333333;
  242. .count {
  243. font-weight: bold;
  244. }
  245. .price {
  246. color: #ff457b;
  247. .label {
  248. color: #333333;
  249. }
  250. }
  251. }
  252. .control {
  253. margin-top: 32rpx;
  254. }
  255. }
  256. }
  257. </style>