小程序端工程代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

294 lines
9.4 KiB

  1. <template>
  2. <view class="productList" ref="container">
  3. <form @submit.prevent="submitForm">
  4. <view class="search bg-color-red acea-row row-between-wrapper">
  5. <view class="input acea-row row-between-wrapper">
  6. <input placeholder="搜索商品信息" v-model="where.keyword" />
  7. <text class="iconfont icon-sousuo" @click="submitForm"></text>
  8. </view>
  9. <view class="iconfont" :class="Switch === true ? 'icon-pailie' : 'icon-tupianpailie'" @click="switchTap"></view>
  10. </view>
  11. </form>
  12. <view class="nav acea-row row-middle">
  13. <view class="item" :class="title ? 'font-color-red' : ''" @click="set_where(0)">{{ title ? title : '默认' }}</view>
  14. <view class="item" @click="set_where(1)">
  15. 价格
  16. <image :src="`${$VUE_APP_RESOURCES_URL}/images/horn.png`" v-if="price === 0" />
  17. <image :src="`${$VUE_APP_RESOURCES_URL}/images/up.png`" v-if="price === 1" />
  18. <image :src="`${$VUE_APP_RESOURCES_URL}/images/down.png`" v-if="price === 2" />
  19. </view>
  20. <view class="item" @click="set_where(2)">
  21. 销量
  22. <image :src="`${$VUE_APP_RESOURCES_URL}/images/horn.png`" v-if="stock === 0" />
  23. <image :src="`${$VUE_APP_RESOURCES_URL}/images/up.png`" v-if="stock === 1" />
  24. <image :src="`${$VUE_APP_RESOURCES_URL}/images/down.png`" v-if="stock === 2" />
  25. </view>
  26. <!-- down -->
  27. <view class="item" :class="nows ? 'font-color-red' : ''" @click="set_where(3)">新品</view>
  28. </view>
  29. <view class="list acea-row row-between-wrapper" :class="Switch === true ? '' : 'on'" ref="container" v-if="!isIntegral">
  30. <view @click="goGoodsCon(item)" class="item" :class="Switch === true ? '' : 'on'" v-for="(item, productListIndex) in productList" :key="productListIndex" :title="item.storeName">
  31. <view class="pictrue" :class="Switch === true ? '' : 'on'">
  32. <image :src="item.image" :class="Switch === true ? '' : 'on'" />
  33. </view>
  34. <view class="text" :class="Switch === true ? '' : 'on'">
  35. <view class="name line1">{{ item.storeName }}</view>
  36. <view class="money font-color-red" :class="Switch === true ? '' : 'on'">
  37. <text class="num">{{ item.price }}</text>
  38. </view>
  39. <view class="vip acea-row row-between-wrapper" :class="Switch === true ? '' : 'on'">
  40. <view class="vip-money">{{ item.otPrice }}</view>
  41. <view>已售{{ item.sales }}</view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="list acea-row row-between-wrapper" :class="Switch === true ? '' : 'on'" ref="container" v-if="isIntegral == 'true'">
  47. <view @click="goIntegralGoodsCon(item)" class="item" :class="Switch === true ? '' : 'on'" v-for="(item, productListIndex) in productList" :key="productListIndex" :title="item.storeName">
  48. <view class="pictrue" :class="Switch === true ? '' : 'on'">
  49. <image :src="item.image" :class="Switch === true ? '' : 'on'" />
  50. </view>
  51. <view class="text" :class="Switch === true ? '' : 'on'">
  52. <view class="name line1">{{ item.storeName }}</view>
  53. <view class="money font-color-red" :class="Switch === true ? '' : 'on'">
  54. <text class="num">{{ item.integral }}积分</text>
  55. </view>
  56. <view class="vip acea-row row-between-wrapper" :class="Switch === true ? '' : 'on'">
  57. <!-- <view class="vip-money">{{ item.otPrice }}</view> -->
  58. <view>已售{{ item.sales }}</view>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. <Loading :loaded="loadend" :loading="loading"></Loading>
  64. <view class="noCommodity" style="background-color: #fff" v-if="productList.length === 0 && where.page > 1">
  65. <view class="noPictrue">
  66. <image :src="`${$VUE_APP_RESOURCES_URL}/images/noGood.png`" class="image" />
  67. </view>
  68. </view>
  69. <Recommend v-if="productList.length === 0 && where.page > 1" :recommendLoading="recommendLoading" @changeRecommendLoading="changeRecommendLoading"></Recommend>
  70. </view>
  71. </template>
  72. <script>
  73. import Recommend from '@/components/Recommend'
  74. import { getProducts, getProductsIntegral } from '@/api/store'
  75. import Loading from '@/components/Loading'
  76. export default {
  77. name: 'GoodsList',
  78. components: {
  79. Recommend,
  80. Loading,
  81. },
  82. props: {},
  83. data: function() {
  84. const s = '',
  85. id = 0,
  86. title = ''
  87. return {
  88. hostProduct: [],
  89. productList: [],
  90. Switch: true,
  91. where: {
  92. page: 1,
  93. limit: 8,
  94. keyword: s,
  95. sid: id, //二级分类id
  96. news: 0,
  97. priceOrder: '',
  98. salesOrder: '',
  99. },
  100. title: title && id ? title : '',
  101. loadTitle: '',
  102. loading: false,
  103. loadend: false,
  104. price: 0,
  105. stock: 0,
  106. nows: false,
  107. recommendLoading: false,
  108. target: false,
  109. isIntegral: false
  110. }
  111. },
  112. watch: {
  113. title() {
  114. this.updateTitle()
  115. },
  116. isIntegral() {
  117. if (this.isIntegral) {
  118. uni.setNavigationBarTitle({
  119. title: '积分商品',
  120. })
  121. } else {
  122. uni.setNavigationBarTitle({
  123. title: '商品列表',
  124. })
  125. }
  126. },
  127. $yroute(to) {
  128. },
  129. },
  130. mounted: function() {
  131. const { s = '', id = 0, title = '', isIntegral = false } = this.$yroute.query
  132. this.where.keyword = s
  133. this.where.isIntegral = isIntegral == 'true' ? 1 : 0
  134. this.isIntegral = isIntegral
  135. this.updateTitle()
  136. this.getProductList()
  137. },
  138. onReachBottom() {
  139. this.recommendLoading = true
  140. !this.loading && this.getProductList()
  141. },
  142. onHide() {
  143. },
  144. methods: {
  145. changeRecommendLoading(recommendLoading) {
  146. this.recommendLoading = recommendLoading
  147. },
  148. goGoodsCon(item) {
  149. this.$yrouter.push({
  150. path: '/pages/shop/GoodsCon/index',
  151. query: {
  152. id: item.id,
  153. isIntegral: this.isIntegral,
  154. },
  155. })
  156. },
  157. goIntegralGoodsCon(item) {
  158. this.$yrouter.push({
  159. path: '/pages/shop/IntegralGoodsCon/index',
  160. query: {
  161. id: item.id,
  162. isIntegral: this.isIntegral,
  163. },
  164. })
  165. },
  166. updateTitle() {
  167. uni.setNavigationBarTitle({
  168. title: this.title,
  169. })
  170. },
  171. getProductList() {
  172. this.setWhere()
  173. const { s = '', id = 0, title = '' } = this.$yroute.query
  174. if (s !== this.where.keyword || id !== this.where.sid) {
  175. this.loadend = false
  176. this.loading = false
  177. this.where.page = 1
  178. this.where.sid = id
  179. this.title = title && id ? title : ''
  180. this.nows = false
  181. this.$set(this, 'productList', [])
  182. this.price = 0
  183. this.stock = 0
  184. // this.getProductList();
  185. }
  186. let q = this.where
  187. let getData = this.isIntegral !== 'true' ? getProducts : getProductsIntegral
  188. getData(q).then(res => {
  189. this.loading = false
  190. if (this.target) {
  191. this.productList = res.data
  192. this.target = false
  193. } else {
  194. this.productList.push.apply(this.productList, res.data)
  195. }
  196. console.log(this.target)
  197. this.loadend = res.data.length < this.where.limit //判断所有数据是否加载完成;
  198. this.where.page = this.where.page + 1
  199. })
  200. },
  201. submitForm: function() {
  202. this.$set(this, 'productList', [])
  203. this.where.page = 1
  204. this.loadend = false
  205. this.loading = false
  206. this.getProductList()
  207. },
  208. //点击事件处理
  209. set_where(index) {
  210. this.productList = []
  211. this.$set(this, 'productList', [])
  212. this.where.page = 1
  213. this.target = true
  214. this.loadend = false
  215. switch (index) {
  216. case 0:
  217. return this.$yrouter.push({
  218. path: '/pages/shop/GoodsClass/index',
  219. })
  220. case 1:
  221. if (this.price === 0) this.price = 1
  222. else if (this.price === 1) this.price = 2
  223. else if (this.price === 2) this.price = 0
  224. this.stock = 0
  225. break
  226. case 2:
  227. if (this.stock === 0) this.stock = 1
  228. else if (this.stock === 1) this.stock = 2
  229. else if (this.stock === 2) this.stock = 0
  230. this.price = 0
  231. break
  232. case 3:
  233. this.nows = !this.nows
  234. break
  235. default:
  236. break
  237. }
  238. // this.getProductList()
  239. this.setWhere()
  240. const { s = '', id = 0, title = '' } = this.$yroute.query
  241. if (s !== this.where.keyword || id !== this.where.sid) {
  242. this.loadend = false
  243. this.loading = false
  244. this.where.page = 1
  245. this.where.sid = id
  246. this.title = title && id ? title : ''
  247. this.nows = false
  248. this.$set(this, 'productList', [])
  249. this.price = 0
  250. this.stock = 0
  251. // this.getProductList();
  252. }
  253. let q = this.where
  254. let getData = this.isIntegral !== 'true' ? getProducts : getProductsIntegral
  255. getData(this.where).then(res => {
  256. this.loading = false
  257. this.productList = res.data
  258. })
  259. },
  260. //设置where条件
  261. setWhere() {
  262. if (this.price === 0) {
  263. this.where.priceOrder = ''
  264. } else if (this.price === 1) {
  265. this.where.priceOrder = 'asc'
  266. } else if (this.price === 2) {
  267. this.where.priceOrder = 'desc'
  268. }
  269. if (this.stock === 0) {
  270. this.where.salesOrder = ''
  271. } else if (this.stock === 1) {
  272. this.where.salesOrder = 'asc'
  273. } else if (this.stock === 2) {
  274. this.where.salesOrder = 'desc'
  275. }
  276. this.where.news = this.nows ? '1' : '0'
  277. },
  278. switchTap() {
  279. this.Switch = !this.Switch
  280. },
  281. },
  282. }
  283. </script>
  284. <style scoped lang="less">
  285. .noCommodity {
  286. border-top: 3px solid #f5f5f5;
  287. padding-bottom: 1px;
  288. }
  289. </style>