shj
2022-03-31 6e3961ad82e2dfb204b79caf50c6637c15cfbe8d
src/views/contingencyplan/index.vue
@@ -54,6 +54,7 @@
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="recordTotal"
      style="text-align: right;margin-top: 20px;"
    >
    </el-pagination>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="40%">
@@ -62,16 +63,16 @@
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="文件类型">
          <el-radio-group v-model="form.fileType">
          <el-radio-group v-model="form.fileType" @change="changeFileType">
            <el-radio :label=0 >图片</el-radio>
            <el-radio :label=1 >文件</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="form.fileType==0" label="图片上传">
            <upload-img  v-bind:imgList="form.fileList" @uploadImgSuccess="uploadImgSuccess" @removeImgSuccess="removeImgSuccess"></upload-img>
            <upload-img :imgList="fileList"   @uploadImgSuccess="uploadImgSuccess" @removeImgSuccess="removeImgSuccess"></upload-img>
        </el-form-item>
        <el-form-item label="文件链接" v-if="form.fileType==1">
            <upload-file v-bind:url="fileUrl" v-bind:name="fileName" @uploadFileSuccess="uploadFileSuccess" ></upload-file>
            <upload-file v-bind:url="fileUrl" v-bind:name="fileName"  @uploadFileSuccess="uploadFileSuccess" ></upload-file>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" :rows="5" type="textarea"></el-input>
@@ -79,7 +80,7 @@
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" class="btns" @click="addemergencyPlan()">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button @click="cancel()">取 消</el-button>
      </span>
    </el-dialog>
  </div>
@@ -97,9 +98,7 @@
  components: { uploadImg , uploadFile},
  data() {
    return {
        name:"111",
        url:"222",
        path:"emergencyPlan",
        uploadDisabled:false,
      dialogVisible: false,
      title: "",
@@ -121,14 +120,15 @@
      },
        fileName:"",
        fileUrl:"",
        fileList:[],
      list: [],
      rules: {
        name: [
          { required: true, message: "预案名称不能为空", trigger: "change" },
        ],
        remark: [
          { required: true, message: "责任人不能为空", trigger: "blur" },
        ],
        // remark: [
        //   { required: true, message: "备注不能为空", trigger: "blur" },
        // ],
      },
    };
  },
@@ -136,17 +136,15 @@
    this.emergencyPlan();
  },
  methods: {
      changeFileType(){
          this.fileUrl=""
          this.fileName=""
          this.fileList=[]
      },
      uploadFileSuccess(res){
          this.fileName=res.fileName
          this.fileUrl=res.fileUrl
          if (this.fileName=="" || this.fileUrl==""){
              this.form.fileList=[]
          }
          this.form.fileList=[{
              fileName: this.fileName,
              fileUrl:this.fileUrl
          }]
      },
      uploadImgSuccess(res){
@@ -154,11 +152,11 @@
              fileUrl : res.fileUrl,
              fileName : res.fileName
          }
          this.form.fileList.push(file)
          this.fileList.push(file)
      },
      removeImgSuccess(res){
          this.form.fileList=res.fileList
          this.fileList=res.fileList
      },
    async emergencyPlan() {
@@ -186,14 +184,27 @@
      } else {
        this.title = "编辑";
        this.form = value;
        this.fileUrl=value.fileList[0].fileUrl;
        this.fileName=value.fileList[0].fileName
        if (this.form.fileType==0){
            this.fileList=value.fileList
        } else{
            this.fileUrl=value.fileList[0].fileUrl;
            this.fileName=value.fileList[0].fileName
        }
      }
    },
    addemergencyPlan() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
            console.log(132,this.form)
            if (this.form.fileType==0){
                this.form.fileList=this.fileList
            }
            if (this.form.fileType==1){
                let file={
                    fileUrl:this.fileUrl,
                    fileName:this.fileName
                }
                this.form.fileList=[file]
            }
          if (this.title === "新增") {
            emergencyPlanAdd(this.form).then((res) => {
              if (res.data.code === "200") {
@@ -204,11 +215,6 @@
                  duration: 2000,
                  message: "新增成功",
                  title: "成功",
                });
              } else {
                this.$message({
                  type: "warning",
                  message: res.data.message,
                });
              }
            });
@@ -224,11 +230,6 @@
                message: "编辑成功",
                title: "成功",
              });
            } else {
              this.$message({
                type: "warning",
                message: res.data.message,
              });
            }
          });
        }
@@ -236,16 +237,29 @@
      });
    },
    deleteById(val) {
      emergencyPlanDel({ id: val }).then(() => {
        this.emergencyPlan();
        this.$notify({
          title: "成功",
          message: "删除成功",
          type: "success",
          duration: 2000,
        });
      });
        this.$confirm('确认删除吗','提示', {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning'
        })
            .then(()=>{
              emergencyPlanDel({ id: val }).then(() => {
                this.emergencyPlan();
                this.$notify({
                  title: "成功",
                  message: "删除成功",
                  type: "success",
                  duration: 2000,
                });
              });
            })
            .catch(error =>{
            });
    },
      cancel(){
          this.emergencyPlan();
          this.dialogVisible = false;
      },
    find() {
      this.emergencyPlan();
    },