uniapp uview微信小程序日历动态渲染

uniapp yekong 169℃

uniapp使用uview开发微信小程序日历动态渲染
uniapp uview微信小程序日历动态渲染

<template>
	<view>
		<u-calendar title="可服务时间" @close="gethide" :show="show" :mode="mode" @confirm="confirm" ref="calendar"
			monthNum="5" mode="single" :show-confirm="false">
		</u-calendar>
	</view>
</template>

<script>
	import moment from 'moment'
	import configs from '@/config/config.js'
	import {
		cookduty,
		docookduty
	} from '@/config/api.js'
	export default {
		components: {},
		data() {
			return {
				id: 1,
				configs,
				show: false,
				curtime: moment(moment().format("YYYY-MM-DD")).unix(),
				data: [],
				startdate: moment().unix(),
				enddate: moment().subtract(-200, "days").unix()
			};
		},
		mounted() {
			this.id = uni.getStorageSync('user_id')
			// this.getdata()
		},
		methods: {
			confirm(e) {
				console.log(e);
				console.log(123);
				var that = this;
				if (this.show && this.curtime != moment(e[0]).unix()) {
					this.curtime = moment(e[0]).unix();
					// this.show = false
					uni.showModal({
						title: '当前日期是否排班',
						content: ' ',
						cancelText: '不可行',
						confirmText: '可行',
						success: function(res) {
							if (res.confirm) {
								that.docookduty(0);
							} else {
								that.docookduty(1);
							}
						}
					});
				}

			},
			gethide(e) {
				console.log(e);
				this.show = false
			},
			getshow() {
				this.show = true
				this.getdata()
			},
			formatter(day) {
				const d = new Date()
				let month = d.getMonth() + 1
				const date = d.getDate()
				var datainfo = moment(moment().format("YYYY") + '-' + day.month + '-' + day.day).unix()
				var sdata = uni.getStorageSync('dutydata')
				sdata.forEach((type) => {
					if (datainfo == type) {
						day.bottomInfo = '可预约'
					}
				});

				return day
			},
			docookduty(is_valid) {
				var that = this;
				docookduty({
					duty: that.curtime,
					is_valid: is_valid,
					status: 1
				}, {
					custom: {
						auth: true
					}
				}).then(res => {
					if (res.code == 1) {
						that.getdata()
					}
				}).catch(err => {

				})
			},
			getchange(e) {
				console.log(e)
			},
			getdata() {
				var that = this;
				cookduty({
					userId: that.id,
					btime: moment(moment().format("YYYY-MM-DD")).unix(),
					etime: moment().subtract(-200, "days").unix()
				}).then(res => {
					if (res.code == 1) {
						that.data = []
						res.data.forEach((type) => {
							that.data.push(moment(moment.unix(type.duty).format("YYYY-MM-DD")).unix())
						});
						uni.setStorageSync('dutydata', that.data)
						that.show = false
						that.$nextTick(() => {
							that.show = true
						})
						that.$refs.calendar.setFormatter(this.formatter)
					}
				}).catch(err => {

				})
			},
		}
	};
</script>

<style scoped lang="scss">
</style>

喜欢 (2)