vue实现价格日历效果
作者:爱喝冰可乐 时间:2023-07-02 17:01:14
本文实例为大家分享了vue实现价格日历效果的具体代码,供大家参考,具体内容如下
1、效果图
2、下载全局安装:npm install ele-calendar
3、在components下新建文件calendar.vue,内容:
<template>
<div style="width:600px">
<ele-calendar
:render-content="renderContent"
:data="datedef"
:prop="prop"
:disabledDate="disabledDate"
:effectiveTimeLimit="effectiveTimeLimit"
:defaultValue="defaultValue"
>
</ele-calendar>
</div>
</template>
<script>
import eleCalendar from 'ele-calendar'
import 'ele-calendar/dist/vue-calendar.css'
export default {
props: {
datedef: {
type: Array,
default: () => {
return []
}
},
defaultPrice: {
type: String,
default: () => {
return ''
}
},
effectiveTimeLimit: {
type: String,
default: () => {
return ''
}
},
defaultValue: {
type: Date,
default: () => {
return new Date()
}
}
},
data () {
const self = this
return {
prop: 'date', // 对应日期字段名
disabledDate: date => {
return (
date.valueOf() < new Date().valueOf() - 1 * 24 * 60 * 60 * 1000 ||
date.valueOf() > new Date(self.effectiveTimeLimit).valueOf()
)
}
}
},
components: {
eleCalendar
},
methods: {
// JSX语法
renderContent (h, parmas) {
const self = this
const loop = data => {
return (
<div class={data.defvalue.value ? 'active' : ''}>
<div>{data.defvalue.text}</div>
<div>
¥
<i-input
value={
data.defvalue.value.content
? data.defvalue.value.content
: self.defaultPrice
}
on-on-blur={event =>
self.handleChange(
event,
data.defvalue.value
? data.defvalue.value.date
: self.handleDate(data.defdate)
)
}
disabled={
data.defvalue.value
? new Date(data.defvalue.value.date).valueOf() <
new Date().valueOf() - 1 * 24 * 60 * 60 * 1000 ||
new Date(data.defvalue.value.date).valueOf() >
new Date(self.effectiveTimeLimit).valueOf()
: data.defdate.valueOf() <
new Date().valueOf() - 1 * 24 * 60 * 60 * 1000 ||
data.defdate.valueOf() >
new Date(self.effectiveTimeLimit).valueOf()
}
key={
data.defvalue.value
? data.defvalue.value.date
: self.handleDate(data.defdate)
}
/>
</div>
</div>
)
}
return <div style='min-height:60px;'>{loop(parmas)}</div>
},
handleChange (event, date) {
console.log(event, date, 'dddddd')
const self = this
const index = self.datedef.findIndex(item => {
return item.date === date
})
if (isNaN(event.target.value)) {
self.$Message.error('请输入正确的价格')
event.target.value = self.defaultPrice
return
}
if (event.target.value && index === -1) {
if (event.target.value === self.defaultPrice) {
return
}
self.datedef.push({
date,
content: event.target.value,
cid: null
})
console.log('self.datedef', self.datedef)
this.$emit('aaa', self.datedef)
} else if (event.target.value && index !== -1) {
if (event.target.value === self.defaultPrice) {
self.datedef.splice(index, 1)
return
}
const selectItem = self.datedef[index]
selectItem.content = event.target.value
self.datedef.splice(index, 1, selectItem)
} else if (!event.target.value && index !== -1) {
self.datedef.splice(index, 1)
} else {
event.target.value = self.defaultPrice
}
},
handleDate (date) {
const year = date.getFullYear()
let month = date.getMonth() + 1
month = month >= 10 ? month : '0' + month
let idate = date.getDate()
idate = idate >= 10 ? idate : '0' + idate
return `${year}-${month}-${idate}`
}
}
}
</script>
<style lang="scss">
.el-picker-panel-calendar.el-date-picker-calendar.el-popper {
box-shadow: none;
}
.el-date-table-calendar td > div > div {
border: 1px solid #aaa;
color: #fff;
margin: 5px;
& > div:first-child {
background-color: #aaa;
}
& > div:nth-child(2) {
padding: 5px;
color: #000;
.ivu-input-wrapper {
width: 80%;
}
}
&.active {
border: 1px solid #2ab561;
& > div:first-child {
background-color: #2ab561;
}
& > div:nth-child(2) {
padding: 5px;
color: #000;
.ivu-input-wrapper {
width: 80%;
}
}
}
}
// 这段如果放开的话当天之前的所有框置灰
// .el-date-table-calendar td.disabled > div > div {
// border: 1px solid #aaa;
// color: #fff;
// margin: 5px;
// & > div:first-child {
// background-color: #aaa;
// }
// & > div:nth-child(2) {
// padding: 5px;
// color: #000;
// .ivu-input-wrapper {
// width: 80%;
// }
// }
// }
.el-date-table-calendar td.available:hover {
color: #000;
}
.el-date-table-calendar td.available.today {
color: #000;
font-weight: normal;
}
.el-date-table-calendar tr td.current.available:not(.disabled) {
background-color: #fff;
}
</style>
4、页面引入注册
<script>
import calendar from '../../components/calendar'
export default {
components: { calendar}
}
data() {
return {
effectiveTimeLimit: '',
ruleForm: {
price: '',
configPriceList: []
}
},
rules: {
}
}
}
</script>
5、html
我是写在dialog中的
<el-form-item label="价格设置" prop="calendarPrice">
<calendar
:datedef="ruleForm.configPriceList"
:default-price="ruleForm.price"
:effectiveTimeLimit="effectiveTimeLimit"
></calendar>
</el-form-item>
来源:https://blog.csdn.net/u013361179/article/details/108603281
标签:vue,价格日历
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python集成开发环境配置(pycharm)
2021-08-28 08:23:10
![](https://img.aspxhome.com/file/2023/8/115678_0s.jpg)
浅谈uniapp页面跳转的解决方案
2023-08-23 01:45:51
![](https://img.aspxhome.com/file/2023/3/56133_0s.jpg)
获取星期几的名称
2012-01-29 18:16:31
Python算法之栈(stack)的实现
2022-09-01 15:26:15
SQL SERVER调用存储过程小结
2024-01-23 18:52:27
go流程控制代码详解
2023-10-15 18:14:19
python读写数据读写csv文件(pandas用法)
2021-06-15 15:28:03
![](https://img.aspxhome.com/file/2023/6/121906_0s.png)
python网络编程学习笔记(五):socket的一些补充
2022-02-03 23:22:48
Numpy数组array和矩阵matrix转换方法
2021-06-25 06:17:26
使用Anaconda创建Pytorch虚拟环境的排坑详细教程
2021-06-14 09:01:03
![](https://img.aspxhome.com/file/2023/7/130957_0s.jpg)
python实现npy格式文件转换为txt文件操作
2021-04-03 08:07:05
![](https://img.aspxhome.com/file/2023/5/92075_0s.jpg)
Python cookbook(数据结构与算法)实现查找两个字典相同点的方法
2022-07-20 22:09:46
![](https://img.aspxhome.com/file/2023/9/130659_0s.png)
Django权限系统auth模块用法解读
2021-03-22 13:27:00
如何从Python字符串中删除最后一个分号或者逗号
2023-12-22 07:29:53
![](https://img.aspxhome.com/file/2023/0/79470_0s.png)
Oracle 多行记录合并/连接/聚合字符串的几种方法
2009-11-17 08:53:00
python 基于 tkinter 做个学生版的计算器
2022-07-30 18:43:54
![](https://img.aspxhome.com/file/2023/1/131351_0s.jpg)
asp Driver和Provider两种连接字符串连接Access时的区别
2011-03-09 11:19:00
Scrapy项目实战之爬取某社区用户详情
2022-04-16 11:36:31
Python 统计Jira的bug 并发送邮件功能
2021-03-24 05:44:24
![](https://img.aspxhome.com/file/2023/3/83783_0s.jpg)
SQL字符串处理函数大全
2024-01-25 07:09:13