chainGoods.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <view class="content">
  3. <view class="content">
  4. <!-- 顶部搜索 -->
  5. <navigator url="/pages/chainGoods/search">
  6. <view class="input-box flex">
  7. <view class="input-content flex">
  8. <!-- <view class="iconfont iconsearch"></view> -->
  9. <image src="https://zhibo.liuniu946.com/img/search.png" mode=""></image>
  10. <view class="input"><input disabled placeholder="商品搜索" /></view>
  11. </view>
  12. </view>
  13. </navigator>
  14. <!-- 顶部导航 -->
  15. <scroll-view scroll-x="true" class="class-box flex" :scroll-left="scrollLeft" :scroll-with-animation="true">
  16. <view @click="tabtap(item,idx)" class="item" v-for="(item, idx) in tabTitle" :key="idx" >
  17. <view class="time" :class="{ action: idx == currentId }">{{ item.cate_name }}</view>
  18. </view>
  19. </scroll-view>
  20. </view>
  21. <swiper :current="currentId" class="list-Box" @change="swiperChange" duration="500">
  22. <swiper-item class="goodsList" v-for="(ls, idx) in tabTitle">
  23. <scroll-view scroll-y="true" class="list">
  24. <empty v-if="ls.dataList.length === 0"></empty>
  25. <view class="goods_item" v-for="(lss,ind) in ls.dataList" :key="ind" @click="navToDetailPage(lss)">
  26. <image :src="lss.image" mode=""></image>
  27. <view class="goods-details">
  28. <view class="title">
  29. {{ lss.store_name}}
  30. </view>
  31. <view class="price">
  32. <view class="purchasingPrice">
  33. <text class="tip">批发价</text>
  34. ¥{{ lss.wholesaler_price}}
  35. </view>
  36. <view class="sellingPrice">
  37. <text class="tip">售价</text>
  38. ¥{{lss.price}}
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </scroll-view>
  44. </swiper-item>
  45. </swiper>
  46. </view>
  47. </template>
  48. <script>
  49. import {
  50. getProducts
  51. } from '@/api/product.js';
  52. import {
  53. getList
  54. } from '@/api/category.js';
  55. import empty from '@/components/empty';
  56. export default {
  57. components: {
  58. empty
  59. },
  60. data() {
  61. return {
  62. page: 1,
  63. limit: 10,
  64. tabTitle: [], //导航栏格式
  65. loadingType: 'more', //加载更多状态
  66. currentId: 0, //一级选择id,
  67. actionClassInd: 0,
  68. }
  69. },
  70. computed: {
  71. // 计算左侧距离
  72. scrollLeft() {
  73. if (this.currentId > 1) {
  74. return this.itemWidht * (this.currentId - 1.5);
  75. } else {
  76. return 0;
  77. }
  78. }
  79. },
  80. onLoad() {
  81. this.loadData()
  82. },
  83. methods: {
  84. //头部导航栏点击事件
  85. tabtap(item,index) {
  86. this.currentId = index;
  87. this.actionClassInd = index
  88. let ls = this.tabTitle[this.actionClassInd];
  89. // 判断当前数据是否已经加载完毕
  90. if (ls.loadingType == 'more') {
  91. this.getDataList(ls);
  92. }
  93. },
  94. swiperChange(e) {
  95. this.currentId = e.target.current;
  96. this.getDataList(this.tabTitle[this.currentId], 'tabChange');
  97. },
  98. // 获取页面数据
  99. async loadData(type = 'add',loading) {
  100. let obj = this;
  101. let data = {
  102. page: obj.page,
  103. limit: obj.limit
  104. };
  105. //没有更多直接返回
  106. if (type === 'add') {
  107. if (obj.loadingType === 'nomore') {
  108. return;
  109. }
  110. obj.loadingType = 'loading';
  111. } else {
  112. obj.loadingType = 'more';
  113. }
  114. if (type === 'refresh') {
  115. // 清空数组
  116. obj.page = 1;
  117. }
  118. getList({})
  119. .then(({ data }) => {
  120. console.log('------',data);
  121. obj.tabTitle = data.map(e => {
  122. e.dataList = [];
  123. e.loadingType = 'more';
  124. e.page = 1;
  125. e.limit = 10;
  126. return e;
  127. });
  128. obj.currentId = 0;
  129. obj.getDataList(obj.tabTitle[0]);
  130. if (obj.tabTitle.length <= 4) {
  131. // 当数量小于等于4的时候自适应宽度
  132. obj.topNavWidth = 100 / obj.tabTitle.length + '%';
  133. } else {
  134. // 页面渲染完毕后加载scroll-view左侧距离
  135. obj.$nextTick(() => {
  136. obj.numClassWidht();
  137. });
  138. }
  139. })
  140. .catch(err => {
  141. console.log(err);
  142. })
  143. },
  144. // 跳转普通商品
  145. navToDetailPage(item) {
  146. console.log('-----item',item)
  147. uni.navigateTo({
  148. url: '/pages/product/product?id=' + item.id + '&wholesale=' + 1
  149. })
  150. },
  151. getDataList(item, type = 'add') {
  152. console.log('1997',item);
  153. const obj = this;
  154. const requestData = {
  155. page: item.page,
  156. limit: item.limit,
  157. cid: item.id,
  158. is_wholesale: 1,
  159. };
  160. // 判断数据是否加载中
  161. if (item.loadingType == 'nomore' || item.loadingType == 'loading') {
  162. return;
  163. }
  164. // 判断是否重新加载数据
  165. if(type=='refresh'){
  166. item.dataList=[];
  167. }
  168. // 设置数据加载中
  169. item.loadingType = 'loading';
  170. return new Promise((ok, erro) => {
  171. getProducts(requestData)
  172. .then(({ data }) => {
  173. data.forEach((sj,index) => {
  174. item.dataList.push(sj);
  175. })
  176. if (item.limit == data.length) {
  177. item.page++;
  178. item.loadingType = 'more';
  179. } else {
  180. item.loadingType = 'nomore';
  181. }
  182. if (type === 'refresh') {
  183. if (loading == 1) {
  184. uni.hideLoading();
  185. } else {
  186. uni.stopPullDownRefresh();
  187. }
  188. }
  189. })
  190. .catch(err => {
  191. console.log(err);
  192. });
  193. });
  194. },
  195. numClassWidht() {
  196. uni.createSelectorQuery()
  197. .select('.content')
  198. .fields(
  199. {
  200. size: true
  201. },
  202. data => {
  203. // 设置项目宽度
  204. // console.log(data);
  205. this.itemWidht = Math.floor((data.width / 750) * 187.5);
  206. }
  207. )
  208. .exec();
  209. },
  210. }
  211. }
  212. </script>
  213. <style lang="scss">
  214. page{
  215. height: 100%;
  216. margin: 0;
  217. padding: 0;
  218. }
  219. .input-box {
  220. padding: 25rpx;
  221. background-color: #FE3D3D;
  222. height: 88rpx;
  223. margin-top: -1px;
  224. .iconsearch {
  225. font-size: 50rpx;
  226. }
  227. .input-content {
  228. border-radius: 99rpx;
  229. flex-grow: 1;
  230. padding: 4rpx 30rpx;
  231. background: #FFFFFF;
  232. image {
  233. width: 32rpx;
  234. height: 32rpx;
  235. margin: 14rpx 0;
  236. }
  237. .input {
  238. flex-grow: 1;
  239. color: #FF9090;
  240. input {
  241. font-size: 30rpx;
  242. color: #FF9090;
  243. }
  244. .input-placeholder {
  245. // height: 70rpx;
  246. color: #FF9090;
  247. margin-left: 14rpx;
  248. }
  249. }
  250. }
  251. .input-button {
  252. padding-left: 20rpx;
  253. font-size: $font-base;
  254. height: 100%;
  255. }
  256. }
  257. .list-Box {
  258. height: calc(100vh - 136px);
  259. // height: 1027rpx;
  260. .list {
  261. height: 100%;
  262. }
  263. }
  264. .class-box {
  265. background: #FFFFFF;
  266. white-space: nowrap;
  267. height: 78rpx;
  268. .item {
  269. text-align: center;
  270. display: inline-block;
  271. color: $font-color-base;
  272. margin: 26rpx 34rpx 15rpx 29rpx;
  273. background-color: #ffffff;
  274. line-height: 1;
  275. .time {
  276. font-family: PingFang SC;
  277. font-weight: bold;
  278. font-size: 30rpx;
  279. padding-bottom: 19rpx;
  280. &.action {
  281. color: $color-red;
  282. border-bottom: 4rpx solid #FF0000;
  283. }
  284. }
  285. }
  286. }
  287. .goodsList {
  288. margin-top: 22rpx;
  289. width: 100%;
  290. background-color: #FFFFFF;
  291. padding: 0 24rpx;
  292. .goods_item:nth-last-child(1){
  293. border-bottom: none;
  294. }
  295. .goods_item {
  296. display: flex;
  297. align-items: center;
  298. padding: 24rpx 0;
  299. border-bottom: 1rpx solid #F0f0f0;
  300. image {
  301. flex-shrink: 0;
  302. width: 146rpx;
  303. height: 146rpx;
  304. border-radius: 8rpx;
  305. }
  306. .goods-details {
  307. width: 100%;
  308. margin-left: 24rpx;
  309. display: flex;
  310. flex-direction: column;
  311. .title {
  312. color: #333;
  313. font-size: 32rpx;
  314. word-break: break-all;
  315. display: -webkit-box;
  316. -webkit-line-clamp: 1;
  317. -webkit-box-orient: vertical;
  318. overflow: hidden;
  319. }
  320. .price {
  321. margin-top: 48rpx;
  322. display: flex;
  323. justify-content: space-between;
  324. color: #ff0000;
  325. font-size: 34rpx;
  326. .purchasingPrice {
  327. }
  328. .sellingPrice {
  329. margin-right: 44rpx;
  330. }
  331. .tip {
  332. margin-bottom: 18rpx;
  333. margin-right: 6rpx;
  334. color: #999999;
  335. font-size: 24rpx;
  336. }
  337. }
  338. }
  339. }
  340. }
  341. </style>