<template>
  <div class="wrapper editwrap">
    <el-dialog
      :visible.sync="dialogVisible"
      title="报送信息"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <el-form ref="editFormA" :model="editFormA"  label-width="100px">
        <el-form-item label="简报" >
          <el-input type="textarea" v-model="editFormA.briefing" disabled></el-input>
        </el-form-item>
        <el-form-item label="报送内容" >
          <el-input type="textarea" v-model="editFormA.content" disabled></el-input>
        </el-form-item>
        <el-form-item label="报送时间">
          <el-input type="text" v-model="editFormA.createTime" disabled></el-input>
        </el-form-item>
        <el-form-item label="报送附件" v-if=" editFormA.sendEnclosure != '' && editFormA.fileUrl != null">
          <span
                  class="dbtn sd qiCr"
                  @click="checkFile(editFormA.sendEnclosure)"
          >
            <i class="el-icon el-icon-view"></i>
            下载文件
          </span>
        </el-form-item>
        <el-form-item label="回复内容" prop="receiveContent">
          <el-input type="textarea" v-model="editFormA.receiveContent"></el-input>
        </el-form-item>
        <el-form-item label="回复时间" v-if="editFormA.receiveTime != null && editFormA.receiveTime != ''" >
          <el-input type="text" v-model="editFormA.receiveTime" disabled></el-input>
        </el-form-item>
        <el-form-item label="材料文件" v-if="editFormA.stutas==0">
          <el-upload
                  ref="uploaderA"
                  class="uploader"
                  :limit="1"
                  :action="actionUrl"
                  :on-success="(a,b,c) => onSuccessA(a,b,c,'fileUrl')"
                  :on-error="onErrorA"
                  :on-remove="handleRemoveA"
                  :before-remove="(a,b,c) => beforeRemoveA(a,b,c,'fileUrl')"
                  :on-exceed="onExceedA"
                  :before-upload="beforeUploadA"
                  :multiple="false"
                  list-type="picture"
                  :file-list="fileListA"
          >
            <i class="el-icon-plus"></i>
            <div slot="tip" class="el-upload__tip" >只能上传doc/docx/pdf/xls/xlsx格式文件，且不超过一个</div>
          </el-upload>
        </el-form-item>
        <el-form-item label="回复附件" id="fileSpan" v-if=" editFormA.fileUrl != '' && editFormA.fileUrl != null">
          <span
                  class="dbtn sd qiCr"
                  @click="checkFile(editFormA.fileUrl)"
          >
            <i class="el-icon el-icon-view"></i>
            下载文件
          </span>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="editFormA.stutas == '0'" size="small" @click="confirmFun('editForm')">确定</el-button>
        <el-button @click="$emit('dialogFun')" size="small">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<style lang="scss">
  @import '@/utils/default.scss';
  .el-col {
    margin-left: 0;
    margin-right: 10px;
  }
</style>
<script lang="ts">
import { Component, Vue, Provide, Prop, Watch } from "vue-property-decorator";
import { State, Getter, Mutation, Action } from "vuex-class";
import METHOD from "@/utils/methods";
let uploadfile = require("@/assets/uploadfile.png");

@Component({
  components: { }
})
export default class EventsInfo extends Vue {
  // @Getter('signs') signsData: any;
  //属性或参数中使用!:表示强制解析（告诉typescript编译器，这里一定有值），常用于vue-decorator中的@Prop
  @Prop(Boolean) dialogVisible!: Boolean;

  @Prop(Object) editForm!: {
    fullName: String;
  };
@Provide() stype:any = "a";
//上传
@Provide() actionUrl: any = "";
@Provide() fileUrl: any = [];
@Provide() fileListA: any = [];
@Provide() fileListB: any = [];
@Provide() rulesA: any = {
    // evaluateContent: [
    //   { required: true, trigger: "change", message: "该项为必填项！" }
    // ],
};
@Provide() editFormA: any = {};
@Provide() editFormB: any = {};

@Watch("fileUrl") change(val: any) {
    if(this.stype == 'a'){
        if (val.length > 0) {
            this.editFormA.fileUrl = val[0].response.data.viewPath;
            this.editFormA.sendEnclosure = val[0].response.data.viewPath;
            this.editFormA.fileOriginalName = val[0].response.data.originalName;

            this.fileListA = [];
            this.fileListA.push({
                name: this.editFormA.fileOriginalName,
                url: uploadfile,
            });
        } else {
            this.editFormA.fileUrl = "";
            this.editFormA.fileOriginalName = "";
        }
    } else {
        if (val.length > 0) {
            this.editFormB.fileUrl = val[0].response.data.viewPath;
            this.editFormA.sendEnclosure = val[0].response.data.viewPath;
            this.editFormB.fileOriginalName = val[0].response.data.originalName;

            this.fileListB = [];
            this.fileListB.push({
                name: this.editFormB.fileOriginalName,
                url: uploadfile,
            });
        } else {
            this.editFormB.fileUrl = "";
            this.editFormB.fileOriginalName = "";
        }
        console.log("this.fileListB", this.fileListB)
    }

}
//选择模板
handleClick(val){
    this.content = val.titlecontent;
    document.querySelector('#bbb').click();
}
//点击文件
checkFile(url: any) {
    window.open("http://" + METHOD.GlobalUrl + "/ioc" + url)
}
  //取消事件要在父级取消是所以用到 $emit
  confirmFun() {
    this.editFormA.receiveEnclosure = this.editFormA.fileUrl
    let that = this,
      //params =that.sendForm;
       // console.log( that.$refs['editForm'] )
      // return
    if(this.editFormA.receiveContent!=''){
        (that as any).$axios
            .post("/eventInfoSubmitted/submittedReceive", this.editFormA)
            .then(() => {
                (that as any).$message({
                    message: "操作成功！",
                    type: "success"
                });
                (that as any).$emit("dialogFun");
                that.$emit("refreshTableData"); //刷新表格
            });
    }else{
        this.$alert('请输入回复内容', '温馨提示', {
            confirmButtonText: '确定',
        });
    }
  }

postPGData() {
    let that = this;
    console.log("that.editFormA", that.editFormA);
    (that as any).$axios
        .post(
            `/eventInfo/addOrEditEventEvaluateInfo`,
            Object.assign({eventId: that.eventId},that.editFormA)
        )
        .then((res: any) => {
            (that as any).$message.success('成功！');
            that.$emit('redialogFun');
            that.$emit("refreshTableData"); //刷新表格
        });
}
//对数组去重排序
sortOut(arr: Array<any>){
    const compare = (a:any, b:any) => {
        if(a.handleTime > b.handleTime) return -1;
        else if(a.handleTime = b.handleTime) return 0;
        else return 1;
    }
    arr.sort(compare)
}
postCLData() {
    let that = this;
    (that as any).$axios
        .post(
            `/eventInfo/addOrEditEventHandleProcessInfo`,
            Object.assign({ eventId: that.eventId }, that.editFormB)
        )
        .then((res: any) => {
            (that as any).$message.success('成功！');
            that.getCLdata()
        });
}
// 上传
onSuccessA(res: any, file: any, fileListA: any, key: string) {
    this.$data[key] = fileListA;
    document.getElementById("fileSpan").style.display="";
}
onErrorA(err: any, file: any, fileListA: any) {
    this.$message.error("上传失败!");
}
handleRemoveA(file: any, fileListA: any, key: string) {
    this.$data[key] = fileListA;
    this.editFormA.fileUrl = "";
    this.editFormA.fileOriginalName = "";
    this.editFormA.receiveEnclosure ="";
    document.getElementById("fileSpan").style.display="none";
}
onExceedA(file: any, fileListA: any) {
    this.$message.warning("只允许上传一个文件，如需更改请先删除！");
}
//删除文件
beforeRemoveA(file: any, fileListA: any) {
    if (file && file.status==="success") {
        let that = this,
            param;
        param = file.response
            ? file.response.data.savePath.replace(/\\/g, "%")
            : file.url.replace(/\\/g, "%").slice(9);
        METHOD.axiosGet(this, `/file/deleteFile?savePath=${param}`, function (
            res: any
        ) {
            if (res.code == 0) that.$message.success("删除成功");
            else return false;
        });
    }
}
beforeUploadA(file: any){
    console.log(file)
    var testmsg=file.name.substring(file.name.lastIndexOf('.')+1)
    const extension = testmsg === 'xls'
    const extension2 = testmsg === 'xlsx'
    const extension3 = testmsg === 'doc'
    const extension4 = testmsg === 'docx'
    const extension5 = testmsg === 'pdf'
    if(!extension && !extension2 && !extension3 && !extension4 && !extension5) {
        this.$message({
            message: '上传文件只能是doc、docx、pdf、xls、xlsx格式!',
            type: 'warning'
        });
    }
    return extension || extension2 || extension3 || extension4 || extension5
}

created() {
    let that = this;
    var id = that.editForm.eventId;
    that.editFormA=that.editForm
    that.value="新乐市消防局"
    that.editFormA.fileUrl=that.editForm.receiveEnclosure
    console.log(that.editFormA.fileUrl)
    that.actionUrl = "http://" + METHOD.GlobalUrl + "/ioc/file/uploadFile";
}
}
</script>