goodslist.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <view :class="[AppTheme]" class="box">
  3. <view class="search">
  4. <view class="usearch">
  5. <u-search v-model="keyword" @search="search" @custom="search"></u-search>
  6. </view>
  7. </view>
  8. <view class="tag" v-if='tag&&tag.length>0'>
  9. <u-tabs :list="tag" :activeStyle="{color:primary}" :lineColor="primary" lineWidth="30" :scrollable="true"
  10. :current="current" @change="change"></u-tabs>
  11. </view>
  12. <view class="NewProducts">
  13. <p class="subtitle text-primary">
  14. 商品列表
  15. <view class="before bg-primary"></view>
  16. <view class="after bg-primary"></view>
  17. </p>
  18. <view class="content">
  19. <view class="guess-section" v-if="shopList&&shopList.length > 0">
  20. <view class="content_box" v-for="item in shopList" :key="item.id" @click="navToDetailPage(item)">
  21. <u--image :src=" item.pic" radius="10rpx" width="355rpx" height="340rpx" :lazy-load="true"
  22. :fade="true" duration="450">
  23. <template v-slot:loading>
  24. <u-loading-icon color="red"></u-loading-icon>
  25. </template>
  26. </u--image>
  27. <view class="message">
  28. <p class="tltile">{{ item.name }}</p>
  29. <view class="message_bot">
  30. <view class="f_left">
  31. <p class="color_org text-neutral">{{ item.price }}元/{{ item.unit }}</p>
  32. <p class="old_price">原价:{{ item.oprice }}元</p>
  33. </view>
  34. <view class="f_right" @click.stop="navToDetailPage(item.id)">
  35. <u-icon size="40" :color="primary" name="shopping-cart-fill"></u-icon>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. <u-empty marginTop="100" style="height: 0% !important;width: 100vw;" v-if="shopList&&shopList.length==0"
  42. text="暂无更多数据" mode="list"></u-empty>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <!-- 商城 -->
  48. <script>
  49. import api from '@/api/mall/index.js';
  50. export default {
  51. data() {
  52. return {
  53. primary: this.$theme.primary,
  54. carouselList: [{
  55. src: 'http://www.zzfcd.com/images/Upload/201507101533569.jpg'
  56. }, {
  57. src: 'http://www.zzfcd.com/images/Upload/201507101533569.jpg'
  58. }],
  59. shopList: null,
  60. settingFile: getApp().globalData.siteinfo,
  61. tag: [{
  62. id: 0,
  63. name: '全部'
  64. }],
  65. current: 0,
  66. keyword: '',
  67. pid: 0,
  68. id: 0
  69. };
  70. },
  71. onLoad(option) {
  72. console.log(option)
  73. if (option.id && option.pid) {
  74. this.id = option.id
  75. this.pid = option.pid
  76. this.shop(option.pid, option.id);
  77. }
  78. },
  79. methods: {
  80. search(e) {
  81. let obj = {
  82. pid: this.pid,
  83. id: this.tag[this.current].id,
  84. name: encodeURI(this.keyword)
  85. }
  86. api.goodslist(obj).then(res => {
  87. if (res.status == 200) {
  88. this.shopList = res.data.list;
  89. } else {
  90. this.$api.msg(res.msg);
  91. }
  92. });
  93. },
  94. change(e) {
  95. this.current = e.index;
  96. let i = this.tag[e.index]
  97. console.log(i, "i")
  98. let obj = {
  99. pid: this.pid,
  100. id: i.id
  101. }
  102. api.goodslist(obj).then(res => {
  103. if (res.status == 200) {
  104. this.shopList = res.data.list;
  105. } else {
  106. this.$api.msg(res.msg);
  107. }
  108. });
  109. },
  110. shop(pid, id) {
  111. let that = this;
  112. let obj = {
  113. pid: pid,
  114. id: id,
  115. }
  116. api.goodslist(obj).then(res => {
  117. console.log(res, "res");
  118. if (res.status == 200) {
  119. let tag = this.tag
  120. let num = 1;
  121. res.data.cate2.forEach(item => {
  122. if (item.id == id) {
  123. that.current = num
  124. }
  125. num++;
  126. tag.push(item)
  127. })
  128. console.log(tag, "tag")
  129. this.shopList = res.data.list;
  130. } else {
  131. this.$api.msg(res.msg);
  132. }
  133. });
  134. },
  135. navToDetailPage(item) {
  136. //测试数据没有写id,用title代替
  137. let id = item.id;
  138. uni.navigateTo({
  139. url: `/pagesD/pages/product/product?id=${id}`
  140. });
  141. }
  142. }
  143. };
  144. </script>
  145. <style lang="scss">
  146. $color-fff: #fff;
  147. @mixin lineH($index) {
  148. height: $index;
  149. line-height: $index;
  150. }
  151. ::-webkit-scrollbar {
  152. display: none
  153. }
  154. page {
  155. background: #f5f5f5;
  156. }
  157. .search {
  158. width: 100%;
  159. height: 100rpx;
  160. background-color: #fff;
  161. .usearch {
  162. width: 95%;
  163. padding: 20rpx;
  164. }
  165. }
  166. .tag {
  167. margin-top: 20rpx;
  168. width: 100%;
  169. height: 80rpx;
  170. background-color: #fff;
  171. .tags {
  172. width: 180rpx;
  173. height: 100%;
  174. text-align: center;
  175. line-height: 80rpx;
  176. font-size: 30rpx;
  177. color: #606266;
  178. display: inline-block;
  179. }
  180. .current {
  181. color: #fe8b31;
  182. }
  183. }
  184. .tltile {
  185. font-size: 12px;
  186. overflow: hidden;
  187. white-space: nowrap;
  188. text-overflow: ellipsis;
  189. }
  190. .box {
  191. .carousel {
  192. height: 400rpx;
  193. }
  194. .carousel-item {
  195. width: 100%;
  196. .s-img {
  197. width: 100%;
  198. height: 100%;
  199. }
  200. .swiper-dots {
  201. left: 45rpx;
  202. bottom: 40rpx;
  203. }
  204. }
  205. .application {
  206. background-color: #fff;
  207. width: 100%;
  208. height: 200rpx;
  209. display: flex;
  210. justify-content: space-around;
  211. align-items: center;
  212. .a-img {
  213. width: 110rpx;
  214. height: 110rpx;
  215. }
  216. .app_to {
  217. p {
  218. margin: 0;
  219. padding: 0;
  220. text-align: center;
  221. color: #f1511e;
  222. font-size: 24rpx;
  223. }
  224. }
  225. }
  226. .NewProducts {
  227. background-color: $color-fff;
  228. margin-top: 20rpx;
  229. .content {
  230. width: 100%;
  231. box-sizing: border-box;
  232. min-height: 80vh;
  233. .guess-section {
  234. margin: 15rpx;
  235. display: flex;
  236. justify-content: space-between;
  237. flex-wrap: wrap;
  238. .content_box {
  239. box-shadow: $box-shadow;
  240. border-radius: 15rpx;
  241. width: 355rpx;
  242. padding-bottom: 10rpx;
  243. margin-bottom: 10rpx;
  244. .new-img {
  245. width: 100%;
  246. height: 355rpx;
  247. }
  248. .message {
  249. box-sizing: border-box;
  250. padding: 10rpx;
  251. line-height: 35rpx;
  252. .message_bot {
  253. height: 84rpx;
  254. margin-top: 20rpx;
  255. border-top: 0.5rpx solid #fafafa;
  256. display: flex;
  257. justify-content: space-between;
  258. align-items: center;
  259. .f_left {
  260. margin-top: 10rpx;
  261. font-size: 24rpx;
  262. .color_org {
  263. margin-top: 10rpx;
  264. }
  265. .old_price {
  266. color: #999;
  267. margin-top: 10rpx;
  268. text-decoration: line-through;
  269. }
  270. }
  271. .f_right {
  272. width: 56rpx;
  273. height: 56rpx;
  274. margin-right: 10rpx;
  275. }
  276. }
  277. }
  278. }
  279. }
  280. }
  281. .tag {
  282. display: flex;
  283. justify-content: space-around;
  284. .tag-box {
  285. width: 200rpx;
  286. height: 98rpx;
  287. border: 1px solid #ff8300;
  288. color: #ff8300;
  289. border-radius: 10rpx;
  290. display: flex;
  291. justify-content: center;
  292. align-items: center;
  293. flex-direction: column;
  294. font-size: 24rpx;
  295. .tag-img {
  296. width: 60rpx;
  297. height: 60rpx;
  298. }
  299. }
  300. }
  301. }
  302. .subtitle {
  303. position: relative;
  304. font-size: 0.24rem;
  305. height: 45px;
  306. line-height: 45px;
  307. text-align: center;
  308. font-size: 14px;
  309. .before {
  310. content: '';
  311. position: absolute;
  312. width: 30%;
  313. height: 1px;
  314. top: 50%;
  315. left: 2%;
  316. }
  317. .after {
  318. content: '';
  319. position: absolute;
  320. width: 30%;
  321. height: 1px;
  322. top: 50%;
  323. right: 2%;
  324. }
  325. }
  326. }
  327. </style>