integralGoods.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <view>
  3. <view class="top-box">
  4. <view class="my-integral">
  5. <view class="left">
  6. <view class="x-ac">
  7. <view class="label">我的健康币</view>
  8. <view class="x-ac" style="margin-left: 20rpx;" @click="goCart()">
  9. <u-icon name="shopping-cart" color="#fff" size="28"></u-icon>
  10. <view class="label">购物车</view>
  11. </view>
  12. </view>
  13. <view style="display: flex;align-items: baseline;">
  14. <view class="integral">{{integral}}</view>
  15. <view class="integralbtn" @click="goIntegral">获取健康币</view>
  16. </view>
  17. </view>
  18. <view class="btn-box">
  19. <view class="btn" @click="navTo('/pages/user/integral/integralLogsList')">获得记录</view>
  20. <view class="btn" @click="navTo('/pages/user/integral/integralOrderList')">健康币订单</view>
  21. </view>
  22. </view>
  23. <!-- 搜索 -->
  24. <view class="search-box">
  25. <uni-search-bar class="search" bgColor="#eee" radius="34" v-model="keyword" placeholder="搜索商品" clearButton="auto" cancelButton="none"
  26. @confirm="refreshList" @clear="handleClear">
  27. <template v-slot:searchIcon>
  28. <image src="@/static/image/hall/search_gray_icon.png" mode="aspectFill"></image>
  29. </template>
  30. </uni-search-bar>
  31. </view>
  32. <view class="tabs" v-if="tabs.length>0">
  33. <u-tabs :current="tabIndex" :scrollable="true" :list="tabs" lineColor="#FF5030" @change="tabChange">
  34. </u-tabs>
  35. </view>
  36. </view>
  37. <view class="integral-box">
  38. <view class="item" @click="navTo('/pages/user/integral/integralGoodsDetails?goodsId='+item.goodsId)"
  39. v-for="(item,index) in dataList">
  40. <view class="top">
  41. <image :src="item.imgUrl"></image>
  42. </view>
  43. <view class="bottom">
  44. <view class="title ellipsis2">
  45. {{item.goodsName}}
  46. </view>
  47. <view class="price-box">
  48. <view class="price">{{item.integral}}健康币</view>
  49. <view class="count">价值:{{item.otPrice.toFixed(2)}}元</view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="x-ac" v-if="dataList&&dataList.length==0">
  55. <u-empty style="padding-top: 20px" mode="data"
  56. icon="https://cos.his.cdwjyyh.com/fs/20240423/cf4a86b913a04341bb44e34bb4d37aa2.png" text="暂无数据"></u-empty>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import { getDictByKey } from '@/api/common.js'
  62. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  63. import { getIntegralGoodsList } from '@/api/integral.js'
  64. import { getUserInfo } from '@/api/user'
  65. export default {
  66. mixins: [MescrollMixin],
  67. props:{
  68. i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
  69. index: { // 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
  70. type: Number,
  71. default(){
  72. return 0
  73. }
  74. },
  75. height: [Number,String] // mescroll的高度
  76. },
  77. data() {
  78. return {
  79. integral: 0,
  80. type: null,
  81. typeOptions: [],
  82. tabIndex: 0,
  83. tabs: [],
  84. mescroll: null,
  85. downOption: { //下拉刷新
  86. use: true,
  87. auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
  88. },
  89. upOption: {
  90. onScroll: false,
  91. use: true, // 是否启用上拉加载; 默认true
  92. page: {
  93. pae: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  94. size: 10 // 每页数据的数量,默认10
  95. },
  96. noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  97. textNoMore: "已经到底了",
  98. empty: {
  99. icon: 'https://cos.his.cdwjyyh.com/fs/20240423/cf4a86b913a04341bb44e34bb4d37aa2.png',
  100. tip: '暂无数据'
  101. }
  102. },
  103. dataList: [],
  104. total:0,
  105. pageNum: 1,
  106. pageSize: 10,
  107. keyword: "",
  108. }
  109. },
  110. mounted() {
  111. this.getDictByKey("sys_integral_goods_type");
  112. this.getUserInfo();
  113. this.refreshList()
  114. },
  115. methods: {
  116. initData() {
  117. this.getUserInfo();
  118. this.refreshList()
  119. },
  120. getUserInfo() {
  121. getUserInfo().then(
  122. res => {
  123. if (res.code == 200) {
  124. if (res.user != null) {
  125. this.integral = res.user.integral;
  126. }
  127. } else {
  128. uni.showToast({
  129. icon: 'none',
  130. title: "请求失败",
  131. });
  132. }
  133. },
  134. rej => {}
  135. );
  136. },
  137. navTo(url) {
  138. uni.navigateTo({
  139. url: url
  140. })
  141. },
  142. handleClear() {
  143. // 清除搜索关键词后刷新列表
  144. this.keyword = '';
  145. this.mescroll.resetUpScroll()
  146. },
  147. goCart() {
  148. if(this.$isLogin()){
  149. uni.navigateTo({
  150. url: '/pages/user/integral/cart'
  151. })
  152. } else {
  153. uni.navigateTo({
  154. url: '/pages/auth/loginIndex'
  155. })
  156. }
  157. },
  158. goIntegral() {
  159. let pages = getCurrentPages();
  160. let url = pages[pages.length - 2];
  161. if (pages.length > 1 && url && url.route == 'pages/user/integral/points') {
  162. uni.navigateBack()
  163. } else {
  164. uni.navigateTo({
  165. url: '/pages/user/integral/points'
  166. })
  167. }
  168. },
  169. getDictByKey(key) {
  170. var data = {
  171. key: key
  172. }
  173. var that = this;
  174. getDictByKey(data).then(
  175. res => {
  176. if (res.code == 200) {
  177. this.typeOptions = res.data;
  178. this.typeOptions.forEach(function(item, index) {
  179. var data = {
  180. name: item.dictLabel
  181. };
  182. that.tabs.push(data);
  183. })
  184. this.tabs.unshift({name: '全部'})
  185. if (this.tabs.length > 0) {
  186. this.tabIndex = 0
  187. }
  188. }
  189. },
  190. err => {}
  191. );
  192. },
  193. tabChange(item) {
  194. this.type = item.index == 0 ? null : this.typeOptions[item.index-1].dictValue;
  195. this.refreshList()
  196. },
  197. refreshList() {
  198. this.pageNum = 1
  199. this.isMore= true
  200. this.dataList = []
  201. this.getList()
  202. },
  203. // 滚动到底部
  204. scrolltolower() {
  205. if (this.isMore) {
  206. this.getList()
  207. }
  208. },
  209. getList() {
  210. //联网加载数据
  211. var that = this;
  212. var data = {
  213. pageNum: this.pageNum,
  214. pageSize: this.pageSize,
  215. keyword: this.keyword,
  216. };
  217. if (this.type != null) {
  218. data.goodsType = this.type
  219. }
  220. getIntegralGoodsList(data).then(res => {
  221. if (res.code == 200) {
  222. //设置列表数据
  223. let list = res.data.list && res.data.list.length > 0 ? res.data.list : []
  224. that.dataList = that.dataList.concat(list)
  225. that.total = res.data.total
  226. that.pageNum++
  227. if (that.dataList.length >= that.total) {
  228. that.isMore = false
  229. }
  230. } else {
  231. that.dataList = []
  232. }
  233. });
  234. }
  235. }
  236. }
  237. </script>
  238. <style scoped lang="scss">
  239. .top-box {
  240. padding: 0 30rpx 0 30rpx;
  241. width: 100%;
  242. .my-integral {
  243. height: 200rpx;
  244. box-shadow: 0px 0px 5px 2px rgba(0, 0, 0, 0.05);
  245. background: linear-gradient(#FF5030, #E2C99E);
  246. border-radius: 30rpx;
  247. display: flex;
  248. align-items: flex-start;
  249. justify-content: space-between;
  250. padding: 30rpx;
  251. .integralbtn {
  252. font-size: 30rpx;
  253. font-weight: bold;
  254. font-family: PingFang SC;
  255. color: #fff;
  256. margin-left: 16rpx;
  257. //text-decoration: underline;
  258. background-color: #F5533C;
  259. padding: 8rpx 15rpx;
  260. border-radius: 30rpx;
  261. }
  262. .btn {
  263. //margin-bottom: 30rpx;
  264. background-color: #fff;
  265. border-radius: 30rpx;
  266. display: flex;
  267. align-items: center;
  268. justify-content: center;
  269. padding: 10rpx 15rpx;
  270. font-size: 24upx;
  271. font-family: PingFang SC;
  272. color: #FF5030;
  273. }
  274. .left {
  275. height: 100%;
  276. display: flex;
  277. flex-direction: column;
  278. align-items: flex-start;
  279. justify-content: space-around;
  280. .label {
  281. font-size: 30upx;
  282. font-family: PingFang SC;
  283. color: #fff;
  284. }
  285. .integral {
  286. font-weight: bold;
  287. font-size: 40upx;
  288. font-family: PingFang SC;
  289. color: #fff;
  290. }
  291. }
  292. .btn-box {
  293. height: 100%;
  294. display: flex;
  295. flex-direction: column;
  296. align-items: flex-start;
  297. justify-content: space-around;
  298. }
  299. }
  300. .tabs {
  301. height: 88rpx;
  302. }
  303. }
  304. .integral-box {
  305. padding: 0 30rpx 30rpx 30rpx;
  306. display: flex;
  307. align-items: flex-start;
  308. justify-content: flex-start;
  309. flex-wrap: wrap;
  310. .item {
  311. box-shadow: 0px 0px 5px 2px rgba(0, 0, 0, 0.05);
  312. background-color: #fff;
  313. width: calc(50% - 20rpx);
  314. border-radius: 15rpx;
  315. margin: 10rpx;
  316. display: flex;
  317. flex-direction: column;
  318. align-items: flex-start;
  319. justify-content: flex-start;
  320. &:last-child {}
  321. .top {
  322. width: 100%;
  323. height: 300rpx;
  324. image {
  325. border-radius: 15rpx 15rpx 0rpx 0rpx;
  326. width: 100%;
  327. height: 300rpx;
  328. }
  329. }
  330. .bottom {
  331. width: 100%;
  332. padding: 15rpx;
  333. .title {
  334. font-weight: bold;
  335. font-size: 28upx;
  336. font-family: PingFang SC;
  337. color: #111111;
  338. }
  339. .price-box {
  340. margin-top: 10rpx;
  341. display: flex;
  342. align-items: center;
  343. justify-content: space-between;
  344. width: 100%;
  345. .price {
  346. padding: 5rpx 10rpx;
  347. background-color: #FF5030;
  348. border-radius: 30rpx;
  349. font-size: 20upx;
  350. font-family: PingFang SC;
  351. color: #ffffff;
  352. }
  353. .count {
  354. font-size: 24upx;
  355. font-family: PingFang SC;
  356. color: #333333;
  357. }
  358. }
  359. }
  360. }
  361. }
  362. .search-box {
  363. display: flex;
  364. align-items: center;
  365. justify-content: space-between;
  366. padding-top: 22rpx;
  367. .search {
  368. padding: 0;
  369. flex: 1;
  370. image {
  371. width: 28rpx;
  372. height: 28rpx;
  373. padding-left: 16rpx;
  374. }
  375. }
  376. }
  377. </style>