import { NForm, NFormItem, NInput, NSelect, NSpace, NButton, useMessage, NCascader, NDatePicker } from 'naive-ui' import type { TreeSelectOption } from 'naive-ui' import { defineComponent, onMounted, PropType, provide, reactive, ref } from 'vue' import UploadFile from '@/components/upload-file' import { sysNewsInformationSave, sysNewsInformationUpdate } from '../api' import dayjs from 'dayjs' import { getTimes } from '@/utils/dateUtil' export default defineComponent({ name: 'ad-operation', props: { type: { type: String, default: 'add' }, data: { type: Object as PropType, default: () => {} }, clientTypeList: { type: Array as PropType>, default: () => [] } }, emits: ['close', 'getList'], setup(props, { slots, attrs, emit }) { const forms = reactive({ type: 'OPEN_SCREEN_AD', clientType: null, title: null, coverImage: null, linkUrl: null, showTime: null, operationTime: null as any, onlineTime: null, offlineTime: null, status: false }) const btnLoading = ref(false) const formsRef = ref() const message = useMessage() // 提交记录 const onSubmit = async () => { formsRef.value.validate(async (error: any) => { if (error) return try { const { operationTime, ...res } = forms let onlineTime = '', offlineTime = '' if (operationTime) { onlineTime = dayjs(operationTime[0]).format('YYYY-MM-DD HH:mm:ss') offlineTime = dayjs(operationTime[1]).format('YYYY-MM-DD HH:mm:ss') } btnLoading.value = true if (props.type === 'add') { await sysNewsInformationSave({ ...res, ...getTimes(operationTime, ['onlineTime', 'offlineTime'], 'YYYY-MM-DD') }) message.success('添加成功') } else if (props.type === 'edit') { await sysNewsInformationUpdate({ ...res, ...getTimes(operationTime, ['onlineTime', 'offlineTime'], 'YYYY-MM-DD'), id: props.data.id }) message.success('修改成功') } emit('getList') emit('close') } catch { // } setTimeout(() => { btnLoading.value = false }, 100) }) } onMounted(async () => { // 初始化数据 if (props.type === 'edit') { const data = props.data forms.title = data.title forms.coverImage = data.coverImage forms.linkUrl = data.linkUrl forms.showTime = data.showTime if (data.onlineTime && data.offlineTime) { forms.operationTime = [ dayjs(data.onlineTime).valueOf(), dayjs(data.offlineTime).valueOf() ] } forms.clientType = data.clientType forms.status = data.status } }) // 只能输入数字 const onlyAllowNumber = (value: string) => !value || /^\d+$/.test(value) return () => (
{{ suffix: () => '秒' }} { return ts < dayjs(dayjs().format('YYYY-MM-DD')).valueOf() }} style={{ width: '100%', textAlign: 'left' }} /> emit('close')}> 取消 onSubmit()} loading={btnLoading.value} disabled={btnLoading.value} > 保存
) } })