<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.title"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20221121201502"
        idname="sa_contractid"
        typeTask="合同"
        ownertable="sa_contract"
        :tabs="tabs"
        :statusCheck="[{key:'status',value:'已提交'},{key:'status',value:'审核'},{key:'status',value:'已终止'}]"
        :attachmentDisabled="mainData.status == '已提交' || mainData.status == '审核' || mainData.status == '已终止' || mainData.status == '已过期'"
        @pageChange="pageChange"
        @onEditSuccess="editSuccess">
      <div slot="tags">
      </div>
      <div slot="customOperation">
        <editBtn class="inline-16" :modelList="modelList" v-if="tool.checkAuth($route.name,'update')" :disabled="mainData.status != '新建' || !isLeader" @onSuccess="queryMainData($route.query.id);$refs.billno && $refs.billno.listData()" :data="mainData" />

        <el-button
          type="primary"
          size="mini"
          @click="changeBill"
          v-if="mainData.status == '审核' && ($route.query.type == '经销项目' || $route.query.type == '直销项目') && (tool.checkAuth($route.name,'changeBillMag') || tool.checkAuth($route.name,'changeBillSaler') || tool.checkAuth($route.name,'changeBillOrder'))"
        >{{$t('一键转单')}}</el-button>

        <revoke class="inline-16" @onSuccess="queryMainData($route.query.id)" :data="mainData" v-if="tool.checkAuth($route.name,'revoke') && mainData.status === '已提交' && isLeader" ></revoke>
        <submit-check class="inline-16"  :disabled="!isLeader" ref="submit" :data="mainData" @onSuccess="queryMainData($route.query.id)" />
        <reverseCheck class="inline-16" @onSuccess="queryMainData($route.query.id)" :data="mainData" v-if="tool.checkAuth($route.name,'reverseCheck') && mainData.status === '审核'"  />
        <contractOver class="inline-16" v-if="tool.checkAuth($route.name,'contractOver') && mainData.status == '审核' && isLeader" :disabled="!isLeader" :id="mainData.sa_contractid" @onSuccess="queryMainData($route.query.id)" />
        <copyTo class="inline-16" v-if="tool.checkAuth($route.name,'copy')"></copyTo>
        <Del class="inline-16" :idName="20221121202502" :id="mainData.sa_contractid" idKey="sa_contractids"  v-if="tool.checkAuth($route.name,'toVoid') && (mainData.status == '新建' || mainData.status == '已终止' || mainData.status == '已过期') && isLeader"/>
      </div>
      <div slot="slot0" >
        <div v-if="mainData.type == '项目'">
          <!--项目产品明细折扣表-->
          <productBillno :data="mainData" :isLeader="isLeader" ref="billno" @priceChange="queryMainData($route.query.id)" @delSuccess="queryMainData" @onSuccess="productAdd" >
            <template v-slot:edit="scope">
            </template>
            <template v-slot:del="scope">
            </template>
            <template v-slot:cooperate="scope">
              <el-button :disabled="mainData.status !== '新建'" size="small" :type="mainData.status === '新建'?'primary':''" @click="cooperateVisible = true" v-if="tool.checkAuth($route.name,'productBillManage') && isLeader">{{$t('同步合作协议')}}</el-button>
              <el-dialog :title="$t('同步合作协议')" :visible.sync="cooperateVisible" append-to-body width="725px">
                <span style="color: #8C8C8C;font-size: 14px">{{$t('请选择同步更新经销商/直销客户合作协议产品的方式')}}：</span>
                <el-form :model="cooperateForm" style="margin-top: 20px">
                  <el-radio v-model="cooperateForm.isadd" label="1" style="margin-bottom: 20px">
                    <span style="font-size: 16px;color: #333333;white-space:normal;">{{$t('同步添加合作协议产品')}}</span><br><br>
                    <div style="font-size: 14px;color: #8C8C8C;padding-left:20px;white-space:normal;">
                    {{$t('将协议中所有产品添加到表体，若表体已存在产品，则协议中相同产品的信息及其折扣价格覆盖更新到表体。')}}
                    </div>
                  </el-radio>
                  <el-radio v-model="cooperateForm.isadd" label="0">
                    <span style="font-size: 16px;color: #333333;white-space:normal;">{{$t('仅更新合作协议的产品折扣价格')}}</span><br><br>
                    <div style="font-size: 14px;color: #8C8C8C;padding-left:20px;white-space:normal;">
                      {{$t('将协议中与表体相同的产品信息及其折扣价格覆盖更新到表体，不添加协议产品。')}}
                    </div>
                  </el-radio>
                </el-form>
                <div slot="footer" class="dialog-footer">
                  <el-button size="small" @click="cooperateVisible = false" class="normal-btn-width">{{$t(`取 消`)}}</el-button>
                  <el-button size="small" type="primary" @click="onCooperate" class="normal-btn-width">{{$t(`确 定`)}}</el-button>
                </div>
              </el-dialog>
            </template>
          </productBillno>
        </div>
        <div v-if="mainData.type == '框架' || mainData.type == '直销' ">
          <!--产品明细折扣表-->
          <productDetailList :data="mainData" :isLeader="isLeader" ref="productDetailList"   @priceChange="queryMainData($route.query.id)" @closeDrawer="queryMainData($route.query.id)">
            <importFile
                v-if="tool.checkAuth($route.name,'exportProduct') && isLeader && mainData.status === '新建'"
                slot="export"
                ref="importFile"
                class="inline-16"
                :bindData="{ownertable:'sa_contract',ownerid:$route.query.id,usetype:'default'}"
                :errorUrl="errorUrl"
                @clearUrl="errorUrl = null"
                @onSuccess="bindImportOrder"
            ></importFile>
            <template v-slot:cooperate="scope">
              <el-button class="inline-16" :disabled="mainData.status !== '新建'" size="small" :type="mainData.status === '新建'?'primary':''" @click="cooperateVisible = true" v-if="tool.checkAuth($route.name,'productDetailManage') && isLeader && mainData.type == '居间'">{{$t('同步协议')}}</el-button>
              <el-dialog :title="$t(`同步协议`)" :visible.sync="cooperateVisible" append-to-body width="703px" center>
              <span style="font-size: 14px;color: #8C8C8C;margin: 20px 0 0 22px;padding-top: 20px">
                {{$t('是否添加关联的项目或客户合同中的产品明细同步更新到列表')}}
              </span>
                <div slot="footer" class="dialog-footer">
                  <el-button size="small" @click="cooperateVisible = false" class="normal-btn-width">{{$t(`取 消`)}}</el-button>
                  <el-button size="small" type="primary" @click="onCooperate" class="normal-btn-width">{{$t(`确 定`)}}</el-button>
                </div>
              </el-dialog>
            </template>
          </productDetailList>
        </div>
        <div v-if="mainData.type == '居间'">
          <!--  详细信息      -->
          <BaseInfo v-if="siteid === 'HY'" :detailInfo="detailInfo"/>
          <!--产品明细折扣表-->
          <productDetailList v-else :data="mainData" :isLeader="isLeader" ref="productDetailList"   @priceChange="queryMainData($route.query.id)" @closeDrawer="queryMainData($route.query.id)">
            <importFile
                v-if="tool.checkAuth($route.name,'exportProduct') && isLeader && mainData.status === '新建'"
                slot="export"
                ref="importFile"
                class="inline-16"
                :bindData="{ownertable:'sa_contract',ownerid:$route.query.id,usetype:'default'}"
                :errorUrl="errorUrl"
                @clearUrl="errorUrl = null"
                @onSuccess="bindImportOrder"
            ></importFile>
            <template v-slot:cooperate="scope">
              <el-button class="inline-16" :disabled="mainData.status !== '新建'" size="small" :type="mainData.status === '新建'?'primary':''" @click="cooperateVisible = true" v-if="tool.checkAuth($route.name,'productDetailManage') && isLeader && mainData.type == '居间'">{{$t('同步协议')}}</el-button>
              <el-dialog :title="$t(`同步协议`)" :visible.sync="cooperateVisible" append-to-body width="703px" center>
              <span style="font-size: 14px;color: #8C8C8C;margin: 20px 0 0 22px;padding-top: 20px">
                {{$t('是否添加关联的项目或客户合同中的产品明细同步更新到列表')}}
              </span>
                <div slot="footer" class="dialog-footer">
                  <el-button size="small" @click="cooperateVisible = false" class="normal-btn-width">{{$t(`取 消`)}}</el-button>
                  <el-button size="small" type="primary" @click="onCooperate" class="normal-btn-width">{{$t(`确 定`)}}</el-button>
                </div>
              </el-dialog>
            </template>
          </productDetailList>
        </div>
        <div v-if="mainData.type == '工具借用'">
          <!--工具清单-->
          <toolList :data="mainData" :isLeader="isLeader" ref="toolList" v-if="mainData.type == '工具借用'" @priceChange="queryMainData($route.query.id)">
            <template v-slot:edit="scope">
            </template>
          </toolList>
        </div>

      </div>
      <div slot="slot1" >
        <!--   居间     -->
        <div v-if="mainData.type === '居间'">
          <contactList v-if="siteid === 'HY' && mainData && tool.checkAuth($route.name,'contact')" :data="mainData"></contactList>
          <linkedOrder v-else-if="siteid === 'HY' && mainData && tool.checkAuth($route.name,'linkedOrder')"></linkedOrder>
          <productClassList v-else :data="mainData" :isLeader="isLeader" ref="classList" @priceChange="queryMainData($route.query.id)">
            <addClass class="inline-16" v-if="tool.checkAuth($route.name,'productClassManage')" :disabled="mainData.status != '新建' || !isLeader" :typeName="mainData.type" slot="addProduct" @onSuccess="$refs.classList.listData()"   ref="addProduct" @closeDrawer="closeDrawer"/>
            <template v-slot:edit="scope">
            </template>
            <template v-slot:cooperate="scope">
              <el-button class="inline-16" :disabled="mainData.status !== '新建'" size="small" :type="mainData.status === '新建'?'primary':''" @click="cooperateVisible = true" v-if="tool.checkAuth($route.name,'productClassManage') && isLeader && mainData.type == '居间'">{{$t('同步协议')}}</el-button>
              <el-dialog :title="$t(`同步协议`)" :visible.sync="cooperateVisible" append-to-body width="703px" center>
              <span style="font-size: 14px;color: #8C8C8C;margin: 20px 0 0 22px;padding-top: 20px">
                {{$t('是否添加关联的项目或客户合同中的产品类别同步更新到列表')}}
              </span>
                <div slot="footer" class="dialog-footer">
                  <el-button size="small" @click="cooperateVisible = false" class="normal-btn-width">{{$t(`取 消`)}}</el-button>
                  <el-button size="small" type="primary" @click="onCooperateItem" class="normal-btn-width">{{$t(`确 定`)}}</el-button>
                </div>
              </el-dialog>
            </template>
          </productClassList>
        </div>
        <div v-if="mainData.type == '框架' || mainData.type == '直销' ">
          <!--产品类别折扣表-->
          <productClassList :data="mainData" :isLeader="isLeader" ref="classList" @priceChange="queryMainData($route.query.id)" >
            <addClass class="inline-16" v-if="tool.checkAuth($route.name,'productClassManage')" :disabled="mainData.status != '新建' || !isLeader" :typeName="mainData.type" slot="addProduct" @onSuccess="$refs.classList.listData()"   ref="addProduct" @closeDrawer="closeDrawer"/>
            <template v-slot:edit="scope">
            </template>
            <template v-slot:cooperate="scope">
              <el-button class="inline-16" :disabled="mainData.status !== '新建'" size="small" :type="mainData.status === '新建'?'primary':''" @click="cooperateVisible = true" v-if="tool.checkAuth($route.name,'productClassManage') && isLeader && mainData.type == '居间'">{{$t('同步协议')}}</el-button>
              <el-dialog :title="$t(`同步协议`)" :visible.sync="cooperateVisible" append-to-body width="703px" center>
              <span style="font-size: 14px;color: #8C8C8C;margin: 20px 0 0 22px;padding-top: 20px">
                {{$t('是否添加关联的项目或客户合同中的产品类别同步更新到列表')}}
              </span>
                <div slot="footer" class="dialog-footer">
                  <el-button size="small" @click="cooperateVisible = false" class="normal-btn-width">{{$t(`取 消`)}}</el-button>
                  <el-button size="small" type="primary" @click="onCooperateItem" class="normal-btn-width">{{$t(`确 定`)}}</el-button>
                </div>
              </el-dialog>
            </template>
          </productClassList>
        </div>
        <div v-if="mainData.type == '项目'">
          <!--    产品类别折扣    -->
          <itemClass ref="itemClass" :data="mainData"  :isLeader="isLeader" >
            <template v-slot:cooperate="scope">
              <addClass class="inline-16" v-if="tool.checkAuth($route.name,'productClassManage') && mainData.status === '新建' && isLeader" :disabled="mainData.status != '新建' || !isLeader" :typeName="mainData.type" slot="addProduct" @onSuccess="$refs.itemClass.listData()" title="自产品类别添加"  ref="addProduct" @closeDrawer="closeDrawer"/>
              <el-button :disabled="mainData.status !== '新建'" size="small" :type="mainData.status === '新建'?'primary':''" @click="cooperateVisible = true" v-if="tool.checkAuth($route.name,'productClassManage') && isLeader">{{$t('同步合作协议')}}</el-button>
              <el-dialog :title="$t('同步合作协议')" :visible.sync="cooperateVisible" append-to-body width="725px">
                <span style="color: #8C8C8C;font-size: 14px">{{$t('请选择同步更新经销商/直销客户合作协议产品类别的方式')}}：</span>
                <el-form :model="cooperateForm" style="margin-top: 20px">
                  <el-radio v-model="cooperateForm.isadd" label="1" style="margin-bottom: 20px">
                    <span style="font-size: 16px;color: #333333;white-space:normal;">{{$t('同步添加合作协议产品类别及其折扣')}}</span><br><br>
                    <div style="font-size: 14px;color: #8C8C8C;padding-left:20px;white-space:normal;">
                      {{$t('将协议中所有产品类别及其折扣添加到表体，若表体已存在产品类别，则协议中相同产品类别的折扣覆盖更新到表体。')}}
                    </div>
                  </el-radio>

                  <el-radio v-model="cooperateForm.isadd" label="0">
                    <span style="font-size: 16px;color: #333333;white-space:normal;">{{$t('仅更新合作协议的产品类别折扣')}}</span><br><br>
                    <span style="font-size: 14px;color: #8C8C8C;padding-left:20px;white-space:normal;">
                   {{$t('将协议中与表体相同的产品类别的折扣价格覆盖更新到表体，不添加协议的产品类别。')}}
                  </span>
                  </el-radio>
                </el-form>
                <div slot="footer" class="dialog-footer">
                  <el-button size="small" @click="cooperateVisible = false" class="normal-btn-width">{{$t(`取 消`)}}</el-button>
                  <el-button size="small" type="primary" @click="onCooperateItem" class="normal-btn-width">{{$t(`确 定`)}}</el-button>
                </div>
              </el-dialog>
            </template>
          </itemClass>
        </div>
        <div v-if="mainData.type === '工具借用'">
          <BaseInfo :detailInfo="detailInfo"/>
        </div>
      </div>
      <div slot="slot2">
        <div v-if="Object.keys(mainData).length > 0 && (mainData.type == '框架' || mainData.type == '直销')" >
          <!--业绩目标-->
          <taskTarget ref="taskTarget" :data="mainData">
            <template v-slot:addTarget="scope">
              <add-target :disabled="mainData.status != '新建' || !isLeader" v-if="tool.checkAuth($route.name,'taskTargetManage')" :data="mainData" @onSuccess="successYear"></add-target>
            </template>
            <template v-slot:edit="scope">
              <edit-target class="inline-16" :disabled="mainData.status != '新建' || !isLeader" v-if="tool.checkAuth($route.name,'taskTargetManage')" :data="scope.data" :salerId="mainData" @onSuccess="$refs.taskTarget.queryData()"/>
            </template>
            <template v-slot:delete="scope">
              <del-target @onSuccess="$refs.taskTarget.queryData()" class="inline-16" :disabled="mainData.status != '新建' || !isLeader" v-if="tool.checkAuth($route.name,'taskTargetManage')" :id="scope.data.sa_salestargetbillid"></del-target>
            </template>
          </taskTarget>
        </div>
        <div v-if="mainData.type == '项目'">
          <!--   备用金     -->
          <priceDifference v-if="siteid == 'HY' && tool.checkAuth($route.name,'brokerageFeeEntrySet')" :data="mainData"></priceDifference>
          <!--   详细信息     -->
          <BaseInfo v-else :detailInfo="detailInfo"/>
        </div>
        <div v-if="mainData.type == '居间'">
          <div v-if="siteid == 'HY' && tool.checkAuth($route.name,'linkedOrder')">
            <linkedOrder></linkedOrder>
          </div>
          <BaseInfo v-else :detailInfo="detailInfo"/>
        </div>
        <div v-if="mainData.type == '工具借用'">
          <div v-if="tool.checkAuth($route.name,'linkedOrder')">
            <linkedOrder></linkedOrder>
          </div>
        </div>
      </div>
      <div slot="slot3">
        <div  v-if="mainData.type === '居间' && siteid !== 'HY'">
          <contactList v-if="mainData && tool.checkAuth($route.name,'contact')" :data="mainData"></contactList>
          <linkedOrder v-else-if="tool.checkAuth($route.name,'linkedOrder')"></linkedOrder>
        </div>
        <div v-if="mainData.type == '框架' || mainData.type == '直销'">
          <priceDifference v-if="siteid == 'HY' && tool.checkAuth($route.name,'brokerageFeeEntrySet')" :data="mainData"></priceDifference>
          <BaseInfo v-else :detailInfo="detailInfo"/>
        </div>
        <div v-if="mainData.type == '项目' && siteid == 'HY'">
          <linkedOrder v-if="tool.checkAuth($route.name,'linkedOrder') && !tool.checkAuth($route.name,'brokerageFeeEntrySet')"></linkedOrder>
          <BaseInfo v-else :detailInfo="detailInfo"/>
        </div>
        <div v-if="mainData.type == '项目' && siteid !== 'HY'">
          <linkedOrder v-if="tool.checkAuth($route.name,'linkedOrder')"></linkedOrder>
        </div>
      </div>
      <div slot="slot4">
        <div v-if="mainData.type == '框架' || mainData.type == '直销'">
          <linkedOrder v-if="tool.checkAuth($route.name,'linkedOrder') && tool.checkAuth($route.name,'brokerageFeeEntrySet') && siteid != 'HY'"></linkedOrder>
          <BaseInfo v-else :detailInfo="detailInfo"/>
        </div>
        <div v-if="mainData.type == '项目'">
          <linkedOrder v-if="tool.checkAuth($route.name,'linkedOrder')"></linkedOrder>
        </div>
        <div v-if="mainData.type == '居间'">
          <linkedOrder v-if="tool.checkAuth($route.name,'linkedOrder')"></linkedOrder>
        </div>
      </div>
      <div slot="slot5">
        <linkedOrder></linkedOrder>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import Del from '../components/delete'
import editBtn from '../components/editContract'
import SubmitCheck from '../components/submitCheck'
import productBillno from '../components/productList/productBillno.vue'
import productDetailList from '../components/productDetailList/productDetailList.vue'
import addProduct from '../components/productList/addProduct'
import addProductDetail from '../components/productDetailList/addProduct.vue'
import addTool from '../components/toolList/addTool'
import toolList from '../components/toolList/toolList.vue'
import addClass from '../components/productClassList/addProduct'
import productClassList from '../components/productClassList/productClassList.vue'
import contractClause from '../components/contractClause/contractClause'
import editTarget from '../components/taskTarget/editTarget'
import addTarget from '../components/taskTarget/addTarget'
import taskTarget from '../components/taskTarget/taskTarget'
import delTarget from '../components/taskTarget/delTarget'
import contractOver from '../components/contractOver'
import reverseCheck from '../components/reverseCheck'
import revoke from "@/HDrpManagement/contractManage/components/revoke";
import BaseInfo from '@/HDrpManagement/projectChange/modules/modules/baseInfo/baseInfo'
import itemClass from '../components/itemClass/index.vue'
import importFile from '../components/importFile'
import copyTo from '../components/copyTo'
import priceDifference from '../components/priceDifference/index'
import contactList from '../components/contactList/index'
import linkedOrder from "../components/linkedOrder";
import { Loading } from 'element-ui';
export default {
  name: "detail",
  data() {
    return {
      mainData:{},
      mainAreaData:{},
      modelList:[],
      isLeader:false,
      detailInfo:{},
      message:'确定删除当前条款吗？',
      errorUrl:null,
      cooperateVisible:false,
      cooperateForm:{
        "sa_contractid": "",
        "isadd":''
      },
      siteid:JSON.parse(sessionStorage.getItem('active_account')).siteid,
      tabs:[]
    }
  },
  components:{
    Del,
    SubmitCheck,
    editBtn,
    productBillno,
    addProduct,
    productDetailList,
    addProductDetail,
    addTool,
    toolList,
    addClass,
    productClassList,
    contractClause,
    editTarget,
    taskTarget,
    contractOver,
    reverseCheck,
    addTarget,
    delTarget,
    BaseInfo,
    revoke,
    itemClass,
    importFile,
    copyTo,
    priceDifference,
    contactList,
    linkedOrder
  },
  provide () {
    return {
      detailData:() => this.mainData,
    }
  },
  watch: {
    mainData: {
      async handler (val) {
        const res = await this.$api.requested({
          "id": 20220930103501,
          "content": {
            "ownertable":"sa_contract",
            "ownerid":this.$route.query.id
          }
        })
        const agent = await this.$api.requested({
          "id":20230329122604,
          "content": {
            "ownertable":"sa_contract",
            "ownerid":this.$route.query.id
          }
        })
        if (this.mainData.leader && this.mainData.leader.length > 0){
          if (JSON.parse(window.sessionStorage.getItem('active_account')).userid === this.mainData.leader[0].userid){
            this.isLeader = true
          }else {
            let flag = 0
            for (var i=0;i<res.data[0].team.length;i++){
              if (res.data[0].team[i].userid === JSON.parse(window.sessionStorage.getItem('active_account')).userid){
                if (res.data[0].team[i].editable === 1){
                  flag =1
                  break
                }else {
                  flag = 0
                  break
                }
              }
            }
            console.log(agent.data.editable,'agent.data.editable')
            flag === 0  ?agent.data.editable === 0?this.isLeader = false:this.isLeader = true:this.isLeader = true
            this.$refs.details.$refs.group.editdataleader = agent.data.editdataleader
            console.log(this.isLeader,'isLeader')
          }
        }
      },
      deep:true,
      immediate:true
    }
  },
  methods:{
    tabsSet(){
      if (this.mainData.type == '项目'){
        if (this.siteid == 'HY'){
          if (this.tool.checkAuth(this.$route.name,'brokerageFeeEntrySet') && !this.tool.checkAuth(this.$route.name,'linkedOrder')){
            this.tabs = ['产品明细折扣','产品类别折扣','备用金','详细信息']
          }else if (this.tool.checkAuth(this.$route.name,'linkedOrder') && !this.tool.checkAuth(this.$route.name,'brokerageFeeEntrySet')){
            this.tabs = ['产品明细折扣','产品类别折扣','详细信息','关联订单']
          }else if (this.tool.checkAuth(this.$route.name,'linkedOrder') && this.tool.checkAuth(this.$route.name,'brokerageFeeEntrySet')){
            this.tabs = ['产品明细折扣','产品类别折扣','备用金','详细信息','关联订单']
          }else {
            this.tabs = ['产品明细折扣','产品类别折扣','详细信息']
          }
        }else {
          if (this.tool.checkAuth(this.$route.name,'linkedOrder')){
            this.tabs = ['产品明细折扣','产品类别折扣','详细信息','关联订单']
          }else {
            this.tabs = ['产品明细折扣','产品类别折扣','详细信息']
          }
        }
      }else if (this.mainData.type == '框架' || this.mainData.type == '直销' ){
        if (this.siteid == 'HY'){
          if (this.tool.checkAuth(this.$route.name,'brokerageFeeEntrySet') && !this.tool.checkAuth(this.$route.name,'linkedOrder')){
            this.tabs = ['产品明细折扣','产品类别折扣','业绩目标','备用金','详细信息']
          }else if (this.tool.checkAuth(this.$route.name,'linkedOrder') && !this.tool.checkAuth(this.$route.name,'brokerageFeeEntrySet')){
            this.tabs = ['产品明细折扣','产品类别折扣','业绩目标','详细信息','关联订单']
          }else if (this.tool.checkAuth(this.$route.name,'linkedOrder') && this.tool.checkAuth(this.$route.name,'brokerageFeeEntrySet')){
            this.tabs = ['产品明细折扣','产品类别折扣','业绩目标','备用金','详细信息','关联订单']
          }else {
            this.tabs = ['产品明细折扣','产品类别折扣','业绩目标','详细信息']
          }
        }else {
          if (this.tool.checkAuth(this.$route.name,'linkedOrder')){
            this.tabs = ['产品明细折扣','产品类别折扣','业绩目标','详细信息','关联订单']
          }else {
            this.tabs = ['产品明细折扣','产品类别折扣','业绩目标','详细信息']
          }
        }
      }else if (this.mainData.type == '居间'){
        if (this.siteid == 'HY'){
          if (this.tool.checkAuth(this.$route.name,'contact') && !this.tool.checkAuth(this.$route.name,'linkedOrder')){
            this.tabs = ['详细信息','联系人']
          }else if (this.tool.checkAuth(this.$route.name,'linkedOrder') && !this.tool.checkAuth(this.$route.name,'contact')){
            this.tabs = ['详细信息','关联订单']
          }else if (this.tool.checkAuth(this.$route.name,'linkedOrder') && this.tool.checkAuth(this.$route.name,'contact')){
            this.tabs = ['详细信息','联系人','关联订单']
          }else {
            this.tabs = ['详细信息']
          }
        }else {
          if (this.tool.checkAuth(this.$route.name,'contact') && !this.tool.checkAuth(this.$route.name,'linkedOrder')){
            this.tabs = ['产品明细折扣','产品类别折扣','详细信息','联系人']
          }else if (this.tool.checkAuth(this.$route.name,'linkedOrder') && !this.tool.checkAuth(this.$route.name,'contact')){
            this.tabs = ['产品明细折扣','产品类别折扣','详细信息','关联订单']
          }else if (this.tool.checkAuth(this.$route.name,'linkedOrder') && this.tool.checkAuth(this.$route.name,'contact')){
            this.tabs = ['产品明细折扣','产品类别折扣','详细信息','联系人','关联订单']
          }else {
            this.tabs = ['产品明细折扣','产品类别折扣','详细信息']
          }
        }
      }else {
        if (this.tool.checkAuth(this.$route.name,'linkedOrder')){
          this.tabs = ['工具清单','详细信息','关联订单']
        }else {
          this.tabs = ['工具清单','详细信息']
        }
      }
    },
    editSuccess(){
      this.queryMainData(this.$route.query.id)
    },
    async queryMainData(id) {
      const res = await this.$api.requested({
        "id":20221121195102,
        "content": {
          "nocache":true,
          "sa_contractid": this.$route.query.id
        }
      })
      this.mainData = res.data
      console.log(this.$refs.details.param.content,'param')
      let listqueryid = sessionStorage.getItem('listqueryid')
      this.mainData.type == '项目'
        ? this.mainData.typemx == '直销'
          ? this.$router.replace({path:'/contractDetail',query:{id:this.$route.query.id,rowindex:this.$route.query.rowindex,type:'直销项目',tabIndex:this.$route.query.tabIndex,listqueryid:listqueryid,fieldname:'sa_contractid'}}) : this.$router.replace({path:'/contractDetail',query:{id:this.$route.query.id,rowindex:this.$route.query.rowindex,type:'经销项目',tabIndex:this.$route.query.tabIndex,listqueryid:listqueryid,fieldname:'sa_contractid'}})
          : this.$router.replace({path:'/contractDetail',query:{id:this.$route.query.id,rowindex:this.$route.query.rowindex,type:this.mainData.type,tabIndex:this.$route.query.tabIndex,listqueryid:listqueryid,fieldname:'sa_contractid'}})

      this.changeDataStructure()
      this.tabsSet()
    },
    changeDataStructure() {
      let that = this
      this.mainData.type == '项目'
        ? this.mainData.typemx == '直销'
          ? this.mainAreaData = [
            /* 直销信息 */
          {
            label:'合同编号',
            value:this.mainData.billno
          },
          {
            label:'合同标题',
            value:this.mainData.title
          },
          {
            label:'合同类型',
            value:this.mainData.type == '项目' ? this.mainData.typemx == '直销' ? this.$t('直销项目协议') : this.$t('经销项目协议') : ''
          },
          {
            label:'合同模板',
            value:this.mainData.type == '项目' ? this.mainData.typemx == '直销' ? this.$t('直销项目协议模板') : this.$t('经销项目协议模板') : ''
          },
          {
            label:'客户',
            value:this.mainData.enterprisename
          },
          {
            label:'项目名称',
            value:this.mainData.projectname
          },
          {
            label:'项目编号',
            value:this.mainData.projectnum?this.mainData.projectnum:'--'
          },

          {
            label:'业务员',
            value:this.mainData.salername
          },
          {
            label:'合同有效期',
            value:`${this.mainData.begdate}至${this.mainData.enddate}`,
            style:function () {
              let style = {color:'#3874f6'}
              return style
            }
          },
          {
            label:'签约日期',
            value:this.mainData.signdate
          },
          {
            label:'签约金额(元)',
            value:this.mainData.signamount?this.tool.formatAmount(this.mainData.signamount,2):0,
            style:function () {
              let style = {color:'#3874f6'}
              return style
            }
          },
          /*{
            label:'收货人',
            value:this.mainData.name
          },
          {
            label:'收货人电话',
            value:this.mainData.phonenumber
          },
          {
            label:'创建时间',
            value:this.mainData.createdate
          },
          {
            label:'创建人',
            value:this.mainData.createby
          },*/
          {
            label:'折扣(%)',
            value:this.mainData.discountrate !== 0?Math.round((this.mainData.discountrate * 100)*100)/100:'--'
          },
          {
            label:'状态',
            value:this.mainData.status,
            style:function () {
            let style = that.tool.getStatusColor(that.mainData.status)
              return style
            }
          },
         /* {
            label:'合同描述',
            value:this.mainData.remarks
          },*/
        ] : this.mainAreaData = [
          /* 经销信息 */
          {
            label:'合同编号',
            value:this.mainData.billno
          },
          {
            label:'合同标题',
            value:this.mainData.title
          },
          {
            label:'合同类型',
            value:this.mainData.type == '项目' ? this.mainData.typemx == '直销' ? this.$t('直销项目协议') : this.$t('经销项目协议') : ''
          },
          {
            label:'经销商',
            value:this.mainData.enterprisename
          },
          {
            label:'项目名称',
            value:this.mainData.projectname
          },
          {
            label:'项目编号',
            value:this.mainData.projectnum
          },
          {
            label:'合同有效期',
            value:`${this.mainData.begdate}至${this.mainData.enddate}`,
            style:function () {
              let style = {color:'#3874f6'}
              return style
            }
          },
          {
            label:'签约日期',
            value:this.mainData.signdate
          },
          {
            label:'签约金额(元)',
            value:this.mainData.signamount?this.tool.formatAmount(this.mainData.signamount,2):0
          },
          {
            label:'折扣(%)',
            value:this.mainData.discountrate !== 0?Math.round((this.mainData.discountrate * 100)*100)/100:'--'
          },
          {
            label:'业务员',
            value:this.mainData.salername
          },
          {
            label:'状态',
            value:this.mainData.status,
            style:function () {
              let style = that.tool.getStatusColor(that.mainData.status)
              return style
            }
          },
        /*  {
            label:'合同模板',
            value:this.mainData.type == '项目' ? this.mainData.typemx == '直销' ? '直销项目协议模板' : '经销项目协议模板' : ''
          },
          {
            label:'创建时间',
            value:this.mainData.createdate
          },
          {
            label:'创建人',
            value:this.mainData.createby
          },

          {
            label:'合同描述',
            value:this.mainData.remarks
          },*/
        ] : this.mainData.type == '框架'
            ? this.mainAreaData = [
            /* 合作协议 */
          {
            label:'合同编号',
            value:this.mainData.billno
          },
          {
            label:'合同标题',
            value:this.mainData.title
          },
          {
            label:'合同类型',
            value:'经销商合作协议'
          },
          {
            label:'经销商',
            value:this.mainData.enterprisename
          },
          {
            label:'折扣(%)',
            value:this.mainData.discountrate !== 0?Math.round((this.mainData.discountrate * 100)*100)/100:'--'
          },
          {
            label:'合同有效期',
            value:`${this.mainData.begdate}至${this.mainData.enddate}`,
            style:function () {
              let style = {color:'#3874f6'}
              return style
            }
          },
          {
            label:'签约日期',
            value:this.mainData.signdate
          },
          // {
          //   label:'签约金额(元)',
          //   value:this.mainData.signamount?this.tool.formatAmount(this.mainData.signamount,2):0.00
          // },
          {
            label:'业务员',
            value:this.mainData.salername
          },
          {
            label:'状态',
            value:this.mainData.status,
            style:function () {
              let style = that.tool.getStatusColor(that.mainData.status)
              return style
            }
          },
         /* {
            label:'合同模板',
            value:'经销商合作协议模板'
          },
          {
            label:'创建时间',
            value:this.mainData.createdate
          },
          {
            label:'创建人',
            value:this.mainData.createby
          },

          {
            label:'合同描述',
            value:this.mainData.remarks
          },*/
        ] : this.mainData.type == '直销'
          ? this.mainAreaData = [
            /* 直销客户协议 */
            {
              label:'合同编号',
              value:this.mainData.billno
            },
            {
              label:'合同标题',
              value:this.mainData.title
            },
            {
              label:'合同类型',
              value:'直销客户合作协议'
            },
            {
              label:'客户',
              value:this.mainData.enterprisename
            },
            {
              label:'折扣(%)',
              value:this.mainData.discountrate !== 0?Math.round((this.mainData.discountrate * 100)*100)/100:'--'
            },
            {
              label:'合同有效期',
              value:`${this.mainData.begdate}至${this.mainData.enddate}`,
              style:function () {
                let style = {color:'#3874f6'}
                return style
              }
            },
            {
              label:'签约日期',
              value:this.mainData.signdate
            },
            {
              label:'业务员',
              value:this.mainData.salername
            },
            {
              label:'状态',
              value:this.mainData.status,
              style:function () {
                let style = that.tool.getStatusColor(that.mainData.status)
                return style
              }
            },
          ]:
          this.mainData.type == '工具借用'
          ? this.mainAreaData = [
          /* 工具借用 */
          {
            label:'合同编号',
            value:this.mainData.billno
          },
          {
            label:'合同标题',
            value:this.mainData.title
          },
          {
            label:'合同模板',
            value:'工具借用协议模板'
          },
          {
            label:'客户',
            value:this.mainData.enterprisename
          },
          {
            label:'合同类型',
            value:'工具借用协议'
          },
          {
            label:'业务员',
            value:this.mainData.salername
          },
          {
            label:'合同有效期',
            value:`${this.mainData.begdate}至${this.mainData.enddate}`,
            style:function () {
              let style = {color:'#3874f6'}
              return style
            }
          },
          {
            label:'签约日期',
            value:this.mainData.signdate
          },
          {
            label:'单套价格(元)',
            value:this.mainData.signamount?this.tool.formatAmount(this.mainData.signamount,2):0
          },
          {
            label:'创建时间',
            value:this.mainData.createdate
          },
          {
            label:'创建人',
            value:this.mainData.createby
          },
          {
            label:'状态',
            value:this.mainData.status,
            style:function () {
            let style = that.tool.getStatusColor(that.mainData.status)
              return style
            }
          },
          {
            label:'合同描述',
            value:this.mainData.remarks
          },
        ] : this.mainAreaData = [
          /* 居间协议 */
          {
            label:'合同编号',
            value:this.mainData.billno
          },
          {
            label:'合同标题',
            value:this.mainData.title
          },
          {
            label:'合同类型',
            value:'居间协议'
          },
          {
            label:'居间商',
            value:this.mainData.ascription_enterprisename
          },
          {
            label:'合同',
            value:this.mainData.ascription_title
          },

          {
            label:'项目名称',
            value:this.mainData.projectname
          },
          {
            label:'项目编号',
            value:this.mainData.projectnum
          },
          {
            label:'客户名称',
            value:this.mainData.enterprisename
          },
          {
            label:'合同有效期',
            value:`${this.mainData.begdate}至${this.mainData.enddate}`,
            style:function () {
              let style = {color:'#3874f6'}
              return style
            }
          },
          {
            label:'签约日期',
            value:this.mainData.signdate
          },
          {
            label:this.mainData.calculatemodel == 1 ? this.$t('订单金额比例(%)') : this.$t('居间产品折扣(%)'),
            value:this.mainData.calculatemodel == 1 ? Math.round((this.mainData.orderratio * 100)*100)/100 : Math.round((this.mainData.productdiscount *100)*100)/100,
            style:function () {
              let style = {color:'#3874f6'}
              return style
            }
          },
         /* {
            label:'合同模板',
            value:'居间协议模板'
          },*/
          {
            label:'状态',
            value:this.mainData.status,
            style:function () {
              let style = that.tool.getStatusColor(that.mainData.status)
              return style
            }
          },

         /* {
            label:'业务员',
            value:this.mainData.salername
          },



          {
            label:'创建时间',
            value:this.mainData.createdate
          },
          {
            label:'创建人',
            value:this.mainData.createby
          },

          {
            label:'合同描述',
            value:this.mainData.remarks
          },*/
        ]

      this.mainData.type == '项目'
          ? this.mainData.typemx == '直销'
              ? this.detailInfo = {
                baseInfo : [
                  /* 直销信息 */
                  {
                    label:'合同编号',
                    value:this.mainData.billno
                  },
                  {
                    label:'合同标题',
                    value:this.mainData.title
                  },
                  {
                    label:'合同模板',
                    value:this.mainData.type == '项目' ? this.mainData.typemx == '直销' ? this.$t('直销项目协议模板') : this.$t('经销项目协议模板') : ''
                  },
                  {
                    label:'合同类型',
                    value:this.mainData.type == '项目' ? this.mainData.typemx == '直销' ? this.$t('直销项目协议') : this.$t('经销项目协议') : ''
                  },
                  {
                    label:'客户',
                    value:this.mainData.enterprisename
                  },
                  {
                    label:'项目名称',
                    value:this.mainData.projectname
                  },
                  {
                    label:'项目编号',
                    value:this.mainData.projectnum
                  },
                  {
                    label:'项目地址',
                    value:this.mainData.projectname ? this.mainData.province + this.mainData.city + this.mainData.county + this.mainData.address:'--'
                  },
                  {
                    label:'收货人',
                    value:this.mainData.name
                  },
                  {
                    label:'收货人电话',
                    value:this.mainData.phonenumber
                  },
                  {
                    label:'合同有效期',
                    value:`${this.mainData.begdate}至${this.mainData.enddate}`,
                    style:function () {
                      let style = {color:'#3874f6'}
                      return style
                    }
                  },
                  {
                    label:'签约日期',
                    value:this.mainData.signdate
                  },
                  {
                    label:'签约金额(元)',
                    value:this.mainData.signamount?this.tool.formatAmount(this.mainData.signamount,2):0
                  },
                  {
                    label:'折扣(%)',
                    value:this.mainData.discountrate !== 0?Math.round((this.mainData.discountrate * 100)*100)/100:'--'
                  },
                  {
                    label:'领域',
                    value:this.mainData.tradefield ? this.mainData.tradefield : '--'
                  },
                  {
                    label:'品牌',
                    value:this.mainData.brandname
                  },
                  {
                    label:'付款条件',
                    value:this.mainData.paytype
                  },
                  {
                    label:'发货日期提醒（天）',
                    value:this.mainData.reminddays
                  },
                  {
                    label:'业务员',
                    value:this.mainData.salername
                  },
                  {
                    label:'状态',
                    value:this.mainData.status,
                    style:function () {
                      let style = that.tool.getStatusColor(that.mainData.status)
                      return style
                    }
                  },
                  {
                    label:'合同描述',
                    value:this.mainData.remarks
                  },
                ],
                systemInfo: [
                  {label:'创建人',value:this.mainData.createby},
                  {label:'创建时间',value:this.mainData.createdate},
                  {label:'最近编辑人',value:this.mainData.changeby},
                  {label:'最近编辑时间',value:this.mainData.changedate},
                  {label:'提交人',value:this.mainData.submitby},
                  {label:'提交时间',value:this.mainData.submitdate},
                  {label:'审核人',value:this.mainData.checkby},
                  {label:'审核时间',value:this.mainData.checkdate},
                 /* {label:'作废原因',value:this.mainData.leader[0].leadernum == 0?'0':this.mainData.leader[0].leadernum},*/
                  {label:'转手次数',value:this.mainData.leader?this.mainData.leader[0].leadernum:"--"}
                ]
              }
             : this.detailInfo = {
                baseInfo : [
                  /* 经销信息 */
                  {
                    label:'合同编号',
                    value:this.mainData.billno
                  },
                  {
                    label:'合同标题',
                    value:this.mainData.title
                  },
                  {
                    label:'合同模板',
                    value:this.mainData.type == '项目' ? this.mainData.typemx == '直销' ? this.$t('直销项目协议模板') : this.$t('经销项目协议模板') : ''
                  },
                  {
                    label:'合同类型',
                    value:this.mainData.type == '项目' ? this.mainData.typemx == '直销' ? this.$t('直销项目协议') : this.$t('经销项目协议') : ''
                  },
                  {
                    label:'项目名称',
                    value:this.mainData.projectname
                  },
                  {
                    label:'项目编号',
                    value:this.mainData.projectnum
                  },
                  {
                    label:'合同有效期',
                    value:`${this.mainData.begdate}至${this.mainData.enddate}`,
                    style:function () {
                      let style = {color:'#3874f6'}
                      return style
                    }
                  },
                  {
                    label:'签约日期',
                    value:this.mainData.signdate
                  },
                  {
                    label:'签约金额(元)',
                    value:this.mainData.signamount?this.tool.formatAmount(this.mainData.signamount,2):0
                  },
                  {
                    label:'折扣(%)',
                    value:this.mainData.discountrate !== 0?Math.round((this.mainData.discountrate * 100)*100)/100:'--'
                  },
                  {
                    label:'领域',
                    value:this.mainData.tradefield ? this.mainData.tradefield : '--'
                  },
                  {
                    label:'品牌',
                    value:this.mainData.brandname
                  },
                  {
                    label:'付款条件',
                    value:this.mainData.paytype
                  },
                  {
                    label:'发货日期提醒（天）',
                    value:this.mainData.reminddays
                  },
                  {
                    label:'业务员',
                    value:this.mainData.salername
                  },

                 /* {
                    label:'经销商',
                    value:this.mainData.enterprisename
                  },*/
                  {
                    label:'状态',
                    value:this.mainData.status,
                    style:function () {
                      let style = that.tool.getStatusColor(that.mainData.status)
                      return style
                    }
                  },
                  {
                    label:'合同描述',
                    value:this.mainData.remarks
                  },
                ],
                systemInfo: [
                  {label:'创建人',value:this.mainData.createby},
                  {label:'创建时间',value:this.mainData.createdate},
                  {label:'最近编辑人',value:this.mainData.changeby},
                  {label:'最近编辑时间',value:this.mainData.changedate},
                  {label:'提交人',value:this.mainData.submitby},
                  {label:'提交时间',value:this.mainData.submitdate},
                  {label:'审核人',value:this.mainData.checkby},
                  {label:'审核时间',value:this.mainData.checkdate},
                  {label:'转手次数',value:this.mainData.leader?this.mainData.leader[0].leadernum:"--"}
                ]
              }
               : this.mainData.type == '框架'
              ? this.detailInfo ={
                baseInfo : [
                  /* 合作协议 */
                  {
                    label:'合同编号',
                    value:this.mainData.billno
                  },
                  {
                    label:'合同标题',
                    value:this.mainData.title
                  },
                  {
                    label:'合同模板',
                    value:'经销商合作协议模板'
                  },
                  {
                    label:'合同类型',
                    value:'经销商合作协议'
                  },
                  {
                    label:'经销商',
                    value:this.mainData.enterprisename
                  },
                  {
                    label:'折扣(%)',
                    value:this.mainData.discountrate !== 0?Math.round((this.mainData.discountrate * 100)*100)/100:'--'
                  },
                  {
                    label:'合同有效期',
                    value:`${this.mainData.begdate}至${this.mainData.enddate}`,
                    style:function () {
                      let style = {color:'#3874f6'}
                      return style
                    }
                  },
                  {
                    label:'签约日期',
                    value:this.mainData.signdate
                  },
                  {
                    label:'签约金额(元)',
                    value:this.mainData.signamount?this.tool.formatAmount(this.mainData.signamount,2):0
                  },
                  {
                    label:'折扣(%)',
                    value:this.mainData.discountrate !== 0?Math.round((this.mainData.discountrate * 100)*100)/100:'--'
                  },
                  {
                    label:'领域',
                    value:this.mainData.tradefield ? this.mainData.tradefield : '--'
                  },
                  {
                    label:'品牌',
                    value:this.mainData.brandname
                  },
                  {
                    label:'付款条件',
                    value:this.mainData.paytype
                  },
                  {
                    label:'发货日期提醒（天）',
                    value:this.mainData.reminddays
                  },
                  {
                    label:'业务员',
                    value:this.mainData.salername
                  },
                  {
                    label:'状态',
                    value:this.mainData.status,
                    style:function () {
                      let style = that.tool.getStatusColor(that.mainData.status)
                      return style
                    }
                  },
                  {
                    label:'合同描述',
                    value:this.mainData.remarks
                  },
                ],
                systemInfo: [
                  {label:'创建人',value:this.mainData.createby},
                  {label:'创建时间',value:this.mainData.createdate},
                  {label:'最近编辑人',value:this.mainData.changeby},
                  {label:'最近编辑时间',value:this.mainData.changedate},
                  {label:'提交人',value:this.mainData.submitby},
                  {label:'提交时间',value:this.mainData.submitdate},
                  {label:'审核人',value:this.mainData.checkby},
                  {label:'审核时间',value:this.mainData.checkdate},
                  {label:'转手次数',value:this.mainData.leader?this.mainData.leader[0].leadernum:"--"}
                ]
              }
               : this.mainData.type == '直销'
                  ? this.detailInfo ={
                    baseInfo : [
                      /* 直销客户协议 */
                      {
                        label:'合同编号',
                        value:this.mainData.billno
                      },
                      {
                        label:'合同标题',
                        value:this.mainData.title
                      },
                      {
                        label:'合同模板',
                        value:'直销客户合作协议模板'
                      },
                      {
                        label:'合同类型',
                        value:'直销客户合作协议'
                      },
                      {
                        label:'客户',
                        value:this.mainData.enterprisename
                      },
                      {
                        label:'合同有效期',
                        value:`${this.mainData.begdate}至${this.mainData.enddate}`,
                        style:function () {
                          let style = {color:'#3874f6'}
                          return style
                        }
                      },
                      {
                        label:'签约日期',
                        value:this.mainData.signdate
                      },
                      {
                        label:'签约金额(元)',
                        value:this.mainData.signamount?this.tool.formatAmount(this.mainData.signamount,2):0
                      },
                      {
                        label:'折扣(%)',
                        value:this.mainData.discountrate !== 0?Math.round((this.mainData.discountrate * 100)*100)/100:'--'
                      },
                      {
                        label:'领域',
                        value:this.mainData.tradefield ? this.mainData.tradefield : '--'
                      },
                      {
                        label:'品牌',
                        value:this.mainData.brandname
                      },
                      {
                        label:'付款条件',
                        value:this.mainData.paytype
                      },
                      {
                        label:'发货日期提醒（天）',
                        value:this.mainData.reminddays
                      },
                      {
                        label:'业务员',
                        value:this.mainData.salername
                      },
                      {
                        label:'状态',
                        value:this.mainData.status,
                        style:function () {
                          let style = that.tool.getStatusColor(that.mainData.status)
                          return style
                        }
                      },
                      {
                        label:'合同描述',
                        value:this.mainData.remarks
                      },
                    ],
                    systemInfo: [
                      {label:'创建人',value:this.mainData.createby},
                      {label:'创建时间',value:this.mainData.createdate},
                      {label:'最近编辑人',value:this.mainData.changeby},
                      {label:'最近编辑时间',value:this.mainData.changedate},
                      {label:'提交人',value:this.mainData.submitby},
                      {label:'提交时间',value:this.mainData.submitdate},
                      {label:'审核人',value:this.mainData.checkby},
                      {label:'审核时间',value:this.mainData.checkdate},
                      {label:'转手次数',value:this.mainData.leader?this.mainData.leader[0].leadernum:"--"}
                    ]
                  }:this.mainData.type == '工具借用'
                  ? this.detailInfo = {
                    baseInfo : [
                      /* 工具借用 */
                      {
                        label:'合同编号',
                        value:this.mainData.billno
                      },
                      {
                        label:'合同标题',
                        value:this.mainData.title
                      },
                      {
                        label:'合同模板',
                        value:'工具借用协议模板'
                      },
                      {
                        label:'客户',
                        value:this.mainData.enterprisename
                      },
                      {
                        label:'合同类型',
                        value:'工具借用协议'
                      },
                      {
                        label:'业务员',
                        value:this.mainData.salername
                      },
                      {
                        label:'合同有效期',
                        value:`${this.mainData.begdate}至${this.mainData.enddate}`,
                        style:function () {
                          let style = {color:'#3874f6'}
                          return style
                        }
                      },
                      {
                        label:'签约日期',
                        value:this.mainData.signdate
                      },
                      {
                        label:'单套价格(元)',
                        value:this.mainData.signamount?this.tool.formatAmount(this.mainData.signamount,2):0
                      },
                      {
                        label:'状态',
                        value:this.mainData.status,
                        style:function () {
                          let style = that.tool.getStatusColor(that.mainData.status)
                          return style
                        }
                      },
                      {
                        label:'合同描述',
                        value:this.mainData.remarks
                      },
                    ],
                    systemInfo: [
                      {label:'创建人',value:this.mainData.createby},
                      {label:'创建时间',value:this.mainData.createdate},
                      {label:'最近编辑人',value:this.mainData.changeby},
                      {label:'最近编辑时间',value:this.mainData.changedate},
                      {label:'提交人',value:this.mainData.submitby},
                      {label:'提交时间',value:this.mainData.submitdate},
                      {label:'审核人',value:this.mainData.checkby},
                      {label:'审核时间',value:this.mainData.checkdate},
                      {label:'转手次数',value:this.mainData.leader?this.mainData.leader[0].leadernum:"--"}
                    ]
                  }
                   : this.detailInfo = {
                    baseInfo : [
                      /* 居间协议 */
                      {
                        label:'合同编号',
                        value:this.mainData.billno
                      },
                      {
                        label:'合同标题',
                        value:this.mainData.title
                      },
                      {
                        label:'合同模板',
                        value:'居间协议模板'
                      },
                      {
                        label:'合同类型',
                        value:'居间协议'
                      },
                      {
                        label:'居间商',
                        value:this.mainData.ascription_enterprisename
                      },
                      {
                        label:'合同',
                        value:this.mainData.ascription_title
                      },

                      {
                        label:'项目名称',
                        value:this.mainData.projectname
                      },
                      {
                        label:'项目编号',
                        value:this.mainData.projectnum
                      },
                      {
                        label:'客户名称',
                        value:this.mainData.enterprisename
                      },
                      {
                        label:'合同有效期',
                        value:`${this.mainData.begdate}至${this.mainData.enddate}`,
                        style:function () {
                          let style = {color:'#3874f6'}
                          return style
                        }
                      },
                      {
                        label:'签约日期',
                        value:this.mainData.signdate
                      },
                      {
                        label:this.mainData.calculatemodel == 1 ? this.$t('订单金额比例(%)') : this.$t('居间产品折扣(%)'),
                        value:this.mainData.calculatemodel == 1 ? Math.round((this.mainData.orderratio * 100)*100)/100 : Math.round((this.mainData.productdiscount *100)*100)/100,
                        style:function () {
                          let style = {color:'#3874f6'}
                          return style
                        }
                      },
                      {
                        label:'业务员',
                        value:this.mainData.salername
                      },


                      {
                        label:'状态',
                        value:this.mainData.status,
                        style:function () {
                          let style = that.tool.getStatusColor(that.mainData.status)
                          return style
                        }
                      },
                      {
                        label:'合同描述',
                        value:this.mainData.remarks
                      },
                    ],
                    systemInfo: [
                      {label:'创建人',value:this.mainData.createby},
                      {label:'创建时间',value:this.mainData.createdate},
                      {label:'最近编辑人',value:this.mainData.changeby},
                      {label:'最近编辑时间',value:this.mainData.changedate},
                      {label:'提交人',value:this.mainData.submitby},
                      {label:'提交时间',value:this.mainData.submitdate},
                      {label:'审核人',value:this.mainData.checkby},
                      {label:'审核时间',value:this.mainData.checkdate},
                      {label:'转手次数',value:this.mainData.leader?this.mainData.leader[0].leadernum:"--"}
                    ]
                  }


    },
    changeBill (data) {
      this.$confirm(this.$t('确定把当前合同转为订单吗')+'?',this.$t('提示'),{
        confirmButtonText:this.$t('确定'),
        cancelButtonText:this.$t('取消'),
        type:'warning'
      }).then(() => {
        Loading.service({ fullscreen: true ,text:this.$t('刷新中...')});
        this.$axios({
          method:'POST',
          url:'/yos/rest/index',
          data: {
          "accesstoken":JSON.parse(sessionStorage.getItem('active_account')).token,
          "id":20230322153702,
            "content": {
              "sa_contractid": this.$route.query.id
            }
          }
        }).then((res) => {
          Loading.service().close()
          this.tool.showMessage(res.data,() => {
            this.oldRoute = {path:this.$route.path,query:this.$route.query}
            this.$store.dispatch('setHistoryRouter',this.oldRoute)
            if (this.tool.checkAuth(this.$route.name,'changeBillMag')) {
              this.$router.push({
                path:'/orderdetail',
                query:{
                  id:res.data.data.sa_orderid,
                }
              })
            } else if (this.tool.checkAuth(this.$route.name,'changeBillSaler')) {
              this.$router.push({
                path:'/saler_orderDetails',
                query:{
                  id:res.data.data.sa_orderid,
                }
              })
            } else if (this.tool.checkAuth(this.$route.name,'changeBillOrder')) {
              this.$router.push({
                path:'/agent_orderDetails',
                query:{
                  id:res.data.data.sa_orderid,
                }
              })
            }
          })
        })
      })

    },
    async bindImportOrder (id) {
      const res = await this.$api.requested({
        "id": 20230314133404,
        "content": {
          "sa_contractid":this.$route.query.id,
          "attachmentid":id
        }
      })
      if (res.data !== '成功') {
        this.errorUrl = res.data
      }
      this.tool.showMessage(res,() => {
        this.$refs.productDetailList.listData()
      })
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex,tabIndex) {
      /*this.flag = false
      tabIndex = this.$route.query.tabIndex
      this.$router.replace({path:'/contractDetail',query:{id:id,rowindex:rowindex,tabIndex:tabIndex}})*/
      this.queryMainData(id)
    },
    onSuccess(){
      this.visible = false
      this.queryMainData(this.$route.query.id)
      this.$emit('onSuccess')
    },
    successYear(year){
      this.$refs.taskTarget.year = year
      this.$refs.taskTarget.queryData()
    },
    closeDrawer(){
      this.$refs.classList.listData()
    },
    productAdd(){
      this.queryMainData()
    },

    /*同步合作协议*/
    async onCooperate(){
      if (this.$route.query.type === '居间'){
        const res = await this.$api.requested({
          "id":20240518155604,
          "content": {
            "sa_contractid": this.$route.query.id
          },
        })
        this.tool.showMessage(res,()=>{
          this.cooperateVisible = false
          this.$refs.productDetailList.params.content.pageNumber = 1
          this.$refs.productDetailList.listData()
          this.queryMainData()
        })
      }else {
        const res = await this.$api.requested({
          "id": 20231204153904,
          "content": {
            "sa_contractid": this.$route.query.id,
            "isadd":this.cooperateForm.isadd
          }
        })
        this.tool.showMessage(res,()=>{
          this.cooperateVisible = false
          this.$refs.billno.params.content.pageNumber = 1
          this.$refs.billno.listData()
          this.queryMainData()
        })
      }

    },

    async onCooperateItem(){
      if (this.$route.query.type === '居间'){
        const res = await this.$api.requested({
          "id": 20240518160504,
          "content": {
            "sa_contractid": this.$route.query.id,
          }
        })
        this.tool.showMessage(res,()=>{
          this.cooperateVisible = false
          this.$refs.classList.params.content.pageNumber = 1
          this.$refs.classList.listData()
          this.queryMainData()
        })
      }else {
        const res = await this.$api.requested({
          "id": 20231208154904,
          "content": {
            "sa_contractid": this.$route.query.id,
            "isadd":this.cooperateForm.isadd
          }
        })
        this.tool.showMessage(res,()=>{
          this.cooperateVisible = false
          this.$refs.itemClass.param.content.pageNumber = 1
          this.$refs.itemClass.listData()
          this.queryMainData()
        })
      }

    }


    // async getModelList () {
    //   let res = await this.$api.requested({
    //     "id": 20221121155801,
    //     "content": {
    //       "pageNumber": 1,
    //         "pageSize": 999999,
    //         "where":{
    //         "condition":""
    //         }
    //     }
    //   })
    //   this.modelList = res.data
    //   console.log(this.modelList);
    // },
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
    // this.getModelList()
  },
  created() {
    /*this.queryMainData(this.$route.query.id)*/
  }
}
</script>

<style scoped>

</style>
