<template>
   <div class="pit-image-drawer" v-if="isOpen" style="padding:0px 10px">
    <el-drawer v-if="isOpen" :visible.sync="isOpen" direction="rtl" size="50%" 
    style="padding-left: 20px" title="项目基坑图片管理">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
    <el-form-item label="基坑图片" prop="imageUrls">
        <image-upload v-model="form.imageUrls" :limit="1" />
    </el-form-item>
    </el-form>
    <div>
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
    </div>
    </el-drawer>
  </div>
</template>

<script>
import { 
  updateSurProject
} from "@/api/project/surProject";
export default {
  name: 'RuoyiUiPitImageDrawer',

  data() {
    return {
      isOpen:false,
      prj:null,
      form:{
        imageUrls:[]
      },
      rules: {
        imageUrls: [{ required: true, message: "请上传验收图片", trigger: "blur" }],
      }
    };
  },

  mounted() {
    
  },

  methods: {
    submitForm(){
        this.$refs["form"].validate((valid) => {
            if (valid) {
                let postData={
                    id:this.prj.id,
                    prjPlanUrl:this.form.imageUrls
                };
                updateSurProject(postData).then(d=>{
                    if(d.code==200){
                        this.prj.prjPlanUrl=this.form.imageUrls;
                        this.$modal.msgSuccess("修改成功!");
                    }else{
                        this.$modal.msgError("修改失败!");
                    }
                    this.isOpen=false;
                });
            }
        });
    },
    cancel(){
        this.isOpen=false;
    },
    show(prj) {        
        this.prj = prj;
        if(prj.prjPlanUrl){
            this.form.imageUrls=prj.prjPlanUrl;
        }
        this.isOpen = true;
    }
  },
};
</script>
<style lang="scss">
 .pit-image-drawer{
    .el-drawer__body{
        padding:0px 20px;
    }
 }
</style>