<template>
  <div class="fbox1">
    <div class="fl">
      <div class="el-form-border">
        <el-form ref="form" :model="form" :rules="rules" label-width="150px">
          <el-row>
            <el-col :span="24">
              <el-form-item label="文件分类" prop="docCategoryId">
                <treeselect v-model="form.docCategoryId" :options="docCategory" :show-count="true" @input="inputSelect"
                            :disabled="detailBoolean"
                            placeholder="请选择文件分类"/>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="文档编号" prop="docCode">
                <template v-if="detailBoolean">{{form.docCode}}</template>
                <template v-else>
                  <el-input v-model="form.docCode" placeholder="请输入文档编号" maxlength="50" show-word-limit/>
                </template>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="文档名称" prop="docName">
                <template v-if="detailBoolean">{{form.docName}}</template>
                <template v-else>
                  <el-input v-model="form.docName" placeholder="请输入文档名称" maxlength="200" show-word-limit/>
                </template>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="文档类别" prop="docType" style="width: 100%">
                <el-select v-model="form.docType" placeholder="请选择文档来源" style="width: 100% !important;"
                :disabled="detailBoolean">
                  <el-option style="width: 100%"
                    v-for="dict in dict.type.doc_class"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="文档来源" prop="docSource">
                <el-select v-model="form.docSource" placeholder="请选择文档来源" style="width: 100%" :disabled="detailBoolean">
                  <el-option
                    v-for="dict in dict.type.doc_source"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
    <!--            <el-input v-model="form.docSource" placeholder="请输入文档来源" maxlength="50" show-word-limit/>-->
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="负责人" prop="docPrincipals">
                <template v-if="detailBoolean">{{form.docPrincipalsName}}</template>
                <template v-else>
                  <el-input v-model="form.docPrincipalsName" placeholder="请选择负责人" maxlength="11" @focus="toolPrincipalsChoose = true"/>
                  <!--                  <el-input v-model="form.docPrincipals" placeholder="请输入负责人" maxlength="50" show-word-limit/>-->
                </template>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="归属单位" prop="docRespDept">
                {{userInfo.dept.deptName}}
                <!--                <treeselect v-model="form.docRespDept" :options="deptOptions" :show-count="true"
                                            :disabled="detailBoolean" placeholder="请输入归属单位"/>-->
              </el-form-item>
            </el-col>
<!--            <el-col :span="24" v-if="relatedTool">
              <el-form-item label="关联工具" prop="toolId">
                <el-select
                  v-model="toolDataInfo"
                  ref="selectHeadTool"
                  multiple
                  value-key="toolId"
                  filterable
                  remote
                  placeholder="请选择关联工具"
                  :disabled="detailBoolean"
                  @focus="toolSelect">
                  <el-option
                    v-for="item in toolDataInfo"
                    :key="item.toolId"
                    :label="item.toolName"
                    :value="item">
                  </el-option>
                </el-select>
              </el-form-item>

            </el-col>-->

<!--            <el-col :span="24">
              <el-form-item label="文件" required>
                <uploadVue
                  :display="editStatus"
                  :uploadUrl="uploadFileUrl"
                  :type="['.txt','.doc','.docx','.pdf','.mp4','.zip','.rar','.7z','.png','.jpg','.jpeg']"
                  :acceptType="acceptType"
                  :limit="1"
                  :dataFile="dataFile"
                  :isDetail="detailBoolean"
                  ref="uploadFile"
                  @handleSuccess="handleUploadSuccess"
                  @handleError="handleUploadError"
                />
              </el-form-item>
            </el-col>-->
            <el-col :span="24">
              <el-form-item label="备注" prop="remark">
                <template v-if="detailBoolean">{{form.remark}}</template>
                <template v-else>
                  <el-input v-model="form.remark" type="textarea" :rows="3" maxlength="500" show-word-limit></el-input>
                </template>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form><!--el-form-->
      </div>

      <div class="divide double"></div><!--divide 分隔-->
      <div class="tboper">
        <div class="tit">关联附件</div>
      </div>
      <div class="el-form-border"  v-loading="previewLoading" element-loading-text="预览转换中，请耐心等待">
        <div class="operate">
          <template v-if="editStatus && !detailBoolean">
            <uploadVue
              :display="editStatus"
              :uploadUrl="uploadFileUrl"
              :type="['.txt','.doc','.docx','.pdf','.mp4','.zip','.rar','.7z','.png','.jpg','.jpeg']"
              :acceptType="acceptType"
              :isMultiple="true"
              :dataFile="dataFile"
              :isDetail="detailBoolean"
              ref="uploadFile"
              @handleSuccess="handleUploadSuccess"
              @handleError="handleUploadError"
            />
          </template>
          <!--            <el-button icon="el-icon-delete">删除</el-button>-->
        </div><!--operate 操作按钮-->
        <el-table :data="paginatedData" style="width: 100%">
          <!--            <el-table-column type="selection" width="50" align="center"> </el-table-column>-->
          <el-table-column label="序号" width="60" type="index" align="center"></el-table-column>
          <el-table-column label="附件名称" prop="fileName" :show-overflow-tooltip="true" />
          <el-table-column label="操作" align="center" width="180" v-if="!detailBoolean">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                v-if="previewAuth(scope.row)"
                @click="handlePreview(scope.row)"
              >预览</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                v-if="editStatus"
                @click="handleDelete(scope.row)"
              >删除</el-button>
              <el-button type="text" icon="el-icon-download"  v-if="isShowOperation(scope.row)"
                         @click="handleDownload(scope.row)" v-loading="loadingDownload">下载</el-button>
            </template>
          </el-table-column>
        </el-table><!--el-table-->
        <!-- 分页组件 -->
        <el-pagination
          v-show="total > 0"
          :current-page.sync="currentPage"
          :page-size.sync="pageSize"
          :total="total"
          @current-change="handlePageChange"
          layout="total, prev, pager, next"
        />
      </div>
    </div><!--fl 左侧页签-->

    <div class="fr" v-if="detailBoolean && isComment">
      <div class="tboper">
        <div class="tit">评论</div>
      </div><!--tboper 标题与操作按钮-->
      <div class="pltextarea">
        <el-input v-model="discussionContent" type="textarea" placeholder="请输入您的意见" :rows="4" maxlength="1000" show-word-limit></el-input>
        <div class="plbtn"><el-button @click="handleDiscussions">发布</el-button></div>
      </div><!--pltextarea-->
      <div class="pllist">
        <template v-if="discussionsList && discussionsList.length > 0">
          <div class="list" v-for="(item,index) in discussionsList" :key="item.id">
            <div class="luser"><span class="xuser">{{getFirstChar(item.nickName)}}</span></div>
            <div class="ltext">
              <div class="nt"><span class="name">{{item.nickName}}</span><span class="time">{{ parseTime(item.createTime, '{y}-{m}-{d} {h}:{i}') }}</span></div>
              <div class="te">{{item.content}}</div>
              <div class="hb">
                <a class="btn" @click="toggleReplyForm(index)">
                  <i class="el-icon-chat-line-round"></i>回复
                </a>
              </div>
              <div class="pltextarea" v-if="showReplyForm[index]">
                <el-input type="textarea" v-model="replyContent[index]" placeholder="请输入您的意见" :rows="2" maxlength="1000" show-word-limit></el-input>
                <div class="plbtn">
                  <el-button @click="cancelReply(index)">取消</el-button>
                  <el-divider direction="vertical"></el-divider>
                  <el-button @click="submitReply(index, item)">发布</el-button>
                </div>
              </div>
              <!--第二层级-->
              <template v-if="item.repliesList && item.repliesList.length > 0">
                <div class="list" v-for="(repItem,repIdex) in item.repliesList" :key="repItem.id">
                  <div class="luser"><span class="xuser">{{getFirstChar(repItem.nickName)}}</span></div>
                  <div class="ltext">
                    <div class="nt"><span class="name">{{repItem.nickName}}</span><span class="time">{{ parseTime(repItem.createTime, '{y}-{m}-{d} {h}:{i}') }}</span></div>
                    <div class="te">{{repItem.content}}</div>
                    <!--                    <div class="hb"><a class="btn" @click="toggleReplyFormSon(index,repIdex)"><i class="el-icon-chat-line-round"></i>回复</a></div>
                                        <div class="pltextarea" v-if="item.showReplyFormSon[repIdex]">
                                          <el-input type="textarea" v-model="item.replyContentSon[repIdex]" placeholder="请输入您的意见" :rows="2" maxlength="1000" show-word-limit></el-input>
                                          <div class="plbtn">
                                            <el-button @click="cancelReplySon(index,repIdex)">取消</el-button>
                                            <el-divider direction="vertical"></el-divider>
                                            <el-button @click="submitReplySon(index,repIdex, item)">发布</el-button>
                                          </div>
                                        </div>-->
                  </div>
                </div>
              </template>
            </div>
          </div>
        </template>
      </div>
    </div>

    <preview-util v-if="isPreviewDisable" ref="previewForm" @previewClose="previewClose"  @previewLoadingClose="previewLoadingClose"></preview-util>

    <tool-selector ref="toolSelect" @selectHandle="selectHandle"></tool-selector>
    <bl-user-selector  ref="peopleSelect" :type="'single'" :isCheck="true" :open="toolPrincipalsChoose" :deptFilter="true" @cancel="toolPrincipalsChoose=false" @submit="submitPeople"></bl-user-selector>

  </div><!--el-form-border 表单-->
</template>

<script>
  import { addDocument, updateDocument, getDocument } from "@/api/document/document";
  import { deptTreeSelect } from "@/api/system/user";
  import { documentTree } from "@/api/documentCategory/documentCategory.js";
  import Treeselect from "@riophae/vue-treeselect";
  import uploadProgress from "./uploadProgress";
  import uploadVue from '@/components/FileUpload/optimizeToolUpload.vue'
  import ToolSelector from '@/components/tool-selector/index.vue'
  import { listDiscussions, addDiscussions } from "@/api/tool/discussions.js";
  import { listReplies, addReplies} from "@/api/tool/replies.js";
  import previewUtil from '@/components/PreviewUtil/previewUtil.vue'
  import blUserSelector from '@/components/user-selector/src/user-selector.vue'
  import { listAttachment } from "@/api/attachment/attachment";
  import { addCount } from "@/api/tool/downloadCount";

  export default {
    name: 'editDocument',
    components: { Treeselect, uploadProgress, uploadVue, ToolSelector, previewUtil, blUserSelector},
    dicts:['doc_class','doc_source'],
    props: {
      tooId: {
        type: String,
        default: "",
        required: false
      },
      relatedTool: {
        type: Boolean,
        default: true,
      },
      //是否展示下载
      isDownload: {
        type: Boolean,
        default() {
          return true
        },
        required: false
      },
      //是否展示评论
      isComment: {
        type: Boolean,
        default() {
          return true
        },
        required: false
      },
    },
    data(){
      return{
        templateSelection: '',
        drawer1: false,
        checkList: [],
        tableData2: [
          {
            prop1: 'GDL-987',
            prop2: 'GDL工具',
            prop3: '检测型 ',
            prop4: '研发部门',
            prop5: '韩健'
          },
          {
            prop1: 'GDL-988',
            prop2: 'GDL工具',
            prop3: '检测型 ',
            prop4: '研发部门',
            prop5: '韩健'
          }
        ],
        // 表单参数
        form: {
          docId: undefined,
          docCategoryId: undefined,
          docCode: '',
          docName: '',
          docType: '',
          docPrincipals: null,
          docPrincipalsName: null,
          docRespDept: this.$store.getters.userInfo.deptId,
          docSource: '',
          toolId: '',
          remark: undefined,
        },
        fileList: [],
        progress: 0,
        // 表单校验
        rules: {
          docCategoryId: [
            { required: true, message: "文档分类不能为空", trigger: "input" }
          ],
          docCode: [
            { required: true, message: "文档编号不能为空", trigger: "blur" }
          ],
          docName: [
            { required: true, message: "文档名称不能为空", trigger: "blur" }
          ],
          docType: [
            { required: true, message: "类别不能为空", trigger: "change" }
          ],
          docSource: [
            { required: true, message: "文档来源不能为空", trigger: "change" }
          ],
          docPrincipals: [
            { required: true, message: "负责人不能为空", trigger: ['change','blur']  }
          ],
          docRespDept: [
            { required: true, message: "请选择归属部门", trigger: ['change','change'] }
          ],
        },
        docCategory:[],
        deptOptions:[],
        uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传文件服务器地址
        fileData: null,
        acceptType: ".txt,.docx,.pdf,.mp4,.zip,.rar,.7z,.png,.jpg",
        editStatus: true,
        toolDataInfo: [],
        dataFile: [],
        //详情
        detailBoolean: false,

        discussionContent: null, // 评论内容
        repliesContent: null, // 回复内容
        // 评论列表
        discussionsList: [],
        // 回复列表
        repliesList: [],
        showReplyForm: [],
        replyContent: [],
        detailLoading: false,
        attachmentList: [],
        attFileType: "zip,rar,7z",
        isPreviewDisable: false,
        loadingDownload: false,
        userInfo: this.$store.getters.userInfo,
        toolPrincipalsChoose: false,
        docQueryParams: {
          pageNum: 1,
          pageSize: 10,
        },
        queryParams: {
          pageNum: 1,
          pageSize: 99999,
        },
        currentPage: 1,     // 当前页
        pageSize: 10,       // 每页显示数量
        previewLoading: false,
      }
    },
    computed: {
      // 分页后的数据
      paginatedData() {
        const start = (this.currentPage - 1) * this.pageSize;
        const end = this.currentPage * this.pageSize;
        return this.attachmentList.slice(start, end);
      },
      // 总数据条数
      total() {
        return this.attachmentList.length;
      },
    },
    created(){
      this.getDeptTree();
      this.getDocumentTree();
    },
    mounted(){
     /* this.$nextTick(() => {
        document.querySelector('.el-upload__input').webkitdirectory = true
      })*/
    },
    methods:{
      chooseToolConfirm(){
        this.$set(this.form, "toolId", this.templateSelection)
        this.drawer1 = false;
      },
      singleElection(row) {
        this.templateSelection = row.prop1
        this.checkList = this.tableData2.filter((item) => item.prop1 === row.prop1)
        console.log(`该行的编号为${row.prop1}`)
      },
      getCurrentRow(row){
        // 获取选中数据   row表示选中这一行的数据，可以从里面提取所需要的值
      },
      showOpenHandle(){
        this.reset();
        this.title = "上传文档";
      },
      // 表单重置
      reset() {
        this.form = {
          docName: '',
          docType: '',
          docPrincipals: '',
          docRespDept: '',
          docSource: '',
          toolId: ''
        };
        this.fileList = []
        this.resetForm("form");
      },
      // 取消按钮
      cancel() {
        this.drawer1 = false;
        this.reset();
      },
      generateUniqueID() {
        // 使用时间戳来生成唯一ID
        const timestamp = new Date().getTime();
        // 在ID前面添加一个前缀，以防止与其他ID冲突
        const uniqueID = 'file_' + timestamp;
        return uniqueID;
      },
      inputSelect(){
        this.$refs.form.validateField('docCategoryId')
      },
      /** 提交按钮 */
      submitForm: function() {
        let self = this
        let fileName = []
        //编辑时走该逻辑
       /*  if(self.form.docId && (self.fileList == null || self.fileList.length <= 0 )){
          fileName = self.$refs.uploadFile.fileList[0]
          self.fileList = self.$refs.uploadFile.fileList
        }else{
          fileName = self.fileList[0]
          self.fileList = self.fileList
        } */
        //判断是否有文件再上传
        if (self.attachmentList.length <= 0) {
          return self.$message.warning('最少上传一个附件')
        }
        /*this.fileList.map(file =>{
          this.form.docName = file.name
        })*/
        /* if(fileName){
          self.$set(self.form,"docUrl", fileName.filePath)
          self.$set(self.form,"docStatus", "ysc")
        } */
        self.$set(self.form,"docStatus", "ysc")
        if(self.toolDataInfo && self.toolDataInfo.length > 0){
          self.$set(self.form,"toolId", self.toolDataInfo[0].toolId)
        }
        self.$set(self.form,'attachmentList',self.attachmentList)


        self.$refs["form"].validate(valid => {
          if (valid) {
            let tipName = '';
            if (self.form.docId){
              tipName = '更新'
            }else{
              tipName = '保存'
            }
            this.$modal.confirm('是否确认' + tipName+  '？').then(() => {
              if (self.form.docId) {
                updateDocument(self.form).then(res => {
                  self.$modal.msgSuccess("修改成功");
                  self.open = false;
                  self.$emit("submit");
                });
              } else {
                addDocument(self.form).then(res => {
                  self.$modal.msgSuccess("新增成功");
                  self.open = false;
                  // self.confirmSubmit(response.data);
                  self.$emit("submit");
                });
              }
            }).catch((err) => {
              console.error(err)
            });

          }
        });
      },
      /** 提交按钮 */
      assembleSubmit: function() {
        let self = this
        let fileName = []
        //编辑时走该逻辑
        if(this.form.docId && (this.fileList == null || this.fileList.length <= 0 )){
          fileName = this.$refs.uploadFile.fileList[0]
          this.fileList = this.$refs.uploadFile.fileList
        }else{
          fileName = this.fileList[0]
        }
        //判断是否有文件再上传
        if (this.fileList.length == 0) {
          return self.$message.warning('最少上传一个附件')
        }
        /*this.fileList.map(file =>{
          this.form.docName = file.name
        })*/
        if(fileName){
          this.$set(this.form,"docUrl", fileName.filePath)
          this.$set(this.form,"docStatus", "ysc")
          this.$set(this.form,"attachment", fileName)
        }
        if(this.toolDataInfo && this.toolDataInfo.length > 0){
          this.$set(this.form,"toolId", this.toolDataInfo[0].toolId)
        }

        this.$refs["form"].validate(valid => {
          if (valid) {
            self.$emit("docSubmitData",self.form)
          }
        });
      },
      /** 查询部门下拉树结构 */
      getDeptTree() {
        deptTreeSelect().then(response => {
          this.deptOptions = response.data;
        });
      },
      /** 查询树形下拉树结构 */
      getDocumentTree() {
        documentTree().then(response => {
          this.docCategory = response.data;
        });
      },
      /** 转换部门数据结构 */
      normalizer(node) {
        if (node.children && !node.children.length) {
          delete node.children;
        }
        return {
          id: node.deptId,
          label: node.deptName,
          children: node.children
        };
      },
      // flag 为true表示新增
      getData(data, flag, index) {
      },
      getError(message) {
        this.$message.error(message);
      },
      toolSelect(){
        this.$refs.selectHeadTool.blur();
        this.$nextTick(()=>{
          this.$refs.toolSelect.init(null,null,false)
        })
      },
      selectHandle(source,index,data){
        this.toolDataInfo = []
        let toolInfo = {toolId:data.toolId,toolCode:data.toolCode,toolName:data.toolName}
        this.toolDataInfo.push(toolInfo)
      },
      /**初始化 **/
      resetForm() {
        let self = this
        self.form.docPrincipalsName = null
        this.$refs.form.resetFields();
        this.toolDataInfo = []
        this.fileList = []
        this.attachmentList = []
        this.detailBoolean = false
        this.setAllRequiredTrue(true)
        this.$nextTick(()=>{
          if(self.$refs.uploadFile){
            self.$refs.uploadFile.clearFile();
          }
        })
      },
      editInit(docId, type){
        let self = this
        if(type == "detail"){
          this.detailBoolean = true
          self.setAllRequiredTrue(false)
        }
        self.$refs.form.resetFields();
        self.toolDataInfo = []
        self.$nextTick(()=>{
          if(self.$refs.uploadFile){
            self.$refs.uploadFile.clearFile();
          }

          getDocument(docId).then(res => {
            self.form = res.data
            self.toolDataInfo = []
            let toolInfo = {toolId:self.form.toolId,toolName:self.form.toolName}
            self.toolDataInfo.push(toolInfo)

            self.dataFile = []
           /*  let fileData = res.data.attachment
            self.$set(fileData, "name", fileData.fileOldName)
            self.$set(fileData, "size", fileData.fileSize)
            self.dataFile.push(fileData) */

            self.getAttachmentList()
          });
        })
      },
      /** 评论 **/
      handleDiscussions(){
        let self = this
        if (this.discussionContent == '' || this.discussionContent == null || this.discussionContent == undefined) {
          self.$message({
            message: '内容不能为空',//提示的信息
            type:'warning',　　//类型是成功
            duration:1200,　　//显示时间, 毫秒。设为 0 则不会自动关闭，建议1200
          });
          return;
        }
        let data = {
          businessId: this.form.docId,
          content: this.discussionContent,
          type: "doc",
        }
        self.$modal.confirm('是否确认发布？').then(()=> {
          addDiscussions(data).then(res => {
            this.discussionContent = null
            self.$message({
              message: '发布成功',//提示的信息
              type:'success',　　//类型是成功
              duration:1200,　　//显示时间, 毫秒。设为 0 则不会自动关闭，建议1200
            });
            self.getAttachmentList()
          }).catch(err =>{
            this.discussionContent = null
            console.error("handleDiscussions==err==", err)
            self.$modal.msgError("发布失败");
          });
        })
      },
      getAttachmentList() {
        let self = this
        this.$set(this.queryParams,'del',"0")
        this.$set(this.queryParams,'businessId',this.form.docId)
        listAttachment(this.queryParams).then(res => {
          self.attachmentList = res.rows;
          // self.total = res.total;
          self.loading = false;
        });
      },
      getFirstChar(value) {
        if(!value){return ''}
        return value.charAt(0);
      },
      toggleReplyForm(index) {
        this.$set(this.showReplyForm, index, !this.showReplyForm[index]);
      },
      cancelReply(index) {
        this.$set(this.showReplyForm, index, false);
        this.$set(this.replyContent, index, '');
      },
      /** 第二级 **/
      toggleReplyFormSon(parentIndex, repIndex) {
        const parentItem = this.discussionsList[parentIndex];
        this.$set(parentItem.showReplyFormSon, repIndex, !parentItem.showReplyFormSon[repIndex]);
        // this.$set(this.showReplyFormSon, index, !this.showReplyFormSon[index]);
      },
      /** 第二级，取消回复 **/
      cancelReplySon(parentIndex, repIndex) {
        const parentItem = this.discussionsList[parentIndex];
        this.$set(parentItem.showReplyFormSon, repIndex, false);
        this.$set(parentItem.replyContentSon, repIndex, '');
      },
      /** 第二级回复 **/
      submitReplySon(parentIndex, repIndex, repItem) {
        let self = this
        const parentItem = this.discussionsList[parentIndex];
        const content = parentItem.replyContentSon[repIndex];
        if (content.trim() == '' || content == null || content == undefined) {
          self.$message({
            message: '回复内容不能为空',//提示的信息
            type:'warning',　　//类型是成功
            duration:1200,　　//显示时间, 毫秒。设为 0 则不会自动关闭，建议1200
          });
          return;
        }
        let data = {
          "discussionId": repItem.id,
          "content": content,
        }

        self.$modal.confirm('是否确认发布？').then(()=> {
          addReplies(data).then(res => {
            self.$message({
              message: '发布成功',//提示的信息
              type:'success',　　//类型是成功
              duration:1200,　　//显示时间, 毫秒。设为 0 则不会自动关闭，建议1200
            });
            self.cancelReplySon(parentIndex, repIndex)
            self.getAttachmentList()
          }).catch(err =>{
            console.error("submitReplySon==err==", err)
            self.$modal.msgError("发布失败");
          });
        })

        // 清空回复内容并隐藏表单
        this.$set(parentItem.replyContentSon, repIndex, '');
        this.$set(parentItem.showReplyFormSon, repIndex, false);
      },
      /** 回复 **/
      submitReply(index, item) {
        let self = this
        const content = this.replyContent[index];
        if (content == '' || content == null || content == undefined) {
          self.$message({
            message: '回复内容不能为空',//提示的信息
            type:'warning',　　//类型是成功
            duration:1200,　　//显示时间, 毫秒。设为 0 则不会自动关闭，建议1200
          });
          return;
        }
        let data = {
          "discussionId": item.id,
          "content": content,
        }

        self.$modal.confirm('是否确认发布？').then(()=> {
          addReplies(data).then(res => {
            self.$message({
              message: '发布成功',//提示的信息
              type:'success',　　//类型是成功
              duration:1200,　　//显示时间, 毫秒。设为 0 则不会自动关闭，建议1200
            });
            self.cancelReply(index)
            self.getAttachmentList()
          }).catch(err =>{
            console.error("handleDiscussions==err==", err)
            self.$modal.msgError("发布失败");
          });
        })

        // 清空回复内容并隐藏表单
        this.replyContent[index] = '';
        this.showReplyForm[index] = false;
      },
      previewAuth(row){
        if(row.fileUrl == null || row.fileUrl == '' || row.fileUrl == undefined){
          return false
        }
        let extension = this.getExtension(row.fileUrl);
        const acceptedExtensions = this.attFileType.toLowerCase().split(',');
        if(acceptedExtensions.includes(extension)){
          return false
        }
        return true
      },
      getExtension(filePath) {
        // 分割字符串，以 '.' 为分隔符
        const parts = filePath.split('.');
        // 取最后一个部分作为后缀名
        const extension = parts.pop();
        return extension;
      },
      handlePreview(row){
        this.isPreviewDisable = true
        this.previewLoading = true
        this.$nextTick(() => {
          this.$refs.previewForm.frontModulePreview(row)
        })
      },
      /** 关闭预览 **/
      previewClose(){
        this.isPreviewDisable = false
      },
      /** 关闭预览遮罩 **/
      previewLoadingClose(){
        this.previewLoading = false
      },
      /**
       * 处理下载
       * **/
      handleDownload(row){
        let self = this
        self.loadingDownload = true
        this.$download.resource(row.fileUrl);

        //保存下载记录
        if(row.businessId){
          let formData = {
            'businessId': row.businessId,
            'businessType': 'doc',
            'attId': row.id,
            'attName': row.fileOldName
          }
          addCount(formData).then(res => {
          });
        }

        setTimeout(()=>{
          self.loadingDownload = false
        },1000)
      },
      handleDelete(row){
        const index = this.attachmentList.findIndex(item => item.fileNewName == row.fileNewName);
        if (index !== -1) {
          // 从 attachmentList 中删除数据
          this.attachmentList.splice(index, 1);
          // 处理当前页面可能没有数据的情况，跳到上一页
          if (this.paginatedData.length === 0 && this.currentPage > 1) {
            this.currentPage--;
          }
        }
        // this.attachmentList.splice(row,1)
      },
      handleBeforeClose() {
        this.viewDialogOpen = false
      },
      handleUploadSuccess(res) {
        this.attachmentList.push(res)
        // 处理上传成功后的逻辑
      },
      handleUploadError(error) {
        // 处理上传失败后的逻辑
      },
      isShowOperation(row){
        let self = this
        if(row.businessId == null || row.businessId == undefined || row.businessId == ''){
          return false
        }
        return true
      },
      submitPeople(peopleList){
        this.$set(this.form,'docPrincipals',peopleList[0]['userId'])
        this.$set(this.form,'docPrincipalsName',peopleList[0]['nickName'])
        this.toolPrincipalsChoose = false;
      },
      setAllRequiredTrue(value) {
        Object.keys(this.rules).forEach(key => {
          this.rules[key].forEach(rule => {
            rule.required = value;
          });
        });
      },
      handlePageChange(newPage) {
        this.currentPage = newPage;
      },

    }
  }
</script>

<style scoped>

</style>
