order.vue 7.9 KB

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