123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667 |
- <template>
- <view class="market">
- <view class="marketTop">
- <view class="top_L">
- <u-icon name="map" color="#999" size="16"></u-icon>
- <view class="top_text">{{AddressData.address}}</view>
- <u-icon @click="linkto('address','1')" name="arrow-right" color="#999" size="16"></u-icon>
- </view>
- <view @click="linkto('address')" class="top_R">
- 编辑
- </view>
- </view>
- <view class="marketContent">
- <u-swipe-action >
- <u-swipe-action-item class="mc_item" v-for="(item,index) in dataList" :key="item.id" @click="swipeAaction(index,$event)"
- :options="options1" :show="swipeShow"
- >
- <view class="item_swipe">
- <checkbox :checked="item.check" @click="checkitem(item)" shape="circle"></checkbox>
- <view class="box_img">
- <u--image radius='16rpx' width="180rpx" height="180rpx" :src="item.fileList[0].fileUrl" ></u--image>
- </view>
- <view class="box_text">
- <view class="box_title">
- {{ item.productName }}
- </view>
- <view class="box_type">
- 已选择 {{item.specsName}}
- </view>
- <view class="box_num">
- <view class="bn_left">
- ¥{{item.specsPrice}}
- </view>
- <view class="bn_right">
- <u-number-box :min="1" :max="999" button-size="28" v-model="item.num"
- @blur="valblur($event,item,index)" @change="valChange(index,item.num)"></u-number-box>
- </view>
- </view>
- </view>
- </view>
- </u-swipe-action-item>
- </u-swipe-action>
-
- </view>
-
- <view class="bottom">
- <view class="w700 bottomflexac">
- <view class="checkall">
- <u-checkbox-group >
- <u-checkbox :checked="checked" shape="circle" class="" @change="checkAll"></u-checkbox><text>全选</text>
- </u-checkbox-group>
- </view>
- <view class="bt_r">
- <view class="num">
- <view>合计:
- <text class="num_n">
- ¥
- <text style="font-size:36rpx">{{shoppingCarCalcData.totalPrice || 0}}</text>
- </text>
- </view>
- <view @click="popupShow = !popupShow" style="font-size: 24rpx;color: #FF655B;text-align: right;margin-right: 20rpx;">{{popupShow?'关闭明细':'查看明细'}}</view>
- </view>
- <view class="btn">
- <u-button shape="circle" size="medium" type="primary"
- @click="submit">结算</u-button>
- </view>
- </view>
- </view>
- </view>
- <u-popup :closeable='true' :round="10" :show="popupShow" @close="close" @open="open">
- <view class="popupView">
- <view class="scrollview">
- <view class="popuptitle">金额明细</view>
-
- <view class="popupimg">
- <view style="margin: 20rpx 10rpx" v-for="(item,index) in tempCheckArray" :key="index">
- <view class="box_img">
- <u--image radius='16rpx' width="180rpx" height="180rpx" :src="item.fileList[0].fileUrl" ></u--image>
- </view>
- </view>
- </view>
- <view class="popupInfo">
- <view class="popupInfo_item">
- <view>商品总额</view>
- <view>¥ {{shoppingCarCalcData.productPrice || 0}}</view>
- </view>
- <view class="popupInfo_item">
- <view>加工费用</view>
- <view>¥ {{shoppingCarCalcData.processPrice || 0}}</view>
- </view>
- <view class="popupInfo_item">
- <view>包装袋费</view>
- <view>¥ {{shoppingCarCalcData.packagePrice || 0}}</view>
- </view>
- <!-- <view class="popupInfo_item">
- <view>优惠券</view>
- <view>¥ 0.00</view>
- </view> -->
- </view>
- <view class="popupInfo2">
- <view class="popupInfo_item2">
- <view>合计</view>
- <view>¥ {{shoppingCarCalcData.totalPrice || 0}}</view>
- </view>
- </view>
- </view>
- </view>
- </u-popup>
- </view>
- </template>
- <script>
- import {
- deliveryAddressList,shoppingCartPage,
- cancelCollection,productcollection,removeShoppingCart,
- shoppingCartCreateOrder,calcShoppingCart
- } from '@/http/api/common.js'
- import * as util from '@/pages/util/util.js'
- export default {
- data() {
- return {
- popupShow:false,
- checked: false,
- disabled: false,
- tempCheckArray:[],//选中的数据列表
- dataList:[],//购物车列表
- options1: [
- // {
- // text: '分享',
- // style: {
- // backgroundColor: '#BBB'
- // }
- // },
- {
- text: '收藏',
- style: {
- backgroundColor: '#FF8C33'
- }
- }, {
- text: '删除',
- style: {
- backgroundColor: '#F6514F'
- }
- }
- ],
- swipeShow:false,
- AddressData:{
- address:'请填写收货地址'
- },
- shoppingCarCalcData:{
- totalPrice:0,//总价
- productPrice:0,//商品价格
- packagePrice:0,//包装费
- processPrice:0,//加工费
- }
- };
- },
- async onShow(e) {
- if(uni.getStorageSync('AppAuthorization')){
- //获取地址列表
- await this.getdeliveryAddressList()
- //获取购物车列表
- await this.getshoppingCartPage()
- }
- if (uni.getStorageSync('selectAddress')) {
- this.AddressData = JSON.parse(uni.getStorageSync('selectAddress'))
- }
- },
- methods: {
-
- async getdeliveryAddressList(){
- let res = await deliveryAddressList()
- if (res.data.code == 200) {
- if (res.data.data) {
- this.AddressData = res.data.data.find(v=>v.defaultAddress == '1')
- if (res.data.data.lenght == 1) {
- this.AddressData = res.data.data[0]
- }
- }
- }
-
- },
- async getshoppingCartPage(){
- //获取购物车列表
- let res = await shoppingCartPage({
- pageSize:10,
- pageNum:1
- })
- if (res.data.code == 200) {
- if (res.data.data) {
- this.dataList = res.data.data.rows.map(v=>{
- let findoldData = this.dataList.find(vv => vv.id == v.id)
- let check = false
- if (findoldData) {
- check = findoldData.check
- }
- return {
- check:check,
- ...v
- }
- })
- let total = res.data.data.total || 0
- uni.setStorageSync('shoppingCartTotal',total)
- if (total != 0) {
- uni.setTabBarBadge({
- index: 3,
- text: total+''
- });
- }else{
- uni.hideTabBarRedDot({
- index: 3,
- });
- }
- //获取购物车后 自动计算一次
- this.calcShoppingCart()
- }
- }
-
- },
- open() {
- },
- close() {
- this.popupShow = false
- },
- valblur(e,item,index){
- console.log(e);
- if (e.value == '') {
- console.log(item === 'object');
- if (typeof item === 'object') {
- item.num = 1
- this.valChange(index,item.num)
- }else{
- this[item] = 2
- }
- }
- },
- async valChange(index,num){
-
- if (this.disabled) {
- return
- }
- this.dataList[index].check = true
- this.dataList[index].num = num
- this.disabled = true
- setTimeout(() => {
- //点击数量触发计算
- this.calcShoppingCart()
- }, 100);
- },
- async checkitem(item){
- // console.log(this.dataList);
- item.check = !item.check
- // this.dataList[index].check = !this.dataList[index]?.check
- //点击单选框触发计算
- setTimeout(() => {
- //点击数量触发计算
- this.calcShoppingCart()
- }, 100);
- },
- //全选
- async checkAll() {
- this.checked = !this.checked
- this.dataList.forEach(v => {
- v.check = this.checked
- })
- //点击单选框触发计算
- setTimeout(() => {
- //点击数量触发计算
- this.calcShoppingCart()
- }, 100);
- },
- async calcShoppingCart(){
- //计算购物车价格
- this.tempCheckArray = this.dataList.filter(v => v.check)
- let shoppingCarSubmitVOList = this.tempCheckArray.map(v => {
- let a = {
- id:v.id,
- num:v.num
- }
- return a
- })
- let res = await calcShoppingCart({
- shoppingCarSubmitVOList:shoppingCarSubmitVOList
- })
- this.disabled = false
- if (res.data.code == 200) {
- this.shoppingCarCalcData = res.data.data
- }
-
- },
- swipeAaction(index,options){
- //index操作了第几个 ,options点了 第几个按钮
- console.log(index,options);
- // 0 收藏 1删除
- if (options.index == 0) {
- if (this.dataList[index].favorites) {
- util.toastFunc('已经收藏过了')
- }else{
- this.toCollection(this.dataList[index])
- }
- }else{
- this.removeShoppingCart(this.dataList[index])
- }
- },
- async toCollection(data){
- //收藏
- let res = null
- if (data.favorites) {
- // favorites true 为收藏过了 调用取消收藏接口
- res = await cancelCollection(data.productId)
- }else{
- res = await productcollection(data.productId)
- }
-
- if (res.data.code == 200) {
- let title = data.favorites ? '取消收藏成功' :'收藏成功'
- uni.showToast({
- title: title,
- duration: 2000
- });
- }
- },
- async removeShoppingCart(data){
- //删除
- let res = await removeShoppingCart(data.id)
-
- if (res.data.code == 200) {
- util.toastFunc('已从购物车中移除',()=>{
- this.getshoppingCartPage()
- })
- }
- },
- async submit(){
- if (!this.AddressData || !this.AddressData?.id) {
- util.toastFunc('请至少设置一个默认地址',()=>{
- this.linkto('address')
- })
- }
- //确认订单
- if (this.tempCheckArray.lenght==0) {
- util.toastFunc('已从购物车中移除',()=>{
- this.getshoppingCartPage()
- })
- }
- console.log('this.tempCheckArray',this.tempCheckArray);
- let shoppingCarSubmitVOList = this.tempCheckArray.map(v => {
- let a = {
- id:v.id
- }
- return a
- })
- //购物车下单
- let res = await shoppingCartCreateOrder({
- shoppingCarSubmitVOList:shoppingCarSubmitVOList,
- deliveryAddressId:this.AddressData.id
- })
- if (res.data.code == 200) {
- let orderId = res.data.data.id
-
- uni.navigateTo({
- url: '/pages/market/confirmOrder?orderId=' + orderId
- });
- }
- },
- linkto(key,type=''){
- if (key == 'address') {
- uni.navigateTo({
- url: '/pages/myinfo/address?selectAddress='+type
- });
- }
-
- },
- },
- };
- </script>
- <style lang="scss">
- .market{
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- .btn{
- width: 200rpx;
- height: 80rpx;
- margin-left: 20rpx;
- }
- .bottomflexac{
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
- .marketTop{
- width: 700rpx;
- height: 90rpx;
- background: #FFFFFF;
- border-radius: 0rpx 0rpx 0rpx 0rpx;
- opacity: 1;
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
- .bottom{
- width: 750rpx;
- height: 120rpx;
- background-color: white;
- display: flex;
- flex-direction: row;
- justify-content: center;
- position: absolute;
- bottom: 0;
- z-index: 10076;
- }
- .top_text{
- width: 260rpx;
- max-height: 80rpx;
- font-size: 28rpx;
- font-weight: 500;
- color: #999999;
- line-height: 40rpx;
- // display: flex;
- // align-items: center;
- display: -webkit-box;
- word-break: break-all;
- text-overflow: ellipsis;
- overflow: hidden;
- -webkit-box-orient: vertical;
- -webkit-line-clamp:2;
- }
- .top_L{
- display: flex;
- align-items: center;
- }
- .top_R{
- width: 56rpx;
- height: 40rpx;
- font-size: 28rpx;
- font-weight: 500;
- color: #666666;
- }
- .checkall{
- display: flex;
- align-items: center;
- width: 150rpx;
- height: 40rpx;
- font-size: 28rpx;
- font-weight: 500;
- color: #666666;
- }
- .bt_r{
- min-width: 440rpx;
- display: flex;
- align-items: center;
- }
- .num{
- min-width: 220rpx;
- height: 47rpx;
- font-size: 28rpx;
- font-weight: 500;
- color: #666666;
- display: flex;
- flex-direction: column;
- }
- .num_n{
- font-size: 28rpx;
- font-weight: bold;
- color: #F6514F;
- }
- .marketContent{
- width: 750rpx;
- height: calc(100vh - 200rpx);
- background: #F1F1F1;
- border-radius: 0rpx 0rpx 0rpx 0rpx;
- overflow: auto;
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- .mc_item{
- width: 702rpx;
- height: 244rpx;
- background: #FFFFFF;
- border-radius: 16rpx 16rpx 16rpx 16rpx;
- opacity: 1;
- margin-top: 24rpx;
- }
- .item_swipe{
- width: 702rpx;
- height: 244rpx;
- background: #FFFFFF;
- border-radius: 16rpx 16rpx 16rpx 16rpx;
- opacity: 1;
- display: flex;
- align-items: center;
- flex-direction: row;
- padding-left: 24rpx;
- }
- .box_img{
- width: 180rpx;
- height: 180rpx;
- background-color: #999999;
- border-radius: 16rpx;
- }
- .box_text{
- width: 392rpx;
- height: 200rpx;
- margin-left: 20rpx;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- }
- .box_title{
- width: 392rpx;
- height: 40rpx;
- font-size: 28rpx;
- font-weight: bold;
- color: #333333;
- line-height: 40rpx;
- display: -webkit-box;
- word-break: break-all;
- text-overflow: ellipsis;
- overflow: hidden;
- -webkit-box-orient: vertical;
- -webkit-line-clamp:1;
- }
- .box_type{
- width: 390rpx;
- height: 48rpx;
- background: #EEEEEE;
- border-radius: 8rpx 8rpx 8rpx 8rpx;
- opacity: 1;
- font-size: 28rpx;
- font-weight: 500;
- color: #999999;
- padding-left: 24rpx;
- line-height: 48rpx;
- display: -webkit-box;
- word-break: break-all;
- text-overflow: ellipsis;
- overflow: hidden;
- -webkit-box-orient: vertical;
- -webkit-line-clamp:1;
- }
- .box_num{
- width: 410rpx;
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .bn_left{
- width: 106rpx;
- height: 38rpx;
- font-size: 28rpx;
- font-weight: bold;
- color: #F6514F;
- line-height: 36rpx;
- }
- .popupView{
- height: 1000rpx;
- display: flex;
- padding-top: 40rpx;
- flex-direction: column;
- align-items: center;
- }
- .scrollview{
- height: 850rpx;
- width: 702rpx;
- overflow: auto;
- }
- .popuptitle{
- // width: 128rpx;
- // height: 45rpx;
- font-size: 32rpx;
- font-weight: bold;
- color: #000000;
- text-align: center;
- }
- .popupimg{
- display: flex;
- flex-wrap: wrap;
- justify-content: flex-start;
- margin-top: 40rpx;
- }
- .popupInfo{
- width: 702rpx;
- height: 180rpx;
- background: #EEEEEE;
- border-radius: 16rpx 16rpx 16rpx 16rpx;
- opacity: 1;
- display: flex;
- align-items: center;
- justify-content: center;
- flex-direction: column;
- }
- .popupInfo_item{
- display: flex;
- justify-content: space-between;
- width: 654rpx;
- height: 40rpx;
- font-size: 28rpx;
- font-weight: 500;
- color: #666666;
- line-height: 36rpx;
- }
- .popupInfo2{
- width: 702rpx;
- height: 80rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- flex-direction: column;
- }
- .popupInfo_item2{
- display: flex;
- justify-content: space-between;
- width: 654rpx;
- height: 40rpx;
- font-size: 28rpx;
- font-weight: bold;
- color: #333;
- line-height: 36rpx;
- }
- checkbox .wx-checkbox-input {
- width: 32rpx;
- height: 32rpx;
- border-color: #409eff;
- background-color: transparent;
- transition: background-color .2s;
- border-radius: 50%;
- }
- checkbox .wx-checkbox-input.wx-checkbox-input-checked {
- color: #fff; /* 这里也可以设置对钩的颜色 */
- background-color: #409eff;
- border-radius: 50%;
- }
- .u-swipe-action-item{
- margin-top: 24rpx;
- border-radius: 16rpx;
- }
- </style>
|