123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <template>
- <view class="warpbox">
- <!-- 搜索 -->
- <view class="searbox">
- <view class="censear">
- <image src="/static/img/search.png" class="searimg" mode=""></image>
- <input type="text" :placeholder="i18n['请输入关键词搜索']" @input="queryData" class="lself">
- </view>
- <image src="/static/img/delete.png" class="deleimg" @click="del" mode=""></image>
- </view>
-
- <scroll-view class="scrollbox" scroll-y @scrolltolower="loadMorePart">
- <view class="part_warp">
- <view class="part_item" v-for="(item,index) in list" :key="index" @tap.stop="selectPart(index)">
- <radio value="r1" color="#7FC2FF" :checked="item.select" />
- <view class="item_infor">
- <image :src="item.parts.img" class="partimg" mode=""></image>
- <view class="info">
- <view class="info_box">
- <view class="title">{{item.parts.name}}</view>
- <view class="desc">{{i18n['规格']}}:{{item.parts.unit}}</view>
- </view>
- <view class="info_bot" @tap.stop.prevent>
- <view class="partmoney">¥{{item.parts.price}}</view>
- <uni-number-box v-model="item.num" @change="(e)=>{changeNum(e,index)}"></uni-number-box>
- </view>
- </view>
- </view>
- </view>
- </view>
- </scroll-view>
-
- <view class="botbox">
- <view class="botleft">
- <image src="/static/img/cart.png" class="carimg"></image>
- <view class="left_te">
- <view class="num" >{{i18n['已选']}}{{selectList.length}}{{i18n['件']}}</view>
- <view class="totalmoney">¥{{totalMoney}}</view>
- </view>
- </view>
- <!-- <view class="botright" @click="subOrder">{{i18n['提交订单']}}</view> -->
- </view>
- </view>
- </template>
- <script>
- import { netCartListnum, netChangePartNum, netDelCartNum } from '@/api/api.js'
-
- export default{
- data(){
- return{
- list:[],
- name:'',
- page:1,
- totalPage:1,
- totalMoney:0,
- selectList:[]
- }
- },
- computed:{
- i18n() {
- return this.$t("shopmall")
- }
- },
- onShow() {
- uni.setNavigationBarTitle({
- title: this.i18n['购物车']
- })
- this.list = []
- this.page = 1
- //购物车 列表
- this.getList()
- },
- methods:{
- queryData(e) {
- this.name = e.detail.value
- this.list = []
- this.page = 1
- setTimeout(()=>{
- this.getList()
- },200)
- },
- loadMorePart() {
- if(this.page < this.totalPage){
- this.page ++
- this.getList()
- }
- },
- getList() {
- let params = {
- page:this.page,
- name: this.name
- }
- netCartListnum(params).then(res=>{
- let data = res.data.data
- data.forEach(ele=>{
- ele.select = false
- })
- this.list = this.list.concat(data)
- this.totalPage = res.data.last_page
- })
- },
- selectPart(index) {
- let obj = this.list[index]
- obj.select = !obj.select
- this.$set(this.list,index,obj)
- //重新计算 money
- this.handleMoney()
- //筛选 已选择的数据
- this.handleSelected()
- },
- handleSelected() {
- let data = this.list
- let arr = []
- data.forEach(ele=>{
- if(ele.select) {
- arr.push(ele.id)
- }
- })
- this.selectList = arr
- },
- changeNum(e,index) {
- let num = e
- let obj = this.list[index]
- obj.num = num
- this.$set(this.list,index,obj)
- //修改数量
- this.changeCartnum(num,obj)
- //重新计算 money
- this.handleMoney()
- },
- changeCartnum(num,obj) {
- let params = {
- id: obj.id,
- num
- }
- netChangePartNum(params).then(res=>{})
- },
- handleMoney(){
- let data = this.list
- let money = 0
- data.forEach(ele=>{
- if(ele.select) {
- money += ele.num * Number(ele.parts.price)
- }
- })
- this.totalMoney = money
- },
- del(){
- let arr = this.selectList
- if(arr.length == 0){
- uni.showToast({
- title:'请选择需要删除的配件',
- icon:'none'
- })
- return
- }
- netDelCartNum({ids:arr.join(',')}).then(res=>{
- uni.showToast({
- title:res.msg,
- icon:'none'
- })
- setTimeout(()=>{
- this.list = []
- this.page = 1
- this.getList()
- this.totalMoney = 0
- this.selectList = []
- },2000)
- })
- },
- subOrder() {
- if(this.selectList.length == 0) {
- uni.showToast({
- title:'请选择要下单的配件',
- icon:'none'
- })
- return
- }
- let ids = this.selectList.join(',')
- uni.navigateTo({
- url:'/pages/serviceMall/orderDetail?ids='+ids
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .searbox{
- padding:10rpx 0 20rpx 0;
- display: flex;
- justify-content: center;
- align-items: center;
-
- .censear{
- display: flex;
- justify-content: flex-start;
- align-items: center;
- padding:0 24rpx;
- border-radius: 34rpx;
- background:#FFFFFF;
- width:564rpx;
- height:68rpx;
- border:1rpx solid #7FC2FF;
- .searimg{
- width:48rpx;
- height:48rpx;
- }
- .lself{
- width:420rpx;
- font-size:26rpx;
- color:rgba(2, 135, 255, 1);
- }
- }
- .deleimg{
- width:44rpx;
- height:44rpx;
- margin-left:35rpx;
- }
- }
- .scrollbox{
- width:750rpx;
- height:calc(100vh - 300rpx);
- .part_warp{
- .part_item{
- width:690rpx;
- margin:0 auto 24rpx;
- background:#fff;
- border-radius: 20rpx;
- padding:30rpx;
- display: flex;
- justify-content: flex-start;
- align-items: center;
- radio{
- transform: scale(0.7);
- flex-shrink: 0;
- }
- .item_infor{
- margin-left:24rpx;
- display: flex;
- justify-content: flex-start;
- align-items: center;
- .partimg{
- width: 130rpx;
- height: 130rpx;
- border-radius: 10rpx;
- margin-right:24rpx;
- flex-shrink: 0;
- }
- .info{
- width:380rpx;
- .info_box{
- .title{
- font-size:30rpx;
- color:#333333;
- }
- .desc{
- font-size:26rpx;
- color:#999999;
- margin-top:15rpx;
- }
- }
- .info_bot{
- width:100%;
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-top:15rpx;
- .partmoney{
- font-size:26rpx;
- color:#7FC2FF;
- }
- }
- }
- }
- }
- }
- }
-
- .botbox{
- width:690rpx;
- background:#fff;
- margin:24rpx auto;
- border-radius: 20rpx;
- padding:24rpx;
- display: flex;
- justify-content: center;
- align-items: center;
- .botleft{
- display: flex;
- justify-content: flex-start;
- align-items: center;
- .carimg{
- width:48rpx;
- height:41rpx;
- margin-right:15rpx;
- }
- .left_te{
- display: flex;
- justify-content: center;
- align-items: center;
- .totalmoney{
- color:#7FC2FF;
- font-size:24rpx;
- margin-left:24rpx;
- }
- .num{
- font-size:24rpx;
- color:#999;
- }
- }
- }
- .botright{
- width:360rpx;
- height:88rpx;
- border-radius: 45rpx;
- background:#7FC2FF;
- font-size:30rpx;
- color:#fff;
- text-align: center;
- line-height: 88rpx;
- }
- }
- </style>
|