马宇豪
2024-01-18 7446bd01fb7eb8ee4dd80176cd0dd5b049edee99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<template>
  <div class="riskBox">
    <el-form ref="formRef" :model="state.formData" :rules="state.rules" class="register-form" label-position="top">
      <el-row :gutter="30" style="margin-bottom: 20px">
        <el-col :span="18">
          <el-alert title="说明:现场勘验记录由项目组成员通过APP端进行信息填报,组长完成现场勘验并在APP端提交后,电脑可对资料信息完善并进行下一步操作。" type="warning" />
        </el-col>
        <el-col :span="6" style="display:flex;justify-content: right">
          <el-button type="primary">全部查看</el-button>
          <el-button type="primary">全部下载</el-button>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="6">
          <el-form-item prop="investigationDate" label="现场勘验时间">
            <el-date-picker
                style="width: 100%"
                v-model="state.formData.investigationPlanDate"
                type="date"
                value-format="YYYY-MM-DD 00:00:00"
                placeholder="选择日期"
                size="large"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="investigationDate" label="现场勘验位置">
            <el-input
                v-model="state.formData.location"
                size="large"
                placeholder="请填写现场勘验位置"
            >
              <template #append>
                <el-button :icon="Search" @click="openLocation"/>
              </template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="isSafetyCheck" label="编制现场安全检查表">
            <el-radio-group v-model="state.formData.isSafetyCheck" size="large">
              <el-radio :label="true" size="large">是</el-radio>
              <el-radio :label="false" size="large">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="6">
          <el-form-item label="附件上传">
            <el-upload accept="image/*" :action="state.uploadUrl" :headers="state.header" method="post" :on-success="handleAvatarSuccess" :on-exceed="showTip" :on-preview="handlePictureCardPreview" :limit='state.imgLimit' v-model:file-list="state.fileList" list-type="picture-card" :before-upload="picSize" :on-remove="handleRemove" :before-remove="beforeRemove">
              <el-icon><Plus /></el-icon>
              <template #tip>
                <div class="el-upload__tip">上传jpg/png图片尺寸小于5M,最多可上传1张</div>
              </template>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item prop="recordData" label="现场勘验记录">
        <el-input
            v-model="state.formData.recordData"
            :autosize="{ minRows: 6 }"
            maxlength="200"
            show-word-limit
            type="textarea">
        </el-input>
      </el-form-item>
      <el-form-item label="企业陪同照片">
 
      </el-form-item>
    </el-form>
    <map-location ref="mapLocationRef" @giveLatLng="achieveLatLng"></map-location>
  </div>
</template>
<script setup>
 
import {defineEmits, onMounted, reactive, ref} from "vue"
import {ElMessage} from "element-plus"
import {Search} from '@element-plus/icons-vue'
import {addRisk, editRisk, getRiskDetail} from "@/api/projectManage/riskAnalysis"
import {delPic} from "@/api/login"
import { getToken } from "@/utils/auth";
import Cookies from "js-cookie"
const emit = defineEmits(["getNextStatus"])
import MapLocation from "./mapLocation.vue"
 
const state = reactive({
  formData: {
    id: null,
    projectId: null,
    investigationDate: '',
    location: '',
    isSafetyCheck: null,
    recordData: ''
  },
  planPersons: [],
  rules: {
    recordData: [{required: true, message: '请填写现场勘验记录', trigger: 'blur'}]
  },
  imgLimit: 1,
  uploadUrl: import.meta.env.VITE_APP_BASE_API + '/system/common/uploadFile',
  header: {
    Authorization: 'Bearer ' + getToken()
  }
})
 
const isAmin = ref(false)
const formRef = ref()
const mapLocationRef = ref()
onMounted(() => {
  const userInfo = JSON.parse(Cookies.get('userInfo'))
  if(userInfo.identity === 0){
    isAmin.value = true;
  }
});
 
const riskOpen = async (type,val) => {
  console.log("type",type,val)
  if(type === 'detail' || type === 'edit' ){
    const res = await getRiskDetail({projectId: val});
    if(res.code == 200){
      state.formData = res.data;
      state.formData.project.business = parseInt(res.data.project.business);
      state.formData.project.area = [res.data.project.province,res.data.project.city];
    }else {
      ElMessage.warning(res.message)
    }
  }
  if(type === 'add' || type === 'clickEdit') {
    const valid = await formRef.value.validate();
    if(valid){
      if (isAmin.value) {
        ElMessage.warning("当前用户暂无权限");
        return;
      }
      if(type === 'add'){
        const {projectId, ...data} = JSON.parse(JSON.stringify(state.formData))
        const res = await addRisk(data);
        if (res.code == 200) {
          ElMessage.success('保存成功')
          formRef.value.clearValidate();
          emit('getNextStatus', res.data);
 
        } else {
          ElMessage.warning(res.message)
        }
      }else if(type === 'clickEdit'){
        const { ...data} = JSON.parse(JSON.stringify(state.formData))
        const res = await editRisk(data);
        if (res.code == 200) {
          ElMessage.success('变更成功')
          formRef.value.clearValidate();
          // emit('getNextStatus', data.project.id);
        } else {
          ElMessage.warning(res.message)
        }
      }
    }
  }
}
 
const openLocation = ()=>{
  mapLocationRef.value.openMapLocation(state.formData.location.split(',')[0],state.formData.location.split(',')[1])
}
 
const achieveLatLng=(lng,lat)=>{
  state.formData.location = lng + ',' + lat
}
 
// 图片上传
const showTip =()=>{
  ElMessage({
    type: 'warning',
    message: '超出文件上传数量'
  });
}
 
const picSize = async (rawFile) => {
  if(rawFile.size / 1024 / 1024 > 5){
    ElMessage({
      type: 'warning',
      message: '文件大小不能超过5M'
    });
    return false
  }
};
 
const handlePictureCardPreview = (uploadFile) => {
  state.dialogImageUrl = uploadFile.url
  state.dialogImg = true
};
 
 
const handleAvatarSuccess = (res, uploadFile) => {
  if(res.code == 200){
    // state.registerForm.agency.reportPath = res.data.path
  }else{
    ElMessage({
      type: 'warning',
      message: '文件上传失败'
    })
  }
}
 
const handleRemove = async (file, uploadFiles) => {
  const res = await delPic({path: state.registerForm.agency.reportPath})
  if(res.code == 200){
    ElMessage({
      type: 'success',
      message: '文件已删除'
    })
  }else{
    ElMessage({
      type: 'warning',
      message: res.message
    })
  }
}
 
defineExpose({
  riskOpen
});
 
 
</script>
<style scoped lang="scss">
.riskBox{
  :deep(.el-form .el-form-item__label) {
    font-size: 15px;
  }
}
 
</style>