member.vue 31.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
<template>
  <div class="memberBox">
    <div>
      <el-row class="flexRow">

        <el-col :span="12">
          <div>
            <label>认证状态:</label>
            <span v-if="authenticationStatus == 0 ||!authenticationStatus" class="text-danger">未认证</span>
            <span v-if="authenticationStatus == 1" class="text-success">认证中</span>
            <span v-if="authenticationStatus == 2" class="text-success">已认证</span>
            <span v-if="authenticationStatus == 3" class="text-danger">认证未通过</span>
            <span v-if="authenticationStatus == 4" class="text-danger">即将过期</span>
            <span v-if="authenticationStatus == 5" class="text-danger">已过期</span>
          </div>
        </el-col>
        <el-col :span="12" style="display: flex; justify-content: end;">
          <!--          <el-button v-if="form.deptType!=2" type="primary" @click="auditEditFN">审核详情</el-button>-->
          <!--          <el-button :disabled="btn" type="primary" @click="payTheFees">去缴费</el-button>-->
        </el-col>
      </el-row>
    </div>
    <br>
    <el-form
      ref="formData" :model="form" :rules="rules"
      label-width="120px"
    >
      <el-form-item class="FileUpload" label="上传营业执照" prop="businessLicense">
        <FileUpload
          v-model="form.businessLicense" v-model:file="file2" :disabled="type" :file-size="100"
          :file-type="['pdf','png','jpg','jpeg']"
          :limit="1"
          class="father"
        />
      </el-form-item>
      <el-form-item label="营业执照名称" prop="companyName">
        <el-input v-model="form.companyName" :disabled="ocrLockedFields.companyName || (!result&&authenticationStatus!=0)" style="width: 100%;" />
      </el-form-item>
      <el-form-item label="社会信用代码" prop="creditCode">
        <el-input v-model="form.creditCode" :disabled="ocrLockedFields.creditCode || (type&&creditCode)" style="width: 100%;" />
      </el-form-item>
      <el-form-item label="机构名称" prop="name">
        <el-input v-model="form.name" :disabled="type" style="width: 100%;" />
      </el-form-item>
      <el-form-item label="认证地址" prop="coordinates1">
        <el-cascader
          ref="cascaderA"
          v-model="form.coordinates1"
          :disabled="ocrLockedFields.address || (type&&coordinates1)"
          :filterable="true"
          :options="options"
          :props="defaultProps"
          placeholder="请选择"
          style="width: 100%;"
          @change="changeAddress"
        />
      </el-form-item>
      <el-form-item label="认证详细地址" prop="adress">
        <el-input v-model="form.adress" :disabled="ocrLockedFields.adress || (type&&adress)" style="width: 100%;" />
      </el-form-item>
      <el-form-item class="cas" label="选择所属协会" prop="parentId">
        <el-cascader
          v-model="form.parentId"
          :disabled="ocrLockedFields.parentId || type"
          :options="list"
          :props="props2"
          clearable
          filterable
          style="width: 100%;"
        />
      </el-form-item>

      <el-form-item class="legalCard" label="法人身份证" prop="legalIdcPhoto1">
        <el-row style="width: 100%;">
          <el-col :span="12" style="min-width: 360px;">
            <ImageUpload2
              v-model="form.legalIdcPhoto1" :crop-height="260"
              :crop-width="440" :disabled="!result&&authenticationStatus!=0&&legalIdcPhoto?.[0]" :limit="1"
              class="card1"
            />
          </el-col>
          <el-col :span="12" style="min-width: 360px;">
            <ImageUpload2
              v-model="form.legalIdcPhoto2" v-model:file="file1" :crop-height="260"
              :crop-width="440" :disabled="!result&&authenticationStatus!=0&&legalIdcPhoto?.[1]"
              :limit="1"
              class="card2"
            />
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item label="法人姓名" prop="legal">
        <el-input v-model="form.legal" :disabled="!result&&authenticationStatus!=0&&legal" style="width: 100%;" />
      </el-form-item>
      <el-form-item label="法人证件号" prop="legalIdcCode">
        <el-input
          v-model="form.legalIdcCode" :disabled="!result&&authenticationStatus!=0&&legalIdcCode"
          style="width: 100%;"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="siteContact">
        <el-input v-model="form.siteContact" :disabled="type" style="width: 100%;" />
      </el-form-item>
      <el-form-item label="联系方式" prop="siteTel">
        <el-input v-model="form.siteTel" :disabled="type" style="width: 100%;" />
      </el-form-item>

      <el-form-item label="上传机构照片" prop="pictures">
        <ImageUpload2
          v-model="form.pictures" :disabled="!result&&authenticationStatus!=0&&pictures?.length>0"
          :limit="3" crop-height="260" crop-width="440"
        />
      </el-form-item>
      <el-form-item v-if="authenticationStatus != 1" label="&nbsp;" prop="notice">
        <el-row>
          <el-checkbox v-model="form.notice" style="margin-right: 10px;" />
          <span>我已阅读并同意</span>
          <el-button link style="margin:0;" type="primary" @click="handelNotice(1)">《注册须知》</el-button>
          <el-button link style="margin:0;" type="primary" @click="handelNotice(2)">《入会须知》</el-button>
          <el-button link style="margin:0;" type="primary" @click="handelNotice(3)">《免责声明》2</el-button>
        </el-row>
      </el-form-item>
      <br>
      <br>
    </el-form>
    <div style="text-align: center;">
      <el-button class="btn" round @click="retreat">上一步</el-button>
      <el-button :disabled="btn" class="btn" round type="primary" @click="submit">下一步</el-button>
    </div>

    <auditEdit ref="auditEditRef" />
    <applyNow ref="applyNowRef" @handel-submit="handelSubmit" />
    <goPay
      ref="goPayRef" :a-name="form.aname" :name="form.name" @payment-success="paymentSuccess"
      @payment-view="paymentView"
    />
    <payOk ref="payOkRef" />
    <payView ref="payViewRef" />
    <zhuCeXuZhi ref="zhuCeXuZhiRef" />
    <ruHuiXuZhi ref="ruHuiXuZhiRef" />
    <mianZeShengMing ref="mianZeShengMingRef" />

  </div>

</template>

<script setup>
import {
  editMyMemberCertifiedInfo,
  getMyOwnMemberInfo,
  regionsList, getBusinessLicense, checkBusinessLicense, getMyMemberCertUnitFee, getMyStatus,
  canUseDiscount, creditCodeExist
} from '@/api/system/userInfo.js'
import { ref, reactive, toRefs, watch, onMounted, getCurrentInstance } from 'vue'
import auditEdit from '@/views/system/user/profile/auditEdit.vue'
import { certifiedDeptTreeRegister } from '@/api/system/userInfo.js'
import { ElMessageBox } from 'element-plus'
import { carUrl } from '@/api/person/info'
import { idcCodeCheck } from '@/utils/ruoyi'
import goPay from '@/views/system/user/profile/components/goPay'
import payView from '@/views/system/user/profile/components/payView.vue'
import applyNow from '@/views/system/user/profile/components/applyNow'
import payOk from '@/components/memberComponents/payOk.vue'
import { getMyRecent, getZtxDiscountPolicy } from '@/api/system/config'
import mianZeShengMing from '@/views/groupMember/components/mianZeShengMing.vue'
import ruHuiXuZhi from '@/views/groupMember/components/ruHuiXuZhi.vue'
import zhuCeXuZhi from '@/views/groupMember/components/zhuCeXuZhi.vue'
import { cancelOrder } from '/@/api/order'

const { proxy } = getCurrentInstance()
const authenticationStatus = ref()
const list = ref([])
const options = ref([])
const defaultProps = {
  children: 'children',
  label: 'text',
  checkStrictly: true
}
const pr = ref([])
const showDialog = ref(false)
const showEdit = ref(false)
const type = ref(false) // 第一次选择认证认证类型
const flag = ref(false)
const result = ref(false)
const pictures = ref()
const businessLicense = ref()

const legal = ref()
const legalIdcCode = ref()
const creditCode = ref()
const adress = ref()
const coordinates1 = ref()
const legalIdcPhoto = ref([])

// OCR 自动带出的字段默认不可编辑,避免手动改动导致和营业执照信息不一致。
const ocrLockedFields = ref({})
const regionOptions = ref([])
const props2 = {
  checkStrictly: true,
  children: 'children',
  value: 'id',
  emitPath: false,
  disabled: 'disabled'
}

const data = reactive({
  form: {
    type: 1
  },
  rules: {
    notice: [
      { required: true, trigger: 'blur', message: '请先阅读并勾选注册须知,入会须知,免责声明' },
      { validator: validateNotice, trigger: ['blur', 'change'] }
    ],
    parentId: [{ required: true, trigger: 'blur', message: '请选择所属协会' }],
    date1: [{ required: true, trigger: 'blur', message: '请选择有效期' }],
    creditCode: [
      { required: true, trigger: 'blur', message: '请输入社会信用代码' },
      { validator: validateCreditCode, trigger: ['blur', 'change'] }
    ],
    businessLicense: [
      { required: true, trigger: 'blur', message: '请上传营业执照' }
    ],
    companyName: [
      { required: true, trigger: 'blur', message: '请输入营业执照名称' }
    ],
    legal: [{ required: true, trigger: 'blur', message: '请输入法人姓名' }],
    legalIdcCode: [
      { required: true, trigger: 'blur', message: '请输入法人证件号' },
      { validator: validateCode, trigger: 'blur' }
    ],
    siteContact: [{ required: true, trigger: 'blur', message: '请输入联系人' }],
    siteTel: [{ required: true, trigger: 'blur', message: '请输入联系方式' }],
    applyPoints: [{ required: true, trigger: 'blur', message: '请选择是否申请考点' }],
    pictures: [{ required: true, trigger: 'blur', message: '请上传机构照片' }],
    name: [{ required: true, trigger: 'blur', message: '请输入机构名称' }],
    // materials1: [{ required: true, trigger: 'blur', message: '请上传入会材料' }],
    // applicationForMembership1: [{ required: true, trigger: 'blur', message: '请上传入会申请书' }],
    renewYear: [{ required: true, trigger: 'blur', message: '请选择认证年限' }],
    deptType: [{ required: true, trigger: 'blur', message: '请选择认证类型' }],
    orgName: [{ required: true, trigger: 'blur', message: '请输入机构名称' }],
    check: [{ required: true, trigger: 'blur', message: '请勾选入会须知' }],
    adress: [{ required: true, trigger: 'blur', message: '请输入认证详细地址' }],
    // ownFlag: [{ required: true, trigger: 'blur', message: '请选择是否为自有场所' }],
    coordinates1: [{ required: true, trigger: 'blur', message: '认证地址不能为空' }],
    leaseValidity: [{ required: true, trigger: 'blur', message: '请选择租赁有效期' }],
    isPoints: [{ required: true, trigger: 'blur', message: '请选择是否为考点' }],
    legalIdcPhoto1: [
      { required: true, trigger: 'blur', message: '请上传身份证正反面' },
      { validator: validateID, trigger: 'blur' }
    ],
    belongProvinceId: [{ required: true, trigger: 'change', message: '请选着所属省份' }]
    // leaseTime: [{ required: true, trigger: 'change', message: '请选择租赁合同有效期' }],
    // leaseContract: [{ required: true, trigger: 'blur', message: '请上传文件' }]
  }
})
const { form, rules } = toRefs(data)
const imgList = ref([])
const inCertProcess = ref()
const newResult = ref(false) // 认证流程至少通过一次
const btn = ref(false)
const file1 = ref(null)
const file2 = ref(null)
const timer = ref()
const emit = defineEmits(['handelNext'])
const validating = ref(false)
const memberFee = ref('')

const preferentialPolicy = ref(false)
const preferentialData = ref({})
const payForm = ref({})
// 考点审核状态  0 未提交 1 审核中 2 审核成功 3 审核失败
const auditStatus = ref('0')
onMounted(() => {
  addressFn()
  initData()
  getTree()
  getMyMemberCertUnitFeeApi()
  canUseDiscountApi()
  getZtxDiscountPolicyApi()
  getMyStatusAPI()
  handelGetMyRecent()
})


function handelGetMyRecent() {
  return new Promise(async(resolve, reject) => {
    const res = await getMyRecent() ?? {}
    if (res.data) payForm.value = res.data.comOrder ?? {}
    // `pay_status` char(1) DEFAULT '0' COMMENT '支付状态 0 未支付 1 已支付 2 已取消 3 无需支付',
    if (payForm.value.payStatus === '0') {
      ElMessageBox.confirm(
        '您有一笔订单尚未支付,请及时支付 或 取消订单。',
        '系统提示', {
          confirmButtonText: '去支付',
          cancelButtonText: '取消订单',
          type: 'warning',
          showClose: false,
          closeOnClickModal: false,
          closeOnPressEscape: false
        }).then(() => {
        console.log(payForm.value)
        payForm.value.content = JSON.parse(payForm.value.content)
        proxy.$refs['goPayRef'].open(payForm.value)
        return reject(res)
      }).catch((err) => {
        console.log(err)
        // 取消订
        handelCancelOrder()
        return reject(res)
      })
      // await proxy.$modal.confirm('您有1笔订单尚未支付,请及时支付 或 取消订单。').final(() => {
      //   router.push({ path: '/group/groupOrder' })
      // })
    } else {
      return resolve(true)
    }
  })
}

async function handelCancelOrder() {
  await proxy.$modal.confirm(`是否确认取消订单?`)
  if (!payForm.value.id) return
  await cancelOrder(payForm.value.id)
  await initData()
  await proxy.$modal.msgSuccess('操作成功')
}


async function addressFn() {
  const res = await regionsList()
  options.value = res.data
}

async function getMyMemberCertUnitFeeApi() {
  const { data } = await getMyMemberCertUnitFee()
  memberFee.value = data
}


async function canUseDiscountApi() {
  const { data } = await canUseDiscount()
  preferentialPolicy.value = data
}


async function getZtxDiscountPolicyApi() {
  const { data } = await getZtxDiscountPolicy()
  preferentialData.value = data
}

// // 考点申请
// function handelApply() {
//   proxy.$refs['applyNowRef'].open(form.value.memId)
// }

function handelSubmit() {
  proxy.$refs['pointsApplyRef'].close()
  getMyStatusAPI()
}

function paymentSuccess() {
  showEdit.value = false
  showDialog.value = false
  proxy.$refs['payOkRef'].open()
  emit('handelNext', 3)
  // proxy.$modal.confirm('支付成功,等待审核中')
  initData()
}

function paymentView(row) {
  showEdit.value = false
  showDialog.value = false
  proxy.$refs['payViewRef'].open(row.orderId)
  initData()
}


async function getMyStatusAPI() {
  const { data } = await getMyStatus()
  if (data && data.auditStatus) {
    auditStatus.value = data.auditStatus
  } else {
    auditStatus.value = 0
  }
}


// true 有
// 营业执照编号校验
async function validateCreditCode(rule, value, callback) {
  if (!value) return callback(new Error('请输入社会信用代码'))
  if (validating.value) return
  validating.value = true
  try {
    // 模拟异步请求
    const res = await creditCodeExist(value)
    if (res.data) {
      proxy.$modal.confirm('该社会统一信用代码已存在,请联系中国跆拳道协会010-87188971')
      callback(new Error('社会信用代码已存在请联系中跆协修改'))
    } else {
      callback()
    }
  } finally {
    validating.value = false
  }
}

function validateNotice(rule, value, callback) {
  if (!value) {
    callback(new Error('请先阅读并勾选注册须知,入会须知,免责声明'))
  } else {
    callback()
  }
}

// 上一步
function retreat() {
  emit('handelNext', 1)
}

// 身份证校验
function validateID(rule, value, callback) {
  if (!form.value.legalIdcPhoto1) {
    callback(new Error('请上传您的身份证国徽面'))
  }
  if (!form.value.legalIdcPhoto2) {
    callback(new Error('请上传您的身份证头像面'))
  }
  return callback()
}

function validateCode(rule, value, callback) {
  if (idcCodeCheck(value)) {
    return callback()
  } else {
    return callback(new Error('亲输入正确的证件号'))
  }
}

async function initData() {
  const res = await getMyOwnMemberInfo()
  newResult.value = res.data.newResult//
  result.value = res.data.result// 认证缴费状态
  authenticationStatus.value = res.data.authenticationStatus
  pr.value = res.data.pr

  if (authenticationStatus.value == 0) {
    btn.value = false
  } else if (authenticationStatus.value == 1) {
    btn.value = true
  } else {
    btn.value = !result.value
  }
  if (res.data.authenticationStatus == 2) {
    // router.push('/index')
    window.location.href = '/'
  }
  // 认证信息
  if (authenticationStatus.value == 1 || authenticationStatus.value == 2 || authenticationStatus.value == 5) {
    type.value = true
  } else {
    type.value = false
  }

  if (authenticationStatus.value != 0) {
    if (newResult.value) {
      // 至少认证过一次
      flag.value = true
    } else {
      // 没有认证
      if (result.value) {
        flag.value = false
      } else {
        flag.value = true
      }
    }
  }

  inCertProcess.value = res.data.inCertProcess
  if (!res.data.memberInfo) res.data.memberInfo = {}
  if (!res.data.dept) res.data.dept = {}
  form.value = { ...res.data.dept, ...res.data.memberInfo }
  if (res.data.lastCert) {
    form.value.renewYear = res.data.lastCert.renewYear.toString()
  }
  form.value.coordinates1 = []
  if (form.value.provinceId) form.value.coordinates1.push(form.value.provinceId)
  if (form.value.cityId) form.value.coordinates1.push(form.value.cityId) // 省份/市/区/州 选择框中的选择
  if (form.value.regionId) form.value.coordinates1.push(form.value.regionId) // 省份/市/区/州 选择框中的选择
  imgList.value = form?.value?.pictures?.split(',')
  form.value.legalIdcPhoto1 = form.value.legalIdcPhoto?.split(',')?.[0] || ''
  form.value.legalIdcPhoto2 = form.value.legalIdcPhoto?.split(',')?.[1] || ''
  legalIdcPhoto.value = form.value.legalIdcPhoto
  pictures.value = form.value.pictures
  try {
    businessLicense.value = form.value.businessLicense
    form.value.businessLicense = JSON.parse(form.value.businessLicense)
  } catch (e) {
  }

  creditCode.value = form.value.creditCode
  legal.value = form.value.legal
  legalIdcCode.value = form.value.legalIdcCode
  coordinates1.value = form.value.provinceId
  adress.value = form.value.adress
  form.value.deptType = res.data.dept.deptType
  form.value.name = form.value.baseName
}

// 获取地址
function changeAddress(value) {
  form.value.provinceId = value?.[0]?.toString()
  form.value.cityId = value?.[1]?.toString()
  form.value.regionId = value?.[2]?.toString()
}


async function getTree() {
  const res = await certifiedDeptTreeRegister({ selfDeptId: '-1', webSiteShow: 1, showDisabled: 1, isBlack: 0 })
  // res.data = setAllDisabledFalse(res.data)
  list.value = res.data
}

function setAllDisabledFalse(arr) {
  return arr.map(item => {
    // 当前项 disabled = false
    item.disabled = false
    // 如果有 children,递归处理
    if (item.children && item.children.length) {
      setAllDisabledFalse(item.children)
    }
    return item
  })
}

function submit() {
  proxy.$refs['formData'].validate(async(valid) => {
    if (valid) {
      if (!form.value.notice) {
        proxy.$modal.msgError('请先阅读并勾选注册须知,入会须知,免责声明')
        return
      }
      
      await handelGetMyRecent()
      
      const res1 = await handelVerify()
      if (!res1.passFlag) {
        // await proxy.$modal.confirm(`${res1.msg},是否继续提交?`)
        await ElMessageBox.alert(
          `<p>${res1.msg} <br/><span style="color: #F56C6C">企业信息异常请检查相关资料信息,确认无误后再次提交!</span></p>`,
          '系统提示', {
            type: 'warning',
            dangerouslyUseHTMLString: true,
            showCancelButton: true,
            confirmButtonText: '确认无误',
            cancelButtonText: '返回修改'
          })
      }
      let res = null
      if (form.value.parentId == 0 || form.value.parentId == -1) {
        return proxy.$message.error('请选择所属协会!')
      }
      res = await editMyMemberCertifiedInfo({
        parentId: form.value.parentId,
        creditCode: form.value.creditCode,
        legal: form.value.legal,
        businessLicense: JSON.stringify(form.value.businessLicense),
        pictures: form.value.pictures,
        // materials: JSON.stringify(form.value.materials1),
        // applicationForMembership: JSON.stringify(form.value.applicationForMembership1),
        memId: form.value.memId,
        id: form.value.deptId,
        name: form.value.name,
        regionId: form.value.regionId,
        cityId: form.value.cityId,
        provinceId: form.value.provinceId,
        adress: form.value.adress,
        // belongProvinceId: form.value.belongProvinceId,
        deptType: form.value.deptType,
        leaseValidity: form.value.leaseValidity,
        legalIdcPhoto: [form.value.legalIdcPhoto1, form.value.legalIdcPhoto2]?.join(','),
        // leaseContract: JSON.stringify(form.value.leaseContract),
        // ownFlag: form.value.ownFlag,
        // leaseTime: form.value.leaseTime ? [...form.value.leaseTime].join() : ''
        applyPoints: '0',
        siteContact: form.value.siteContact,
        siteTel: form.value.siteTel,
        companyName: form.value.companyName,
        legalIdcCode: form.value.legalIdcCode
      })
      if (res.code === 200) {
        showEdit.value = false
        await payTheFees()
        // await initData()
      } else {
        proxy.$modal.msgError('操作失败!')
      }
    } else {
      proxy.$modal.msgError('请完善信息')
    }
  })
}

// 审核详情
function auditEditFN() {
  proxy.$refs['auditEditRef'].open(pr.value)
}

function payTheFees() {
  if (!form.value.siteContact) {
    return proxy.$modal.msgError('请完善基础信息!')
  }
  // showDialog.value = true
  proxy.$refs['goPayRef'].open()
}

watch(() => file1.value, (v) => {
  if (v) {
    clearTimeout(timer.value)
    timer.value = setTimeout(() => {
      cardExtract()
    }, 500)
  }
})

watch(() => file2.value, (v) => {
  if (v) {
    clearTimeout(timer.value)
    timer.value = setTimeout(() => {
      licenseFn()
    }, 500)
  }
})

function handelNotice(v) {
  if (v == 1) {
    proxy.$refs['zhuCeXuZhiRef'].open()
  }
  if (v == 2) {
    proxy.$refs['ruHuiXuZhiRef'].open()
  }
  if (v == 3) {
    proxy.$refs['mianZeShengMingRef'].open()
  }
}

// 身份证提取
async function cardExtract() {
  try {
    const formData = new FormData()
    formData.append('pic', file1.value)
    const res = await carUrl(formData, '0')
    form.value.legal = res.data.name
    form.value.legalIdcCode = res.data.code
  } catch (e) {
    console.log(e)
    form.value.legal = null
    form.value.legalIdcCode = null
  } finally {
    clearTimeout(timer.value)
  }
}

// OCR字段锁定函数
function lockOcrField(field, value) {
  if (value !== undefined && value !== null && String(value).trim() !== '') {
    ocrLockedFields.value[field] = true
  }
}

// 地址文本标准化
function normalizeAddressText(text) {
  return String(text || '').replace(/\s/g, '')
}

// 获取地址关键词
function getAddressKeywords(name) {
  const fullName = normalizeAddressText(name)
  const shortName = fullName.replace(/省|市|区|县|自治区|壮族自治区|回族自治区|维吾尔自治区|地区|自治州|盟|旗/g, '')
  return [...new Set([fullName, shortName].filter(keyword => keyword && keyword.length > 1))]
}

// 地址包含判断
function addressIncludes(target, name) {
  return getAddressKeywords(name).some(keyword => target.includes(keyword))
}

// 获取节点文本
function getNodeText(node) {
  return node?.text ?? node?.label ?? node?.name ?? ''
}

// 获取节点值
function getNodeValue(node) {
  return node?.value ?? node?.id ?? ''
}

// 根据地址查找地区路径
function findRegionPathByAddress(address) {
  const target = normalizeAddressText(address)
  if (!target || !regionOptions.value?.length) return null
  const candidates = []

  for (const province of regionOptions.value) {
    const provinceMatched = addressIncludes(target, getNodeText(province))
    const provincePath = [province]
    const cities = province.children || []
    for (const city of cities) {
      const cityMatched = addressIncludes(target, getNodeText(city))
      const cityPath = [province, city]
      const regions = city.children || []
      for (const region of regions) {
        const regionMatched = addressIncludes(target, getNodeText(region))
        if (provinceMatched || cityMatched || regionMatched) {
          const score = (provinceMatched ? 1 : 0) + (cityMatched ? 2 : 0) + (regionMatched ? 4 : 0)
          candidates.push({ path: [province, city, region], score })
        }
      }
      if (provinceMatched || cityMatched) {
        const score = (provinceMatched ? 1 : 0) + (cityMatched ? 2 : 0)
        candidates.push({ path: cityPath, score })
      }
    }
    if (provinceMatched) {
      candidates.push({ path: provincePath, score: 1 })
    }
  }
  candidates.sort((a, b) => b.score - a.score || b.path.length - a.path.length)
  return candidates[0]?.path || null
}

// 应用地区路径
function applyRegionPath(path) {
  if (!path?.length) return false
  const valuePath = path.map(node => getNodeValue(node))
  form.value.coordinates1 = valuePath
  form.value.provinceId = getNodeValue(path[0]) || ''
  form.value.cityId = getNodeValue(path[1]) || ''
  form.value.regionId = getNodeValue(path[2]) || ''
  lockOcrField('address', form.value.provinceId || form.value.cityId || form.value.regionId)
  return true
}

// 根据地区名称查找协会路径
function findAssoPathByRegionNames(regionPath) {
  if (!regionPath?.length || !list.value?.length) return null
  const names = regionPath.map(node => normalizeAddressText(getNodeText(node))).filter(Boolean)
  const candidates = []

  function walk(listData, path) {
    for (const item of listData || []) {
      const itemName = normalizeAddressText(getNodeText(item))
      const nextPath = [...path, item]
      const score = names.reduce((total, name, index) => {
        const shortName = name.replace(/省|市|区|县|自治区|壮族自治区|回族自治区|维吾尔自治区|地区|自治州|盟|旗/g, '')
        return total + (itemName.includes(name) || (shortName.length > 1 && itemName.includes(shortName)) ? index + 1 : 0)
      }, 0)
      if (score > 0) candidates.push({ path: nextPath, score })
      if (item.children?.length) walk(item.children, nextPath)
    }
  }

  walk(list.value, [])
  candidates.sort((a, b) => b.score - a.score || b.path.length - a.path.length)
  return candidates[0]?.path || null
}

// 应用协会路径
function applyAssoPath(path) {
  if (!path?.length) return false
  const lastNode = path[path.length - 1]
  form.value.parentId = getNodeValue(lastNode) || ''
  lockOcrField('parentId', form.value.parentId)
  return !!form.value.parentId
}

// 应用营业执照地址
function applyBusinessAddress(address) {
  const businessAddress = String(address || '').trim()
  if (!businessAddress) return
  form.value.adress = businessAddress
  lockOcrField('adress', businessAddress)

  const regionPath = findRegionPathByAddress(businessAddress)
  if (applyRegionPath(regionPath)) {
    const assoPath = findAssoPathByRegionNames(regionPath)
    applyAssoPath(assoPath)
  }
}

// 获取地区列表
function getRegionsList() {
  return regionsList().then(res => {
    regionOptions.value = res.data
    options.value = res.data
  })
}

// 营业执照提取
async function licenseFn() {
  try {
    const formData = new FormData()
    formData.append('pic', file2.value)
    const res = await getBusinessLicense(formData)
    if (res.code === 200 && res.data) {
      const ocrData = res.data
      form.value.creditCode = ocrData.creditCode || form.value.creditCode
      form.value.companyName = ocrData.companyName || form.value.companyName
      form.value.legal = ocrData.legalPerson || form.value.legal
      lockOcrField('creditCode', form.value.creditCode)
      lockOcrField('companyName', form.value.companyName)
      lockOcrField('legal', form.value.legal)
      
      if (!regionOptions.value?.length) {
        await getRegionsList().catch(() => {})
      }
      if (!list.value?.length) {
        await getTree().catch(() => {})
      }
      
      applyBusinessAddress(ocrData.businessAddress)
    }
    console.log(res)
  } catch (e) {
    form.value.creditCode = null
    form.value.companyName = null
    form.value.legal = null
    console.log(e)
  } finally {
    clearTimeout(timer.value)
  }
}

function handelVerify() {
  return new Promise(async(resolve, reject) => {
    if (!form.value.legalIdcCode || !form.value.legal) {
      proxy.$modal.msgError('请重新上传身份证')
      return reject()
    }
    if (!form.value.companyName || !form.value.creditCode) {
      proxy.$modal.msgError('请重新上传营业执照')
      return reject()
    }
    const res = await checkBusinessLicense({
      creditCode: form.value.creditCode,
      companyName: form.value.companyName,
      legalIdcCode: form.value.legalIdcCode,
      legal: form.value.legal
    })
    if (res.code == 200) {
      return resolve(res.data)
    } else {
      return reject(res)
    }
  })
}
</script>

<style lang="scss" scoped>
.memberBox {
  width: 900px;
  padding: 20px;
}

.box {
  padding: 30px;
}

.ping {
  display: flex;
  justify-content: center;
}

.title-header {
  border: 1px solid black;
  padding: 10px;
}

.header {
  padding-left: 40px;
}

.header-1 {
  font-size: 20px;
}

.heder-right {
  padding-left: 20px;
  padding-top: 20px;
}

.quBtn {
  background-color: #920f20;
  color: #fff;
}

.left {
  margin-left: 20px;
}

.idCard {
  margin-top: 5px;
  margin-bottom: 5px;
}

.m0 {
  margin: 0
}

.mb20 {
  margin-bottom: 20px;
}

.flexRow {
  display: flex;
  align-items: center;

  label {
    font-size: 16px;
    color: #7B7F83;
  }
}

:deep(.el-upload--picture-card) {
  width: 220px;
  height: 130px;
}

:deep(.el-upload-list__item) {
  width: 220px;
  height: 130px;
}

:deep( .FileUpload .el-upload-list__item) {
  width: auto;
  height: 32px;

  .el-upload-list {
    margin: 0 0 10px 0
  }
}

:deep( .FileUpload ) {
  .el-upload-list {
    margin: 0 0 10px 0
  }
}

:deep(.el-upload-list--picture-card .el-upload-list__item) {
  width: 220px;
  height: 130px;
}

:deep(.component-upload-image) {
  display: flex;

  .el-upload__tip {
    width: 200px;
    margin-left: 20px;
  }
}

.father {
  position: relative;
}

.son2 {
  position: absolute;
  top: 6px;
  left: 250px;
}

.hint {
  text-align: left;
  font-size: 12px;
  color: #f56c6c;
  margin: 0;
  padding: 0;
}

.textFather {
  position: relative;
}

.TextSon {
  position: absolute;
  top: 125px;
  z-index: 2;
  padding: 0;
  margin: 0;
  width: 100%;
}

.tex1 {
  z-index: 9;
  font-size: 10px;
  font-weight: 600;
  transform: scale(0.45);
  margin: 0;
  padding: 0;
  width: 100% !important;
}

.right {
  margin-right: 10px;
}

.left {
  margin-left: 150px;
}

:deep(.legalCard) {
  .el-upload__tip {
    display: none;
  }

  .card1 {
    .el-upload--picture-card {
      background-image: url(@/assets/images/card2.png);
      background-size: 100%;
    }
  }

  .card2 {
    .el-upload--picture-card {
      background-image: url(@/assets/images/card1.png);
      background-size: 100%;
    }
  }

  .el-upload-list--picture-card {
    width: 360px;
    height: 225px;

    .el-upload--picture-card {
      width: 100%;
      height: 100%;
    }
  }

  .el-upload-list__item {
    width: 360px;
    height: 225px;
  }
}

.checkBox {
  position: relative;
  top: 3px

}

.btn {
  width: 200px;
  height: 38px;
}
</style>