第一版绿谷官网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

174 lines
4.5 KiB

<!--
Copyright (c) 2020.
author: song
email: 15235360226@163.com
-->
<template>
<div class="inner">
<bread-crumb :arr="arr" class="my-1" />
<div class="white pa-5 mb-5 d-flex flex-nowrap align-center justify-space-between">
<div>
<span class="font-16 textColor">联系人</span>
<a-input style="width: auto" v-model="name" />
</div>
<div>
<span class="font-16 textColor">联系电话:</span>
<a-input @change="onChange" style="width: auto" v-model="phone" />
</div>
<div>
<span class="font-16 textColor">公司名称:</span>
<a-input style="width: 200px" v-model="company" />
</div>
</div>
<div class="cart-box" v-if="cart && cart.length > 0">
<div :key="list.id" class="d-flex flex-column pa-5 white div-box mb-8" v-for="list in cart">
<p class="font-bold-20 title-color">{{ list.type === 0 ? '服务' : list.type === 1 ? '设备' : '成果' }}</p>
<div :key="index" class="d-flex flex-nowrap flex-row mb-8" v-for="(item, index) in list.carDetailList">
<img :src="item.picUrl" class="cart-pic mr-8" />
<div class="flex-1 flex-column">
<p class="font-bold-20 title-color">{{ item.name }}</p>
<p class="font-14 textColor">{{ item.description }}</p>
</div>
</div>
</div>
<div class="d-flex flex-row-reverse pb-10">
<a-button @click="handleSubmit" type="primary">提交</a-button>
<cart-model :phone="phone" :show-model="showModel" @handleCancel="handleCancel" @submitCart="submitCart" />
</div>
</div>
</div>
</template>
<script>
import { mapState, mapMutations, mapActions } from 'vuex';
import BreadCrumb from 'components/BreadCrumb/BreadCrumb.vue';
import CartModel from './CartModel.vue';
import { searchCar, carAndBuy } from 'config/api';
export default {
name: 'Cart',
components: { BreadCrumb, CartModel },
data() {
return {
arr: [{ name: '购物车', url: '' }],
name: '',
phone: '',
company: '',
cart: {},
showModel: false,
phoneRules: [
{ required: true, pattern: new RegExp(/^[1][3,4,5,6,7,8,9][0-9]{9}$/), whitespace: true, message: '请输入正确的手机号' },
],
};
},
computed: mapState('home', ['userSer']),
async created() {
await this.getData();
await this.getUserSer();
if (this.userSer) {
if (this.userSer.name) {
this.name = this.userSer.name;
}
if (this.userSer.phone) {
this.phone = this.userSer.phone;
}
if (this.userSer.companyName) {
this.company = this.userSer.companyName;
}
}
},
methods: {
...mapMutations('home', []),
...mapActions('home', ['getUserSer']),
// 获取购物车列表
async getData() {
try {
const params = { param: { pageNum: 1, pageSize: 10 } };
const res = await searchCar(params);
const { data, msg, code } = res.data;
if (code === 200) {
this.cart = data;
}
} catch (error) {
// console.log(error);
}
},
// 电话变化
onChange(e) {
this.phone = e.target.value;
},
handleSubmit() {
if (this.userSer.phone !== this.phone) {
this.openModel();
} else {
this.submitCart();
}
},
// 提交
async submitCart(tel) {
try {
if (tel) {
this.phone = tel;
}
const { name, phone, company, cart } = this;
const ids = cart[0].carId;
const params = {
param: {
contactName: company,
contactPhone: phone,
companyName: name,
ids,
},
};
const res = await carAndBuy(params);
const { data, msg, code } = res.data;
if (code === 200) {
this.$message.success('提交成功');
this.confirmLoading = false;
} else {
throw msg;
this.confirmLoading = false;
}
} catch (error) {
this.$message.error(error);
this.confirmLoading = false;
}
},
// 打开弹窗
openModel() {
this.showModel = true;
},
// 关闭弹窗
handleCancel() {
this.showModel = false;
},
},
};
</script>
<style scoped lang="stylus">
.inner {
margin: 40px auto;
}
.cart-box {
.div-box {
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16);
}
.cart-pic {
width: 233px;
height: 128px;
}
}
</style>