<template>
  <div class="ratingReport">
    <div style="padding-top: 5px">
      <h3>评级报告</h3>
      <div class="dataInfo">
        <div class="item-left">
          <div
            class="info-bin_page-content-line"
            v-for="(item) in baseInfo.filter((item,index)=>index<8)"
            :key="item.reportOrder"
          >
            <div class="info-bin_page-content-item">{{item.reportItem}}：{{ item.reportText}}</div>
          </div>
        </div>
        <div class="item-right">
          <div
            class="info-bin_page-content-line"
            v-for="(item) in baseInfo.filter((item,index)=>index>=8)"
            :key="item.reportOrder"
          >
            <div class="info-bin_page-content-item">{{item.reportItem}}：{{ item.reportText}}</div>
          </div>
        </div>
      </div>
    </div>
    <hr style="margin: 10px 0" />
    <el-form
      label-position="top"
      label-width="80px"
      :model="dataList"
      :validate-on-rule-change="false"
      :rules="gropRules"
      ref="ruleform"
    >
      <el-form-item
        v-for="(item,index) in formGroup"
        :key="item.key"
        :label="item.type==='toggleTextarea'?'':item.reportItem"
        :prop="item.key"
      >
        <template
          v-if="formGroup[index+1]?formGroup[index+1].type==='toggleTextarea':false"
          slot="label"
        >
          {{item.reportItem}}
          <img
            class="checkIcon"
            @click="toggleInput(formGroup[index+1].key)"
            src="~@/assets/checkIcon.png"
            alt
          />
        </template>
        <template v-if="item.type==='textarea'">
          <el-input
            class="textareaInput"
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList[item.key]"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </template>
        <template v-if="item.type==='richText'">
          <tinymce v-model="dataList[item.key]"></tinymce>
        </template>
        <template v-if="item.type==='toggleTextarea'">
          <div :ref="`t_${item.key}`" style="display:none;">
            <el-input
              type="textarea"
              :autosize="{ minRows: 3, maxRows: 5 }"
              placeholder="请输入审核意见"
              v-model="dataList[item.key]"
              maxlength="300"
              show-word-limit
              clearable
              onchange="this.value=this.value.trim()"
              :disabled="!isMyAndIsEdit"
            ></el-input>
          </div>
        </template>
      </el-form-item>
    </el-form>
    <el-form
      label-position="top"
      label-width="80px"
      :model="dataList"
      ref="ruleform"
      :rules="rules"
    >
      <!-- <el-row>
        <el-form-item :span="12" class="info-bin_page-content-line">
          <el-form-item label="外部评级结果及时间" prop="externalRatingTime" class="change_label right">
            <div class="info-bin_page-content-item input">
              <el-input
                type="textarea"
                v-model="dataList.externalRatingTime"
                show-word-limit
                placeholder="请输入"
                clearable
                onchange="this.value=this.value.trim()"
                maxlength="100"
                :disabled="formDisabled"
              ></el-input>
            </div>
          </el-form-item>
        </el-form-item>
      </el-row>-->
      <!-- <div>
        <div class="itemTitle">
          <div class="itemName">评级概要</div>
          <img
            v-if="isMyAndIsAudit||dataList.ratingSummary"
            class="checkIcon"
            @click="toggleInput('checkAdvice')"
            src="~@/assets/checkIcon.png"
            alt
          />
        </div>
        <el-input
          class="textareaInput"
          type="textarea"
          :autosize="{ minRows: 3, maxRows: 5 }"
          placeholder="请输入"
          v-model="dataList.ratingSummary"
          maxlength="5000"
          show-word-limit
          clearable
          onchange="this.value=this.value.trim()"
          :disabled="formDisabled"
        ></el-input>
        <div ref="checkAdvice" style="display:none;">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入审核意见"
            v-model="dataList.ratingSummary"
            maxlength="300"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="!isMyAndIsAudit"
          ></el-input>
        </div>
      </div>-->
      <!-- <el-form-item label="评级概要" prop="ratingSummary">
        <el-input
          type="textarea"
          :autosize="{ minRows: 3, maxRows: 5 }"
          placeholder="请输入"
          v-model="dataList.ratingSummary"
          maxlength="5000"
          show-word-limit
          clearable
          onchange="this.value=this.value.trim()"
          :disabled="formDisabled"
        ></el-input>
      </el-form-item>
      <el-form-item label="审核意见" prop="advantage">
        <el-input
          type="textarea"
          :autosize="{ minRows: 3, maxRows: 5 }"
          placeholder="请输入"
          v-model="dataList.advantage"
          maxlength="5000"
          show-word-limit
          clearable
          onchange="this.value=this.value.trim()"
          :disabled="formDisabled"
        ></el-input>
      </el-form-item>-->
      <!-- <el-form-item label="关注点" prop="focus">
        <el-input
          type="textarea"
          :autosize="{ minRows: 3, maxRows: 5 }"
          placeholder="请输入"
          v-model="dataList.focus"
          maxlength="5000"
          show-word-limit
          clearable
          onchange="this.value=this.value.trim()"
          :disabled="formDisabled"
        ></el-input>
      </el-form-item>-->
      <el-form-item label="评级改变原因" prop="ratingChange">
        <el-input
          type="textarea"
          :autosize="{ minRows: 3, maxRows: 5 }"
          placeholder="请输入"
          v-model="dataList.ratingChange"
          maxlength="5000"
          show-word-limit
          clearable
          onchange="this.value=this.value.trim()"
          :disabled="formDisabled"
        ></el-input>
      </el-form-item>
      <el-form-item label="最终评级与系统评级差异原因" prop="difference">
        <el-input
          type="textarea"
          :autosize="{ minRows: 3, maxRows: 5 }"
          placeholder="请输入"
          v-model="dataList.difference"
          maxlength="5000"
          show-word-limit
          clearable
          onchange="this.value=this.value.trim()"
          disabled
        ></el-input>
      </el-form-item>
      <el-form-item label="展望说明" prop="expectationInstructions">
        <el-input
          type="textarea"
          :autosize="{ minRows: 3, maxRows: 5 }"
          placeholder="请输入"
          v-model="dataList.expectationInstructions"
          maxlength="5000"
          show-word-limit
          clearable
          onchange="this.value=this.value.trim()"
          :disabled="formDisabled"
        ></el-input>
      </el-form-item>
      <el-form-item label="财报质量及审计师意见" prop="opinion">
        <el-input
          type="textarea"
          :autosize="{ minRows: 3, maxRows: 5 }"
          placeholder="请输入"
          v-model="dataList.opinion"
          maxlength="5000"
          show-word-limit
          clearable
          onchange="this.value=this.value.trim()"
          :disabled="formDisabled"
        ></el-input>
      </el-form-item>
      <div class="financialAnalysis">
        <h3>定量财务分析</h3>
        <hr />
        <el-form-item label="财务指标数据" prop="financialTargetList" v-if="financialTargetListShow">
          <financialTarget
            :guaranteeList="dataList.financialTargetList"
            :branchType="dataList.branchType"
          />
        </el-form-item>
        <el-form-item label="财务指标数据" v-else>
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 3 }"
            placeholder="暂无数据"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="盈利能力" prop="profitability" v-if="typeFlag">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.profitability"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="营业收入/盈利能力" prop="taking" v-else>
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.taking"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="杠杆/资本化/覆盖率" prop="lever" v-if="!typeFlag">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.lever"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="流动性" prop="mobility">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.mobility"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="资本充足水平" prop="capitalLevel" v-if="typeFlag">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.capitalLevel"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="现金流" prop="cashFlow" v-if="!typeFlag">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.cashFlow"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="资产质量" prop="capitalQuality" v-if="typeFlag">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.capitalQuality"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="定量财务分析-其他" prop="financialOther">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.financialOther"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
      </div>
      <div class="businessAssessment">
        <h3>定性业务评估</h3>
        <hr />
        <el-form-item label="公司概况" prop="companyProfile" v-if="typeFlag">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.companyProfile"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item prop="uploadFiles" v-if="typeFlag">
          <div>
            <button-upload
              ref="uploadFiles"
              v-model="dataList.uploadFiles"
              :file.sync="dataList.uploadFiles"
              :is-view="isView"
              :suffix="suffix"
              :limited="limited"
              :download-flag="downloadFlag"
              :delete-flag="deleteFlag"
              :upload-flag="uploadFlag"
              :case-id="caseId"
              report-item="公司概况"
              report-order="37"
            ></button-upload>
            <div class="uploadTitle">
              <span>最多可上传5张，上传文件支持格式：jpg，jpeg，png</span>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="公司简介" prop="introduction" v-if="!typeFlag">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.introduction"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item prop="uploadFiles" v-if="!typeFlag">
          <div>
            <button-upload
              ref="uploadFiles1"
              v-model="dataList.uploadFiles1"
              :file.sync="dataList.uploadFiles1"
              :is-view="isView"
              :suffix="suffix"
              :limited="limited"
              :download-flag="downloadFlag"
              :delete-flag="deleteFlag"
              :upload-flag="uploadFlag"
              :case-id="caseId"
              report-item="公司简介"
              report-order="49"
            ></button-upload>
            <div class="uploadTitle">
              <span>最多可上传5张，上传文件支持格式：jpg，jpeg，png</span>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="经营环境" prop="condition" v-if="typeFlag">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.condition"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="行业分析" prop="analysis" v-else>
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.analysis"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="公司地位" prop="companyStatus">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.companyStatus"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="管理/战略/风险偏好" prop="Management" v-if="typeFlag">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.Management"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="管理/战略" prop="strategy" v-else>
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.strategy"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="定性业务评估-其他" prop="businessOthter">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.businessOthter"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
      </div>
      <div class="supportRating">
        <h3>支持评级</h3>
        <hr />
        <el-form-item prop="supportRating">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.supportRating"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
          ></el-input>
        </el-form-item>
      </div>
      <div class="marketData">
        <h3>市场数据</h3>
        <hr />
        <el-form-item label="市值" prop="marketValue">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.marketValue"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
            @blur="changeData('marketValue')"
          ></el-input>
        </el-form-item>
        <el-form-item label="最新收盘价" prop="latestPrice">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.latestPrice"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
            @blur="changeData('latestPrice')"
          ></el-input>
        </el-form-item>
        <el-form-item label="最近52周最高价" prop="topPrice">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.topPrice"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
            @blur="changeData('topPrice')"
          ></el-input>
        </el-form-item>
        <el-form-item label="最近52周最低价" prop="minimumPrice">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 5 }"
            placeholder="请输入"
            v-model="dataList.minimumPrice"
            maxlength="5000"
            show-word-limit
            clearable
            onchange="this.value=this.value.trim()"
            :disabled="formDisabled"
            @blur="changeData('minimumPrice')"
          ></el-input>
        </el-form-item>
      </div>
    </el-form>
    <div class="footer">
      <el-button type="primary" class="btnwidth" @click="save" v-if="!formDisabled">保 存</el-button>
      <el-button @click="cancel" class="btnwidth" v-if="!formDisabled">取 消</el-button>
      <el-button @click="cancel" class="btnwidth" v-else>退 出</el-button>
    </div>
  </div>
</template>
<script>
import { ratingFind, ratingFindAudit, ratingReportAdd } from '@/api/index';
import { toThousandsNoZero } from '@/utils/formatter';
import financialTarget from '@/components/financialTarget/financialTarget.vue';
import tinymce from '@/components/tinymce/index.vue'
const RTM_DETAIL_PATH = ['/home/ratingmanage/reportdetail', '/home/psu-srt/home/ratingmanage/reportdetail'];
const RTV_DETAIL_PATH = ['/home/ratingverify/reportdetail', '/home/psu-srt/home/ratingverify/reportdetail'];
const RTM_EDIT_PATH = ['/home/ratingmanage/editreport', '/home/psu-srt/home/ratingmanage/editreport'];

export default {
  components: { financialTarget, tinymce },
  name: 'ratingReport',
  data () {
    return {
      showCheckAdvice: false,
      isMyAndIsAudit: false,
      financialTargetListShow: true,
      parentCompanyName: '',
      type: '',
      suffix: ['jpg', 'jpeg', 'png'], //文件类型
      limited: 5, //文件个数
      formDisabled: false, //禁用表单
      viewFlag: 0,
      form: [
        { reportItem: '公司名称', reportText: '' },
        { reportItem: '评级结果', reportText: '' },
        { reportItem: '组织形式', reportText: '' },
        { reportItem: '评级时间', reportText: '' },
        { reportItem: '营业执照号', reportText: '' },
        { reportItem: '上次评级结果', reportText: '' },
        { reportItem: '公司编号', reportText: '' },
        { reportItem: '上次评级时间', reportText: '' },
        { reportItem: '机构类型', reportText: '' },
        { reportItem: '评级分析员', reportText: '' },
        { reportItem: '财报日期', reportText: '' },
        { reportItem: '评级复核员', reportText: '' },
      ],
      rsData: [],
      ratingTime: '',
      typeFlag: null, //true表示银行
      isFlag: true,
      downloadFlag: null,
      deleteFlag: null,
      uploadFlag: null,
      baseInfo: [],
      gropRules: {},
      formGroup: [
        { reportItem: '外部评级结果及时间', key: 'externalRatingTime', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 1 },
        { reportItem: '评级概要', key: 'ratingSummary', type: 'richText', required: true, disabled: false, reportText: '', reportOrder: 2 },
        { reportItem: '审核意见', key: 'ratingSummaryyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 3 },
        { reportItem: '关注点', key: 'focus', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 4 },
        { reportItem: '审核意见', key: 'focusyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 5 },
        // { reportItem: '财务指标数据', key: 'financialTarget', type: 'financialTable', required: false, disabled: false, reportText: '', reportOrder: 4 },
        { reportItem: '评级改变原因', key: 'ratingChange', type: 'textarea', required: false, disabled: false, reportText: '', reportOrder: 6 },
        { reportItem: '审核意见', key: 'ratingChangeyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 7 },
        { reportItem: '最终评级与系统评级差异原因', key: 'difference', type: 'textarea', required: false, disabled: false, reportText: '', reportOrder: 8 },
        { reportItem: '审核意见', key: 'differenceyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 9 },
        { reportItem: '展望说明', key: 'expectationInstructions', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 10 },
        { reportItem: '审核意见', key: 'expectationInstructionsyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 11 },
        { reportItem: '财报质量及审计师意见', key: 'opinion', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 12 },
        { reportItem: '审核意见', key: 'opinionyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 13 },
        { reportItem: '财务指标数据', key: 'financialTarget', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 14 },
        { reportItem: '审核意见', key: 'financialTargetyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 15 },
        { reportItem: '盈利能力', key: 'profitability', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 16 },
        { reportItem: '审核意见', key: 'profitabilityyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 17 },
        { reportItem: '营业收入/盈利能力', key: 'taking', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 18 },
        { reportItem: '审核意见', key: 'takingyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 19 },
        { reportItem: '流动性', key: 'mobility', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 20 },
        { reportItem: '审核意见', key: 'mobilityyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 21 },
        { reportItem: '资本充足水平', key: 'capitalLevel', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 22 },
        { reportItem: '审核意见', key: 'capitalLevelyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 23 },
        { reportItem: '杠杆/资本化/覆盖率', key: 'lever', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 24 },
        { reportItem: '审核意见', key: 'leveryj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 25 },
        { reportItem: '资产质量', key: 'capitalQuality', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 26 },
        { reportItem: '审核意见', key: 'capitalQualityyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 27 },
        { reportItem: '现金流', key: 'cashFlow', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 28 },
        { reportItem: '审核意见', key: 'cashFlowyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 29 },
        { reportItem: '定量财务分析-其他', key: 'financialOther', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 30 },
        { reportItem: '审核意见', key: 'financialOtheryj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 31 },
        { reportItem: '公司概况', key: 'companyProfile', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 32 },
        { reportItem: '审核意见', key: 'companyProfileyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 33 },
        { reportItem: '经营环境', key: 'condition', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 34 },
        { reportItem: '审核意见', key: 'conditionyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 35 },
        { reportItem: '公司地位', key: 'companyStatus', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 36 },
        { reportItem: '审核意见', key: 'companyStatusyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 37 },
        { reportItem: '管理/战略/风险偏好', key: 'Management', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 38 },
        { reportItem: '审核意见', key: 'Managementyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 39 },
        { reportItem: '管理/战略', key: 'strategy', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 40 },
        { reportItem: '审核意见', key: 'strategyyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 41 },
        { reportItem: '定性业务评估-其他', key: 'businessOthter', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 42 },
        { reportItem: '审核意见', key: 'businessOthteryj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 43 },
        { reportItem: '支持评级', key: 'supportRating', type: 'textarea', required: true, disabled: false, reportText: '', remarks: '', reportOrder: 44 },
        { reportItem: '审核意见', key: 'supportRatingyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 45 },
        { reportItem: '市值', key: 'marketValue', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 46 },
        { reportItem: '审核意见', key: 'marketValueyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 47 },
        { reportItem: '最新收盘价', key: 'latestPrice', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 48 },
        { reportItem: '审核意见', key: 'latestPriceyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 49 },
        { reportItem: '最近52周最高价', key: 'topPrice', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 50 },
        { reportItem: '审核意见', key: 'topPriceyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 51 },
        { reportItem: '最近52周最低价', key: 'minimumPrice', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 52 },
        { reportItem: '审核意见', key: 'minimumPriceyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 53 },
        { reportItem: '公司简介', key: 'introduction', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 54 },
        { reportItem: '审核意见', key: 'introductionyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 55 },
        { reportItem: '行业分析', key: 'analysis', type: 'textarea', required: true, disabled: false, reportText: '', reportOrder: 56 },
        { reportItem: '审核意见', key: 'analysisyj', type: 'toggleTextarea', required: true, disabled: false, reportText: '', reportOrder: 57 },
      ],
      formData: [
        { reportItem: '外部评级结果及时间', key: 'externalRatingTime', reportText: '', remarks: '', reportOrder: 13 },
        { reportItem: '评级概要', key: 'ratingSummary', reportText: '', reportOrder: 22 },
        { reportItem: '优势', key: 'advantage', reportText: '', reportOrder: 23 },
        { reportItem: '关注点', key: 'focus', reportText: '', reportOrder: 24 },
        { reportItem: '评级改变原因', key: 'ratingChange', reportText: '', reportOrder: 25 },
        { reportItem: '最终评级与系统评级差异原因', key: 'difference', reportText: '', reportOrder: 26, updateTime: '' },
        { reportItem: '展望说明', key: 'expectationInstructions', reportText: '', reportOrder: 27 },
        { reportItem: '财报质量及审计师意见', key: 'opinion', reportText: '', reportOrder: 28 },
        { reportItem: '财务指标数据', key: 'financialTarget', reportText: '', reportOrder: 20 },
        { reportItem: '盈利能力', key: 'profitability', reportText: '', reportOrder: 29 },
        { reportItem: '营业收入/盈利能力', key: 'taking', reportText: '', reportOrder: 30 },
        { reportItem: '流动性', key: 'mobility', reportText: '', reportOrder: 31 },
        { reportItem: '资本充足水平', key: 'capitalLevel', reportText: '', reportOrder: 32 },
        { reportItem: '杠杆/资本化/覆盖率', key: 'lever', reportText: '', reportOrder: 33 },
        { reportItem: '资产质量', key: 'capitalQuality', reportText: '', reportOrder: 34 },
        { reportItem: '现金流', key: 'cashFlow', reportText: '', reportOrder: 35 },
        { reportItem: '定量财务分析-其他', key: 'financialOther', reportText: '', reportOrder: 36 },
        { reportItem: '公司概况', key: 'companyProfile', reportText: '', reportOrder: 37 },
        { reportItem: '经营环境', key: 'condition', reportText: '', reportOrder: 39 },
        { reportItem: '公司地位', key: 'companyStatus', reportText: '', reportOrder: 40 },
        { reportItem: '管理/战略/风险偏好', key: 'Management', reportText: '', reportOrder: 41 },
        { reportItem: '管理/战略', key: 'strategy', reportText: '', reportOrder: 42 },
        { reportItem: '定性业务评估-其他', key: 'businessOthter', reportText: '', reportOrder: 43 },
        { reportItem: '支持评级', key: 'supportRating', reportText: '', remarks: '', reportOrder: 44 },
        { reportItem: '市值', key: 'marketValue', reportText: '', reportOrder: 45 },
        { reportItem: '最新收盘价', key: 'latestPrice', reportText: '', reportOrder: 46 },
        { reportItem: '最近52周最高价', key: 'topPrice', reportText: '', reportOrder: 47 },
        { reportItem: '最近52周最低价', key: 'minimumPrice', reportText: '', reportOrder: 48 },
        { reportItem: '公司简介', key: 'introduction', reportText: '', reportOrder: 49 },
        { reportItem: '行业分析', key: 'analysis', reportText: '', reportOrder: 50 },
      ],
      dataList: {
        branchName: '',
        masterResult: '',
        branchOrgaform: '',
        ratingTime: '',
        businessLicense: '',
        latestLevel: '',
        branchNum: '',
        latestLevelTime: '',
        branchType: '',
        ratingAnalyst: '',
        earningsTime: '',
        ratingReview: '',
        parentCompanyName: '',
        externalRatingTime: '',
        expectation: '',
        expectationInstructions: '',
        ratingSummary: '',
        advantage: '',
        focus: '',
        ratingChange: '',
        difference: '',
        opinion: '',
        financialTargetList: {},
        profitability: '',
        taking: '',
        mobility: '',
        capitalLevel: '',
        lever: '',
        capitalQuality: '',
        cashFlow: '',
        financialOther: '',
        companyProfile: '',
        uploadFiles: '',
        condition: '',
        companyStatus: '',
        Management: '',
        businessOthter: '',
        supportRating: '',
        marketValue: '',
        latestPrice: '',
        topPrice: '',
        minimumPrice: '',
        strategy: '',
        introduction: '', //公司简介
        analysis: '', //行业分析
        uploadFiles1: '', //公司简介附件
      },
      uploadFiles: '',
      isView: false,
      IntervalTask: null,
      caseId: '', //案例编号
      updateTime: '', //用于区分页面的时间
      intervalFlag: true,
      rules: {
        expectationInstructions: [{ required: true, message: '请输入展望说明', trigger: 'blur' }],
        ratingSummary: [{ required: true, message: '请输入评级概要', trigger: 'blur' }],
        advantage: [{ required: true, message: '请输入优势', trigger: 'blur' }],
        focus: [{ required: true, message: '请输入关注点', trigger: 'blur' }],
        difference: [{ required: true, message: '请输入最终评级与系统评级差异原因', trigger: 'blur' }],
        opinion: [{ required: true, message: '请输入财报质量及审计师意见', trigger: 'blur' }],
        profitability: [{ required: true, message: '请输入盈利能力', trigger: 'blur' }],
        taking: [{ required: true, message: '请输入营业收入/盈利能力', trigger: 'blur' }],
        mobility: [{ required: true, message: '请输入流动性', trigger: 'blur' }],
        capitalLevel: [{ required: true, message: '请输入资本充足水平', trigger: 'blur' }],
        lever: [{ required: true, message: '请输入杠杆/资本化/覆盖率', trigger: 'blur' }],
        capitalQuality: [{ required: true, message: '请输入资产质量', trigger: 'blur' }],
        cashFlow: [{ required: true, message: '请输入现金流', trigger: 'blur' }],
        companyProfile: [{ required: true, message: '请输入公司概况', trigger: 'blur' }],
        introduction: [{ required: true, message: '请输入公司简介', trigger: 'blur' }],
        companyStatus: [{ required: true, message: '请输入公司地位', trigger: 'blur' }],
        Management: [{ required: true, message: '请输入管理/战略/风险偏好', trigger: 'blur' }],
        strategy: [{ required: true, message: '请输入管理/战略', trigger: 'blur' }],
      },
      findDetail: [
        {
          caseId: "B0739-220304-1323",
          comments: null,
          createBy: "srt-test24@aexpec.com",
          createTime: "2022-03-04 11:07:33",
          fileList: null,
          reportItem: "公司名称",
          reportOrder: 0,
          reportText: "测试银行使用-Xiaolong",
          updateBy: null,
          updateTime: 0,
        },
        {
          caseId: "B0739-220304-1323",
          comments: null,
          createBy: "srt-test24@aexpec.com",
          createTime: "2022-03-04 11:07:33",
          fileList: null,
          reportItem: "组织形式",
          reportOrder: 1,
          reportText: "",
          updateBy: null,
          updateTime: 0,
        },
        {
          caseId: "B0739-220304-1323",
          comments: null,
          createBy: "srt-test24@aexpec.com",
          createTime: "2022-03-04 11:07:33",
          fileList: null,
          reportItem: "统一社会信用代码",
          reportOrder: 2,
          reportText: "1234567",
          updateBy: null,
          updateTime: 0,
        }
      ]
    };
  },
  watch: {
    $route (to, from) {
      if ([...RTM_DETAIL_PATH, ...RTV_DETAIL_PATH].includes(this.$route.path)) {
        this.formDisabled = true;
        this.viewFlag = 0;
      } else {
        this.formDisabled = false;
        this.viewFlag = 1;
      }
    },
  },
  mounted () {
    this.initGroup()
    this.caseId = this.$route.query.caseId;
    this.type = this.$route.query.type;
    // this.downloadFlag = this.$hasBtnPerm('downloadFlag');
    if ([...RTM_DETAIL_PATH, ...RTV_DETAIL_PATH].includes(this.$route.path)) {
      this.formDisabled = true;
      this.viewFlag = 0;
      if (RTM_DETAIL_PATH.includes(this.$route.path)) {
        this.downloadFlag = this.$hasBtnPerm('ratingMDownloadReportAttach');
      } else {
        this.downloadFlag = this.$hasBtnPerm('ratingVDownloadReportAttach');
      }
    } else {
      //评级报告维护页面
      this.formDisabled = false;
      this.viewFlag = 1;
      this.downloadFlag = this.$hasBtnPerm('ratingMDownloadReportAttach');
      this.deleteFlag = this.$hasBtnPerm('ratingMDeleteReportAttach');
      this.uploadFlag = this.$hasBtnPerm('ratingMUploadReportAttach');
    }
    this.getCaseDetail();
    if (this.formDisabled === false) {
      this.isView = false;
      this.IntervalTask = setInterval(() => {
        this.saveForm();
      }, 30000);
    } else {
      this.isView = true;
      if (this.IntervalTask) {
        clearInterval(this.IntervalTask);
      }
    }
    this.isMyAndIsAudit = this.$route.query.isMyAndIsAudit
    console.log('this.isMyAndIsAudit: ', this.isMyAndIsAudit);
  },
  beforeDestroy () {
    if (this.IntervalTask) {
      clearInterval(this.IntervalTask);
    }
  },
  methods: {
    initGroup () {
      this.formGroup.map(item => {
        if (item.required) {
          this.$set(this.gropRules, item.key, [
            {
              required: true,
              message: `请输入${item.reportItem}`,
              trigger: 'blur'
            }
          ])
        }
        this.$set(this.dataList, item.key, '')
      })
    },
    toggleInput (id) {
      if (this.$refs[`t_${id}`][0].style.display === 'none') {
        this.$refs[`t_${id}`][0].style.display = 'block'
      } else {
        this.$refs[`t_${id}`][0].style.display = 'none'
      }
    },
    //获取数据
    async getCaseDetail () {
      try {
        let res = '';
        if ([...RTM_DETAIL_PATH, ...RTM_EDIT_PATH].includes(this.$route.path)) {
          res = await ratingFind({ caseId: this.caseId, flag: this.viewFlag });
          if (res != 'code') {
            this.parentCompanyName = res.reportList[5].reportText;
          }
        } else {
          res = await ratingFindAudit({ caseId: this.caseId });
          if (res != 'code') {
            this.parentCompanyName = res.reportList[5].reportText;
          }
        }
        if (res !== 'code') {
          this.init(res.reportList);
          if (res.financialList) {
            this.dataList.financialTargetList = res.financialList;
            if (res.financialList.financialList.length) {
              this.financialTargetListShow = true;
            }
          } else {
            this.financialTargetListShow = false;
          }
        }
      } catch (error) {
        console.log(error);
      }
    },
    //回显评级报告信息
    async init (data) {
      const path = this.$route.path
      if (path.indexOf('/editreport') >= 0) {
        this.baseInfo = data.slice(0, 16).filter((item) => {
          return item.reportItem != '外部评级结果及时间'
        })
      }
      if (path.indexOf('/reportdetail') >= 0) {
        this.baseInfo = data.slice(0, 16)
      }
      data.forEach((element) => {
        this.formData.forEach(item => {
          if (item.reportItem === element.reportItem) {
            this.dataList[item.key] = element.reportText
            this.dataList[item.remarkKey] = element.remark
            if (item.reportItem == '最终评级与系统评级差异原因') {
              this.updateTime = element.updateTime
            }
          }
        })
      })
      this.typeFlag = this.dataList.branchType === '银行' ? true : false;
    },
    //自动保存
    async saveForm () {
      this.formData.forEach(item => {
        item.reportText = this.dataList[item.key]
        if (item.remarkKey) {
          item.remark = this.dataList[item.remarkKey]
        }
        if (item.reportItem == '最终评级与系统评级差异原因') {
          item.updateTime = this.updateTime
        }
      })
      this.rsData = JSON.parse(JSON.stringify(this.formData));
      this.rsData = this.rsData.filter((el) => {
        if (!this.typeFlag) {
          if (
            el.reportItem !== '盈利能力' &&
            el.reportItem !== '资本充足水平' &&
            el.reportItem !== '资产质量' &&
            el.reportItem !== '公司概况' &&
            el.reportItem !== '经营环境' &&
            el.reportItem !== '管理/战略/风险偏好'
          ) {
            return el;
          }
        } else {
          if (
            el.reportItem !== '营业收入/盈利能力' &&
            el.reportItem !== '杠杆/资本化/覆盖率' &&
            el.reportItem !== '现金流' &&
            el.reportItem !== '公司简介' &&
            el.reportItem !== '行业分析' &&
            el.reportItem !== '管理/战略'
          ) {
            return el;
          }
        }
      });
      let result = await ratingReportAdd({ caseId: this.caseId, reportList: this.rsData });
      if (result !== 'code') {
        if (result !== 40024) {
          this.updateTime = result;
        } else {
          if (this.IntervalTask) {
            clearInterval(this.IntervalTask);
          }
          // this.$alert('保存报告项失败,请勿开启多个评级报告编辑页面! 该页面已失效，请关闭!', '提示', {
          //   confirmButtonText: '确定',
          //   showClose: false,
          //   callback: (action) => {
          //     this.intervalFlag = false;
          //     this.$router.push({ path: '/home/ratingmanage/verify', query: { caseId: this.caseId, source: 'manage' } });
          //   },
          // });
        }
        this.isFlag = true;
      } else {
        this.isFlag = false;
      }
    },
    // 点击保存
    save () {
      let flag = this.validateForm();
      if (flag) {
        this.saveForm();
        if (this.isFlag) {
          this.$message.success('评级信息已保存');
          // this.$router.push({ path: '/home/ratingmanage/verify', query: { caseId: this.caseId, source: 'verify' } });
          setTimeout(() => {
            this.cancel();
          }, 1000);
        } else {
          this.$message.error('评级信息保存失败');
        }
      } else {
        this.$confirm('报告未填写完整，确认要保存当前报告？')
          .then((_) => {
            this.saveForm();
            // this.$router.push({ path: '/home/ratingmanage/verify', query: { caseId: this.caseId, source: 'manage' } });
            setTimeout(() => {
              this.cancel();
            }, 1000);
          })
          .catch((_) => { });
        return;
      }
    },
    // 取消
    cancel () {
      // window.location.href = 'javascript:history.go(-1)';
      window.opener = window; //关闭页面,部分页面不可关闭
      var win = window.open('', '_self');
      win.close();
    },
    //提交表单校验
    validateForm () {
      // if (this.dataList.parentCompanyName != null) {
      //   this.dataList.parentCompanyName = this.dataList.parentCompanyName.trim();
      // }
      // if (this.dataList.externalRatingTime != null) {
      //   this.dataList.externalRatingTime = this.dataList.externalRatingTime.trim();
      // }
      // if (this.dataList.parentCompanyName == null || this.dataList.parentCompanyName == undefined || this.dataList.parentCompanyName == '') {
      //   this.$message.error('请输入母公司名称');
      //   return;
      // }
      // if (this.dataList.externalRatingTime == null || this.dataList.externalRatingTime == undefined || this.dataList.externalRatingTime == '') {
      //   this.$message.error('请输入外部评级结果及时间');
      //   return;
      // }
      for (let item in this.dataList) {
        if (typeof this.dataList[item] === 'string') {
          this.dataList[item] = this.dataList[item].trim();
        }
      }
      this.$refs['ruleform'].clearValidate();
      let res = false;
      this.$refs['ruleform'].validate((valid) => {
        if (valid) {
          res = true;
        } else {
          res = false;
          this.dealCallback();
        }
      });

      return res;
    },
    //回滚锚点定位函数
    dealCallback () {
      this.$nextTick(() => {
        this.$el.querySelector('.el-form-item__error').scrollIntoView();
      });
    },
    isShowCheckAdvice () {
      this.showCheckAdvice = !this.showCheckAdvice
    },
    //设置千分位
    changeData (value) {
      let arr1 = [];
      if (value === 'marketValue') {
        let arr = this.dataList.marketValue.match(/\d+(.\d+)?/g);
        if (this.dataList.marketValue !== null) {
          this.dataList.marketValue = this.dataList.marketValue.trim();
        }
        if (arr != null && arr.length != 0) {
          arr1 = arr.map((item) => {
            return toThousandsNoZero(item);
          });
          arr.forEach((ele, index) => {
            this.dataList.marketValue = this.dataList.marketValue.replace(ele, arr1[index]);
          });
        }
      } else if (value === 'latestPrice') {
        let arr = this.dataList.latestPrice.match(/\d+(.\d+)?/g);
        if (this.dataList.latestPrice !== null) {
          this.dataList.latestPrice = this.dataList.latestPrice.trim();
        }
        if (arr != null && arr.length != 0) {
          arr1 = arr.map((item) => {
            return toThousandsNoZero(item);
          });
          arr.forEach((ele, index) => {
            this.dataList.latestPrice = this.dataList.latestPrice.replace(ele, arr1[index]);
          });
        }
      } else if (value === 'topPrice') {
        let arr = this.dataList.topPrice.match(/\d+(.\d+)?/g);
        if (this.dataList.topPrice !== null) {
          this.dataList.topPrice = this.dataList.topPrice.trim();
        }
        if (arr != null && arr.length != 0) {
          arr1 = arr.map((item) => {
            return toThousandsNoZero(item);
          });
          arr.forEach((ele, index) => {
            this.dataList.topPrice = this.dataList.topPrice.replace(ele, arr1[index]);
          });
        }
      } else if (value === 'minimumPrice') {
        let arr = this.dataList.minimumPrice.match(/\d+(.\d+)?/g);
        if (this.dataList.minimumPrice !== null) {
          this.dataList.minimumPrice = this.dataList.minimumPrice.trim();
        }
        if (arr != null && arr.length != 0) {
          arr1 = arr.map((item) => {
            return toThousandsNoZero(item);
          });
          arr.forEach((ele, index) => {
            this.dataList.minimumPrice = this.dataList.minimumPrice.replace(ele, arr1[index]);
          });
        }
      }
    },
  },
};
</script>

<style scoped lang="less">
.el-submenu {
  .el-menu-item {
    padding: 0;
  }
}
.btnwidth {
  width: 80px;
  margin-left: 30px;
}
.itemTitle {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  .checkIcon {
    width: 20px;
    height: 20px;
    margin-left: 10px;
    display: inline-block;
    cursor: pointer;
  }
  .textareaInput {
    margin-bottom: 10px;
  }
}

.ratingReport {
  padding: 10px 30px 0 30px;
  background: #ffffff;
  height: 100%;
  margin-bottom: 10px;
  position: relative;
  padding-bottom: 60px;
  &::-webkit-scrollbar {
    /*滚动条整体样式*/
    width: 4px; /*高宽分别对应横竖滚动条的尺寸*/
    height: 4px;
  }
  &::-webkit-scrollbar-thumb {
    /*滚动条里面小方块*/
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.2);
  }
  &::-webkit-scrollbar-track {
    /*滚动条里面轨道*/
    border-radius: 0;
    background: rgba(0, 0, 0, 0.1);
  }
  .info-bin {
    background: #fff;
    padding: 0 40px;
    &_page-title {
      font-weight: bold;
      font-size: 20px;
      padding: 10px;
    }
    &_page-content {
      padding: 20px;
    }
    &_page-content-title {
      background: #006fcf;
      padding: 10px;
      color: #fff;
    }
    &_page-content-line {
      padding: 10px 0;
      font-size: 14px;
      .input {
        display: flex;
        width: 50%;
        > span {
          margin-right: 10px;
          white-space: nowrap;
          line-height: 30px;
        }
      }
    }
    .upfilesName {
      font-size: 15px;
    }
  }
  .el-input--mini {
    height: 100%;
  }
  .dataInfo {
    padding-left: 20px;
    display: flex;
    .item-left {
      width: 48%;
      margin-right: 4%;
    }
    .item-right {
      width: 48%;
    }
  }
  .el-col {
    padding: 5px 0px;
  }
  .el-textarea {
    /deep/.el-input__count {
      line-height: 20px !important;
      bottom: 1px !important;
      right: 10px !important;
    }
  }

  .footer {
    position: fixed;
    bottom: 0;
    width: calc(100% - 258px);
    height: 50px;
    background: #fff;
    display: flex;
    justify-content: flex-end;
    padding: 00px 100px 20px 0;
    padding-right: 100px;
  }
  .change_label /deep/ .el-form-item__label {
    float: left;
    margin-right: 10px;
  }
  .change_label /deep/ .el-form-item__content {
    .el-form-item__error {
      left: 90px;
    }
  }
  .right /deep/ .el-form-item__content {
    .el-form-item__error {
      left: 145px;
    }
  }
  .uploadTitle {
    display: inline-block;
    vertical-align: top;
    height: 30px;
    line-height: 30px;
    margin-left: 10px;
  }
}
</style>