goods-list.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <template>
  2. <view :class="!empty ? 'padding-top-big' : '' ">
  3. <!-- 空白页 -->
  4. <use-empty v-if="empty" e-style="round" e-type="search" tip="搜索数据为空" btn-tip="重新搜索" height="70vh" :auto="false"
  5. @goto="tosearch"></use-empty>
  6. <!-- 列表区 -->
  7. <view v-else>
  8. <!-- 筛选区 -->
  9. <view class="navbar pos-f w-full dflex bg-main" :style="{ position: headerPosition }">
  10. <view class="nav-item dflex-c flex1 pos-r h-full" :class="{active: filterIndex === 0}"
  11. @click="navbarClick(0)">
  12. 综合排序
  13. </view>
  14. <!-- <view class="nav-item dflex-c flex1 pos-r h-full" :class="{active: filterIndex === 1}"
  15. @click="navbarClick(1)">
  16. 销量优先
  17. </view> -->
  18. <view class="nav-item dflex-c flex1 pos-r h-full" :class="{active: filterIndex === 2}"
  19. @click="navbarClick(2)">
  20. <text>价格</text>
  21. <view class="">
  22. <view class="iconfont iconjiantou02 ft-dark dflex-c"
  23. :class="{active: priceOrder === 1 && filterIndex === 2}"></view>
  24. <view class="iconfont iconjiantou ft-dark dflex-c"
  25. :class="{active: priceOrder === 2 && filterIndex === 2}"></view>
  26. </view>
  27. </view>
  28. </view>
  29. <!-- 商品列表区 -->
  30. <view class="goods-list">
  31. <view class="list dflex-b dflex dflex-wrap-w w-full" style="padding-top: 60px;">
  32. <view class="item bg-main border-radius-sm padding-bottom-sm" v-for="(item, index) in goodsDatas"
  33. :key="index" @click="togoods(item)">
  34. <view class="image-wrapper">
  35. <image mode="aspectFill" :lazy-load="true" v-if="((item.imgs).indexOf(',')) != -1"
  36. :src="((item.imgs).substring(0, ((item.imgs).indexOf(','))))"></image>
  37. <image mode="aspectFill" :lazy-load="true" v-else
  38. :src="item.imgs"></image>
  39. </view>
  40. <text class="title clamp padding-sm">{{ item.name }}</text>
  41. <view class="padding-left-sm dflex-b">
  42. <text class="price">{{ item.price }}</text>
  43. <text class="ft-dark margin-right-sm fs-xs">
  44. <template v-if="item.state=='1'">已售 {{item.saleCnt }}</template>
  45. <template v-if="item.state=='0'">已下架</template>
  46. <template v-if="item.state=='2'">审核中</template>
  47. </text>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- 上拉加载更多 -->
  53. <!-- <use-loadmore :type="loadmoreType"></use-loadmore> -->
  54. </view>
  55. <!-- 置顶 -->
  56. <use-totop ref="usetop"></use-totop>
  57. <!-- 03. 猜你想要 -->
  58. <use-hot-goods v-if="empty" title-type="round" title="猜你想要"></use-hot-goods>
  59. </view>
  60. </template>
  61. <script>
  62. import {
  63. searchadd
  64. } from '../../utils/api_goods.js'
  65. import {
  66. goodslistlimit
  67. } from '../../utils/api_home.js'
  68. import useEmpty from '../../components/use-empty/use-empty.vue'
  69. import useTotop from '../../components/use-totop/use-totop.vue'
  70. import useHotGoods from '../../components/use-hot-goods/use-hot-goods.vue'
  71. export default {
  72. components:{
  73. useEmpty,
  74. useTotop,
  75. useHotGoods
  76. },
  77. data() {
  78. return {
  79. empty: false,
  80. headerPosition: "fixed",
  81. // 0综合排序 1销量优先 2价格排序
  82. filterIndex: 0,
  83. // 1价格从低到高 2价格从高到低
  84. priceOrder: 0,
  85. // 商品数据
  86. goodsDatas: [],
  87. // 加载更多状态
  88. loadmoreType: 'more',
  89. // 请求数据
  90. reqdata: {
  91. page: 1,
  92. rows: 8,
  93. sidx: 'sort',
  94. sord: 'asc'
  95. },
  96. scrollTop: 0,
  97. pan:0,//0是搜索,1是热门,2是限时
  98. leiId:'',//类别id
  99. leiLevel:'',//类别level
  100. keyword:'',//关键字
  101. now_date:'',//当前时间
  102. };
  103. },
  104. watch: {
  105. // 显示空白页
  106. goodsDatas(e) {
  107. let empty = e.length === 0;
  108. if (this.empty !== empty) {
  109. this.empty = empty;
  110. }
  111. }
  112. },
  113. onPageScroll(e) {
  114. // 兼容iOS端下拉时顶部漂移
  115. if (e.scrollTop >= 0) {
  116. this.headerPosition = "fixed";
  117. } else {
  118. this.headerPosition = "absolute";
  119. }
  120. // this.scrollTop = e.scrollTop
  121. this.$refs.usetop.change(e.scrollTop);
  122. },
  123. //下拉刷新
  124. onPullDownRefresh() {
  125. this.loadData('refresh');
  126. },
  127. //加载更多
  128. onReachBottom() {
  129. this.loadData();
  130. },
  131. onLoad(options) {
  132. this.getNowDate()
  133. var userId=options.userId || ''
  134. var searchCnt=options.searchCnt || 1
  135. var createBy=options.createBy || ''
  136. var createTime=decodeURIComponent(options.createTime) || this.now_date
  137. this.leiId=options.cid || ''
  138. this.leiLevel=options.level || ''
  139. this.keyword=decodeURIComponent(options.keyword) || ''
  140. let title = '搜索列表';
  141. if (options && options.hot) {
  142. title = '热门推荐';
  143. this.pan=1
  144. } else if (options && options.limited) {
  145. title = '限时精选';
  146. this.pan=2
  147. }
  148. uni.setNavigationBarTitle({
  149. title: title
  150. })
  151. for (let key in options) {
  152. this.reqdata[key] = decodeURIComponent(options[key]);
  153. }
  154. var data={
  155. "id": 0,
  156. "userId": '',
  157. "keyword": this.keyword,
  158. "searchCnt": searchCnt,
  159. "createBy": createBy,
  160. "createTime": this.now_date,
  161. "updateTime": this.now_date,
  162. "updateBy": ""
  163. }
  164. var headers={
  165. 'Content-Type': 'application/json; charset=utf-8',
  166. }
  167. //新增历史搜索
  168. searchadd(data,headers).then((res) => {
  169. if(res.success){
  170. }
  171. })
  172. this.loadData();
  173. },
  174. methods: {
  175. //获取当前时间
  176. getNowDate() {
  177. var _this = this;
  178. // this.timer = setInterval(function() {
  179. var aData = new Date();
  180. var month = aData.getMonth() < 9 ? "0" + (aData.getMonth() + 1) : aData.getMonth() + 1;
  181. var date = aData.getDate() <= 9 ? "0" + aData.getDate() : aData.getDate();
  182. var date2 = aData.getDate() <= 9 ? "0" + (aData.getDate()-1) : (aData.getDate()-1);
  183. var Hour = aData.getHours() <= 9 ? "0" + (aData.getHours()) : aData.getHours();
  184. var Miunte = aData.getMinutes() <= 9 ? "0" + (aData.getMinutes()) : aData.getMinutes();
  185. var Seconds = aData.getSeconds() <= 9 ? "0" + (aData.getSeconds()) : aData.getSeconds();
  186. // console.log(aData.getTime())
  187. _this.now_date = aData.getFullYear() + "-" + month + "-" + date + ' '+ Hour +":"+ Miunte +":"+ Seconds;
  188. // console.log(aData.getFullYear() + "-" + month + "-" + date2)昨天
  189. // }, 86400000);
  190. },
  191. // 加载商品,下拉刷新|上拉加载
  192. loadData(type = 'add', loading) {
  193. if (this.loadmoreType === 'loading') {
  194. // 防止重复加载
  195. return;
  196. }
  197. if (loading == 1 || type == 'refresh') {
  198. // 从首页开始加载
  199. this.reqdata.page = 1;
  200. }
  201. // 没有更多直接返回
  202. if (type === 'add') {
  203. if (this.loadmoreType === 'nomore') {
  204. return;
  205. }
  206. // 加载中
  207. // this.loadmoreType = 'loading';
  208. } else {
  209. // 更多
  210. this.loadmoreType = 'more'
  211. }
  212. if (this.pan==2){
  213. //限时精选
  214. let _self = this;
  215. _self.goodsDatas=[]
  216. var data='?limited=1&state=1&orderField='+_self.reqdata.sidx+'&order='+_self.reqdata.sord
  217. goodslistlimit(data).then((res) => {
  218. if (res.success) {
  219. var total=res.data.totalCount
  220. data='?limited=1&state=1&pageSize='+total+'&curPage='+_self.reqdata.page+'&orderField='+_self.reqdata.sidx+'&order='+_self.reqdata.sord
  221. goodslistlimit(data).then((res) => {
  222. if (res.success) {
  223. res.data.list.forEach(data => {
  224. _self.goodsDatas.push(data)
  225. })
  226. }else{
  227. _self.$message.warning('没有符合条件的数据!')
  228. }
  229. })
  230. }
  231. })
  232. }else if (this.pan==1){
  233. let _self = this;
  234. _self.goodsDatas=[]
  235. var data='?hot=1'+'&state=1&orderField='+_self.reqdata.sidx+'&order='+_self.reqdata.sord
  236. // 热门推荐
  237. goodslistlimit(data).then((res) => {
  238. if (res.success) {
  239. var total=res.data.totalCount
  240. data='?hot=1&state=1&pageSize='+total+'&curPage='+_self.reqdata.page+'&orderField='+_self.reqdata.sidx+'&order='+_self.reqdata.sord
  241. goodslistlimit(data).then((res) => {
  242. if (res.success) {
  243. res.data.list.forEach(data => {
  244. _self.goodsDatas.push(data)
  245. })
  246. }else{
  247. _self.$message.warning('没有符合条件的数据!')
  248. }
  249. })
  250. }
  251. })
  252. }else{
  253. let _self = this;
  254. //根据类别
  255. var data='?categoryId='+_self.leiId+'&state=1&categoryLevel='+_self.leiLevel
  256. +'&curPage='+_self.reqdata.page+'&pageSize='+_self.reqdata.rows
  257. +'&orderField='+_self.reqdata.sidx+'&order='+_self.reqdata.sord
  258. goodslistlimit(data).then((res) => {
  259. if (res.success) {
  260. if (res.data) {
  261. if (loading == 1 || type == 'refresh') {
  262. _self.goodsDatas = [];
  263. }
  264. let _datas = [];
  265. res.data.list.forEach((row) => {
  266. if(row.state === '1'){
  267. _datas.push(row);
  268. }
  269. });
  270. _self.goodsDatas = [..._self.goodsDatas, ..._datas];
  271. if (res.data.list.length >= _self.reqdata.rows) {
  272. _self.reqdata.page++;
  273. _self.loadmoreType = 'more'
  274. } else {
  275. _self.loadmoreType = 'nomore'
  276. }
  277. } else {
  278. _self.loadmoreType = 'nomore'
  279. }
  280. }
  281. if (_self.goodsDatas.length === 0) {
  282. _self.empty = true;
  283. }
  284. if (loading == 1) {
  285. uni.hideLoading()
  286. } else if (type == 'refresh') {
  287. uni.stopPullDownRefresh();
  288. }
  289. })
  290. }
  291. },
  292. // 点击筛选
  293. navbarClick(index) {
  294. //
  295. if (this.filterIndex === index && index !== 2) {
  296. return;
  297. }
  298. this.filterIndex = index;
  299. if (index === 2) {
  300. this.priceOrder = this.priceOrder === 1 ? 2 : 1;
  301. } else {
  302. this.priceOrder = 0;
  303. }
  304. if (this.filterIndex == 0) {
  305. // 综合排序
  306. this.reqdata.sidx = 'sort';
  307. this.reqdata.sord = 'asc';
  308. } else if (this.filterIndex == 1) {
  309. // 销量优先
  310. this.reqdata.sidx = 'saleCnt';
  311. this.reqdata.sord = 'desc';
  312. } else if (this.filterIndex == 2) {
  313. // 价格排序
  314. this.reqdata.sidx = 'price';
  315. if (this.priceOrder == 1) {
  316. // 降序
  317. this.reqdata.sord = 'desc';
  318. } else if (this.priceOrder == 2) {
  319. // 升序
  320. this.reqdata.sord = 'asc';
  321. }
  322. }
  323. uni.pageScrollTo({
  324. duration: 300,
  325. scrollTop: 0
  326. })
  327. this.loadData('refresh', 1);
  328. uni.showLoading({
  329. title: '正在加载'
  330. })
  331. },
  332. // 搜索页
  333. tosearch() {
  334. if (this.$api.pages().length > 1) {
  335. uni.navigateBack();
  336. return;
  337. }
  338. this.$api.tosearch();
  339. },
  340. // 商品详情
  341. togoods(options) {
  342. this.$api.togoods({
  343. id: options.id
  344. });
  345. }
  346. },
  347. }
  348. </script>
  349. <style lang="scss">
  350. @import url('/packageShang/components/iconfont/iconfont.css');
  351. @import url('/packageShang/common/common.scss');
  352. page {
  353. background-color: $page-color-base;
  354. }
  355. .navbar {
  356. top: var(--window-top);
  357. left: 0;
  358. height: 100rpx;
  359. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, .06);
  360. z-index: 10;
  361. .nav-item {
  362. font-size: 30rpx;
  363. &.active {
  364. &:after {
  365. content: '';
  366. position: absolute;
  367. left: 50%;
  368. bottom: 0;
  369. transform: translateX(-50%);
  370. width: 120rpx;
  371. height: 0;
  372. border-bottom: 4rpx solid $base-color;
  373. }
  374. }
  375. }
  376. .iconfont {
  377. width: 30rpx;
  378. height: 14rpx;
  379. font-size: 20rpx;
  380. line-height: 1;
  381. margin-left: 4rpx;
  382. }
  383. }
  384. .goods-list {
  385. .list {
  386. padding: 0 3vw 20rpx;
  387. }
  388. .item {
  389. width: 46vw;
  390. overflow: hidden;
  391. margin-top: 2vw;
  392. &:nth-child(2n) {
  393. margin-left: 1vw;
  394. }
  395. &:nth-child(2n + 1) {
  396. margin-right: 1vw;
  397. }
  398. }
  399. .image-wrapper {
  400. width: 100%;
  401. height: 300rpx;
  402. overflow: hidden;
  403. image {
  404. width: 100%;
  405. height: 100%;
  406. opacity: 1;
  407. }
  408. }
  409. }
  410. </style>