water-design-const-web/src/views/basic/survey/index.vue

443 lines
17 KiB
Vue

<template>
<div class="app-container">
<el-form
:model="queryParams"
ref="queryForm"
size="small"
:inline="true"
v-show="showSearch"
label-width="68px"
>
<el-form-item label="项目名称" prop="proName">
<el-input
v-model="queryParams.proName"
placeholder="请输入项目名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="堪查人" prop="surveyUser">
<el-input
v-model="queryParams.surveyUser"
placeholder="请输入堪查人"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="勘查时间" prop="surveyTime">
<el-date-picker
v-model="queryParams.surveyTime"
format="yyyy-MM-dd"
value-format="yyyy-MM-dd"
placeholder="请选择日期选择"
clearable
>
</el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<!-- <el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['basic:survey:add']"
>新增</el-button
>
</el-col> -->
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="proList">
<el-table-column label="序号" align="center" type="index" />
<el-table-column label="所属项目" align="center" prop="proName" />
<el-table-column label="堪查人" align="center" prop="surveyUser" />
<el-table-column label="勘查附件" align="center" prop="surveyAttach">
<template slot-scope="{ row }">
<template v-if="row.surveyAttach.length > 0">
<template v-for="(item, index) in row.surveyAttach">
<el-button type="text" @click="handlePreviewFile(item)" :key="index">
附件{{ index + 1 }}
</el-button>
<br :key="index" />
</template>
</template>
</template>
</el-table-column>
<el-table-column label="勘查内容" align="center" prop="surveyContent" />
<el-table-column label="操作" align="center">
<template slot-scope="scope">
<el-button
size="mini"
type="success"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['basic:survey:edit']"
>
详情
</el-button>
<!-- <el-button
size="mini"
type="danger"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['basic:survey:remove']"
>
删除 -->
</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改岗位对话框 -->
<el-dialog :title="title" :visible.sync="open" width="50%" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px" disabled>
<el-form-item label="项目名称" prop="proId">
<el-select
v-model="form.proId"
placeholder="请选择项目"
style="width: 100%"
@change="handleProChange"
>
<el-option
v-for="item in projectOptions"
:key="item.proId"
:label="item.proName"
:value="item.proId"
>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="勘查时间" prop="surveyTime" style="width: 100%">
<el-date-picker
clearable
format="yyyy-MM-dd"
style="width: 100%"
v-model="form.surveyTime"
value-format="yyyy-MM-dd"
placeholder="请选择日期选择"
>
</el-date-picker>
</el-form-item>
<el-form-item label="勘查人" prop="surveyUser" style="width: 100%">
<el-input v-model="form.surveyUser" placeholder="请输入勘查人" />
</el-form-item>
<!-- <el-form-item label="勘查内容" prop="surveyContent" style="width: 100%">
<el-input v-model="form.surveyContent" placeholder="请输入勘查内容" />
</el-form-item> -->
<el-form-item label="勘察模型" prop="surveyContent" style="width: 100%">
<el-select
v-model="form.modelId"
placeholder="请选择勘察模型"
style="width: 100%"
@change="handleModelChange"
>
<el-option v-for="item in modelOptions" :key="item.id" :label="item.nodeName" :value="item.id">
</el-option>
</el-select>
</el-form-item>
<!-- <el-form-item label="勘查结果" prop="surveyResult" style="width: 100%">
<el-input
type="textarea"
:autosize="{ minRows: 2, maxRows: 4 }"
v-model="form.surveyResult"
placeholder="请输入勘查结果"
/>
</el-form-item> -->
<el-form-item label="勘查附件" prop="fileList">
<el-upload
:limit="3"
:multiple="true"
:auto-upload="true"
:on-preview="handlePreview"
:on-remove="handleRemove"
:on-success="handleSuccess"
:file-list="form.fileList"
:headers="headers"
action="/dev-api/common/uploadFile"
>
<!-- <el-button size="small">上传附件</el-button> -->
</el-upload>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listSurvey, getSurvey, delSurvey, addSurvey, updateSurvey, projectSelect } from '@/api/basic/survey'
import { getModelListApi } from '@/api/basic/model'
import { getToken } from '@/utils/auth'
export default {
name: 'Post',
dicts: ['sys_normal_disable'],
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 项目选择
projectOptions: [],
// 岗位表格数据
proList: [],
// 弹出层标题
title: '',
// 日期范围
dateRange: [],
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
proName: undefined,
surveyUser: undefined,
surveyTime: undefined,
},
// 表单参数
form: {
fileList: [],
},
// 表单校验
rules: {
proId: [{ required: true, message: '项目名称不能为空', trigger: 'blur' }],
surveyTime: [{ required: true, message: '勘查时间不能为空', trigger: 'blur' }],
surveyUser: [{ required: true, message: '勘查人不能为空', trigger: 'blur' }],
surveyContent: [{ required: true, message: '勘查内同不能为空', trigger: 'blur' }],
modelId: [{ required: true, message: '请选择勘察模型', trigger: 'change' }],
surveyResult: [{ required: true, message: '请输入勘察结果', trigger: 'blur' }],
fileList: [{ required: true, message: '请上传勘察附件', trigger: 'change' }],
},
// 模型数据
modelOptions: [],
// 请求头
headers: {
Authorization: 'Bearer ' + getToken(),
},
}
},
created() {
this.getList()
},
methods: {
/** 查询岗位列表 */
getList() {
this.loading = true
listSurvey(this.queryParams).then((response) => {
this.proList = response.rows
this.proList.forEach((item) => {
if (item.surveyAttach) {
item.surveyAttach = item.surveyAttach.split(',')
} else {
item.surveyAttach = []
}
})
this.total = response.total
this.loading = false
})
},
// 取消按钮
cancel() {
this.open = false
this.reset()
},
// 表单重置
reset() {
this.form = {
// id: undefined,
// proId: undefined,
// proName: undefined,
// proType: undefined,
// unit: undefined,
// chargePerson: undefined,
// location: undefined,
// remark: undefined,
// dataRange: undefined,
id: null,
projectName: '', // 勘察项目名称
proId: '', // 勘察项目ID
surveyUser: '', // 勘察人
surveyTime: '', // 勘察日期转换后
surveyContent: '', // 勘察内容
modelId: '', // 模型id
surveyResult: '', // 勘察结果
surveyAttach: '', // 勘察附件
modelName: '', // 模型名称
fileList: [],
}
this.resetForm('form')
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm('queryForm')
this.handleQuery()
},
/** 新增按钮操作 */
handleAdd() {
this.reset()
projectSelect().then((response) => {
this.open = true
this.projectOptions = response.rows
this.title = '添加勘查日志'
})
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset()
const id = row.id || this.ids
projectSelect().then((response) => {
this.projectOptions = response.rows
})
getSurvey(id).then(async (response) => {
this.form = response.data
const fileList = response.data.surveyAttach.split(',')
this.form.fileList = fileList.map((item, index) => ({
name: '附件' + (index + 1),
url: item,
}))
const { rows: res } = await getModelListApi({ page: 1, pageSize: 999, projectId: this.form.proId })
this.modelOptions = res.filter((item) => item.nodelevel == item.nodeCount)
this.open = true
this.title = '修改勘查日志'
})
},
/** 提交按钮 */
submitForm: function () {
this.$refs['form'].validate((valid) => {
if (valid) {
const {
id,
// projectName, // 勘察项目名称
proId, // 勘察项目ID
surveyUser, // 勘察人
surveyTime, // 勘察日期转换后
surveyContent, // 勘察内容
modelId, // 模型id
surveyResult, // 勘察结果
modelName, // 模型名称
fileList,
} = this.form
const params = {
// projectName,
proId, // 勘察项目ID
surveyUser, // 勘察人
surveyTime, // 勘察日期转换后
surveyContent, // 勘察内容
modelId, // 模型id
surveyResult, // 勘察结果
surveyAttach: fileList.map((item) => item.url).join(','), // 勘察附件
modelName, // 模型名称
}
if (id) {
params.id = id
updateSurvey(params).then((response) => {
this.$modal.msgSuccess('修改成功')
this.open = false
this.getList()
})
} else {
addSurvey(params).then((response) => {
this.$modal.msgSuccess('新增成功')
this.open = false
this.getList()
})
}
}
})
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids
this.$modal
.confirm('是否确认删除项目编号为"' + ids + '"的数据项?')
.then(function () {
return delSurvey(ids)
})
.then(() => {
this.getList()
this.$modal.msgSuccess('删除成功')
})
.catch(() => {})
},
handlePreviewFile(item) {
window.open(item, '_blank')
},
handlePreview(file) {
window.open(file.url, '_blank')
},
handleSuccess(response, file, fileList) {
console.log(response, file, fileList)
if (file.response.code === 200) {
this.form.fileList.push({
name: file.response.data.newFileName,
...file.response.data,
})
}
},
handleRemove(file, fileList) {
console.log(file, fileList)
this.form.fileList = this.form.fileList.filter((item) => item.url !== file.url)
},
async handleProChange(val) {
console.log(val)
const { rows: res } = await getModelListApi({ page: 1, pageSize: 999, projectId: val })
this.modelOptions = res.filter((item) => item.nodelevel == item.nodeCount)
},
handleModelChange(val) {
this.form.modelName = this.modelOptions.find((item) => item.id == val).nodeName
},
},
}
</script>