<template>
  <div class="app-container">
    <AppointmentEdit
      source="policyList"
      :policyId="route.query"
      v-if="showTab"
      :policyDetailInfo="policyInfo"
    />
  </div>
</template>
<script setup name="FollowUpDetail">
import { processUserName } from '@/utils/common'
import AppointmentEdit from '@/views/sign/appointment/appointmentEdit'
import { getPolicyfollow, getPolicyInfo } from '@/api/sign/underwritingMain'
import useUserStore from '@/store/modules/user'
import useDictStore from '@/store/modules/dict'
import {
  listTenantUser,
  getInsuranceProductList,
  getAdditionalProductList,
  getAllCompanys,
  getClientUser
} from '@/api/common'
import { ref } from 'vue'
const userStore = useUserStore()
const dictStore = useDictStore()
const { proxy } = getCurrentInstance()
const route = useRoute()
const showTab = ref(false)

const policyInfo = ref({}) //新单信息详情

// 获取各个流程所需要得字典数据
const getDictsData = async () => {
  // 获取租户用户列表
  const params1 = {
    tenantBizId: userStore.projectInfo.tenantBizId,
    pageNo: 1,
    pageSize: 10
  }
  const response1 = await listTenantUser(params1)
  if (response1.code == 200) {
    let result = processUserName(response1.data.records)
    result = result.map(item => {
      return {
        value: item.userBizId,
        label: item.showName
      }
    })
    dictStore.setTenantUserList(result)
  }
  const params2 = {
    loginTenantBizId: userStore.projectInfo.tenantBizId,
    pageNo: 1,
    pageSize: 10
  }

  const response2 = await getInsuranceProductList(params2)
  if (response2.code == 200) {
    response2.data.records = response2.data.records.map(item => {
      return {
        ...item,
        label: item.productName,
        value: item.productBizId
      }
    })
    dictStore.setInsureProductList(response2.data.records)
  }
  const params3 = {
    pageNo: 1,
    pageSize: 10
  }

  const response3 = await getAdditionalProductList(params3)
  if (response3.code == 200) {
    response3.data.records = response3.data.records.map(item => {
      return {
        ...item,
        label: item.productName,
        value: item.additionalProductBizId
      }
    })
    dictStore.setAdditionalProductList(response3.data.records)
  }
  const params4 = {
    pageNo: 1,
    pageSize: 10
  }

  const response4 = await getAllCompanys(params4)
  if (response4.code == 200) {
    response4.data.records = response4.data.records.map(item => {
      return {
        ...item,
        label: item.deptName,
        value: item.deptBizId
      }
    })
    dictStore.setInsureCompanyList(response4.data.records)
  }
  const params5 = {
    projectBizId: 'project_IbjfmMTYvNEBuh2S',
    tenantBizId: userStore.projectInfo.tenantBizId,
    pageNo: 1,
    pageSize: 10
  }

  const response5 = await getClientUser(params5)
  if (response5.code == 200) {
    response5.data.records = response5.data.records.map(item => {
      return {
        ...item,
        label: item.name,
        value: item.clientUserBizId
      }
    })
    dictStore.setClientUserList(response5.data.records)
  }
  // 请求每个流程中所涉及到的字典值数据
  proxy.useDictLists([
    'csf_employment',
    'sys_no_yes',
    'bx_currency_type',
    'csf_liquid_asset_type',
    'csf_premium_funding_source',
    'csf_customer_type',
    'csf_customer_title',
    'sys_gender',
    'csf_marriage',
    'csf_education',
    'csf_id_type',
    'csf_ap_apply_type',
    'csf_ap_meeting_point',
    'csf_ap_first_issue',
    'csf_ap_dividend',
    'csf_ap_frequency',
    'csf_ap_rel',
    'csf_ap_registration',
    'csf_ap_exercise',
    'csf_ap_risk',
    'csf_ap_movie',
    'csf_ap_game',
    'wj_question_first_category',
    'wj_question_second_category',
    'csf_ap_policy_transfer',
    'md_bank',
    'bx_product_type',
    'csf_policy_follow_mailing_method'
  ])
}
// 获取新单跟进详情数据
const getPolicyDetail = () => {
  // 使用 Promise.all 并行发送请求
  Promise.all([getPolicyfollow(route.query.policyBizId), getPolicyInfo(route.query.policyBizId)])
    .then(([followRes, infoRes]) => {
      // 只有当两个请求都成功时才执行后续操作
      if (followRes.code === 200 && infoRes.code === 200) {
        // 合并两个响应数据，infoRes.data 会覆盖 followRes.data 中的同名属性
        policyInfo.value = {
          ...followRes.data,
          ...infoRes.data
        }
        showTab.value = true
        // if (policyInfo.value.nextStatusList && policyInfo.value.nextStatusList.length > 0) {

        // }
      }
    })
    .catch(error => {
      // 统一错误处理（可选）
      console.error('请求失败:', error)
    })
}
if (route.query.type == 'edit') {
  getPolicyDetail()
}
getDictsData()
</script>
<style lang="scss" scoped>
 :deep(.el-card ) {
  border: none !important;
}
 :deep(.el-input-group__append ),
 :deep(.el-input-group__prepend ) {
  background-color: #fff !important;
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 84.5px);
  padding: 20px;
  background-color: #f2f3f5;
  .cardHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    .left {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      .iconBox {
        width: 40px;
        height: 40px;
        margin-right: 5px;
        background-color: #e8f3ff;
        border-radius: 3px;
        text-align: center;
        padding: 5px;
      }
      .rightBox {
        margin-left: 10px;
        display: flex;
        flex-direction: column;
        .num {
          font-size: 14px;
        }
        .bottom {
          display: flex;
          align-items: center;
          margin-top: 3px;
          .status {
            font-size: 11px;
            color: #00b42a;
            background-color: #e8ffea;
            padding: 4px 6px;
            border-radius: 2px;
            margin-right: 10px;
          }

          .time {
            font-size: 12px;
            color: #86909c;
            .icon-yanqiweiwancheng {
              margin-right: 5px;
              font-size: 12px;
            }
          }
        }
      }
    }
  }
  .tabsBox {
    .tabButton {
      box-shadow: 0 -1px 14px #00000014;
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: flex-end;
      padding-right: 20px;
      padding-top: 20px;
      .sumbitBtn {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 16px;
        height: 60px;
        background-color: #165dff;
        color: #fff;
        padding: 0 30px;
        .buttonIcon {
          font-size: 16px;
          color: #fff;
        }
      }
    }
  }
  .tabPaneBox {
    /* height: calc(100vh - 317px); */
    height: calc(100vh - 215px);
    overflow-y: auto;
    padding-right: 10px;
  }
  .overviewBox {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .oneItem {
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      .circle {
        width: 35px;
        height: 35px;
        box-sizing: border-box;
        border-radius: 50%;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-bottom: 5px;
      }
      .el-icon {
        font-size: 16px;
        font-weight: 600;
      }
    }
    .finfishCircle {
      background-color: #e8f3ff;
      color: #165dff;
    }
    .todoCircle {
      background-color: #165dff;
      color: #fff;
    }
    .unFinishCircle {
      background-color: #f2f3f5;
      color: #4e5969;
    }
    .title {
      font-size: 14px;
      margin-bottom: 5px;
    }
    .finfishTitle {
      color: #1d2129;
      font-size: 14px;
    }
    .unFinishTitle {
      color: #4e5969;
      font-size: 13px;
    }
    .status {
      font-size: 12px;
      margin-bottom: 8px;
      color: #86909c;
    }
    .finfishStatus {
      color: #165dff;
    }
    .unFinishStatus {
      color: #4e5969;
    }
    .operation {
      display: flex;
      align-items: center;
      font-size: 12px;
      .editIcon {
        margin-right: 3px;
        color: #165dff;
        font-size: 12px;
      }
    }
    .finfishOperation {
      color: #4e5969;
    }
    .unFinishOperation {
      color: #165dff;
    }
  }
}
</style>
