Files
ks-app-employment-service/packageRc/pages/demand/components/otherService.vue

480 lines
11 KiB
Vue
Raw Normal View History

2025-11-03 12:30:37 +08:00
<!--
* @Date: 2024-10-08 14:29:36
2025-11-03 17:48:14 +08:00
* @LastEditors: shirlwang
2025-11-05 17:07:17 +08:00
* @LastEditTime: 2025-11-04 16:14:41
2025-11-03 12:30:37 +08:00
-->
<template>
<view class="container">
2025-11-05 17:07:17 +08:00
<scroll-view scroll-y="true" :style="{height: edit?'calc(100vh - 380rpx)':'calc(100vh - 194rpx)'}">
2025-11-03 12:30:37 +08:00
<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"
style="font-weight: normal;display: flex;" @click="edit=true">编辑<view class="icon-right"></view></view>
</view>
<view class="inner-part">
<view class="self-form">
<view class="form-item">
<view class="form-label">姓名 <text class="required">*</text></view>
<view v-if="name" style="width: 100%;" class="disabledLine">
{{ formData.personName || '请选择' }}
</view>
<view v-else style="width: 100%;" @click="openPersonChooser"
:class="{disabledLine: !edit||!canChoosePerson, noValue: !formData.personName}">
{{ formData.personName || '请选择' }}
</view>
<view class="icon-right"></view>
</view>
<view class="form-item">
<view class="form-label">需求说明 <text class="required">*</text></view>
<textarea :disabled="!edit" v-model="formData.jobDescription" placeholder="请输入" :class="['form-textarea', { 'form-textarea-disabled': !edit }]"></textarea>
</view>
</view>
</view>
</view>
<!-- 办理完成后 需求说明 -->
</scroll-view>
<choose-person ref="personChooser" @confirm="personNameConfirm" />
<view class="button-area" v-if="edit">
<view class="btn" @click="cancelPage">取消</view>
<view class="btn reset" @click="formData.id ? getDetail(formData.id) : setDefaultValues()">重置</view>
<view class="btn save" @click="saveInfo">保存</view>
</view>
</view>
</template>
<script>
2025-11-05 17:07:17 +08:00
import {
getPersonBase
2025-11-07 18:38:01 +08:00
} from "@/packageRc/apiRc/person";
2025-11-05 17:07:17 +08:00
import {
addPersonDemand,
updatePersonDemand,
getPersonDemand
2025-11-07 18:38:01 +08:00
} from "@/packageRc/apiRc/needs/personDemand";
2025-11-05 17:07:17 +08:00
import ImageUpload from '/packageRc/components/ImageUpload'
import ChoosePerson from '/packageRc/pages/needs/components/choosePerson';
import {
listJobType
2025-11-07 18:38:01 +08:00
} from "@/packageRc/apiRc/jobType/index";
2025-11-05 17:07:17 +08:00
import dayjs from "dayjs";
2025-11-03 12:30:37 +08:00
export default {
components: {
2025-11-05 17:07:17 +08:00
ChoosePerson,
ImageUpload
},
2025-11-03 12:30:37 +08:00
props: {
2025-11-05 17:07:17 +08:00
needId: {
2025-11-03 12:30:37 +08:00
type: String,
default: ''
},
name: {
type: String,
default: ''
}
},
data() {
return {
2025-11-05 17:07:17 +08:00
fileList: [],
2025-11-03 12:30:37 +08:00
edit: true,
2025-11-05 17:07:17 +08:00
personBase: {},
dates: {},
2025-11-03 12:30:37 +08:00
formData: {
2025-11-05 17:07:17 +08:00
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,
2025-11-03 12:30:37 +08:00
}
},
onReady() {
2025-11-05 17:07:17 +08:00
this.$refs.uForm.setRules(this.rules)
2025-11-03 12:30:37 +08:00
},
created() {
this.loading = true;
},
methods: {
cancelPage() {
2025-11-05 17:07:17 +08:00
if (this.formData.id) {
2025-11-03 12:30:37 +08:00
this.edit = false;
2025-11-05 17:07:17 +08:00
this.getDetail(this.formData.id)
} else {
uni.navigateBack()
2025-11-03 12:30:37 +08:00
}
},
2025-11-05 17:07:17 +08:00
workTypeRemoteMethod(key) {
listJobType({
workTypeName: key,
pageNum: 1,
pageSize: 50
}).then(
(res) => {
this.jobTypeList = res.rows;
}
);
},
2025-11-03 12:30:37 +08:00
openPersonChooser() {
if (this.edit && this.canChoosePerson) {
this.$refs.personChooser.open();
}
},
personNameConfirm(event) {
this.formData.personName = event.name
this.formData.personId = event.id
this.formData.userId = event.userId
2025-11-05 17:07:17 +08:00
this.formNameChange();
2025-11-03 12:30:37 +08:00
this.$forceUpdate();
},
2025-11-05 17:07:17 +08:00
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);
2025-11-03 12:30:37 +08:00
}
2025-11-05 17:07:17 +08:00
}
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) {
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();
2025-11-03 12:30:37 +08:00
},
goBack() {
uni.navigateBack();
},
2025-11-05 17:07:17 +08:00
cancelPicker(type) {
this.show[type] = false
this.$forceUpdate();
},
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()
2025-11-03 12:30:37 +08:00
}
},
2025-11-05 17:07:17 +08:00
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();
2025-11-03 12:30:37 +08:00
try {
2025-11-05 17:07:17 +08:00
// 验证表单
const isValid = await this.$refs.uForm.validate();
if (!isValid) {
throw new Error('请检查必填项填写');
2025-11-03 12:30:37 +08:00
}
2025-11-05 17:07:17 +08:00
// 显示全局加载
// 根据 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 = '保存成功';
2025-11-03 12:30:37 +08:00
}
2025-11-05 17:07:17 +08:00
// 检查响应码是否为200
if (response.code === 200) {
this.$u.toast(successMessage);
// 如果是编辑模式,关闭编辑状态;否则返回上一页
if (this.formData.id) {
2025-11-03 12:30:37 +08:00
this.edit = false;
} else {
2025-11-05 17:07:17 +08:00
await this.$delay(1000); // 延迟1秒后返回上一页
uni.navigateBack();
2025-11-03 12:30:37 +08:00
}
2025-11-05 17:07:17 +08:00
} else {
throw new Error('服务器响应错误');
}
2025-11-03 12:30:37 +08:00
} catch (error) {
2025-11-05 17:07:17 +08:00
if(error.length){
this.$u.toast('请填写完整信息!');
}else{
this.$u.toast('系统错误,请联系管理员!');
}
2025-11-03 12:30:37 +08:00
} finally {
2025-11-05 17:07:17 +08:00
// 确保加载页总是会被隐藏
2025-11-03 12:30:37 +08:00
uni.hideLoading();
}
}
2025-11-05 17:07:17 +08:00
// 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'
// })
// })
// }
2025-11-03 12:30:37 +08:00
}
}
</script>
2025-11-03 17:48:14 +08:00
<style lang="scss">
2025-11-05 17:07:17 +08:00
@import "/packageRc/static/scss/index.scss";
2025-11-03 12:30:37 +08:00
.inner {
background: #fff;
2025-11-03 17:48:14 +08:00
width: calc(100% - 64rpx);
margin: 0 auto;
box-sizing: border-box;
2025-11-03 12:30:37 +08:00
border-radius: 16rpx;
padding: 32rpx;
margin-bottom: 24rpx;
2025-11-05 17:07:17 +08:00
2025-11-03 12:30:37 +08:00
}
.inner-part {
width: 100%;
}
2025-11-05 17:07:17 +08:00
2025-11-03 12:30:37 +08:00
.self-form {
width: 100%;
}
.form-item {
display: flex;
align-items: flex-start;
margin-bottom: 24rpx;
background-color: #fff;
border-radius: 8rpx;
2025-11-03 17:48:14 +08:00
padding: 24rpx 0;
2025-11-03 12:30:37 +08:00
}
.form-label {
width: 200rpx;
font-size: 28rpx;
color: #333;
flex-shrink: 0;
line-height: 48rpx;
}
.required {
color: #f56c6c;
margin-left: 4rpx;
}
.form-textarea {
flex: 1;
border: none;
outline: none;
font-size: 28rpx;
color: #333;
background: none;
min-height: 120rpx;
line-height: 40rpx;
}
.form-textarea-disabled {
color: #909399;
background-color: #f5f7fa;
}
.icon-right {
width: 40rpx;
height: 40rpx;
display: flex;
align-items: center;
justify-content: center;
color: #A6A6A6;
margin-left: 16rpx;
}
2025-11-05 17:07:17 +08:00
2025-11-03 12:30:37 +08:00
.button-area {
padding: 24rpx 32rpx 68rpx;
background: #fff;
display: flex;
box-sizing: border-box;
margin-top: 40rpx;
border-radius: 16px 16px 0px 0px;
2025-11-05 17:07:17 +08:00
box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
2025-11-03 12:30:37 +08:00
.btn {
line-height: 72rpx;
width: 176rpx;
margin-right: 16rpx;
font-size: 28rpx;
border: 1px solid #B8C5D4;
color: #282828;
text-align: center;
border-radius: 8rpx;
}
.reset {
background: #DCE2E9;
}
.save {
background: linear-gradient(103deg, #1D64CF 0%, #1590D4 99%);
color: #fff;
border: 0;
flex-grow: 1;
}
}
.self-form {
width: 100%;
}
.form-item {
display: flex;
align-items: flex-start;
margin-bottom: 24rpx;
background-color: #fff;
border-radius: 8rpx;
padding: 24rpx;
}
.form-label {
width: 200rpx;
font-size: 28rpx;
color: #333;
flex-shrink: 0;
line-height: 48rpx;
}
.required {
color: #f56c6c;
margin-left: 4rpx;
}
.form-textarea {
flex: 1;
border: none;
outline: none;
font-size: 28rpx;
color: #333;
background: none;
min-height: 120rpx;
line-height: 40rpx;
}
.form-textarea-disabled {
color: #909399;
background-color: #f5f7fa;
}
.icon-right {
width: 40rpx;
height: 40rpx;
display: flex;
align-items: center;
justify-content: center;
color: #A6A6A6;
margin-left: 16rpx;
}
.noValue {
color: rgb(192, 196, 204);
}
.disabledLine {
background: rgb(245, 247, 250);
cursor: not-allowed;
}
</style>