| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644 |
- import {
- getMemoList,
- getMemoDetail,
- addMemo,
- updateMemo,
- deleteMemo,
- deleteMemoBatch,
- } from '@/api/memoManage.js'
- import { getAuditTaskList } from '@/api/auditInitiation.js'
- import moment from 'moment'
- export const memoManageMixin = {
- data() {
- // 表格列配置
- const tableColumns = [
- {
- prop: 'reminderType',
- label: '提醒',
- width: 80,
- headerAlign: 'center',
- align: 'center',
- slotName: 'reminder-type',
- },
- {
- prop: 'task',
- label: '成本监审任务',
- width: 160,
- headerAlign: 'center',
- align: 'center',
- },
- {
- prop: 'memoDate',
- label: '日期',
- width: 120,
- headerAlign: 'center',
- align: 'center',
- },
- {
- prop: 'title',
- label: '标题',
- width: 120,
- headerAlign: 'center',
- align: 'center',
- },
- {
- prop: 'content',
- label: '内容',
- minWidth: 200,
- headerAlign: 'center',
- align: 'center',
- },
- {
- prop: 'action',
- label: '操作',
- width: 150,
- headerAlign: 'center',
- align: 'center',
- slotName: 'action-buttons',
- showOverflowTooltip: false,
- },
- ]
- // 按项目查询标签页的表格列配置(项目名称列宽更大)
- const projectTableColumns = [
- ...tableColumns.map((col) => {
- if (col.prop === 'projectName') {
- return { ...col, width: 220 }
- } else if (col.prop === 'title') {
- return { ...col, width: 200 }
- } else if (col.prop === 'content') {
- return { ...col, minWidth: 300 }
- }
- return col
- }),
- ]
- return {
- type: 'index', // 列表类型:index-首页列表,memoManage-备忘录列表
- dictData: {
- reminderType: [],
- },
- activeTab: 'calendar',
- selectedDate: new Date(),
- today: new Date(),
- // 表格配置
- tableColumns,
- projectTableColumns,
- searchParams: {
- year: '',
- projectId: '',
- content: '',
- startTime: '',
- endTime: '',
- page: 1,
- pageSize: 50,
- },
- listTotal: 0,
- memoList: [],
- formTitle: '',
- formDisabled: false,
- formRules: {
- projectId: [
- {
- required: true,
- message: '请选择成本监审项目',
- trigger: 'change',
- },
- ],
- title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
- content: [{ required: true, message: '请输入内容', trigger: 'blur' }],
- memoDate: [
- { required: true, message: '请选择日期', trigger: 'change' },
- ],
- startTime: [
- { required: true, message: '请选择开始时间', trigger: 'change' },
- ],
- endTime: [
- { required: true, message: '请选择结束时间', trigger: 'change' },
- ],
- reminderType: [
- { required: true, message: '请选择提醒方式', trigger: 'change' },
- ],
- // attachmentName: [
- // { required: true, message: '请上传附件', trigger: 'change' },
- // ],
- },
- editForm: {
- attachmentName: '',
- attachmentSize: 0,
- attachmentUrl: '',
- content: '',
- memoDate: '',
- projectId: 0,
- reminderType: '0',
- task: '',
- startTime: '',
- endTime: '',
- title: '',
- },
- // 时间数据字段已移除,改为直接使用editForm中的startTime和endTime
- fileList: [],
- isEditDialogOpen: false,
- auditTaskList: [],
- lunarInfo: {},
- }
- },
- computed: {
- // 获取指定日期的任务列表
- getTasksByDate() {
- return (date) => {
- const dateStr = moment(date).format('YYYY-MM-DD')
- return this.memoList.filter((task) => task.memoDate === dateStr)
- }
- },
- },
- watch: {
- // // 监听选中日期变化,更新搜索参数
- selectedDate: {
- handler(newVal) {
- if (newVal) {
- this.lunarInfo = this.getLunarInfo(this.selectedDate)
- this.searchParams.memoDate = moment(newVal).format('YYYY-MM-DD')
- this.handleSearch()
- }
- },
- deep: true,
- },
- },
- methods: {
- // 优化后的获取详情方法,不再接收单个item参数
- async getTasksByDateList() {
- if (this.memoList.length > 0) {
- try {
- // 使用Promise.all并行获取所有备忘录的详情
- const detailPromises = this.memoList.map(async (memo, index) => {
- try {
- const params = {
- id: memo.id,
- }
- const res = await getMemoDetail(params)
- if (res.code === 200 && res.value) {
- // 更新原数组中的数据
- const memoIndex = this.memoList.findIndex(
- (item) => item.id === memo.id
- )
- if (memoIndex !== -1) {
- this.memoList[memoIndex] = {
- ...this.memoList[memoIndex],
- ...res.value,
- }
- }
- // 返回更新后的数据
- return {
- ...memo,
- ...res.value,
- }
- }
- return memo // 如果获取失败,返回原数据
- } catch (err) {
- console.error('获取备忘录详情失败:', memo.id, err)
- return memo // 发生错误时返回原数据
- }
- })
- // 等待所有详情请求完成
- this.memoList = await Promise.all(detailPromises)
- } catch (error) {
- console.error('批量获取备忘录详情失败:', error)
- // 发生错误时返回原始列表
- }
- }
- },
- // 根据提醒类型获取对应的颜色
- getReminderTypeColor(type) {
- const colorMap = {
- 1: '#c0c4cc', // 不提醒 - 浅灰色
- 2: '#f56c6c', // 提前1小时 - 红色
- 3: '#e6a23c', // 提前2小时 - 橙色
- 4: '#e6a23c', // 提前3小时 - 橙色
- 5: '#73c0de', // 提前1天 - 天蓝色
- 6: '#98fb98', // 提前2天 - 浅绿色
- 7: '#c0c4cc', // 提前3天 - 浅灰色
- }
- return colorMap[type] || '#c0c4cc'
- },
- // 时间处理逻辑已移除,改为直接使用editForm中的startTime和endTime
- // 优化 saveFiles 方法
- saveFiles(data) {
- console.log('saveFiles', data)
- this.fileList = data
- this.editForm.attachmentName = data[0].fileName
- this.editForm.attachmentSize = data[0].fileSize
- this.editForm.attachmentUrl = data[0].savePath
- },
- // 优化 removeFile 方法
- removeFile(index, removedFile, currentFiles) {
- this.fileList = []
- this.editForm.attachmentName = ''
- this.editForm.attachmentSize = 0
- this.editForm.attachmentUrl = ''
- },
- // 获取监审任务列表
- async getAuditTaskList() {
- try {
- let params = {
- projectName: '',
- }
- const res = await getAuditTaskList(params)
- console.log('监审任务列表数据:', res)
- if (res.code == 200) {
- this.auditTaskList = res.value || []
- }
- } catch (error) {
- console.error('获取监审任务列表数据失败:', error)
- }
- },
- // 日历选择日期
- handleDateClick(date, data) {
- const dateStr = moment(date).format('YYYY-MM-DD')
- // const tasks = this.memoList.filter((task) => task.memoDate === dateStr)
- this.searchParams.memoDate = dateStr
- this.handleSearch()
- // if (tasks.length > 0) {
- // this.searchParams.startTime = dateStr
- // this.searchParams.endTime = dateStr
- // }
- },
- // 获取提醒类型的文本描述
- getReminderTypeText(type) {
- const textMap = {
- 0: '不提醒',
- 1: '提前1小时',
- 2: '提前2小时',
- 3: '提前3小时',
- 4: '提前1天',
- 5: '提前2天',
- 6: '提前3天',
- }
- return textMap[type] || '不提醒'
- },
- /**
- * 获取指定日期的农历信息,包括节日和节气信息
- * @param {Date} date - 日期对象
- * @returns {Object|null} 包含公历农历详细信息的对象,如果超出范围则返回基本信息对象
- */
- getLunarInfo(date) {
- try {
- // 从日期对象获取年月日
- const year = date.getFullYear()
- const month = date.getMonth() + 1 // 月份从1开始
- const day = date.getDate()
- // 检查是否在solar2lunar支持的范围内 (1900.1.31~3000.12.31)
- const isInRange =
- (year > 1900 ||
- (year === 1900 && month > 1) ||
- (year === 1900 && month === 1 && day >= 31)) &&
- (year < 3000 ||
- (year === 3000 && month < 12) ||
- (year === 3000 && month === 12 && day <= 31))
- if (window.calendar && window.calendar.solar2lunar && isInRange) {
- // 在范围内,调用calendar-converter.js中的solar2lunar函数
- const lunarDate = window.calendar.solar2lunar(year, month, day)
- if (lunarDate !== -1) {
- return lunarDate || { IDayCn: '' }
- }
- }
- // 超出范围时,返回基本日期信息
- console.warn(
- `日期 ${year}-${month}-${day} 超出了农历转换支持的范围(1900.1.31~3000.12.31)`
- )
- return this._getBasicDateInfo(year, month, day)
- } catch (error) {
- // 出错时也返回基本日期信息
- return this._getBasicDateInfo(
- date.getFullYear(),
- date.getMonth() + 1,
- date.getDate()
- )
- }
- },
- /**
- * 获取基本的日期信息,当超出solar2lunar范围时使用
- * @private
- * @param {number} year - 阳历年
- * @param {number} month - 阳历月
- * @param {number} day - 阳历日
- * @returns {Object} 基本日期信息对象
- */
- _getBasicDateInfo(year, month, day) {
- const dateStr = `${year}-${month}-${day}`
- // 创建基本信息对象,格式尽量与solar2lunar返回的一致
- return {
- date: dateStr,
- lunarDate: '超出转换范围',
- festival: null,
- lunarFestival: null,
- lYear: year,
- lMonth: month,
- lDay: day,
- Animal: null,
- IMonthCn: '',
- IDayCn: '',
- cYear: year,
- cMonth: month,
- cDay: day,
- gzYear: '',
- gzMonth: '',
- gzDay: '',
- isToday: false,
- isLeap: false,
- nWeek: new Date(year, month - 1, day).getDay() || 7, // 周日为7
- ncWeek: `星期${
- ['日', '一', '二', '三', '四', '五', '六'][
- new Date(year, month - 1, day).getDay()
- ]
- }`,
- isTerm: false,
- Term: null,
- astro: '',
- outOfRange: true, // 标记为超出范围
- }
- },
- // 上一个月
- handlePrevMonth() {
- this.selectedDate = moment(this.selectedDate)
- .subtract(1, 'month')
- .toDate()
- },
- // 下一个月
- handleNextMonth() {
- this.selectedDate = moment(this.selectedDate).add(1, 'month').toDate()
- },
- // 获取备忘录列表
- async handleSearch() {
- try {
- let params = {
- ...this.searchParams,
- // memoDate:''
- }
- let _url = ''
- if (this.type === 'memoManage') {
- _url = '/api/costProjectMemo/v1/pageList'
- } else {
- _url = '/api/costProjectMemo/v1/pageIndexList'
- }
- if (this.activeTab == 'project') {
- delete params.memoDate
- } else if (this.activeTab == 'calendar') {
- params.memoDate = this.searchParams.memoDate
- delete params.year
- }
- const res = await getMemoList(_url, params)
- if (res.value && res.value.records.length > 0) {
- this.memoList = res.value.records || []
- // 只处理day字段,不调用详情接口
- this.memoList.forEach((item) => {
- const date = new Date(item.memoDate)
- item.day = date.getDate()
- })
- // 在列表数据设置完成后,只调用一次详情接口获取所有需要的详情
- await this.getTasksByDateList()
- this.listTotal = res.value.total || 0
- } else {
- this.memoList = []
- this.listTotal = 0
- }
- } catch (error) {
- console.error('获取数据失败:', error)
- }
- },
- handleReset() {
- this.searchParams = {
- page: 1,
- pageSize: 10,
- startTime: '',
- endTime: '',
- year: '',
- projectId: '',
- content: '',
- }
- this.handleSearch()
- },
- handleCurrentChange(val) {
- this.searchParams.pageNum = val
- this.handleSearch()
- },
- handleSizeChange(val) {
- this.searchParams.pageSize = val
- this.handleSearch()
- },
- // 处理分页变化
- handlePaginationChange({ currentPage, pageSize }) {
- this.searchParams.page = currentPage
- this.searchParams.pageSize = pageSize
- this.handleSearch()
- },
- // 初始化日历相关数据
- initCalendarData(type) {
- this.type = type
- this.selectedDate = new Date()
- this.lunarInfo = this.getLunarInfo(this.selectedDate)
- // this.handleSearch(num)
- },
- onTabChange(tab) {
- this.searchParams.startTime = ''
- this.searchParams.endTime = ''
- this.searchParams.year = ''
- this.searchParams.projectId = ''
- this.searchParams.content = ''
- this.searchParams.page = 1
- if (tab.name == 'calendar') {
- this.setCalendarTitle()
- this.handleSearch()
- } else {
- this.handleSearch()
- }
- },
- // prevMonth() {
- // console.log('日历切换:上一个月')
- // if (this.currentMonth === 1) {
- // this.currentYear--
- // this.currentMonth = 12
- // } else {
- // this.currentMonth--
- // }
- // this.setCalendarTitle()
- // },
- // nextMonth() {
- // console.log('日历切换:下一个月')
- // if (this.currentMonth === 12) {
- // this.currentYear++
- // this.currentMonth = 1
- // } else {
- // this.currentMonth++
- // }
- // this.setCalendarTitle()
- // },
- handleAdd() {
- this.getAuditTaskList()
- this.formTitle = '添加备忘录'
- this.formDisabled = false
- this.editForm = {
- attachmentName: '',
- attachmentSize: 0,
- attachmentUrl: '',
- content: '',
- memoDate: '',
- projectId: '',
- reminderType: '0',
- task: '',
- startTime: '',
- endTime: '',
- title: '',
- }
- this.fileList = []
- this.isEditDialogOpen = true
- },
- // 获取备忘录详情
- async getMemoDetail(row) {
- this.getAuditTaskList()
- try {
- let params = {
- id: row.id,
- }
- const res = await getMemoDetail(params)
- if (res.code == 200) {
- // 处理时间范围
- let startTime = ''
- let endTime = ''
- const data = { ...row, ...res.value }
- if (data.timePeriod) {
- const timeRange = data.timePeriod.split('-')
- if (timeRange.length === 2) {
- startTime = timeRange[0]
- endTime = timeRange[1]
- }
- }
- this.editForm = {
- ...data,
- startTime: startTime,
- endTime: endTime,
- }
- // 删除timePeriod字段避免混淆
- delete this.editForm.timePeriod
- this.fileList = this.editForm.attachmentUrl
- ? [res.value.attachmentUrl]
- : []
- this.isEditDialogOpen = true
- }
- } catch (error) {
- console.error('获取详情数据失败:', error)
- }
- },
- handleView(row) {
- this.formTitle = '查看备忘录详情'
- this.formDisabled = true
- this.getMemoDetail(row)
- },
- handleEdit(row) {
- this.formTitle = '编辑备忘录'
- this.formDisabled = false
- this.getMemoDetail(row)
- },
- handleDelete(row) {
- this.$confirm('确定要删除该数据吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- })
- .then(async () => {
- const response = await deleteMemo(row.id)
- this.$message.success('删除成功')
- // 重新加载数据
- this.handleSearch()
- })
- .catch(() => {
- this.$message.info('已取消删除')
- })
- },
- handleSave() {
- this.$refs['ruleForm'].validate((valid) => {
- if (valid) {
- let task = this.auditTaskList.find(
- (item) => item.projectId === this.editForm.projectId
- )
- const formData = {
- ...this.editForm,
- areaCode: task.areaCode,
- }
- // 合并开始时间和结束时间为timePeriod格式
- formData.timePeriod = `${formData.startTime}-${formData.endTime}`
- // 删除单独的时间字段,避免后端接收多余数据
- delete formData.startTime
- delete formData.endTime
- if (formData.id) {
- this.updateMemo(formData)
- } else {
- this.addMemo(formData)
- }
- } else {
- console.log('表单验证失败')
- }
- })
- },
- // 添加备忘录
- async addMemo(formData) {
- try {
- const res = await addMemo(formData)
- if (res.code == 200) {
- this.$message.success('添加成功')
- this.handleSearch()
- this.isEditDialogOpen = false
- }
- } catch (error) {
- console.error('添加失败:', error)
- this.$message.error('添加失败')
- }
- },
- // 更新备忘录
- async updateMemo(formData) {
- delete formData.day
- delete formData.projectName
- try {
- const res = await updateMemo(formData)
- if (res.code == 200) {
- this.$message.success('更新成功')
- this.handleSearch()
- this.isEditDialogOpen = false
- }
- } catch (error) {
- console.error('更新失败:', error)
- this.$message.error('更新失败')
- }
- },
- // 设置日历标题
- setCalendarTitle() {
- // 可以在这里添加设置日历标题的逻辑
- let lunarInfo = this.lunarInfo
- return `${lunarInfo.cYear}年${lunarInfo.cMonth}月 农历${lunarInfo.gzYear}年【${lunarInfo.Animal}】`
- },
- },
- }
|