order-search.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. this.fetchSerachRecord()
  189. this.$on('orderAction', () => {
  190. this.resetOrderList()
  191. })
  192. },
  193. beforeDestroy() {
  194. this.$off('orderAction')
  195. },
  196. methods: {
  197. handleSearch() {
  198. this.keywordVisible = false
  199. this.isRequest = true
  200. this.resetOrderList()
  201. },
  202. // 跳转详情
  203. handleToDetail(orderInfo) {
  204. this.$api.navigateTo('/pages/order/order-detail?orderId=' + orderInfo.orderId)
  205. },
  206. // 获取订单列表 使用防抖函数封装
  207. fetchOrderData: debounce(function() {
  208. this.loadmore = true
  209. const params = {
  210. searchWord: this.keyword,
  211. // orderState: 0,
  212. // orderType: 0,
  213. userId: this.userId,
  214. pageNum: this.pageNum,
  215. pageSize: 10
  216. }
  217. // if (this.isDealer) {
  218. // this.queryOrderDealerList(params)
  219. // } else {
  220. // this.queryOrderList(params)
  221. // }
  222. this.searchOrderInfo(params)
  223. }, 500),
  224. // 普通用户获取订单列表
  225. // queryOrderList(params) {
  226. // this.OrderService.QueryOrderList(params)
  227. // .then(res => {
  228. // if (this.refresh) this.orderList = []
  229. // this.updateOrderList(res)
  230. // })
  231. // .catch(err => {
  232. // console.log(err)
  233. // })
  234. // .finally(() => {
  235. // this.refresh = false
  236. // this.loadmore = false
  237. // this.isRequest = false
  238. // })
  239. // },
  240. // 分销者获取订单列表
  241. // queryOrderDealerList(params) {
  242. // this.OrderService.QueryOrderDealerList(params)
  243. // .then(res => {
  244. // if (this.refresh) this.orderList = []
  245. // this.updateOrderList(res)
  246. // })
  247. // .catch(err => {
  248. // console.log(err)
  249. // })
  250. // .finally(() => {
  251. // this.refresh = false
  252. // this.loadmore = false
  253. // this.isRequest = false
  254. // })
  255. // },
  256. // 机构搜索订单列表
  257. searchOrderInfo(params){
  258. this.OrderService.SearchOrderInfo(params)
  259. .then(res => {
  260. if (this.refresh) this.orderList = []
  261. this.updateOrderList(res)
  262. })
  263. .catch(err => {
  264. console.log(err)
  265. })
  266. .finally(() => {
  267. this.refresh = false
  268. this.loadmore = false
  269. this.isRequest = false
  270. })
  271. },
  272. // 更新订单列表
  273. updateOrderList(response) {
  274. this.pageNum++
  275. this.orderList = this.orderList.concat(response.data.list)
  276. this.hasMore = response.data.hasNextPage
  277. },
  278. // 重置订单列表
  279. resetOrderList() {
  280. this.refresh = true
  281. this.pageNum = 1
  282. this.fetchOrderData()
  283. },
  284. // 获取搜索历史
  285. async fetchSerachRecord() {
  286. try {
  287. const res = await this.OrderService.SearchOrderHistory({ userId: this.userId })
  288. this.keywordList = res.data
  289. } catch (error) {
  290. this.$util.msg(error.msg, 2000)
  291. }
  292. },
  293. // 清空搜索历史
  294. async clearSearchRecord(e) {
  295. if (!e.index) return (this.removeKeywordModal = false)
  296. try {
  297. await this.OrderService.ClearOrderHistory({ userId: this.userId })
  298. await this.fetchSerachRecord()
  299. this.removeKeywordModal = false
  300. this.$util.msg('已清空搜索历史记录', 2000)
  301. } catch (error) {
  302. this.$util.msg(error.msg, 2000)
  303. }
  304. }
  305. }
  306. }
  307. </script>
  308. <style lang="scss" scoped>
  309. .order-search {
  310. min-height: 100vh;
  311. background: #f7f7f7;
  312. overflow: hidden;
  313. padding-top: 90rpx;
  314. box-sizing: border-box;
  315. }
  316. .order-top {
  317. position: fixed;
  318. top: 0;
  319. left: 0;
  320. width: 100%;
  321. z-index: 100000;
  322. }
  323. .grid {
  324. height: 20rpx;
  325. background: #f7f7f7;
  326. }
  327. .order-section {
  328. padding: 38rpx 0;
  329. background-color: #fff;
  330. .line {
  331. width: 702rpx;
  332. height: 1px;
  333. background: #f7f7f7;
  334. }
  335. .order-info {
  336. position: relative;
  337. padding: 0 24rpx;
  338. margin-bottom: 32rpx;
  339. line-height: 1.6;
  340. .order-num,
  341. .order-time {
  342. font-size: 26rpx;
  343. color: #333333;
  344. .label {
  345. color: #999999;
  346. }
  347. }
  348. .status {
  349. position: absolute;
  350. font-size: 26rpx;
  351. color: #ff457b;
  352. right: 24rpx;
  353. bottom: 0;
  354. }
  355. }
  356. .origin {
  357. padding: 0 24rpx;
  358. margin-top: 24rpx;
  359. margin-bottom: 16rpx;
  360. display: flex;
  361. justify-content: flex-start;
  362. align-items: center;
  363. .cover {
  364. width: 56rpx;
  365. height: 56rpx;
  366. border-radius: 4rpx;
  367. border: 1px solid #f7f7f7;
  368. box-sizing: border-box;
  369. }
  370. .name {
  371. margin-left: 16rpx;
  372. font-size: 30rpx;
  373. color: #333333;
  374. font-weight: bold;
  375. }
  376. }
  377. .goods-list {
  378. .order-goods {
  379. padding-top: 32rpx;
  380. &:first-child {
  381. padding-top: 0;
  382. }
  383. }
  384. }
  385. .total {
  386. display: flex;
  387. justify-content: space-between;
  388. align-items: center;
  389. padding: 0 24rpx;
  390. margin: 32rpx 0;
  391. font-size: 26rpx;
  392. color: #333333;
  393. .count {
  394. font-weight: bold;
  395. }
  396. .status {
  397. color: #ff457b;
  398. .label {
  399. color: #333333;
  400. }
  401. }
  402. }
  403. }
  404. </style>