order.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view class="container">
  3. <view class="header-box">
  4. <view class="search-box">
  5. <u-search
  6. v-model="searchForm.keyword"
  7. :clearabled="true"
  8. bg-color="#E5E5E5"
  9. :input-style="searchInputStyle"
  10. placeholder="搜索您想要的内容"
  11. @search="onSearchConfirm"
  12. @custom="onSearchConfirm"
  13. ></u-search>
  14. </view>
  15. <view class="tab-box">
  16. <u-tabs
  17. name="label"
  18. :list="searchType"
  19. :is-scroll="true"
  20. v-model="searchForm.typeCurrent"
  21. @change="onSearchTypeChange"
  22. font-size="24"
  23. :bold="false"
  24. inactive-color="#000000"
  25. active-color="#000000"
  26. :bar-style="{'background-color': '#2979ff'}"
  27. :gutter="25"
  28. height="45"
  29. ></u-tabs>
  30. </view>
  31. </view>
  32. <u-empty
  33. mode="data"
  34. v-if="list.length === 0"
  35. iconSize="120"
  36. textSize="58"
  37. text="暂无数据"
  38. >
  39. </u-empty>
  40. <view class="list-box">
  41. <view class="list-item-box" v-for="item in list" :key="item.id" @click="onItem(item)">
  42. <view class="title-box">
  43. {{item.title}}
  44. </view>
  45. <view class="main-box">
  46. <view class="info-box">
  47. <view class="info-item-box">
  48. <view class="label">
  49. 订单编号:
  50. </view>
  51. <view class="text">
  52. {{item.orderNo}}
  53. </view>
  54. </view>
  55. <view class="info-item-box">
  56. <view class="label">
  57. 订单时间:
  58. </view>
  59. <view class="text">
  60. {{item.buyDate}}
  61. </view>
  62. </view>
  63. </view>
  64. <view class="price-box">
  65. <view class="text" v-if="item.status === '1'">
  66. 实付款:&nbsp;¥{{item.buyPrice}}元
  67. </view>
  68. <view class="button error" v-if="item.status === '0'" @click.stop="onPay(item)">
  69. 待支付
  70. </view>
  71. <view class="button" v-if="item.status === '2'">
  72. 订单关闭
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. <uni-load-more v-show="visualLoadMore" :status="loadMoreStatus"></uni-load-more>
  79. <view class="buttom-block"></view>
  80. <view class="bottom-box">
  81. <view class="button" @click="onToInvoiceApplication">
  82. 发票申请
  83. </view>
  84. </view>
  85. </view>
  86. </template>
  87. <script setup>
  88. import { ref } from 'vue'
  89. import { onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app'
  90. import { query } from '@/api/order.js'
  91. import { msgError, msgSuccess } from '@/utils/common'
  92. const searchInputStyle = {
  93. backgroundColor: '#E5E5E5'
  94. }
  95. const searchType = [
  96. {
  97. label: '全部',
  98. value: null
  99. },
  100. {
  101. label: '研究报告',
  102. value: 8
  103. },
  104. {
  105. label: '培训课程',
  106. value: 9
  107. },
  108. ]
  109. const pageNum = ref(1)
  110. const pageSize = ref(10)
  111. const visualLoadMore = ref(false)
  112. const loadMoreStatus = ref('more')
  113. const searchForm = ref({
  114. keyword: '',
  115. type: null,
  116. typeCurrent: 0,
  117. pageNumber: 1,
  118. pageSize: 10
  119. })
  120. const list = ref([
  121. {
  122. id: '01',
  123. title: '【市场研究】2024年11月广州市中介促成二手住宅市场交易简报',
  124. type: 8,
  125. orderNo: '123456789987654321',
  126. buyDate: '2023年8月8日',
  127. buyPrice: 9.9,
  128. invoice: true,
  129. status: 1
  130. },
  131. ])
  132. function onItem(order) {
  133. console.log('点击订单', order)
  134. if (order.type === '8') {
  135. // 研究报告
  136. }
  137. if (order.type === '9') {
  138. // 培训课程
  139. }
  140. }
  141. function onPay(order) {
  142. wx.requestPayment({
  143. timeStamp: order.prepay.timeStamp,
  144. nonceStr: order.prepay.nonceStr,
  145. package: order.prepay.package,
  146. signType: order.prepay.signType,
  147. paySign: order.prepay.paySign,
  148. success (res) {
  149. msgSuccess('支付成功')
  150. onSearch()
  151. },
  152. fail (res) {
  153. // console.log('支付失败', res)
  154. const errMsg = res.errMsg
  155. if (errMsg.indexOf('fail cancel')) {
  156. msgError('已取消支付')
  157. }
  158. }
  159. })
  160. }
  161. function onSearchConfirm() {
  162. searchForm.value.pageNumber = 1
  163. pageNum.value = 1
  164. onSearch()
  165. }
  166. function onSearchClear() {
  167. searchForm.value.keyword = null
  168. searchForm.value.pageNumber = 1
  169. pageNum.value = 1
  170. onSearch()
  171. }
  172. function onSearch() {
  173. loadMoreStatus.value = 'more'
  174. query(searchForm.value).then(res => {
  175. if (res && res.message === 'success') {
  176. list.value = res.data
  177. if (res.count === 0) {
  178. visualLoadMore.value = false
  179. }
  180. }
  181. })
  182. }
  183. function onSearchTypeChange(val) {
  184. searchForm.value.type = searchType[val].value
  185. onSearchConfirm()
  186. }
  187. // 前往发票申请
  188. function onToInvoiceApplication() {
  189. uni.navigateTo({
  190. url: '/pages/InvoiceApplication/InvoiceApplication'
  191. })
  192. }
  193. onPullDownRefresh((e) => {
  194. searchForm.value.pageNumber = 1
  195. loadMoreStatus.value = 'more'
  196. query(searchForm.value).then(res => {
  197. if (res && res.message === 'success') {
  198. list.value = res.data
  199. if (res.count === 0) {
  200. visualLoadMore.value = false
  201. }
  202. uni.showToast({
  203. title: '刷新成功',
  204. icon: 'success',
  205. duration: 2000
  206. })
  207. }
  208. uni.stopPullDownRefresh()
  209. })
  210. })
  211. onReachBottom(async () => {
  212. if (loadMoreStatus.value === 'noMore') {
  213. uni.showToast({
  214. title: '没有更多啦>﹏<',
  215. icon: 'none'
  216. })
  217. return
  218. }
  219. visualLoadMore.value = true
  220. loadMoreStatus.value = 'loading'
  221. searchForm.value.pageNumber++
  222. query(searchForm.value).then(res => {
  223. if (res && res.message === 'success') {
  224. if (res.data) {
  225. if (res.count >= list.value.length) {
  226. if (list.value.length === res.count) {
  227. loadMoreStatus.value = 'noMore'
  228. visualLoadMore.value = true
  229. } else {
  230. list.value.push(...res.data)
  231. loadMoreStatus.value = 'more'
  232. visualLoadMore.value = false
  233. }
  234. } else {
  235. loadMoreStatus.value = 'noMore'
  236. visualLoadMore.value = true
  237. }
  238. } else {
  239. loadMoreStatus.value = 'noMore'
  240. visualLoadMore.value = true
  241. }
  242. }
  243. })
  244. })
  245. onLoad(() => {
  246. onSearch()
  247. })
  248. </script>
  249. <style lang="scss" scoped>
  250. .container {
  251. height: 100vh;
  252. width: 100vw;
  253. background-color: $uni-text-color-inverse;
  254. .header-box {
  255. padding: 0 20rpx;
  256. background-color: $uni-text-color-inverse;
  257. @include topMagnet();
  258. }
  259. .search-box {
  260. margin-bottom: 20rpx;
  261. ::v-deep(.u-search) {
  262. background-color: #e5e5e5;
  263. border-radius: 50rpx;
  264. .u-action {
  265. width: 18%;
  266. background-color: $uni-color-primary;
  267. border-radius: 50rpx;
  268. color: $uni-text-color-inverse;
  269. margin-right: 8rpx;
  270. font-size: 28rpx;
  271. line-height: 50rpx;
  272. letter-spacing: 3rpx;
  273. text-align: center;
  274. }
  275. }
  276. }
  277. .list-box {
  278. padding: 0 20rpx;
  279. .list-item-box {
  280. padding: 20rpx;
  281. border-bottom: 5rpx solid #E6E6E6;
  282. &:active {
  283. background-color: $uni-bg-color-hover;
  284. }
  285. .title-box {
  286. font-size: $uni-title-font-size-3;
  287. font-weight: bold;
  288. margin-bottom: 20rpx;
  289. @include text-overflow()
  290. }
  291. .main-box {
  292. display: flex;
  293. justify-content: space-between;
  294. padding-left: 20rpx;
  295. .info-box {
  296. width: 50%;
  297. .info-item-box {
  298. display: flex;
  299. font-size: $uni-font-size-3;
  300. color: $uni-text-color-grey;
  301. line-height: 30rpx;
  302. .label {
  303. width: 80rpx;
  304. }
  305. }
  306. }
  307. .price-box {
  308. display: flex;
  309. align-items: flex-end;
  310. text-align: right;
  311. color: $uni-color-error;
  312. font-size: $uni-title-font-size-3;
  313. font-weight: bold;
  314. .button {
  315. background-color: #CCCCCC;
  316. color: $uni-text-color-inverse;
  317. padding: 6rpx 25rpx;
  318. border-radius: $uni-card-border-radius;
  319. }
  320. .error {
  321. background-color: $uni-color-error;
  322. }
  323. }
  324. }
  325. }
  326. }
  327. .buttom-block {
  328. height: 100rpx;
  329. padding-bottom: env(5rpx + safe-area-inset-bottom, 0);
  330. }
  331. .bottom-box {
  332. text-align: center;
  333. font-size: $uni-title-font-size-2;
  334. background-color: $uni-bg-color-grey;
  335. position: fixed;
  336. bottom: 0;
  337. width: 100%;
  338. .button {
  339. width: 100%;
  340. height: 100rpx;
  341. line-height: 100rpx;
  342. color: $uni-color-primary;
  343. letter-spacing: 2rpx;
  344. border: 1rpx solid #E9E9E9;
  345. &:active {
  346. background-color: $uni-bg-color-hover;
  347. }
  348. }
  349. }
  350. }
  351. </style>