xytSk-App/pages/xcrw/detail/dbForm.vue

436 lines
12 KiB
Vue
Raw Normal View History

2024-10-16 18:02:59 +08:00
<template>
2024-11-08 18:00:54 +08:00
<view class="contentItem" >
2024-10-31 17:39:30 +08:00
<uni-collapse>
<uni-collapse-item title-border="none" v-for="(item,index) in listData" :key="index" :border="false"
:show-animation="true">
<template v-slot:title>
<view style="display: flex;align-items: center;">
<text class="yuandian"></text>
<text>{{item.name}}</text>
<text style="margin-left: auto; color:#ff0000">{{getIsItem(item.children)}}项未填写</text>
</view>
</template>
2024-10-16 18:02:59 +08:00
<view class="xj-content">
<view class="xj-text" v-for="(o,i) in item.children" :key="i">
<text>{{o.itemDesc}}</text>
<view class="subsectioin">
2024-11-07 17:44:20 +08:00
<u--form labelPosition="left" :model="o" ref="uForm" label-width="80px">
2024-11-07 16:40:56 +08:00
<u-form-item label="状态" prop="isNormal" borderBottom required >
2024-10-31 17:39:30 +08:00
<u-subsection :list="list" :current="getNormal(o.isNormal)" mode="subsection"
@change="(e)=>change(e,o,index,i,'isNormal')"
2024-11-07 17:44:20 +08:00
style="width:150px"></u-subsection>
2024-10-16 18:02:59 +08:00
</u-form-item>
2024-11-07 16:40:56 +08:00
<view class="" v-if="o.isNormal==0">
2024-10-31 17:39:30 +08:00
<u-form-item label="现场图片" prop="inspectPics" borderBottom required>
<u-upload accept="image" :fileList="o.inspectPics"
@afterRead="(e)=>afterRead(e,o,index,i)"
@delete="(e)=>deletePic(e,o,index,i)" name="inspectPics" multiple
:maxCount="10"></u-upload>
</u-form-item>
<u-form-item label="现场视频" prop="inspectVideos" borderBottom>
<u-upload accept="video" :fileList="o.inspectVideos"
@afterRead="(e)=>afterRead(e,o,index,i)"
@delete="(e)=>deletePic(e,o,index,i)" name="inspectVideos" multiple
:maxCount="10"></u-upload>
</u-form-item>
2024-11-08 18:00:54 +08:00
<u-form-item label="问题描述" prop="problemDesc" borderBottom required>
<u--textarea v-model="o.problemDesc" placeholder="请输入内容"></u--textarea>
2024-10-31 17:39:30 +08:00
</u-form-item>
<u-form-item label="处理状态" prop="isHandle" borderBottom required>
<u-subsection :list="listStatus" :current="getHandle(o.isHandle)"
mode="subsection" @change="(e)=>change(e,o,index,i,'isHandle')"
2024-11-07 17:44:20 +08:00
style="width:150px"></u-subsection>
2024-10-31 17:39:30 +08:00
</u-form-item>
2024-11-07 16:40:56 +08:00
<view class="" v-if="o.isHandle == 1">
2024-11-11 13:57:46 +08:00
<u-form-item label="处理图片" prop="handlePics" borderBottom required>
2024-10-31 17:39:30 +08:00
<u-upload accept="image" :fileList="o.handlePics"
@afterRead="(e)=>afterRead(e,o,index,i)"
@delete="(e)=>deletePic(e,o,index,i)" name="handlePics" multiple
:maxCount="10"></u-upload>
</u-form-item>
2024-11-11 13:57:46 +08:00
<u-form-item label="处理视频" prop="handleVideos" borderBottom>
2024-10-31 17:39:30 +08:00
<u-upload accept="video" :fileList="o.handleVideos"
@afterRead="(e)=>afterRead(e,o,index,i)"
@delete="(e)=>deletePic(e,o,index,i)" name="handleVideos" multiple
:maxCount="10"></u-upload>
</u-form-item>
<u-form-item label="问题描述" prop="handleDesc" borderBottom required>
<u--textarea v-model="o.handleDesc" placeholder="请输入内容"></u--textarea>
</u-form-item>
</view>
2024-11-07 16:40:56 +08:00
<view class="" v-if="o.isHandle == 0">
<u-form-item label="责任人" prop="handleUserId" borderBottom required>
<uni-data-picker :localdata="treeList" popup-title="" v-model="o.handleUserId"
2024-11-07 16:40:56 +08:00
:border="false"
:map="{'text':'title','value':'value'}"
2024-11-07 17:44:20 +08:00
v-slot:default="{data, error, options}"
>
<view v-if="error" class="error">
<text>{{error}}</text>
</view>
<view v-else-if="data.length" class="selected">
<text>{{data[data.length-1].text}}</text>
</view>
<view v-else>
<text>请选择</text>
</view>
</uni-data-picker>
2024-10-31 17:39:30 +08:00
</u-form-item>
</view>
2024-10-16 18:02:59 +08:00
</view>
</u--form>
2024-11-07 16:40:56 +08:00
2024-10-16 18:02:59 +08:00
</view>
2024-11-07 16:40:56 +08:00
2024-10-16 18:02:59 +08:00
</view>
</view>
2024-10-31 17:39:30 +08:00
</uni-collapse-item>
2024-11-07 16:40:56 +08:00
2024-10-16 18:02:59 +08:00
</uni-collapse>
2024-11-07 16:40:56 +08:00
<view class="" style="display: flex;">
<u-button text="保存" customStyle="margin-top: 50px" @click="submit(1)"></u-button>
<u-button type="primary" text="结束巡检" customStyle="margin-top: 50px" @click="submit(2)"></u-button>
</view>
2024-10-31 17:39:30 +08:00
2024-10-16 18:02:59 +08:00
</view>
</template>
<script>
2024-10-31 17:39:30 +08:00
export default {
props: {
xjItem: Array
2024-10-16 18:02:59 +08:00
},
2024-10-31 17:39:30 +08:00
data() {
return {
2024-11-07 16:40:56 +08:00
list: ["异常","正常", ],
listStatus: ["未处理","已处理"],
2024-10-31 17:39:30 +08:00
current: 0,
listData: [],
showSex: false,
2024-11-07 16:40:56 +08:00
treeList:[],
deptUserList:[],
2024-10-16 18:02:59 +08:00
actions: [{
2024-10-31 17:39:30 +08:00
name: '男',
},
{
name: '女',
},
{
name: '保密',
},
2024-10-16 18:02:59 +08:00
],
}
},
mounted() {
// this.listData = this.xjItem
2024-11-07 16:40:56 +08:00
this.getTreeList()
2024-10-16 18:02:59 +08:00
},
2024-10-31 17:39:30 +08:00
watch: {
xjItem: function(n, o) {
this.listData = n.map(item => {
item.childen = item.children.map(i => {
2024-11-07 16:40:56 +08:00
i.handlePics?.map(item1=>{
item1.url ='http://223.75.53.141:9102/test.by-lyf.tmp' + item1.filePath
return item1
})
i.handleVideos?.map(item1=>{
item1.url ='http://223.75.53.141:9102/test.by-lyf.tmp' + item1.filePath
return item1
})
i.inspectPics?.map(item1=>{
item1.url ='http://223.75.53.141:9102/test.by-lyf.tmp' + item1.filePath
return item1
})
i.inspectVideos?.map(item1=>{
item1.url ='http://223.75.53.141:9102/test.by-lyf.tmp' + item1.filePath
return item1
})
2024-10-31 17:39:30 +08:00
if (!i.handlePics) {
i.handlePics = []
2024-10-16 18:02:59 +08:00
}
2024-10-31 17:39:30 +08:00
if (!i.handleVideos) {
i.handleVideos = []
2024-10-16 18:02:59 +08:00
}
2024-10-31 17:39:30 +08:00
if (!i.inspectPics) {
i.inspectPics = []
2024-10-16 18:02:59 +08:00
}
2024-10-31 17:39:30 +08:00
if (!i.inspectVideos) {
i.inspectVideos = []
2024-10-16 18:02:59 +08:00
}
return i
})
return item
})
}
},
2024-10-31 17:39:30 +08:00
methods: {
2024-11-07 16:40:56 +08:00
nodeclick(e){
console.log(e,'1212');
},
buildTree (data, parentId) {
let tree = [];
data.forEach((node) => {
node.title = node.deptName;
node.key = node.deptId;
if (node.parentId === parentId) {
let children = this.buildTree(data, node.deptId);
if (children.length) {
node.children = children;
}
tree.push(node);
}
});
return tree;
},
handleTreeList(dept, user) {
const deptArr = dept.map(item => {
return {
...item,
value: item.deptId,
title: item.deptName,
disabled: item.userId ? false : true,
children: user.filter(u => u.deptId == item.deptId).map(u => ({
...u,
value: String(u.userId),
title: u.nickName
}))
}
})
console.log("deptArr",deptArr);
const treelist = this.buildTree(deptArr,0)
return treelist
},
async getTreeList (){
const res = await uni.$http.get('/gunshiApp/xyt/system/dept/list')
2024-11-07 17:44:20 +08:00
const resUser = await uni.$http.get('/gunshiApp/xyt/system/user/list?pageNum=1&pageSize=9999')
2024-11-07 16:40:56 +08:00
this.deptUserList = resUser.data.rows
if (res.data.data?.length > 0 && resUser.data.rows?.length > 0) {
// return this.handleTreeList(res.data.data,res.data.rows)
console.log();
this.treeList = this.handleTreeList(res.data.data,resUser.data.rows)
} else {
// return []
this.treeList =[]
}
},
2024-10-31 17:39:30 +08:00
getIsItem(arr) {
return arr.filter(item1 => item1.isNormal !== 1 && item1.isNormal !== 0).length
2024-10-16 18:02:59 +08:00
},
2024-10-31 17:39:30 +08:00
getNormal(isNormal) {
if (isNormal == 0) {
2024-10-16 18:02:59 +08:00
return 0
}
2024-10-31 17:39:30 +08:00
if (isNormal == 1) {
2024-10-16 18:02:59 +08:00
return 1
}
2024-10-31 17:39:30 +08:00
if (isNormal == null) {
2024-10-16 18:02:59 +08:00
return 3
}
},
2024-10-31 17:39:30 +08:00
getHandle(isHandle) {
if (isHandle == 0) {
2024-10-16 18:02:59 +08:00
return 0
}
2024-10-31 17:39:30 +08:00
if (isHandle == 1) {
2024-10-16 18:02:59 +08:00
return 1
}
2024-10-31 17:39:30 +08:00
if (isHandle == null) {
2024-10-16 18:02:59 +08:00
return 3
}
},
2024-11-07 16:40:56 +08:00
async uploadContent(status) {
2024-10-31 17:39:30 +08:00
try {
let params = {
2024-11-07 16:40:56 +08:00
status: status,
2024-10-31 17:39:30 +08:00
list: []
}
2024-11-11 14:35:16 +08:00
console.log(this.listData);
2024-10-31 17:39:30 +08:00
this.listData.map(i => {
2024-11-11 14:35:16 +08:00
const arr=i.children.map(item=>{
item.handleUserName = this.deptUserList.find(it=>it.userId==item.handleUserId)?.nickName
2024-11-07 16:40:56 +08:00
return item
})
2024-11-11 14:35:16 +08:00
params.list=[...params.list,...arr]
2024-10-31 17:39:30 +08:00
})
2024-11-11 14:35:16 +08:00
console.log(params);
2024-10-31 17:39:30 +08:00
const {
data
} = await uni.$http.post(`/gunshiApp/xyt/inspect/task/finish`, params)
2024-11-07 16:40:56 +08:00
console.log(data,'2121');
if(data.code==200){
uni.$showMsg('提交成功');
2024-11-08 18:00:54 +08:00
uni.navigateBack()
2024-11-07 16:40:56 +08:00
}
2024-10-31 17:39:30 +08:00
} catch (error) {
uni.$showMsg();
}
},
2024-11-07 16:40:56 +08:00
submit(status) {
2024-11-08 16:10:48 +08:00
const timer = uni.getStorageSync('timer');
if(timer) {
clearInterval(timer);
uni.removeStorageSync('timer')
}
2024-10-31 17:39:30 +08:00
let tigger = true
2024-10-16 18:02:59 +08:00
//判断是否符合提交条件
2024-10-31 17:39:30 +08:00
this.listData.forEach(item => {
item.ab = item.children.filter(i => {
2024-11-07 16:40:56 +08:00
if (i.isNormal == 0) {
2024-11-08 18:00:54 +08:00
if (i.inspectPics?.length && i.problemDesc) {
2024-10-31 17:39:30 +08:00
tigger = true
} else {
tigger = false
2024-11-07 16:40:56 +08:00
uni.$showMsg('请填写现场问题描述和上传现场照片');
2024-10-31 17:39:30 +08:00
}
2024-11-07 16:40:56 +08:00
if (i.isHandle == 1) {
2024-10-31 17:39:30 +08:00
if (i.handlePics?.length && i.handleDesc) {
tigger = true
} else {
tigger = false
2024-11-07 16:40:56 +08:00
uni.$showMsg('请填写处理问题描述和上传处理照片');
2024-10-31 17:39:30 +08:00
}
2024-11-07 16:40:56 +08:00
} else if (i.isHandle == 0) {
2024-10-31 17:39:30 +08:00
tigger = true
}
2024-11-07 16:40:56 +08:00
} else if (i.isNormal == 1) {
2024-10-31 17:39:30 +08:00
tigger = true
}
2024-10-16 18:02:59 +08:00
})
return item
})
2024-10-31 17:39:30 +08:00
console.log(tigger, 'arr');
if (tigger) {
2024-11-07 16:40:56 +08:00
this.uploadContent(status)
}else{
2024-10-31 17:39:30 +08:00
}
//
// if()
},
// 删除图片
deletePic(event, o, index, index1) {
this.listData[index].children[index1][event.name].splice(event.index, 1)
},
// 新增图片
async afterRead(event, o, index, index1) {
console.log(event, index1, this.listData[index]);
// let file
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
let lists = [].concat(event.file)
let fileListLen = this.listData[index].children[index1][event.name]?.length
lists.map((item) => {
this.listData[index].children[index1][event.name].push({
...item,
status: 'uploading',
message: '上传中'
2024-10-16 18:02:59 +08:00
})
2024-10-31 17:39:30 +08:00
})
for (let i = 0; i < lists.length; i++) {
const result = await this.uploadFilePromise(lists[i].url, event.name, index, index1)
console.log(result);
let item = this.listData[index].children[index1][event.name][fileListLen]
this.listData[index].children[index1][event.name].splice(fileListLen, 1, Object.assign(item, {
status: 'success',
message: '',
...result
}))
fileListLen++
}
},
uploadFilePromise(url, name, index, index1) {
return new Promise((resolve, reject) => {
let a = uni.uploadFile({
2024-11-07 16:40:56 +08:00
url: 'http://local.gunshiiot.com:18083/gunshiApp/xyt/inspect/task/file/upload/singleSimple', // 仅为示例,非真实的接口地址
2024-10-31 17:39:30 +08:00
filePath: url,
name: 'file',
formData: {
user: 'test'
},
success: (res) => {
setTimeout(() => {
// this.listData[index].children[index1][name].push({...res.data.data,url:res.data.data.filePath})
console.log(res.data)
resolve(JSON.parse(res.data).data)
}, 1000)
}
});
// resolve(a)
})
},
change(e, o, index, i, key) {
this.listData[index].children[i][key] = e;
2024-10-16 18:02:59 +08:00
this.$forceUpdate()
},
sexSelect(e) {
2024-10-31 17:39:30 +08:00
// this.model1.userInfo.sex = e.name
// this.$refs.uForm.validateField('userInfo.sex')
2024-10-16 18:02:59 +08:00
},
2024-11-07 16:40:56 +08:00
2024-10-16 18:02:59 +08:00
}
}
</script>
<style lang="scss" scoped>
2024-10-31 17:39:30 +08:00
.contentItem {
2024-11-08 18:00:54 +08:00
height: 100%;
overflow: auto;
2024-10-31 17:39:30 +08:00
.itemC {
2024-10-16 18:02:59 +08:00
display: flex;
justify-content: space-between;
display: flex;
color: #666666;
padding: 10px;
border-bottom: 1px solid #f0f0f0;
}
2024-10-31 17:39:30 +08:00
.itemNo {
2024-10-16 18:02:59 +08:00
color: #666666;
padding: 10px;
}
}
2024-10-31 17:39:30 +08:00
.circle-btn {
2024-10-16 18:02:59 +08:00
width: 120px;
height: 120px;
background-color: #007aff;
border-radius: 50%;
2024-10-31 17:39:30 +08:00
color: #fff;
2024-10-16 18:02:59 +08:00
text-align: center;
line-height: 120px;
}
2024-10-31 17:39:30 +08:00
.yuandian {
2024-10-16 18:02:59 +08:00
display: inline-block;
width: 10px;
height: 10px;
background-color: #409eff;
border-radius: 50%;
margin-right: 10px;
}
2024-10-31 17:39:30 +08:00
.xj-content {
2024-11-08 18:00:54 +08:00
// height: 300px;
// overflow-y: auto;
2024-10-16 18:02:59 +08:00
}
2024-10-31 17:39:30 +08:00
.xj-text {
2024-10-16 18:02:59 +08:00
margin-left: 10%;
2024-11-07 17:44:20 +08:00
margin-right: 10%;
2024-10-16 18:02:59 +08:00
margin-top: 2%;
}
2024-10-31 17:39:30 +08:00
.subsectioin {
2024-10-16 18:02:59 +08:00
display: flex;
column-gap: 10px;
align-items: center;
margin-top: 10px;
}
</style>