123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- <template>
- <view>
- <view style="background-color: #fff;padding: 20rpx;border-radius: 20rpx;">
- <view style="display: flex;justify-content: space-between;">
- <view>
- <view style="display: flex;width: 580rpx;" v-if="!editDel" @click="clickAddress">
- <u-icon name="map"></u-icon>
- <u--text :text="addres.belongtoarea + addres.detailedAddress" size="28rpx" lines="1"></u--text>
- </view>
- </view>
- <view style="display: flex;">
- <view style="margin-right: 40rpx;">|</view>
- <view @click="editDel = !editDel">{{editDel?'取消':'编辑'}}</view>
- </view>
- </view>
- </view>
- <u-checkbox-group v-model="companyValue" placement="column" @change="companyChange">
- <view class="collection" v-for="(item,index) in dataList" :key="index">
- <view>
- <u-checkbox activeColor="#FD4B09" shape="circle" :customStyle="{marginBottom: '8px'}"
- :label="item.name" :name="item.name" labelSize="28rpx"></u-checkbox>
- </view>
- <view style="margin-left: 20rpx;display: flex;align-items: center;" v-for="(ite,ind) in item.list"
- :key="ind">
- <view>
- <image v-for="(li,inde) in ite.filesList" :key="inde" v-if="li.version === '0'" :src="li.url"
- style="width: 200rpx;height: 200rpx;border-radius: 20rpx;">
- </image>
- </view>
- <view class="goods">
- <u--text :text="ite.goodsName" size="24rpx" lines="2"></u--text>
- <view class="price">
- <view>¥{{ite.price}}</view>
- <view v-if="!editDel">
- <u-number-box v-model="ite.goodsNum" :min="1" :max="ite.inventory" buttonSize="40rpx"
- @change="(val)=>{statistics(val,index,ind)}"></u-number-box>
- </view>
- </view>
- </view>
- <view v-if="editDel">
- <u-icon name="minus-circle-fill" color="#ff0000" size="52rpx"
- @click="deleteGoods(ite.id)"></u-icon>
- </view>
- </view>
- </view>
- </u-checkbox-group>
- <view style="height: 100rpx;"></view>
- <view class="submitBar">
- <view class="bar_view">
- <view>
- <u-checkbox-group v-model="radiovalue" placement="column" @change="radioGroupChange">
- <u-checkbox label="全选" name="全选" activeColor="#FD4B09" shape="circle"></u-checkbox>
- </u-checkbox-group>
- </view>
- <view v-if="!editDel">
- <view>总计:¥<text>{{totalPrice}}</text></view>
- <view style="font-size: 22rpx;color: #FD4B09;">运费:¥{{totalFreight}}</view>
- </view>
- <view style="width: 200rpx;">
- <u-button shape="circle" size="small" text="提交订单" v-if="!editDel"
- :disabled="this.selectedProduct.length == 0"
- color="linear-gradient(0deg, #FD5003 0%, #FBA680 100%)" @click="submit"></u-button>
- <u-button shape="circle" size="small" text="删除" v-else :disabled="this.selectedProduct.length == 0"
- color="linear-gradient(0deg, #FD5003 0%, #FBA680 100%)" @click="deleteShopping"></u-button>
- </view>
- </view>
- </view>
- <u-empty style="position: absolute;top: 45%;left: 50%;transform:translate(-50%,-50%)"
- v-if="dataList.length == 0" mode="car" icon="http://cdn.uviewui.com/uview/empty/car.png" />
- </view>
- </template>
- <script>
- import {
- shoppingCartList,
- generateOrder,
- shoppingCartUpdate,
- getCorpsAddr
- } from '@/api/tabBar/shoppingCart.js'
- import { registerRuntimeCompiler } from "vue"
- export default {
- data() {
- return {
- editDel: false,
- radiovalue: [],
- companyValue: [],
- dataList: [],
- companyValueLength: 0,
- selectedProduct: [],
- totalPrice: 0.00,
- totalFreight: 0.00,
- addres: {}
- }
- },
- watch: {
- companyValue() {
- if (this.companyValue.length != 0 || this.companyValueLength != 0) {
- if (this.companyValue.length == this.companyValueLength) {
- this.radiovalue = ["全选"]
- } else {
- this.radiovalue = []
- }
- }
- this.statistics()
- }
- },
- onShow() {
- this.editDel = false
- this.companyValue = []
- shoppingCartList().then(res => {
- this.dataList = res.data
- this.companyValueLength = this.dataList.length
- })
- getCorpsAddr().then(res => {
- this.addres = res.data
- })
- },
- methods: {
- clickAddress() {
- this.$u.route('/pages/views/personalInformation/addressManagement');
- },
- deleteGoods(val) {
- uni.showLoading({
- title: '加载中',
- mask: true
- });
- shoppingCartUpdate({
- ids: val
- }).then(res => {
- uni.showToast({
- title: "删除成功",
- icon: 'none'
- });
- uni.showLoading({
- title: '加载中',
- mask: true
- });
- this.editDel = false
- this.companyValue = []
- shoppingCartList().then(res => {
- this.dataList = res.data
- this.companyValueLength = this.dataList.length
- uni.hideLoading();
- }).catch(err => {
- uni.hideLoading();
- })
- uni.hideLoading();
- }).catch(err => {
- uni.hideLoading();
- })
- },
- deleteShopping() {
- let data = []
- for (let item of this.companyValue) {
- for (let ite of this.dataList) {
- if (item == ite.name) {
- for (let it of ite.list) {
- data.push(it.id)
- }
- }
- }
- }
- uni.showLoading({
- title: '加载中',
- mask: true
- });
- shoppingCartUpdate({
- ids: data.join(',')
- }).then(res => {
- uni.showToast({
- title: "删除成功",
- icon: 'none'
- });
- uni.hideLoading();
- uni.showLoading({
- title: '加载中',
- mask: true
- });
- this.editDel = false
- this.companyValue = []
- shoppingCartList().then(res => {
- this.dataList = res.data
- this.companyValueLength = this.dataList.length
- uni.hideLoading();
- }).catch(err => {
- uni.hideLoading();
- })
- }).catch(err => {
- uni.hideLoading();
- })
- },
- submit() {
- if (this.companyValue.length > 0) {
- let data = []
- for (let item of this.companyValue) {
- for (let ite of this.dataList) {
- if (item == ite.name) {
- data.push({
- name: item,
- list: ite.list
- })
- }
- }
- }
- uni.showLoading({
- title: '加载中',
- mask: true
- });
- generateOrder({
- address: this.addres.belongtoarea + this.addres.detailedAddress,
- list: data,
- }).then(res => {
- console.log(res);
- return
- uni.showToast({
- title: "提交成功",
- icon: 'none'
- });
- uni.hideLoading();
- uni.showLoading({
- title: '加载中',
- mask: true
- });
- this.editDel = false
- this.companyValue = []
- shoppingCartList().then(res => {
- this.dataList = res.data
- this.companyValueLength = this.dataList.length
- uni.hideLoading();
- }).catch(err => {
- uni.hideLoading();
- })
- }).catch(err => {
- uni.hideLoading();
- })
- }
- },
- radioGroupChange(e) {
- this.radiovalue = e
- if (e.length == 0) {
- this.companyValue = []
- } else {
- for (let li of this.dataList) {
- if (!this.companyValue.includes(li.name)) {
- this.companyValue.push(li.name)
- }
- }
- }
- this.statistics()
- },
- statistics(val, index, ind) {
- if (val) {
- this.dataList[index].list[ind].goodsNum = val.value
- }
- let data = []
- for (let item of this.companyValue) {
- for (let ite of this.dataList) {
- if (item == ite.name) {
- for (let it of ite.list) {
- data.push(it)
- }
- }
- }
- }
- this.totalPrice = 0
- this.totalFreight = 0
- for (let item of data) {
- this.totalPrice += Number(item.price) * Number(item.goodsNum)
- if (Number(item.goodsNum) == 1) {
- this.totalFreight += 5
- }
- }
- this.totalFreight = this.totalFreight.toFixed(2)
- this.totalPrice = this.totalPrice.toFixed(2)
- this.selectedProduct = data
- },
- companyChange(n) {
- this.companyValue = n
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .collection {
- background-color: #fff;
- padding: 20rpx;
- border-radius: 20rpx;
- margin-top: 20rpx;
- }
- .goods {
- width: 100%;
- margin-left: 20rpx;
- height: 200rpx;
- display: grid;
- align-content: space-between;
- .price {
- display: flex;
- justify-content: space-between !important;
- margin-top: 20rpx;
- align-items: center;
- view:nth-child(1) {
- color: #FD4B09;
- font-size: 40rpx;
- }
- }
- }
- .submitBar {
- position: fixed;
- bottom: 0;
- background-color: #fff;
- width: 100%;
- z-index: 10;
- .bar_view {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 10rpx;
- }
- }
- </style>
|