index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <view class="main">
  3. <view class="one">
  4. <input type="text" v-model="searchInfo.title" @input="toInput" placeholder="搜索标题">
  5. </view>
  6. <view class="two">
  7. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  8. <view class="list-scroll-view">
  9. <view class="list" v-for="(item, index) in list" :key="index" @tap="toInfo(item)">
  10. 111
  11. </view>
  12. <view class="is_bottom" v-if="is_bottom">
  13. <text>{{config.bottom_title||'到底了!'}}</text>
  14. </view>
  15. </view>
  16. </scroll-view>
  17. <button class="button" type="primary" size="mini" @tap.stop="toPay()">支付</button>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. config: {},
  26. user: {},
  27. list: [],
  28. total: 0,
  29. skip: 0,
  30. limit: 6,
  31. page: 0,
  32. // 数据是否触底
  33. is_bottom: false,
  34. scrollTop: 0,
  35. }
  36. },
  37. onLoad: async function(e) {
  38. const that = this;
  39. that.searchToken();
  40. that.searchConfig();
  41. },
  42. onShow: async function() {
  43. const that = this;
  44. // that.clearPage();
  45. // await that.search();
  46. },
  47. onPullDownRefresh: async function() {
  48. const that = this;
  49. // that.clearPage();
  50. // await that.search();
  51. uni.stopPullDownRefresh();
  52. },
  53. methods: {
  54. // 用户信息
  55. searchToken() {
  56. const that = this;
  57. try {
  58. const res = uni.getStorageSync('token');
  59. if (res) {
  60. const user = that.$jwt(res);
  61. that.$set(that, `user`, user);
  62. }
  63. } catch (e) {}
  64. },
  65. searchConfig() {
  66. const that = this;
  67. try {
  68. const res = uni.getStorageSync('config');
  69. if (res) that.$set(that, `config`, res);
  70. } catch (e) {}
  71. },
  72. async search() {
  73. const that = this;
  74. let info = {
  75. skip: that.skip,
  76. limit: that.limit,
  77. is_use: '0'
  78. }
  79. const res = await that.$api(`/article`, 'GET', {
  80. ...info,
  81. ...that.searchInfo
  82. })
  83. if (res.errcode == '0') {
  84. let list = [...that.list, ...res.data];
  85. that.$set(that, `list`, list)
  86. that.$set(that, `total`, res.total)
  87. } else {
  88. uni.showToast({
  89. title: res.errmsg,
  90. icon: 'none'
  91. });
  92. }
  93. },
  94. // 支付
  95. async toPay() {
  96. const that = this;
  97. // 支付信息
  98. uni.request({
  99. url: `https://broadcast.waityou24.cn/wechat/api/pay/payOrder`,
  100. method: 'POST',
  101. data: {
  102. config: 'newCourtApp',
  103. money: 0.01,
  104. openid: 'wx34436977cd1e02e4',
  105. order_no: String(Date.now())
  106. },
  107. header: {},
  108. success: (res) => {
  109. console.log(res);
  110. // if (pay.errcode == '0' && pay.data.paySign) {
  111. // // 微信支付
  112. // uni.showLoading({
  113. // title: '加载中'
  114. // })
  115. // uni.requestPayment({
  116. // "provider": "wxpay",
  117. // ...pay.data,
  118. // success: function(res) {
  119. // uni.showToast({
  120. // title: '支付成功',
  121. // icon: 'none'
  122. // })
  123. // },
  124. // fail: function(err) {
  125. // uni.showToast({
  126. // title: `支付失败`,
  127. // icon: 'none'
  128. // })
  129. // },
  130. // complete: function() {
  131. // uni.hideLoading();
  132. // that.clearPage();
  133. // that.search()
  134. // }
  135. // })
  136. // } else {
  137. // uni.showToast({
  138. // title: pay.errmsg || '错误信息',
  139. // icon: 'none'
  140. // })
  141. // }
  142. },
  143. fail: (err) => {
  144. uni.showToast({
  145. title: '请求接口失败',
  146. icon: 'fail',
  147. });
  148. },
  149. });
  150. },
  151. // 输入框
  152. toInput(e) {
  153. const that = this;
  154. if (that.searchInfo.title) that.$set(that.searchInfo, `title`, e.detail.value)
  155. else that.$set(that, `searchInfo`, {})
  156. that.clearPage();
  157. that.search();
  158. },
  159. // 查看详情
  160. toInfo(item) {
  161. uni.navigateTo({
  162. url: `/pagesScience/science/index?id=${item.id||item._id}`
  163. })
  164. },
  165. // 分页
  166. toPage(e) {
  167. const that = this;
  168. let list = that.list;
  169. let limit = that.limit;
  170. if (that.total > list.length) {
  171. uni.showLoading({
  172. title: '加载中',
  173. mask: true
  174. })
  175. let page = that.page + 1;
  176. that.$set(that, `page`, page)
  177. let skip = page * limit;
  178. that.$set(that, `skip`, skip)
  179. that.search();
  180. uni.hideLoading();
  181. } else that.$set(that, `is_bottom`, true)
  182. },
  183. toScroll(e) {
  184. const that = this;
  185. let up = that.scrollTop;
  186. that.$set(that, `scrollTop`, e.detail.scrollTop);
  187. let num = Math.sign(up - e.detail.scrollTop);
  188. if (num == 1) that.$set(that, `is_bottom`, false);
  189. },
  190. // 清空列表
  191. clearPage() {
  192. const that = this;
  193. that.$set(that, `list`, [])
  194. that.$set(that, `skip`, 0)
  195. that.$set(that, `limit`, 6)
  196. that.$set(that, `page`, 0)
  197. }
  198. }
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. .main {
  203. display: flex;
  204. flex-direction: column;
  205. width: 100vw;
  206. height: 100vh;
  207. .one {
  208. display: flex;
  209. justify-content: center;
  210. align-items: center;
  211. padding: 2vw;
  212. input {
  213. width: 100%;
  214. padding: 2vw;
  215. background-color: var(--f1Color);
  216. font-size: var(--font14Size);
  217. border-radius: 5px;
  218. }
  219. }
  220. .two {
  221. position: relative;
  222. flex-grow: 1;
  223. background-color: var(--f9Color);
  224. margin: 2vw 0 0 0;
  225. .list {
  226. display: flex;
  227. background-color: var(--mainColor);
  228. border: 1px solid var(--f5Color);
  229. padding: 2vw;
  230. margin: 2vw 2vw 0 2vw;
  231. border-radius: 5px;
  232. }
  233. }
  234. }
  235. .scroll-view {
  236. position: absolute;
  237. top: 0;
  238. left: 0;
  239. right: 0;
  240. bottom: 0;
  241. .list-scroll-view {
  242. display: flex;
  243. flex-direction: column;
  244. }
  245. }
  246. .is_bottom {
  247. width: 100%;
  248. text-align: center;
  249. text {
  250. padding: 2vw 0;
  251. display: inline-block;
  252. color: var(--f85Color);
  253. font-size: var(--font14Size);
  254. }
  255. }
  256. </style>