order.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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" v-if="false"></view>
  80. <view class="bottom-box" v-if="false">
  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, byId } 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. if (order.status === '2') {
  134. uni.showToast({
  135. title: '订单已关闭',
  136. icon: 'none'
  137. })
  138. return
  139. }
  140. uni.showLoading({
  141. title: '加载中...'
  142. })
  143. byId(order.id).then(res => {
  144. if (res && res.message === 'success') {
  145. uni.hideLoading()
  146. const objId = res.data.objId
  147. const title = res.data.title
  148. if (res.data.objType === '8') {
  149. uni.navigateTo({
  150. url: `/pages/reportDetail/reportDetail?id=${objId}&title=${title}`
  151. })
  152. }
  153. if (res.data.objType === '9') {
  154. uni.navigateTo({
  155. url: `/pages/goOnEdu/course/courseDetail/courseDetail?id=${objId}&title=${title}`
  156. })
  157. }
  158. } else {
  159. uni.hideLoading()
  160. }
  161. }).catch(e => {
  162. uni.hideLoading()
  163. })
  164. }
  165. function onPay(order) {
  166. wx.requestPayment({
  167. timeStamp: order.prepay.timeStamp,
  168. nonceStr: order.prepay.nonceStr,
  169. package: order.prepay.package,
  170. signType: order.prepay.signType,
  171. paySign: order.prepay.paySign,
  172. success (res) {
  173. msgSuccess('支付成功')
  174. onSearch()
  175. },
  176. fail (res) {
  177. // console.log('支付失败', res)
  178. const errMsg = res.errMsg
  179. if (errMsg.indexOf('fail cancel')) {
  180. msgError('已取消支付')
  181. }
  182. }
  183. })
  184. }
  185. function onSearchConfirm() {
  186. searchForm.value.pageNumber = 1
  187. pageNum.value = 1
  188. onSearch()
  189. }
  190. function onSearchClear() {
  191. searchForm.value.keyword = null
  192. searchForm.value.pageNumber = 1
  193. pageNum.value = 1
  194. onSearch()
  195. }
  196. function onSearch() {
  197. loadMoreStatus.value = 'more'
  198. query(searchForm.value).then(res => {
  199. if (res && res.message === 'success') {
  200. list.value = res.data
  201. if (res.count === 0) {
  202. visualLoadMore.value = false
  203. }
  204. }
  205. })
  206. }
  207. function onSearchTypeChange(val) {
  208. searchForm.value.type = searchType[val].value
  209. onSearchConfirm()
  210. }
  211. // 前往发票申请
  212. function onToInvoiceApplication() {
  213. uni.navigateTo({
  214. url: '/pages/InvoiceApplication/InvoiceApplication'
  215. })
  216. }
  217. onPullDownRefresh((e) => {
  218. searchForm.value.pageNumber = 1
  219. loadMoreStatus.value = 'more'
  220. query(searchForm.value).then(res => {
  221. if (res && res.message === 'success') {
  222. list.value = res.data
  223. if (res.count === 0) {
  224. visualLoadMore.value = false
  225. }
  226. uni.showToast({
  227. title: '刷新成功',
  228. icon: 'success',
  229. duration: 2000
  230. })
  231. }
  232. uni.stopPullDownRefresh()
  233. })
  234. })
  235. onReachBottom(async () => {
  236. if (loadMoreStatus.value === 'noMore') {
  237. uni.showToast({
  238. title: '没有更多啦>﹏<',
  239. icon: 'none'
  240. })
  241. return
  242. }
  243. visualLoadMore.value = true
  244. loadMoreStatus.value = 'loading'
  245. searchForm.value.pageNumber++
  246. query(searchForm.value).then(res => {
  247. if (res && res.message === 'success') {
  248. if (res.data) {
  249. if (res.count >= list.value.length) {
  250. if (list.value.length === res.count) {
  251. loadMoreStatus.value = 'noMore'
  252. visualLoadMore.value = true
  253. } else {
  254. list.value.push(...res.data)
  255. loadMoreStatus.value = 'more'
  256. visualLoadMore.value = false
  257. }
  258. } else {
  259. loadMoreStatus.value = 'noMore'
  260. visualLoadMore.value = true
  261. }
  262. } else {
  263. loadMoreStatus.value = 'noMore'
  264. visualLoadMore.value = true
  265. }
  266. }
  267. })
  268. })
  269. onLoad(() => {
  270. onSearch()
  271. })
  272. </script>
  273. <style lang="scss" scoped>
  274. .container {
  275. height: 100vh;
  276. width: 100vw;
  277. background-color: $uni-text-color-inverse;
  278. .header-box {
  279. padding: 0 20rpx;
  280. background-color: $uni-text-color-inverse;
  281. @include topMagnet();
  282. }
  283. .search-box {
  284. margin-bottom: 20rpx;
  285. ::v-deep(.u-search) {
  286. background-color: #e5e5e5;
  287. border-radius: 50rpx;
  288. .u-action {
  289. width: 18%;
  290. background-color: $uni-color-primary;
  291. border-radius: 50rpx;
  292. color: $uni-text-color-inverse;
  293. margin-right: 8rpx;
  294. font-size: 28rpx;
  295. line-height: 50rpx;
  296. letter-spacing: 3rpx;
  297. text-align: center;
  298. }
  299. }
  300. }
  301. .list-box {
  302. padding: 0 20rpx;
  303. .list-item-box {
  304. padding: 20rpx;
  305. border-bottom: 5rpx solid #E6E6E6;
  306. &:active {
  307. background-color: $uni-bg-color-hover;
  308. }
  309. .title-box {
  310. font-size: $uni-title-font-size-3;
  311. font-weight: bold;
  312. margin-bottom: 20rpx;
  313. @include text-overflow()
  314. }
  315. .main-box {
  316. display: flex;
  317. justify-content: space-between;
  318. padding-left: 20rpx;
  319. .info-box {
  320. width: 50%;
  321. .info-item-box {
  322. display: flex;
  323. font-size: $uni-font-size-3;
  324. color: $uni-text-color-grey;
  325. line-height: 30rpx;
  326. .label {
  327. width: 80rpx;
  328. }
  329. }
  330. }
  331. .price-box {
  332. display: flex;
  333. align-items: flex-end;
  334. text-align: right;
  335. color: $uni-color-error;
  336. font-size: $uni-title-font-size-3;
  337. font-weight: bold;
  338. .button {
  339. background-color: #CCCCCC;
  340. color: $uni-text-color-inverse;
  341. padding: 6rpx 25rpx;
  342. border-radius: $uni-card-border-radius;
  343. }
  344. .error {
  345. background-color: $uni-color-error;
  346. }
  347. }
  348. }
  349. }
  350. }
  351. .buttom-block {
  352. height: 100rpx;
  353. padding-bottom: env(5rpx + safe-area-inset-bottom, 0);
  354. }
  355. .bottom-box {
  356. text-align: center;
  357. font-size: $uni-title-font-size-2;
  358. background-color: $uni-bg-color-grey;
  359. position: fixed;
  360. bottom: 0;
  361. width: 100%;
  362. .button {
  363. width: 100%;
  364. height: 100rpx;
  365. line-height: 100rpx;
  366. color: $uni-color-primary;
  367. letter-spacing: 2rpx;
  368. border: 1rpx solid #E9E9E9;
  369. &:active {
  370. background-color: $uni-bg-color-hover;
  371. }
  372. }
  373. }
  374. }
  375. </style>