order-search.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <view class="order-search">
  3. <tui-skeleton v-if="isRequest" loadingType="2"></tui-skeleton>
  4. <!-- 搜索框 -->
  5. <view class="order-top">
  6. <cm-search
  7. v-model="keyword"
  8. @search="handleSearch"
  9. placeholder="请输入搜索关键字"
  10. :keywordVisible="keywordVisible"
  11. :keywordList="keywordList"
  12. @focus="keywordVisible = true"
  13. @clear="keywordVisible = true"
  14. @remove="removeKeywordModal = true"
  15. ></cm-search>
  16. </view>
  17. <!-- orderList.length === 0 -->
  18. <view class="order-empty" v-if="orderList.length === 0">
  19. <cm-empty :image="emptyInfo.image" :message="emptyInfo.message" :offset="100"></cm-empty>
  20. </view>
  21. <view class="order-list" v-else>
  22. <template v-for="(orderInfo, orderIndex) in orderList">
  23. <view class="grid" :key="orderIndex"></view>
  24. <view class="order-section" :key="orderIndex" @click="handleToDetail(orderInfo)">
  25. <!-- 订单信息 -->
  26. <view class="order-info">
  27. <view class="order-num">
  28. <text class="label">订单编号:</text>
  29. <text>{{ orderInfo.orderNo }}</text>
  30. </view>
  31. <view class="order-time">
  32. <text class="label">下单时间:</text>
  33. <text>{{ orderInfo.orderTime }}</text>
  34. </view>
  35. <view class="status">{{ stateExpFormat(orderInfo.status) }}</view>
  36. </view>
  37. <view class="line"></view>
  38. <view
  39. class="shop-order"
  40. v-for="(shopOrder, shopOrderIndex) in orderInfo.shopOrderList"
  41. :key="shopOrderIndex"
  42. >
  43. <!-- 供应商 -->
  44. <view class="origin">
  45. <image class="cover" :src="shopOrder.shopLogo"></image>
  46. <view class="name">{{ shopOrder.shopName }}</view>
  47. </view>
  48. <!-- 商品列表 -->
  49. <view class="goods-list">
  50. <!-- 商品信息 -->
  51. <view
  52. class="order-goods"
  53. v-for="goods in shopOrder.orderProductList"
  54. :key="goods.productId"
  55. >
  56. <cm-order-prodcut :goods-data="goods"></cm-order-prodcut>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 统计 -->
  61. <view class="total">
  62. <view class="count">共{{ orderInfo.productCount }}件商品</view>
  63. <view class="status">
  64. <template v-if="['31', '32', '33'].includes(orderInfo.status)">
  65. <text class="label">已支付:</text>
  66. <text>¥{{ orderInfo.receiptAmount | formatPrice }}</text>
  67. </template>
  68. <template v-else>
  69. <text class="label">待付总额:</text>
  70. <text>¥{{ orderInfo.pendingPayments | formatPrice }}</text>
  71. </template>
  72. </view>
  73. </view>
  74. <!-- 操作 -->
  75. <cm-order-control-nav
  76. v-if="orderInfo.userId == userId"
  77. :orderInfo="orderInfo"
  78. @confirm="handleConfirmClick"
  79. ></cm-order-control-nav>
  80. </view>
  81. </template>
  82. </view>
  83. <!-- loading -->
  84. <view class="loading-more" v-if="orderList.length > 0">
  85. <tui-loadmore :index="3" :visible="loadmore"></tui-loadmore>
  86. <tui-nomore :text="loadMoreText" :visible="!loadmore" backgroundColor="#f7f7f7"></tui-nomore>
  87. </view>
  88. <!-- 操作弹窗 -->
  89. <tui-modal
  90. :show="modal"
  91. :content="modalText"
  92. :size="32"
  93. :maskClosable="false"
  94. color="#333"
  95. shape="circle"
  96. @click="handleModalConfirm"
  97. ></tui-modal>
  98. <!-- 加载框 -->
  99. <cm-loading :visible="isSubLoading" :text="loadingText"></cm-loading>
  100. <!-- 失效商品列表 -->
  101. <cm-order-invalid-modal
  102. :goodsList="invalidList"
  103. :visible="buyAgainModal"
  104. @confirm="buyAgainModalClick"
  105. @cancel="buyAgainModalHide"
  106. ></cm-order-invalid-modal>
  107. <!-- 操作弹窗 -->
  108. <tui-modal
  109. :show="removeKeywordModal"
  110. content="确认清空搜索历史记录?"
  111. :size="32"
  112. :maskClosable="false"
  113. color="#333"
  114. shape="circle"
  115. @click="clearSearchRecord"
  116. ></tui-modal>
  117. </view>
  118. </template>
  119. <script>
  120. import CmOrderProdcut from '@/components/cm-module/cm-order-prodcut/cm-order-prodcut.vue'
  121. import CmOrderControlNav from '@/components/cm-module/cm-order-control-nav/cm-order-control-nav.vue'
  122. import CmOrderInvalidModal from '@/components/cm-module/cm-order-invalid-modal/cm-order-invalid-modal.vue'
  123. import CmLoading from '@/components/cm-module/cm-loading/cm-loading.vue'
  124. import CmEmpty from '@/components/cm-module/cm-empty/cm-empty.vue'
  125. import CmSearch from '@/components/cm-module/cm-search/cm-search.vue'
  126. import { debounce } from '@/common/common.js'
  127. import orderMixins from './mixins/orderList.js'
  128. import wechatPay from './mixins/wechatPay.js'
  129. import { mapGetters } from 'vuex'
  130. export default {
  131. mixins: [orderMixins, wechatPay],
  132. components: {
  133. CmSearch,
  134. CmOrderProdcut,
  135. CmOrderControlNav,
  136. CmOrderInvalidModal,
  137. CmEmpty,
  138. CmLoading
  139. },
  140. data() {
  141. return {
  142. isRequest: false,
  143. keywordVisible: true,
  144. keywordList: [],
  145. keyword: '',
  146. pageNum: 1,
  147. hasMore: false,
  148. loadmore: false, // 正在加载更多
  149. orderList: [],
  150. refresh: false,
  151. removeKeywordModal: false
  152. }
  153. },
  154. computed: {
  155. ...mapGetters(['userId', 'userIdentity']),
  156. // 当前用户是否为协销
  157. isDealer() {
  158. return this.userIdentity === 2
  159. },
  160. // 上拉加载文案
  161. loadMoreText() {
  162. if (this.orderList.length === 0) return '没有更多了'
  163. return this.hasMore ? '上拉加载更多' : '没有更多了'
  164. },
  165. // 列表为空
  166. emptyInfo() {
  167. const info = {}
  168. info.image = `${this.$Static}icon-empty-address.png`
  169. info.message = '未找到相关订单~_~'
  170. if(this.keywordList.length <= 0){
  171. info.message = '暂无任何搜索历史记录~_~'
  172. }
  173. return info
  174. }
  175. },
  176. watch: {
  177. keywordVisible(nVal){
  178. if(!nVal) return
  179. this.fetchSerachRecord()
  180. this.orderList = []
  181. }
  182. },
  183. onReachBottom() {
  184. if (!this.hasMore) return
  185. this.fetchOrderData()
  186. },
  187. onLoad() {
  188. setTimeout(() => {
  189. this.fetchSerachRecord()
  190. }, 2000)
  191. this.$on('orderAction', () => {
  192. this.resetOrderList()
  193. })
  194. },
  195. beforeDestroy() {
  196. this.$off('orderAction')
  197. },
  198. methods: {
  199. handleSearch() {
  200. this.keywordVisible = false
  201. this.isRequest = true
  202. this.resetOrderList()
  203. },
  204. // 跳转详情
  205. handleToDetail(orderInfo) {
  206. this.$api.navigateTo('/pages/order/order-detail?orderId=' + orderInfo.orderId)
  207. },
  208. // 获取订单列表 使用防抖函数封装
  209. fetchOrderData: debounce(function() {
  210. this.loadmore = true
  211. const params = {
  212. searchWord: this.keyword,
  213. // orderState: 0,
  214. // orderType: 0,
  215. userId: this.userId,
  216. pageNum: this.pageNum,
  217. pageSize: 10
  218. }
  219. // if (this.isDealer) {
  220. // this.queryOrderDealerList(params)
  221. // } else {
  222. // this.queryOrderList(params)
  223. // }
  224. this.searchOrderInfo(params)
  225. }, 500),
  226. // 普通用户获取订单列表
  227. // queryOrderList(params) {
  228. // this.OrderService.QueryOrderList(params)
  229. // .then(res => {
  230. // if (this.refresh) this.orderList = []
  231. // this.updateOrderList(res)
  232. // })
  233. // .catch(err => {
  234. // console.log(err)
  235. // })
  236. // .finally(() => {
  237. // this.refresh = false
  238. // this.loadmore = false
  239. // this.isRequest = false
  240. // })
  241. // },
  242. // 分销者获取订单列表
  243. // queryOrderDealerList(params) {
  244. // this.OrderService.QueryOrderDealerList(params)
  245. // .then(res => {
  246. // if (this.refresh) this.orderList = []
  247. // this.updateOrderList(res)
  248. // })
  249. // .catch(err => {
  250. // console.log(err)
  251. // })
  252. // .finally(() => {
  253. // this.refresh = false
  254. // this.loadmore = false
  255. // this.isRequest = false
  256. // })
  257. // },
  258. // 机构搜索订单列表
  259. searchOrderInfo(params){
  260. this.OrderService.SearchOrderInfo(params)
  261. .then(res => {
  262. if (this.refresh) this.orderList = []
  263. this.updateOrderList(res)
  264. })
  265. .catch(err => {
  266. console.log(err)
  267. })
  268. .finally(() => {
  269. this.refresh = false
  270. this.loadmore = false
  271. this.isRequest = false
  272. })
  273. },
  274. // 更新订单列表
  275. updateOrderList(response) {
  276. this.pageNum++
  277. this.orderList = this.orderList.concat(response.data.list)
  278. this.hasMore = response.data.hasNextPage
  279. },
  280. // 重置订单列表
  281. resetOrderList() {
  282. this.refresh = true
  283. this.pageNum = 1
  284. this.fetchOrderData()
  285. },
  286. // 获取搜索历史
  287. async fetchSerachRecord() {
  288. try {
  289. const res = await this.OrderService.SearchOrderHistory({ userId: this.userId })
  290. this.keywordList = res.data
  291. } catch (error) {
  292. this.$util.msg(error.msg, 2000)
  293. }
  294. },
  295. // 清空搜索历史
  296. async clearSearchRecord(e) {
  297. if (!e.index) return (this.removeKeywordModal = false)
  298. try {
  299. await this.OrderService.ClearOrderHistory({ userId: this.userId })
  300. await this.fetchSerachRecord()
  301. this.removeKeywordModal = false
  302. this.$util.msg('已清空搜索历史记录', 2000)
  303. } catch (error) {
  304. this.$util.msg(error.msg, 2000)
  305. }
  306. }
  307. }
  308. }
  309. </script>
  310. <style lang="scss" scoped>
  311. .order-search {
  312. min-height: 100vh;
  313. background: #f7f7f7;
  314. overflow: hidden;
  315. padding-top: 90rpx;
  316. box-sizing: border-box;
  317. }
  318. .order-top {
  319. position: fixed;
  320. top: 0;
  321. left: 0;
  322. width: 100%;
  323. z-index: 100000;
  324. }
  325. .grid {
  326. height: 20rpx;
  327. background: #f7f7f7;
  328. }
  329. .order-section {
  330. padding: 38rpx 0;
  331. background-color: #fff;
  332. .line {
  333. width: 702rpx;
  334. height: 1px;
  335. background: #f7f7f7;
  336. }
  337. .order-info {
  338. position: relative;
  339. padding: 0 24rpx;
  340. margin-bottom: 32rpx;
  341. line-height: 1.6;
  342. .order-num,
  343. .order-time {
  344. font-size: 26rpx;
  345. color: #333333;
  346. .label {
  347. color: #999999;
  348. }
  349. }
  350. .status {
  351. position: absolute;
  352. font-size: 26rpx;
  353. color: #ff457b;
  354. right: 24rpx;
  355. bottom: 0;
  356. }
  357. }
  358. .origin {
  359. padding: 0 24rpx;
  360. margin-top: 24rpx;
  361. margin-bottom: 16rpx;
  362. display: flex;
  363. justify-content: flex-start;
  364. align-items: center;
  365. .cover {
  366. width: 56rpx;
  367. height: 56rpx;
  368. border-radius: 4rpx;
  369. border: 1px solid #f7f7f7;
  370. box-sizing: border-box;
  371. }
  372. .name {
  373. margin-left: 16rpx;
  374. font-size: 30rpx;
  375. color: #333333;
  376. font-weight: bold;
  377. }
  378. }
  379. .goods-list {
  380. .order-goods {
  381. padding-top: 32rpx;
  382. &:first-child {
  383. padding-top: 0;
  384. }
  385. }
  386. }
  387. .total {
  388. display: flex;
  389. justify-content: space-between;
  390. align-items: center;
  391. padding: 0 24rpx;
  392. margin: 32rpx 0;
  393. font-size: 26rpx;
  394. color: #333333;
  395. .count {
  396. font-weight: bold;
  397. }
  398. .status {
  399. color: #ff457b;
  400. .label {
  401. color: #333333;
  402. }
  403. }
  404. }
  405. }
  406. </style>