Zlpt_Portal/src/views/order/index.vue

601 lines
18 KiB
Vue
Raw Normal View History

2024-11-26 18:30:19 +08:00
<template>
2024-12-13 10:20:22 +08:00
<div style="width: 100%; background-color: #f5f5f5">
<Header class="wapper" />
</div>
2024-11-26 18:30:19 +08:00
<div class="container">
2024-12-03 16:00:10 +08:00
<el-breadcrumb separator="/" class="primary-lease">
2024-11-26 18:30:19 +08:00
<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
<el-breadcrumb-item>提交订单</el-breadcrumb-item>
</el-breadcrumb>
<div class="cart-title">
<div></div>
<div style="margin: 0 8px">提交订单</div>
<div>({{ amountNum }})</div>
</div>
<el-row class="cart-th">
<el-col :span="2">
2024-12-02 14:06:16 +08:00
<!-- <div>
<el-checkbox v-model="allChecked" @change="onChangeAll" :key="allKey">
全选
</el-checkbox>
</div> -->
2024-11-26 18:30:19 +08:00
</el-col>
<el-col :span="8">
<div>装备信息</div>
</el-col>
<el-col :span="4">
<div>租期</div>
</el-col>
<el-col :span="2">
<div>日租金/</div>
</el-col>
<el-col :span="2">
<div>天数</div>
</el-col>
<el-col :span="2">
<div>数量</div>
</el-col>
<el-col :span="2">
<div>总金额/</div>
</el-col>
<el-col :span="2">
<div>操作</div>
</el-col>
</el-row>
<div class="cart-tbody" v-for="(item, index) in orderList" :key="index">
<el-row style="border-bottom: 1px solid #ccc">
<el-col :span="1">
<div style="text-align: center">
2024-12-02 15:33:53 +08:00
<!-- <el-checkbox
2024-11-26 18:30:19 +08:00
v-model="item.isChecked"
@change="onChangeCompany($event, index, item)"
>
2024-12-02 15:33:53 +08:00
</el-checkbox> -->
2024-11-26 18:30:19 +08:00
</div>
</el-col>
<el-col :span="22" class="cart-user-info">
<div>{{ item.companyName }}</div>
<div class="user-name">{{ item.person }}</div>
<div class="user-phone">{{ item.personPhone }}</div>
</el-col>
</el-row>
<el-row class="cart-list">
<el-col :span="1">
<!-- <div style="text-align: center">
<el-checkbox v-model="goods.isChecked" @change="onChangeGoods(index)">
</el-checkbox>
</div> -->
</el-col>
<el-col :span="9" class="goods-info">
2024-12-02 14:06:16 +08:00
<img :src="item.picUrl" alt="" />
2024-11-26 18:30:19 +08:00
<div class="goods-code">
<div style="font-size: 14px; font-weight: bold">{{ item.deviceName }}</div>
<div>装备编号 {{ item.code }}</div>
<div>装备型号 {{ item.typeName }}</div>
</div>
</el-col>
<el-col :span="4">
<div class="lease-date">
2024-12-02 15:33:53 +08:00
<!-- <div>{{ item.lease_date_string }}</div> -->
<div style="margin-bottom: 8px">
{{ item.rentBeginTime }}
<span v-if="item.rentBeginTime && item.rentEndTime">-</span>
{{ item.rentEndTime }}
</div>
<!-- <el-date-picker
2024-11-26 18:30:19 +08:00
style="width: 100px; margin-top: 10px"
v-model="item.lease_date"
type="daterange"
size="small"
value-format="YYYY-MM-DD"
@change="onLeaseDateChange($event, item)"
2024-12-02 15:33:53 +08:00
/> -->
<CustomDatePickerButton
:modelValue="item.lease_date"
:companyIndex="index"
:goodsIndex="index"
type="primary"
size="large"
placeholder="选择日期"
@onLeaseDateChange="onLeaseDateChange"
2024-11-26 18:30:19 +08:00
/>
</div>
</el-col>
<el-col :span="2">
<div class="red-font">
{{ item.dayLeasePrice }}
</div>
</el-col>
<el-col :span="2">
<div class="red-font" style="color: #0062ff">
2024-12-02 14:06:16 +08:00
{{ item.days }}
2024-11-26 18:30:19 +08:00
</div>
</el-col>
<el-col :span="2">
<div>
<el-input-number
2024-12-02 14:06:16 +08:00
v-model="item.num"
style="width: 100px; margin-left: 10px"
:min="1"
:max="item.deviceCount"
2024-11-26 18:30:19 +08:00
size="small"
/>
</div>
</el-col>
<el-col :span="2">
2024-12-02 14:06:16 +08:00
<div class="red-font" style="margin-left: 20px">
{{ item.num * item.dayLeasePrice * item.days }}
2024-11-26 18:30:19 +08:00
</div>
</el-col>
<el-col :span="2">
<div>
<el-button
@click="onDeleteGoods(index)"
2024-12-02 15:33:53 +08:00
link
2024-11-26 18:30:19 +08:00
style="color: #ff4800; font-weight: bold"
>
删除
</el-button>
</div>
</el-col>
</el-row>
</div>
<div class="protocol-handle">
2024-12-16 13:06:54 +08:00
<el-row style="margin: 15px 0">
<el-col :span="24">
<el-collapse v-model="activeNames">
<el-collapse-item :title="addressTitle" name="1">
2024-12-16 15:45:48 +08:00
<template v-if="addressList.length > 0">
<div
:key="index"
class="address-item"
@click="onSelectAddress(item.addressName)"
v-for="(item, index) in addressList"
>
{{ item.addressName }}
</div>
</template>
<template v-else>
<div style="width: 100%; text-align: center; font-size: 14px">
当前没有收货地址...
<a
style="
color: #00a288;
cursor: pointer;
margin-left: 5px;
text-decoration: underline;
"
@click="onAddAddress"
>
点击新增
</a>
</div>
</template>
2024-12-16 13:06:54 +08:00
</el-collapse-item>
</el-collapse>
</el-col>
</el-row>
2024-11-26 18:30:19 +08:00
<el-row style="display: flex; align-items: center">
<el-col :span="16">
<div class="checkbox-container">
<el-checkbox v-model="protocolChecked">
我已阅读并同意签署
<a href="#"> xxxx公司租赁服务合同 </a>
</el-checkbox>
</div>
</el-col>
<el-col :span="3">
<div>
<span style="color: #ff4800; font-weight: bold">{{
amountDevice
}}</span>
件装备
</div>
</el-col>
<el-col :span="3">
<div class="red-font">
订单总金额<span style="color: #ff4800; font-weight: bold"
>{{ orderAmountPice }} </span
>
</div>
</el-col>
<el-col :span="2">
<div style="text-align: right">
<el-button
size="small"
@click="onCartSubmit"
style="padding: 6px 24px; background-color: #1abc9c; color: #fff"
>提交</el-button
>
</div>
</el-col>
</el-row>
</div>
</div>
<FooterInfo />
</template>
<script setup lang="ts">
import Header from '../../components/header/index.vue'
import FooterInfo from '../../components/FooterInfo/index.vue'
import { ElMessage } from 'element-plus'
2024-12-02 14:06:16 +08:00
import { getBookCarDetailByMaId, submitBookCarApi } from '../../http/api/order/index'
2024-12-02 15:33:53 +08:00
import CustomDatePickerButton from '../cart/components/date-picker-button.vue'
2024-12-16 15:45:48 +08:00
import { getAddressListApi } from 'http/api/address-manage/index'
2024-12-02 14:06:16 +08:00
import { getDetail } from 'http/api/equip'
2024-11-26 18:30:19 +08:00
import moment from 'moment'
import { useRoute, useRouter } from 'vue-router'
2024-12-02 15:43:54 +08:00
import { useStore } from '../../store/user'
const userStore = useStore()
2024-11-26 18:30:19 +08:00
const router = useRouter()
const route = useRoute()
const pageParams = route.params
console.log(pageParams.maId)
2024-11-27 09:11:02 +08:00
const allKey = ref(0)
2024-12-16 13:06:54 +08:00
const activeNames = ref('')
2024-11-26 18:30:19 +08:00
const protocolChecked = ref<boolean>(false)
const orderList = ref<any>([])
2024-12-16 13:06:54 +08:00
const addressTitle = ref('请选择收货地址')
2024-12-16 15:45:48 +08:00
const addressList = ref<any>([])
2024-11-26 18:30:19 +08:00
2024-12-02 14:06:16 +08:00
const getOrderListData = async () => {
2024-11-26 18:30:19 +08:00
const addParams = {
2024-12-02 14:06:16 +08:00
maId: Number(pageParams.maId),
2024-11-26 18:30:19 +08:00
}
2024-12-02 14:06:16 +08:00
const res: any = await getDetail(route.query.id, false)
console.log(res, '装备详情')
orderList.value = []
// orderList.value = res.data
2024-11-26 18:30:19 +08:00
2024-12-02 14:06:16 +08:00
// 组装参数
const orderInfo = {
rentBeginTime: '',
rentEndTime: '',
lease_date: '',
days: 0,
num: 1,
2024-12-02 15:33:53 +08:00
...res.data,
2024-12-02 14:06:16 +08:00
}
orderList.value.push(orderInfo)
// orderList.value.forEach((e: any) => {
// e.isChecked = false
// e.goods_num = 1
// e.lease_day = 1
// // e.devInfoVoList.forEach((j: any) => {
// // j.isChecked = false
// // })
// })
2024-11-26 18:30:19 +08:00
2024-12-02 14:06:16 +08:00
// console.log(orderList.value, '***********')
2024-11-26 18:30:19 +08:00
// console.log(res, '购物车详情')
}
onMounted(() => {
2024-12-02 14:06:16 +08:00
setTimeout(() => {
2024-11-28 17:35:25 +08:00
getOrderListData()
2024-12-02 14:06:16 +08:00
}, 500)
2024-11-26 18:30:19 +08:00
})
// 日期change事件
2024-12-02 15:33:53 +08:00
// const onLeaseDateChange = (e: any, item: any) => {
// item.lease_date_string = `${e[0]}至${e[1]}`
// item.lease_day = moment(e[1]).diff(e[0], 'day')
// }
const onLeaseDateChange = (value: any, companyIndex: number, goodsIndex: number) => {
orderList.value.forEach((e: any) => {
if (!value) {
e.rentBeginTime = ''
e.rentEndTime = ''
e.days = 0
} else {
e.rentBeginTime = value[0]
e.rentEndTime = value[1]
e.days = moment(value[1]).diff(value[0], 'day')
}
})
2024-11-26 18:30:19 +08:00
}
// 删除按钮
const onDeleteGoods = (index: number) => {
2024-12-03 18:07:30 +08:00
// console.log('删除---', index)
orderList.value.splice(index, 1)
2024-11-26 18:30:19 +08:00
}
// 全选change事件
const onChangeAll = (e: boolean) => {
orderList.value.forEach((item: any) => {
item.isChecked = e
// item.devInfoVoList.forEach((j: any) => {
// j.isChecked = e
// })
})
}
// 公司全选事件
const onChangeGoods = (index: number) => {
orderList.value[index].isChecked = orderList.value[index].devInfoVoList.every(
(e: any) => e.isChecked === true,
)
}
// 公司全选事件
const onChangeCompany = (e: boolean, index: number, item: any) => {
orderList.value[index].devInfoVoList.every((j) => (j.isChecked = e))
}
// 计算所有装备
const amountNum = computed(() => {
let amountNum = 0
orderList.value.forEach((e) => {
amountNum = amountNum + 1
})
return amountNum
})
// 计算全选按钮的选中状态
const allChecked = computed(() => {
return orderList.value.every((e: any) => e.isChecked === true)
})
2024-11-27 09:11:02 +08:00
// 已勾选的装备数量
2024-11-26 18:30:19 +08:00
const amountDevice = computed(() => {
2024-12-02 15:33:53 +08:00
// let amountNum = 0
// orderList.value.forEach((e) => {
// if (e.isChecked) {
// amountNum++
// }
// })
return 1
2024-11-26 18:30:19 +08:00
})
2024-11-27 09:11:02 +08:00
// 已勾选的装备数量
const amountDeviceList = computed(() => {
let selectList: any = []
2024-12-02 14:06:16 +08:00
orderList.value.forEach((e: any) => {
2024-11-27 09:11:02 +08:00
if (e.isChecked) {
selectList.push(e)
2024-12-02 14:06:16 +08:00
}
2024-11-27 09:11:02 +08:00
})
return selectList
})
2024-11-26 18:30:19 +08:00
// 计算订单总价格
const orderAmountPice = computed(() => {
let orderAmountPice = 0
2024-12-02 14:06:16 +08:00
orderList.value.forEach((e) => {
2024-12-02 15:33:53 +08:00
// if (e.isChecked) {
// }
orderAmountPice = e.num * e.dayLeasePrice * e.days
2024-11-26 18:30:19 +08:00
})
return orderAmountPice
})
// 提交按钮
2024-11-27 09:11:02 +08:00
const onCartSubmit = async () => {
2024-12-02 15:33:53 +08:00
// ElMessage.closeAll()
// if (amountDevice.value < 1) {
// ElMessage({
// showClose: false,
// message: '请选择装备',
// type: 'error',
// })
// return
// }
// console.log(amountDeviceList.value[0].lease_date == undefined)
if (orderList.value[0].days < 1) {
2024-11-28 17:35:25 +08:00
ElMessage({
showClose: false,
message: '请选择租期',
type: 'error',
})
return
}
2024-11-26 18:30:19 +08:00
if (!protocolChecked.value) {
ElMessage({
showClose: false,
message: '请阅读公司合同',
type: 'error',
})
2024-11-27 09:11:02 +08:00
return
2024-11-26 18:30:19 +08:00
}
2024-12-02 14:06:16 +08:00
2024-12-16 15:45:48 +08:00
if (addressTitle.value === '请选择收货地址') {
ElMessage({
showClose: false,
message: '请选择收货地址',
type: 'error',
})
return
}
2024-12-02 15:33:53 +08:00
const orderInfo = orderList.value[0]
const submitInfo = {
maId: orderInfo.maId,
id: orderInfo.id,
rentBeginTime: orderInfo.rentBeginTime + ' ' + '00:00:00',
rentEndTime: orderInfo.rentEndTime + ' ' + '00:00:00',
manageType: orderInfo.manageType,
days: orderInfo.days,
num: orderInfo.num,
costs: orderInfo.num * orderInfo.days * orderInfo.dayLeasePrice,
}
2024-11-27 09:11:02 +08:00
const submitParams = {
cost: orderAmountPice.value,
2024-12-16 15:45:48 +08:00
address: addressTitle.value.split('')[1],
2024-12-02 15:33:53 +08:00
detailsList: [submitInfo],
2024-11-27 09:11:02 +08:00
}
2024-12-03 18:07:30 +08:00
// console.log('submitParams', submitParams)
const res: any = await submitBookCarApi([submitParams])
2024-11-27 09:11:02 +08:00
if (res.code === 200) {
ElMessage({
showClose: false,
message: '提交成功',
type: 'success',
})
2024-12-03 18:07:30 +08:00
userStore.editcurrentMenuItem('orderManagement')
2024-12-02 15:33:53 +08:00
setTimeout(() => {
router.push({
name: 'my-user',
})
}, 500)
// router.push({
// path: `/equipDetail/${pageParams.maId}`,
// })
2024-11-27 09:11:02 +08:00
}
2024-11-26 18:30:19 +08:00
}
2024-12-16 13:06:54 +08:00
2024-12-16 15:45:48 +08:00
// 获取收货地址
const getReceiptGoodsAddress = async () => {
const res: any = await getAddressListApi({})
addressList.value = res.rows.map((e: any) => {
return {
addressName: `${e.provinceName}${e.cityName}${e.areaName}${e.address}`,
}
})
}
// 去往地址管理
const onAddAddress = () => {
userStore.editcurrentMenuItem('address-manage')
setTimeout(() => {
router.push({
name: 'my-user',
})
}, 500)
}
2024-12-16 13:06:54 +08:00
// 选择收货地址
const onSelectAddress = (address: any) => {
2024-12-16 15:45:48 +08:00
addressTitle.value = '收货地址:' + address
2024-12-16 13:06:54 +08:00
activeNames.value = ''
}
2024-12-16 15:45:48 +08:00
getReceiptGoodsAddress()
2024-11-26 18:30:19 +08:00
</script>
<style lang="scss" scoped>
.container {
width: 1200px;
margin: 0 auto;
padding: 10px;
background: #eeeff6;
font-size: 14px;
.cart-title {
margin-top: 20px;
padding: 10px 0;
display: flex;
align-items: center;
font-size: 14px;
font-weight: bold;
letter-spacing: 1px;
}
.cart-title div:first-child {
width: 5px;
height: 20px;
background-color: #4fabfe;
}
.cart-th {
margin: 15px 0;
div {
text-align: center;
}
}
.cart-tbody {
background: #fff;
padding: 8px 12px;
margin: 10px;
.cart-user-info {
display: flex;
align-items: center;
font-size: 13px;
.user-name,
.user-phone {
padding: 3px 18px;
border: 1px solid #ccc;
}
.user-name {
margin-left: 20px;
border-right: none;
}
}
.cart-list {
margin: 15px 0;
display: flex;
align-items: center;
font-size: 13px;
div {
text-align: center;
}
.goods-info {
display: flex;
align-content: center;
img {
width: 160px;
height: 100px;
}
.goods-code {
margin-left: 20px;
display: flex;
flex-direction: column;
justify-content: space-around;
div {
text-align: left;
}
}
}
.lease-date {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: 12px;
}
.red-font {
color: #ff4800;
font-weight: bold;
}
}
}
.protocol-handle {
background: #fff;
padding: 8px 12px;
margin: 10px;
font-size: 13px;
.checkbox-container a {
color: #ff4800;
text-decoration: underline;
}
}
}
2024-12-16 13:06:54 +08:00
.address-item {
margin: 0 auto;
padding: 6px 10px;
cursor: pointer;
}
.address-item:hover {
background-color: #c9e7e5;
}
2024-11-26 18:30:19 +08:00
</style>