Your Name
2022-09-28 fe48637b8197e55cb2b454f79d29dab88bd5f7dd
src/views/specialWorkManage/workTicket/workApply/components/plate.vue
@@ -9,9 +9,9 @@
                  <el-select v-model="form.operatorUids" multiple>
                     <el-option
                           v-for="item in workerList"
                           :key="item.uid"
                           :label="item.username"
                           :value="item.uid"
                           :key="item.id"
                           :label="item.realname + '(' + item.username.toString().replace(/^(\d{3})\d{4}(\d{4})$/,'$1****$2') + ')'"
                           :value="item.id"
                     />
                  </el-select>
               </el-form-item>
@@ -44,7 +44,6 @@
                    <el-form-item label="作业时间" prop="workTimeLine">
                        <el-date-picker
                            v-model="form.workTimeLine"
                            format="yyyy-MM-dd HH:mm:ss"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            type="datetimerange"
                            range-separator="至"
@@ -151,8 +150,7 @@
               <el-form-item label="盲板时间" prop="workDetail.installLine">
                  <el-date-picker
                        v-model="form.workDetail.installLine"
                        format="YYYY-MM-DD HH:mm"
                        value-format="YYYY-MM-DD HH:mm:00"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        type="datetimerange"
                        range-separator="--"
                        start-placeholder="装盲板时间"
@@ -160,18 +158,19 @@
                  />
               </el-form-item>
            </el-col>
                <el-col :span="12">
                    <el-form-item label="盲板位置" prop="workDetail.bpLocation">
                        <el-input
                            v-model="form.workDetail.bpLocation"
                            autosize
                            type="textarea"
                            placeholder="请输入"
                        />
                    </el-form-item>
                </el-col>
         </el-row>
         <el-row>
            <el-col :span="12">
               <el-form-item label="盲板位置" prop="workDetail.bpLocation">
                  <el-input
                        v-model="form.workDetail.bpLocation"
                        autosize
                        type="textarea"
                        placeholder="请输入"
                  />
               </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item label="关联作业" prop="workDetail.otherSpecialWork">
                  <el-select v-model="form.workDetail.otherSpecialWork" multiple>
@@ -185,18 +184,49 @@
               </el-form-item>
            </el-col>
         </el-row>
         <el-row>
            <el-col :span="24">
               <el-form-item label="盲板位置图" prop="workDetail.bpLocationMapPath">
                  <el-upload accept="image/*" :on-exceed="showTip" :on-preview="handlePictureCardPreview" :limit='imgLimit' v-model:file-list="fileList" :http-request="upload" :action="uploadUrl" list-type="picture-card" :on-remove="handleRemove" :before-remove="beforeRemove" :before-upload="getUploadUrl">
                     <el-icon><Plus /></el-icon>
                     <template #tip>
                        <div class="el-upload__tip">上传jpg/png图片尺寸小于500KB,最多可上传5张</div>
                     </template>
                  </el-upload>
               </el-form-item>
            </el-col>
         </el-row>
                <el-row>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-form-item label="隐患上报图" prop="img">
                            <el-upload
                                accept=".pdf,.jpg,.png"
                                :action="fileRoad"
                                class="upload-demo"
                                ref="upload"
                                :headers="header"
                                :data="uploadForm"
                                list-type="picture-card"
                                :file-list="fileList"
                                v-model="form.workDetail.bpLocationMapPath"
                                :on-change="handleChangeFile"
                                :on-success="onFileSuccess"
                                :multiple="false"
                                :auto-upload="true">
                                <i slot="default" class="el-icon-plus"></i>
                                <div slot="file" slot-scope="{file}">
                                    <img
                                        class="el-upload-list__item-thumbnail"
                                        :src="file.url" alt=""
                                    >
                                    <span class="el-upload-list__item-actions">
                                <span
                                    class="el-upload-list__item-preview"
                                    @click="handleFile(file)"
                                >
                                  <i class="el-icon-zoom-in"></i>
                                </span>
                                <span
                                    v-if="!disabled"
                                    class="el-upload-list__item-delete"
                                    @click="handleRemove(file,file.$index)"
                                >
                                  <i class="el-icon-delete"></i>
                                </span>
                              </span>
                                </div>
                            </el-upload>
                        </el-form-item>
                    </el-col>
                </el-row>
         </div>
      </el-form>
      <div class="applyBtn">
@@ -210,13 +240,26 @@
</template>
<script>
   export default{
   import {workApplyApi} from "../../../../../api/workApply";
    import Cookies from "_js-cookie@2.2.0@js-cookie";
    export default{
      name: 'brokenForm',
      components: {},
      props:['workerList'],
        data(){
            return{
                fileRoad:process.env.BASE_API + '/task/web/upload',
                uploadForm:{
                },
                header:{Authorization:''},
                disabled:false,
                form: {
                    fileRoad:process.env.BASE_API + '/task/web/upload',
                    uploadForm:{
                    },
                    header:{Authorization:''},
                    disabled:false,
                    operatorUids: [],
                    workType: 8,
                    workLevel: null,
@@ -337,32 +380,55 @@
            }
        },
        methods:{
            async submitForm(formEl) {
                if (!formEl) return
                await formEl.validate(async (valid, fields) => {
            submitForm(formEl) {
                this.$refs["ruleFormRef"].validate(async (valid, fields) => {
                    if (valid) {
                        state.form.expStartTime = JSON.parse(JSON.stringify(state.form.workTimeLine))[0]
                        state.form.expEndTime = JSON.parse(JSON.stringify(state.form.workTimeLine))[1]
                        state.form.workDetail.installBpTime = JSON.parse(JSON.stringify(state.form.workDetail.installLine))[0]
                        state.form.workDetail.uninstallBpTime = JSON.parse(JSON.stringify(state.form.workDetail.installLine))[1]
                        let { workTimeLine, ...data } = JSON.parse(JSON.stringify(state.form))
                        let { installLine, ...data2 } = JSON.parse(JSON.stringify(state.form.workDetail))
                        this.form.expStartTime = JSON.parse(JSON.stringify(this.form.workTimeLine))[0]
                        this.form.expEndTime = JSON.parse(JSON.stringify(this.form.workTimeLine))[1]
                        this.form.workDetail.installBpTime = JSON.parse(JSON.stringify(this.form.workDetail.installLine))[0]
                        this.form.workDetail.uninstallBpTime = JSON.parse(JSON.stringify(this.form.workDetail.installLine))[1]
                        let { workTimeLine, ...data } = JSON.parse(JSON.stringify(this.form))
                        let { installLine, ...data2 } = JSON.parse(JSON.stringify(this.form.workDetail))
                        data.workDetail = data2
                        data.workDetail.otherSpecialWork = data.workDetail.otherSpecialWork.join(',')
                        data.workDetail.bpLocationMapPath = data.workDetail.bpLocationMapPath.join(',')
                        data.workDetail.bpLocationMapPath = JSON.stringify(this.fileList.map(item => { return item.url.substring(process.env.IMG_API.length) }))
                        data.workDetail.temperature = Number(data.workDetail.temperature)
                        data.workDetail.pressure = Number(data.workDetail.pressure)
                        const res = await workApplyApi().postPlateApply(data)
                        if (res.data.code === '200') {
                            ElMessage({
                            this.$message({
                                type: 'success',
                                message: '提交成功!'
                            });
                            formEl.resetFields()
                            state.form.workDetail.bpLocationMapPath = []
                            state.fileList = []
                            this.$refs["ruleFormRef"].clearValidate()
                            this.form = {
                                operatorUids: [],
                                workType: 8,
                                workLevel: null,
                                workContent: '',
                                workLocation: '',
                                workDetail:{
                                    bpCode: '',
                                    mainMedia: '',
                                    temperature: null,
                                    pressure: null,
                                    bpMaterialQuality: '',
                                    bpSpecification: '',
                                    bpLocation: '',
                                    bpLocationMapPath: [],
                                    installLine: [],
                                    installBpTime: '',
                                    uninstallBpTime: '',
                                    hazardIdentification: '',
                                    otherSpecialWork: []
                                },
                                workTimeLine: [],
                                expStartTime: '',
                                expEndTime: ''
                            }
                            this.fileList = []
                        } else {
                            ElMessage({
                            this.$message({
                                type: 'warning',
                                message: res.data.msg
                            });
@@ -371,7 +437,42 @@
                        console.log('error submit!', fields)
                    }
                })
            }
            },
            handleChangeFile(){
                this.header.Authorization = Cookies.get('token')
            },
            onFileSuccess(response){
                if(response.code === '200'){
                    this.fileList.push({url:process.env.IMG_API + response.result.path})
                    this.$notify({
                        type:'success',
                        duration:2000,
                        message:'上传成功',
                        title:'成功',
                    })
                }else{
                    this.$message({
                        message:res.data.message,
                        type:'warning'
                    })
                }
            },
            handleFile(file){
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            },
            showImg(file){
                window.open(file, '_blank')
            },
            handleRemove(file,value){
                return this.$confirm(`确定移除 ${ file.uid }?`,'提示',{
                    confirmButtonText:'确定',
                    cancelButtonText:'取消',
                    type:'warning',
                }).then(()=> {
                    this.fileList.splice(value,1)
                })
            },
        },
   };
</script>