添加页面
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
<!--
|
||||
* @Date: 2024-10-08 14:29:36
|
||||
* @LastEditors: shirlwang
|
||||
* @LastEditTime: 2025-11-03 16:07:40
|
||||
* @LastEditTime: 2025-11-04 16:14:41
|
||||
-->
|
||||
<template>
|
||||
<view class="container">
|
||||
<scroll-view scroll-y="true" >
|
||||
<scroll-view scroll-y="true" :style="{height: edit?'calc(100vh - 380rpx)':'calc(100vh - 194rpx)'}">
|
||||
<view class="inner">
|
||||
<view class="part-title" style="display: flex;justify-content: space-between;">需求信息
|
||||
<view v-if="!edit&&formData.id&&formData.currentStatus!=3" class="btn"
|
||||
@@ -32,12 +32,8 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 办理完成后 需求说明 -->
|
||||
|
||||
|
||||
</scroll-view>
|
||||
|
||||
<choose-person ref="personChooser" @confirm="personNameConfirm" />
|
||||
<view class="button-area" v-if="edit">
|
||||
<view class="btn" @click="cancelPage">取消</view>
|
||||
@@ -48,16 +44,28 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getPersonBase } from "@/packageRc/api/personinfo/index";
|
||||
import { addPersonDemand, updatePersonDemand, getPersonDemand } from "@/packageRc/api/needs/personDemand";
|
||||
//import reqComp from './req-comp';
|
||||
import {
|
||||
getPersonBase
|
||||
} from "@/apiRc/person";
|
||||
import {
|
||||
addPersonDemand,
|
||||
updatePersonDemand,
|
||||
getPersonDemand
|
||||
} from "@/apiRc/needs/personDemand";
|
||||
import ImageUpload from '/packageRc/components/ImageUpload'
|
||||
import ChoosePerson from '/packageRc/pages/needs/components/choosePerson';
|
||||
import {
|
||||
listJobType
|
||||
} from "@/apiRc/jobType/index";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
export default {
|
||||
components: {
|
||||
// reqComp
|
||||
},
|
||||
ChoosePerson,
|
||||
ImageUpload
|
||||
},
|
||||
props: {
|
||||
needId: {
|
||||
needId: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
@@ -68,60 +76,65 @@ import { addPersonDemand, updatePersonDemand, getPersonDemand } from "@/packageR
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
fileList: [],
|
||||
edit: true,
|
||||
canChoosePerson: false,
|
||||
personBase: {},
|
||||
dates: {},
|
||||
formData: {
|
||||
id: '',
|
||||
personName: '',
|
||||
personId: '',
|
||||
demandType:"9",
|
||||
userId: '',
|
||||
demandTitle: '',
|
||||
jobDescription: '',
|
||||
actualSolveDate: '',
|
||||
actualSolvePeople: '',
|
||||
solveDesc: '',
|
||||
fileUrl: '',
|
||||
currentStatus: ''
|
||||
}
|
||||
isAcceptAssistance: '',
|
||||
isAcceptApprovalResult: '',
|
||||
qtxqsm: ''
|
||||
},
|
||||
rules: {
|
||||
personName: [{
|
||||
required: true,
|
||||
message: '请填写姓名',
|
||||
trigger: ['blur', 'change'],
|
||||
}, ],
|
||||
qtxqsm: [{
|
||||
required: true,
|
||||
message: '请填写需求说明',
|
||||
trigger: ['blur', 'change'],
|
||||
}, ],
|
||||
},
|
||||
dict: {},
|
||||
show: {},
|
||||
currentCityArr: [],
|
||||
originalDept: [],
|
||||
currentCity: '请选择',
|
||||
bysj: '',
|
||||
loading: false,
|
||||
jobTypeList: [],
|
||||
route: {},
|
||||
canChoosePerson: false,
|
||||
}
|
||||
},
|
||||
onReady() {
|
||||
// 组件已准备就绪
|
||||
this.$refs.uForm.setRules(this.rules)
|
||||
},
|
||||
created() {
|
||||
this.loading = true;
|
||||
// 直接使用传入的参数设置姓名信息
|
||||
if(this.name && this.needId) {
|
||||
this.formData.personName = this.name;
|
||||
this.formData.personId = this.needId;
|
||||
this.formData.userId = this.needId;
|
||||
}
|
||||
// 如果需要获取详情
|
||||
if (this.needId) {
|
||||
this.getDetail(this.needId);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
cancelPage() {
|
||||
if (!this.formData.id) {
|
||||
this.$u.navigateBack();
|
||||
} else {
|
||||
if (this.formData.id) {
|
||||
this.edit = false;
|
||||
this.getDetail(this.formData.id);
|
||||
this.getDetail(this.formData.id)
|
||||
} else {
|
||||
uni.navigateBack()
|
||||
}
|
||||
},
|
||||
// workTypeRemoteMethod(key) {
|
||||
// listJobType({
|
||||
// workTypeName: key,
|
||||
// pageNum: 1,
|
||||
// pageSize: 50
|
||||
// }).then(
|
||||
// (res) => {
|
||||
// this.jobTypeList = res.rows;
|
||||
// }
|
||||
// );
|
||||
// },
|
||||
workTypeRemoteMethod(key) {
|
||||
listJobType({
|
||||
workTypeName: key,
|
||||
pageNum: 1,
|
||||
pageSize: 50
|
||||
}).then(
|
||||
(res) => {
|
||||
this.jobTypeList = res.rows;
|
||||
}
|
||||
);
|
||||
},
|
||||
openPersonChooser() {
|
||||
if (this.edit && this.canChoosePerson) {
|
||||
this.$refs.personChooser.open();
|
||||
@@ -131,110 +144,178 @@ import { addPersonDemand, updatePersonDemand, getPersonDemand } from "@/packageR
|
||||
this.formData.personName = event.name
|
||||
this.formData.personId = event.id
|
||||
this.formData.userId = event.userId
|
||||
this.formNameChange();
|
||||
this.$forceUpdate();
|
||||
},
|
||||
|
||||
|
||||
|
||||
changeFile(e) {
|
||||
// 清空当前的 fileUrl 数组
|
||||
this.formData.fileUrl = [];
|
||||
// 如果 e 有长度(即用户选择了文件)
|
||||
if (e.length) {
|
||||
// 遍历每个文件对象并获取其 url
|
||||
for (let data of e) {
|
||||
const url = data.data ? data.data.url : data.url;
|
||||
this.formData.fileUrl.push(url);
|
||||
}
|
||||
}
|
||||
this.formData.fileUrl = this.$arrayToString(this.formData.fileUrl)
|
||||
},
|
||||
addOne() {
|
||||
this.formData = {}
|
||||
this.getPersonInfo()
|
||||
if(this.name){
|
||||
this.formData.personName = this.name
|
||||
this.formData.userId = this.needid
|
||||
}
|
||||
this.edit = true
|
||||
|
||||
},
|
||||
getDetail(id) {
|
||||
this.$request({
|
||||
url: '/mini/demand/getPersonDemandById',
|
||||
method: 'GET',
|
||||
data: {
|
||||
id: id
|
||||
}
|
||||
}).then(res => {
|
||||
if (res.code == 200) {
|
||||
this.formData = res.data;
|
||||
}
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
getPersonDemand(id).then(res => {
|
||||
this.formData = res.data;
|
||||
this.edit = false
|
||||
})
|
||||
},
|
||||
confirmDate(type, e) {
|
||||
this.show[type] = false;
|
||||
let date = new Date(e.value)
|
||||
this.formData[type] =
|
||||
`${date.getFullYear()}-${(date.getMonth()+1)>9?(date.getMonth()+1):('0'+(date.getMonth()+1))}-${date.getDate()>9?date.getDate():('0'+date.getDate())}`
|
||||
this.$forceUpdate();
|
||||
},
|
||||
goBack() {
|
||||
uni.navigateBack();
|
||||
},
|
||||
|
||||
setName() {
|
||||
// 确保personName存在
|
||||
if (!this.formData.personName) {
|
||||
this.formData.personName = '未知用户';
|
||||
}
|
||||
let date = new Date();
|
||||
let year = date.getFullYear();
|
||||
let month = date.getMonth() + 1;
|
||||
month = month < 10 ? '0' + month : month;
|
||||
let day = date.getDate();
|
||||
day = day < 10 ? '0' + day : day;
|
||||
this.formData.demandTitle = `${this.formData.personName}_于${year}-${month}-${day}_提出其他需求`;
|
||||
cancelPicker(type) {
|
||||
this.show[type] = false
|
||||
this.$forceUpdate();
|
||||
},
|
||||
saveInfo() {
|
||||
console.log("执行")
|
||||
getDictLabel(value, list) {
|
||||
if (list) {
|
||||
let arr = list.filter(ele => ele.dictValue == value)
|
||||
if (arr.length) {
|
||||
return arr[0].dictLabel
|
||||
} else {
|
||||
return '请选择'
|
||||
}
|
||||
}
|
||||
},
|
||||
pickerConfirm(type, event) {
|
||||
this.show[type] = false
|
||||
this.formData[type] = event.value[0].dictValue
|
||||
this.$forceUpdate();
|
||||
},
|
||||
showPicker(type) {
|
||||
if (this.edit) {
|
||||
this.show[type] = true
|
||||
this.$forceUpdate()
|
||||
}
|
||||
},
|
||||
getPersonInfo() {
|
||||
this.loading = true;
|
||||
this.$store.dispatch("GetInfo").then((res) => {
|
||||
if (res.data.roles.indexOf('qunzhong') == -1) {
|
||||
this.canChoosePerson = true;
|
||||
} else {
|
||||
this.canChoosePerson = false;
|
||||
getPersonBase(res.data.user.userId).then(resp => {
|
||||
this.formData.personId = resp.data.id
|
||||
this.formData.userId = resp.data.userId
|
||||
this.formData.personName = resp.data.name
|
||||
this.formNameChange();
|
||||
this.$forceUpdate();
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
formNameChange() {
|
||||
let date = new Date()
|
||||
let day =
|
||||
`${date.getFullYear()}-${(date.getMonth()+1) + 1 > 9 ? (date.getMonth()+1) + 1: '0'+((date.getMonth()+1) + 1)}-${date.getDate() > 9 ? date.getDate(): '0'+date.getDate()}`
|
||||
const dayNew = dayjs(date).format("YYYY-MM-DD");
|
||||
this.formData.demandTitle = `${this.formData.personName}_于${dayNew}_提出其他需求`
|
||||
},
|
||||
async saveInfo() {
|
||||
uni.showLoading();
|
||||
try {
|
||||
// 验证必填项
|
||||
if (!this.formData.personName) {
|
||||
uni.showToast({
|
||||
title: '请选择姓名',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
// 验证表单
|
||||
const isValid = await this.$refs.uForm.validate();
|
||||
if (!isValid) {
|
||||
throw new Error('请检查必填项填写');
|
||||
}
|
||||
if (!this.formData.jobDescription) {
|
||||
uni.showToast({
|
||||
title: '请输入需求说明',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
// 显示全局加载
|
||||
|
||||
// 根据 formData 是否有 id 来决定是更新还是新增
|
||||
let response;
|
||||
let successMessage;
|
||||
this.formData.demandType = 9;
|
||||
// this.formData.userId = this.formData.personId
|
||||
if (this.formData.id) {
|
||||
response = await updatePersonDemand(this.formData);
|
||||
successMessage = '修改成功';
|
||||
} else {
|
||||
response = await addPersonDemand(this.formData);
|
||||
successMessage = '保存成功';
|
||||
}
|
||||
uni.showLoading({
|
||||
title: '保存中...'
|
||||
});
|
||||
this.setName();
|
||||
let params = {
|
||||
...this.formData,
|
||||
type: '3'
|
||||
};
|
||||
const requestFn = this.formData.id ? updatePersonDemand : addPersonDemand;
|
||||
requestFn(params).then(res => {
|
||||
if (res.code == 200) {
|
||||
uni.showToast({
|
||||
title: '保存成功',
|
||||
icon: 'success'
|
||||
});
|
||||
// 检查响应码是否为200
|
||||
if (response.code === 200) {
|
||||
this.$u.toast(successMessage);
|
||||
// 如果是编辑模式,关闭编辑状态;否则返回上一页
|
||||
if (this.formData.id) {
|
||||
this.edit = false;
|
||||
if (!this.formData.id) {
|
||||
this.formData.id = res.data;
|
||||
}
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.message,
|
||||
icon: 'none'
|
||||
});
|
||||
await this.$delay(1000); // 延迟1秒后返回上一页
|
||||
uni.navigateBack();
|
||||
}
|
||||
}).catch(err => {
|
||||
if (err.message) {
|
||||
uni.showToast({
|
||||
title: err.message,
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
throw new Error('服务器响应错误');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('保存失败:', error);
|
||||
if(error.length){
|
||||
this.$u.toast('请填写完整信息!');
|
||||
}else{
|
||||
this.$u.toast('系统错误,请联系管理员!');
|
||||
}
|
||||
} finally {
|
||||
// 确保加载页总是会被隐藏
|
||||
uni.hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
// saveInfo() {
|
||||
// this.$refs.uForm.validate().then(res => {
|
||||
// if (this.formData.id) {
|
||||
// updatePersonDemand(this.formData).then(res => {
|
||||
// if (res.code == 200) {
|
||||
// uni.showToast({
|
||||
// title: '修改成功'
|
||||
// })
|
||||
// this.edit = false;
|
||||
// }
|
||||
// })
|
||||
// } else {
|
||||
// addPersonDemand(this.formData).then(res => {
|
||||
// if (res.code == 200) {
|
||||
// uni.showToast({
|
||||
// title: '保存成功'
|
||||
// })
|
||||
// uni.navigateBack();
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// }).catch(() => {
|
||||
// uni.showToast({
|
||||
// title: '请检查必填项填写',
|
||||
// icon: 'none'
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.container {
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
background-color: #f7f7f7;
|
||||
}
|
||||
@import "/packageRc/static/scss/index.scss";
|
||||
|
||||
.inner {
|
||||
background: #fff;
|
||||
@@ -244,12 +325,14 @@ import { addPersonDemand, updatePersonDemand, getPersonDemand } from "@/packageR
|
||||
border-radius: 16rpx;
|
||||
padding: 32rpx;
|
||||
margin-bottom: 24rpx;
|
||||
|
||||
}
|
||||
|
||||
.inner-part {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
|
||||
.self-form {
|
||||
width: 100%;
|
||||
}
|
||||
@@ -302,14 +385,15 @@ import { addPersonDemand, updatePersonDemand, getPersonDemand } from "@/packageR
|
||||
margin-left: 16rpx;
|
||||
}
|
||||
|
||||
|
||||
.button-area {
|
||||
padding: 24rpx 32rpx 68rpx;
|
||||
width: 100%;
|
||||
background: #fff;
|
||||
display: flex;
|
||||
box-sizing: border-box;
|
||||
margin-top: 40rpx;
|
||||
border-radius: 16px 16px 0px 0px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
|
||||
|
||||
.btn {
|
||||
line-height: 72rpx;
|
||||
@@ -333,16 +417,6 @@ import { addPersonDemand, updatePersonDemand, getPersonDemand } from "@/packageR
|
||||
flex-grow: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.container {
|
||||
background-color: #f7f7f7;
|
||||
}
|
||||
|
||||
.inner {
|
||||
background-color: #f7f7f7;
|
||||
padding: 24rpx 32rpx;
|
||||
}
|
||||
|
||||
.self-form {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user