index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <view class="warpbox">
  3. <!-- 搜索 -->
  4. <view class="censear">
  5. <image src="/static/img/search.png" class="searimg" mode=""></image>
  6. <input type="text" :placeholder="i18n['请输入关键词搜索']" @input="queryData" class="lself">
  7. </view>
  8. <view class="conbox">
  9. <scroll-view scroll-x style="width:642rpx">
  10. <view class="tablist_new" style="justify-content: flex-start;padding:0">
  11. <view
  12. class="tabtn"
  13. @click="changeProduct(index)"
  14. :class="{'tabtn_active':index == productIndex}"
  15. v-for="(item,index) in product_list"
  16. :key="index"
  17. >{{item.name}}</view>
  18. </view>
  19. </scroll-view>
  20. <scroll-view scroll-y style="height:calc(100vh - 320rpx);padding-top:24rpx;box-sizing: border-box;" @scrolltolower="loadMorePart">
  21. <view class="pro_box">
  22. <view class="pro_item" v-for="(item,index) in part_list" :key="index" @click="selectPart(index)">
  23. <image :src="item.img" class="productimg"></image>
  24. <view class="product_name">{{item.name}}</view>
  25. <view class="se_box">
  26. <image src="/static/img/dui.png" v-if="item.select" class="duiimg"></image>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="noData" v-if="part_list.length == 0">{{i18n['暂无更多']}}</view>
  31. </scroll-view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import { netProductList, netPartList, netCartListnum, netAddCart } from '@/api/api.js'
  37. export default{
  38. data() {
  39. return{
  40. name:'',
  41. product_list:[{id:0,name:'全部'}],
  42. productIndex:0,
  43. part_list:[],
  44. partPage:1,
  45. partTotalpage:1,
  46. cartNum:0
  47. }
  48. },
  49. computed:{
  50. i18n() {
  51. return this.$t("shopmall")
  52. }
  53. },
  54. onLoad() {
  55. //设备 列表
  56. this.getProductList()
  57. },
  58. onShow() {
  59. uni.setNavigationBarTitle({
  60. title: this.i18n['服务商城']
  61. })
  62. //购物车 数量
  63. this.getCartNum()
  64. },
  65. methods:{
  66. getCartNum() {
  67. netCartListnum().then(res=>{
  68. this.cartNum = res.data.total
  69. })
  70. },
  71. getProductList() {
  72. netProductList().then(res=>{
  73. res = res.data
  74. this.product_list.push(...res)
  75. //备件列表
  76. this.part_list = []
  77. this.partPage = 1
  78. setTimeout(()=>{
  79. this.getPartlist(this.product_list[0].id)
  80. },200)
  81. })
  82. },
  83. changeProduct(index) {
  84. this.productIndex = index
  85. this.part_list = []
  86. this.partPage = 1
  87. //备件列表
  88. setTimeout(()=>{
  89. this.getPartlist(this.product_list[index].id)
  90. },200)
  91. },
  92. loadMorePart() {
  93. if(this.partPage >= this.partTotalpage) {
  94. return
  95. }
  96. this.partPage ++
  97. this.getPartlist()
  98. },
  99. getPartlist(id) {
  100. let params = {
  101. product_id:id,
  102. name: this.name
  103. }
  104. netPartList(params).then(res=>{
  105. let data = res.data.data
  106. data.forEach(ele=>{
  107. ele.select = false
  108. })
  109. this.part_list = this.part_list.concat(data)
  110. this.partTotalpage = res.data.last_page
  111. })
  112. },
  113. selectPart(index) {
  114. let obj = this.part_list[index]
  115. obj.select = !obj.select
  116. this.$set(this.part_list,index,obj)
  117. },
  118. queryData(e) {
  119. this.name = e.detail.value
  120. this.part_list = []
  121. setTimeout(()=>{
  122. this.getPartlist(this.product_list[this.productIndex].id)
  123. },200)
  124. },
  125. //加入购物车
  126. addCart() {
  127. let data = this.part_list
  128. let arr = []
  129. data.forEach(ele=>{
  130. if(ele.select){
  131. arr.push(ele.id)
  132. }
  133. })
  134. if(arr.length <= 0) {
  135. uni.showToast({
  136. title:'请选择要加入的配件',
  137. icon:'none'
  138. })
  139. return
  140. }
  141. netAddCart({parts_id:arr.join(',')}).then(res=>{
  142. uni.showToast({
  143. title: res.msg,
  144. icon:'none'
  145. })
  146. this.getCartNum()
  147. })
  148. },
  149. toCart() {
  150. uni.navigateTo({
  151. url:'/pages/serviceMall/cart'
  152. })
  153. }
  154. }
  155. }
  156. </script>
  157. <style lang="scss" scoped>
  158. .censear{
  159. display: flex;
  160. justify-content: center;
  161. align-items: center;
  162. padding:0 24rpx;
  163. border-radius: 34rpx;
  164. background:#FFFFFF;
  165. width:584rpx;
  166. height:68rpx;
  167. border:1rpx solid #7FC2FF;
  168. margin:0 auto;
  169. .searimg{
  170. width:34rpx;
  171. height:34rpx;
  172. }
  173. .lself{
  174. width:450rpx;
  175. font-size:26rpx;
  176. }
  177. }
  178. .conbox{
  179. width:690rpx;
  180. background:#fff;
  181. margin:24rpx auto;
  182. border-radius: 20rpx;
  183. padding:24rpx;
  184. }
  185. .pro_box{
  186. display: flex;
  187. justify-content: flex-start;
  188. flex-wrap: wrap;
  189. .pro_item{
  190. width:160rpx;
  191. flex-shrink: 0;
  192. text-align: center;
  193. margin-right:80rpx;
  194. margin-bottom:24rpx;
  195. position: relative;
  196. &:nth-child(3n){
  197. margin-right:0;
  198. }
  199. .se_box{
  200. width:32rpx;
  201. height:32rpx;
  202. position: absolute;
  203. right:10rpx;
  204. top:10rpx;
  205. border:1rpx solid #C8C8C8;
  206. border-radius: 8rpx;
  207. .duiimg{
  208. width:32rpx;
  209. height:32rpx;
  210. }
  211. }
  212. .productimg{
  213. width:157rpx;
  214. height:157rpx;
  215. background:#F6F6F6;
  216. border-radius: 20rpx;
  217. margin-bottom:10rpx;
  218. border:1rpx solid #C8C8C8;
  219. }
  220. .product_name{
  221. font-size:26rpx;
  222. color:#999999;
  223. }
  224. }
  225. }
  226. .botbox{
  227. width:690rpx;
  228. background:#fff;
  229. margin:24rpx auto;
  230. border-radius: 20rpx;
  231. padding:24rpx;
  232. display: flex;
  233. justify-content: space-between;
  234. align-items: center;
  235. .botleft{
  236. display: flex;
  237. justify-content: flex-start;
  238. align-items: center;
  239. .carimg{
  240. width:48rpx;
  241. height:41rpx;
  242. margin-right:15rpx;
  243. }
  244. .left_te{
  245. .num{
  246. font-size:24rpx;
  247. color:#999;
  248. }
  249. }
  250. }
  251. .botright{
  252. width:360rpx;
  253. height:88rpx;
  254. border-radius: 45rpx;
  255. background:#7FC2FF;
  256. font-size:30rpx;
  257. color:#fff;
  258. text-align: center;
  259. line-height: 88rpx;
  260. }
  261. }
  262. </style>