commodity.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <view>
  3. <view class="searchBox" style="margin-top: 10rpx;">
  4. <view class="search" style="margin-top: 10rpx;background: #F6F6F6;width: 630rpx;">
  5. <u-search bgColor='#F6F6F6' placeholder="请输入关键词"
  6. :showAction='false' @custom="searchList" v-model="searchword"></u-search>
  7. <view @click="searchList" class="searchBtn">搜索</view>
  8. </view>
  9. <!-- <view class="search">
  10. <u-search placeholder="请输入关键词" @custom="searchList" v-model="searchword"></u-search>
  11. </view> -->
  12. <view @click="changeMode">
  13. <u--image width="48rpx" height="48rpx" :src="Modeimg" ></u--image>
  14. </view>
  15. </view>
  16. <view style="font-size: 32rpx;" class="flex flexfend">
  17. <view @click="checkType('1')" :class="ischeck=='1'?'check':''">
  18. 综合
  19. </view>
  20. <view class="flex" style="align-items: center;" @click="checkType('2')" :class="ischeck=='2'?'check':''">
  21. 价格 <view>
  22. <u-icon name="arrow-up-fill" :color="checkup?'#46A6FF':'#ccc'" size="8"></u-icon>
  23. <u-icon name="arrow-down-fill" :color="!checkup?'#46A6FF':'#ccc'" size="8"></u-icon>
  24. </view>
  25. </view>
  26. <view @click="checkType('3')" :class="ischeck=='3'?'check':''">
  27. 销量
  28. </view>
  29. <view @click="openTabs()" class="selectTypebox">
  30. {{selectType}}<u--image style="margin-top: 10rpx;" width="40rpx" height="40rpx" src="/static/market/btn_screening.png" ></u--image>
  31. </view>
  32. </view>
  33. <u-popup :closeable='true' :round="10" :show="showTabs" @close="close" @open="open">
  34. <view class="popupView">
  35. <view class="scrollview">
  36. <!-- <tabsColumn :tabsItem="tabsItem" :tabsList="tabsList" :openType="current"></tabsColumn> -->
  37. <view class="btnList" >
  38. <view @click="changeType(index)"
  39. :class="item.plain ?'btnview': 'checkbtnview'"
  40. v-for="(item,index) in tabsList" :key="index">
  41. {{ item.name }}
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </u-popup>
  47. <rowList v-if="showRow" :listdata="newsList" ></rowList>
  48. <columnList v-else :listdata="newsList" ></columnList>
  49. <view class="loadmore" @click="loadmore()" >
  50. {{jiazaitext}}
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import rowList from '@/pages/market/base/rowList.vue' //左右布局
  56. import columnList from '@/pages/market/base/columnList.vue' //竖排列表
  57. import tabsColumn from '@/pages/home/base/tabs-column.vue'
  58. import {productPage,categoriesList} from '@/http/api/common.js'
  59. export default {
  60. components: {
  61. rowList,
  62. columnList,
  63. tabsColumn
  64. },
  65. data() {
  66. return {
  67. current:'commodity',
  68. showRow:true,
  69. checkup:true,
  70. showTabs:false,
  71. loadingType:false,
  72. ischeck:'1',
  73. searchword:'',
  74. selectType:'筛选',
  75. Modeimg:'/static/market/btn_chanpxx.png',
  76. newsList:[],
  77. tabsList:[],
  78. tabsItem:[],
  79. pageNum:1,
  80. jiazaitext:'加载更多',
  81. categoryId:'',
  82. }
  83. },
  84. async onLoad() {
  85. // 获取商品分类
  86. await this.getcategoriesList()
  87. },
  88. async onShow(){
  89. let categoryId = uni.getStorageSync('categoryId')
  90. let columnIdName = uni.getStorageSync('columnIdName')
  91. if (categoryId) {
  92. this.selectType = columnIdName
  93. this.categoryId = categoryId
  94. this.tabsList.forEach(item => {
  95. if (item.id == this.categoryId) {
  96. item.plain = false
  97. }else{
  98. item.plain = true
  99. }
  100. });
  101. //获取商品列表
  102. //每次切换页签初始化请求页签
  103. this.pageNum = 1
  104. this.newsList = []
  105. await this.getProductPage()
  106. uni.setStorageSync('categoryId', '')
  107. uni.setStorageSync('columnIdName', '')
  108. }else{
  109. //每次切换页签初始化请求页签
  110. this.pageNum = 1
  111. this.newsList = []
  112. //获取商品列表
  113. await this.getProductPage()
  114. }
  115. },
  116. onReachBottom() {
  117. this.loadmore()
  118. },
  119. methods: {
  120. async getProductPage(categoryId=''){
  121. if (this.loadingType) {
  122. //加载中禁止重复加载
  123. return
  124. }
  125. this.loadingType=true
  126. let data = {
  127. priceAsc:false, //价格正序排序
  128. priceDesc:false, //价格倒序排序
  129. salesVolumeDesc:false, //销量倒序排序
  130. keyword:this.searchword, //标题,副标题搜索
  131. pageSize:10,
  132. pageNum:this.pageNum,
  133. categoryId:this.categoryId //类目id
  134. }
  135. if (this.ischeck == '1') {
  136. //综合
  137. data.priceAsc = false
  138. data.priceDesc = false
  139. data.salesVolumeDesc = false
  140. }else if (this.ischeck == '2') {
  141. //价格
  142. data.priceAsc = this.checkup
  143. data.priceDesc = !this.checkup
  144. data.salesVolumeDesc = false
  145. } else {
  146. //销量
  147. data.priceAsc = false
  148. data.priceDesc = false
  149. data.salesVolumeDesc = true
  150. }
  151. let res = await productPage(data)
  152. if (res.data.code == 200) {
  153. let newrows = res.data.data?.rows || []
  154. this.newsList.push(...newrows)
  155. if(this.newsList.length!=res.data.data.total){
  156. this.jiazaitext="加载更多"
  157. }else{
  158. this.jiazaitext="已经到底"
  159. }
  160. }
  161. this.loadingType=false
  162. },
  163. async searchList(){
  164. // if (this.searchword == '') {
  165. // return
  166. // }
  167. //每次切换页签初始化请求页签
  168. this.pageNum = 1
  169. this.newsList = []
  170. await this.getProductPage()
  171. },
  172. //加载更多
  173. loadmore(){
  174. console.log('下拉加载',this.jiazaitext);
  175. if (this.jiazaitext=="加载更多") {
  176. this.pageNum=this.pageNum+1
  177. this.jiazaitext="加载中..."
  178. this.getProductPage()
  179. }
  180. },
  181. async getcategoriesList(){
  182. //获取商品分类
  183. let res = await categoriesList()
  184. if (res.data.code == 200) {
  185. let list = res.data.data.map(v=>{
  186. return {
  187. ...v,
  188. plain:true
  189. }
  190. })
  191. let a = {
  192. name:'全部',
  193. plain:false
  194. }
  195. this.tabsList.push(a)
  196. this.tabsList.push(...list)
  197. }
  198. },
  199. async openTabs(){
  200. this.showTabs = true
  201. },
  202. changeType(index) {
  203. //选择商品类目
  204. this.tabsList.forEach(item => {
  205. item.plain = true
  206. });
  207. this.tabsList[index].plain = false
  208. this.selectType = this.tabsList[index].name
  209. //每次切换页签初始化请求页签
  210. this.pageNum = 1
  211. this.newsList = []
  212. this.categoryId = this.tabsList[index].id
  213. this.getProductPage()
  214. this.showTabs = false
  215. },
  216. checkType(type){
  217. //选择列表排序类型
  218. this.ischeck = type
  219. if (this.ischeck == '2' && this.ischeck == type) {
  220. this.checkup = !this.checkup
  221. }
  222. //每次切换页签初始化请求页签
  223. this.pageNum = 1
  224. this.newsList = []
  225. this.getProductPage()
  226. },
  227. changeMode(){
  228. this.showRow = !this.showRow
  229. this.Modeimg = this.showRow ? '/static/market/btn_chanpfl.png' : '/static/market/btn_chanpxx.png'
  230. },
  231. open() {
  232. // console.log('open');
  233. },
  234. close() {
  235. this.showTabs = false
  236. // console.log('close');
  237. },
  238. }
  239. }
  240. </script>
  241. <style>
  242. .check{
  243. color: #46A6FF;
  244. }
  245. .searchBox{
  246. width: 750rpx;
  247. height: 126rpx;
  248. background: #FFFFFF;
  249. border-radius: 0rpx 0rpx 0rpx 0rpx;
  250. opacity: 1;
  251. display: flex;
  252. align-items: center;
  253. justify-content: space-around;
  254. }
  255. .scrollview{
  256. width: 750rpx;
  257. height: 850rpx;
  258. overflow: auto;
  259. }
  260. .loadmore{
  261. height:200rpx;
  262. text-align: center;
  263. font-size: 28rpx;
  264. font-weight: 400;
  265. color: #999;
  266. padding-top: 24rpx;
  267. }
  268. .btnList{
  269. display: flex;
  270. flex-direction: row;
  271. flex-wrap: wrap;
  272. justify-content: flex-start;
  273. }
  274. .checkbtnview{
  275. width: 206rpx;
  276. height: 80rpx;
  277. background: #46A6FF;
  278. border-radius: 40rpx 40rpx 40rpx 40rpx;
  279. opacity: 1;
  280. font-size: 28rpx;
  281. font-weight: 400;
  282. color: #FFFFFF;
  283. line-height: 80rpx;
  284. text-align: center;
  285. margin: 20rpx;
  286. }
  287. .btnview{
  288. width: 206rpx;
  289. height: 80rpx;
  290. background: #F1F1F1;
  291. border-radius: 40rpx 40rpx 40rpx 40rpx;
  292. opacity: 1;
  293. font-size: 28rpx;
  294. font-weight: 400;
  295. color: #666;
  296. line-height: 80rpx;
  297. text-align: center;
  298. margin: 20rpx;
  299. }
  300. .selectTypebox{
  301. display: flex;
  302. width: 200rpx;
  303. align-items: flex-end;
  304. justify-content: space-evenly;
  305. border-left: 1rpx solid #ccc;
  306. height: 40rpx;
  307. }
  308. </style>