smartContractCreate.vue 28.8 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
<route lang="yaml">
  name: smartContractCreate
</route>

<script lang="ts" setup name="smartContractCreate">
import { useValidator } from "@/hooks/useValidator";
import useUserStore from "@/store/modules/user";
import {
  getContractDetail,
  getActionPolicyList,
  getConstraintPolicyList,
  getContractDataProduct,
  getContractTenantList,
  saveContract,
  updateContract,
} from "@/api/modules/dataSmartContract"
import StrategyTable from "./components/strategyTable.vue";
import { CirclePlus } from "@element-plus/icons-vue";
import { scrollLastRowToView } from "@/utils/common";
import { TableColumnWidth, USERROLE } from "@/utils/enum";
import {
  getParamsList,
} from "@/api/modules/queryService";
import useDataSmartContract from "@/store/modules/dataSmartContract";
import { getEnterpriseData } from "@/api/modules/dataIdentify";

const { required } = useValidator();
const userStore = useUserStore();
const userData = JSON.parse(localStorage.userData);
const tenantData = JSON.parse(localStorage.tenantInfo);
const router = useRouter();
const route = useRoute();
const fullscreenLoading = ref(false);
const expandBase = ref(false);
const expandInfo = ref(false);
const expandPolicy = ref(false);
const fullPath = route.fullPath;
const dataSmartContract = useDataSmartContract();
const { proxy } = getCurrentInstance() as any;

/** 是否是数据提供方 */
const isDataUse = computed(() => {
  return localStorage.getItem('userRole') == USERROLE.USE;
})

const signModeList = ref([]);

const baseInfoFormRef = ref();

const baseInfoFormItems = ref([{
  label: '合约名称',
  type: 'input',
  placeholder: '请输入',
  field: 'contractName',
  default: '',
  maxlength: 50,
  clearable: true,
  required: true
}, {
  label: '签署模式',
  type: 'select',
  placeholder: '请选择',
  field: 'signModeCode',
  default: '01',
  options: signModeList.value,
  props: {
    value: 'value',
    label: 'label'
  },
  disabled: false,
  required: true,
  visible: true
}, {
  label: "终止时间",
  type: "datetime",
  field: "endTime",
  defaultTime: new Date(2000, 1, 1, 23, 59, 59),
  default: null,
  placeholder: "请选择",
  clearable: true,
  disabledDate: (date) => {
    const today = new Date();
    // 将 today 设置为 00:00:00,只比较日期部分(本地时间)
    const todayStart = new Date(
      today.getFullYear(),
      today.getMonth(),
      today.getDate()
    );

    // 将 date 也转换为本地日期的开始时间(避免 UTC 问题)
    const dateStart = new Date(
      date.getFullYear(),
      date.getMonth(),
      date.getDate()
    );

    // 禁用 dateStart < todayStart 的日期(即今天之前)
    return dateStart.getTime() < todayStart.getTime();
  },
  required: true,
}, {
  label: '合约简介',
  type: 'textarea',
  focusValue: false,
  placeholder: '请输入',
  field: 'contractAbstract',
  default: '',
  clearable: true,
  required: false,
  block: true,
  maxlength: 500
}]);

const baseInfoFormRules = ref({
  contractName: [required('请填写合约名称')],
  signModeCode: [required('请选择签署模式')],
  endTime: [required('请选择终止时间')],
});

const handleFormSelectChange = (val, row, info) => {
  if (row.field == 'signModeCode') { //签署模式改变会影响下面的合约策略执行者的显示
    let nodeInfo = nodeInfoFormRef.value.formInline;
    nodeInfoFormItems.value.forEach((item, index) => {
      item.default = nodeInfo[item.field];
      if (index == 1) {
        item.default = val == '01' ? userData.tenantGuid : '';
      } else if (index == 2) {
        item.default = val == '01' ? tenantList.value.find(t => t.guid == userData.tenantGuid)?.socialCreditCode : '';
      }
    })
    productList.value = productList.value?.map(d => {
      d.disabled = val == '01' && d.enterpriseName != userData.tenantName; //点对点,只能选择自己公司所属产品
      return d;
    }) || [];
    productTableInfo.value.editInfo.dataProductId.options = productList.value;
  }
}

/** ----------------- 扩展字段相关信息 ----------------------------- */
const extendTableRef = ref();
const extendData: any = ref([]);

/** 合约扩展字段类型 */
const dataTypeList: any = ref([]);

/** 基本信息的入参定义表格配置 */
const extendTableInfo = ref({
  id: "input-extend-table",
  height: '214px',
  fields: [
    { label: "序号", type: "index", width: TableColumnWidth.INDEX, align: "center" },
    { label: "扩展字段名称", field: "expansionFieldName", width: 160, required: true, columClass: 'edit-colum', type: 'edit' },
    { label: "字段类型", field: "fieldType", width: 140, required: true, columClass: 'edit-colum', type: 'edit' },
    { label: "输入内容", field: "content", width: 300, required: false, columClass: 'edit-colum', type: 'edit' },
  ],
  editInfo: {
    expansionFieldName: {
      label: '',
      type: 'input',
      field: 'expansionFieldName',
      default: '',
      maxlength: 50,
      placeholder: '请输入',
      clearable: true,
    },
    fieldType: {
      label: '',
      type: 'select',
      field: 'fieldType',
      default: '',
      options: dataTypeList.value,
      props: {
        label: 'label',
        value: 'value'
      },
      placeholder: '请选择',
      clearable: false,
      filterable: true
    },
    content: {
      label: '',
      type: 'input',
      field: 'content',
      default: '',
      maxlength: 200,
      placeholder: '请输入',
      clearable: true,
    }
  },
  STATUS: 'edit',
  data: extendData.value,
  showPage: false,
  actionInfo: {
    show: true,
    label: "操作",
    type: "btn",
    width: 60,
    fixed: 'right',
    btns: [
      {
        label: "删除", value: "remove", click: (scope) => {
          let index = scope.$index;
          proxy.$openMessageBox("此操作将永久删除, 是否继续?", () => {
            extendData.value.splice(index, 1);
            extendTableInfo.value.data = extendData.value;
            proxy.$ElMessage.success('扩展字段删除成功');
          }, () => {
            proxy.$ElMessage.info("已取消");
          });
        }
      },
    ]
  },
  loading: false
});

/** 给表格添加一行入参定义。 */
const addExtend = () => {
  extendData.value.push({ expansionFieldName: '', fieldType: '', content: '' });
  extendTableInfo.value.data = extendData.value;
  nextTick(() => {
    scrollLastRowToView(extendTableRef.value?.tableRef, extendData.value.length);
  })
}

/** ----------------- 数据产品表格相关信息 ----------------------------- */
const productTableRef = ref();
const productData: any = ref([{ dataProductId: '' }]);

const productList: any = ref([]);

/** 基本信息的入参定义表格配置 */
const productTableInfo = ref({
  id: "input-product-table",
  height: '75px',
  minHeight: '60px',
  minPanelHeight: '60px',
  fields: [
    { label: "序号", type: "index", width: TableColumnWidth.INDEX, align: "center" },
    { label: "数据产品", field: "dataProductId", width: 180, required: true, columClass: 'edit-colum', type: 'edit' },
    { label: "数据产品编码", field: "dataProductId", width: 261 },
    { label: "所属主体名称", field: "dataProductEntityName", width: 200 },
    { label: "产品简介", field: "dataProductAbstract", width: 240 },
  ],
  editInfo: {
    dataProductId: {
      label: '',
      type: 'select',
      field: 'dataProductId',
      default: '',
      options: productList.value,
      props: {
        label: 'productNameDesc',
        value: 'productId',
        disabled: 'disabled'
      },
      placeholder: '请选择',
      clearable: false,
      filterable: true
    },
  },
  STATUS: 'edit',
  data: productData.value,
  showPage: false,
  actionInfo: {
    show: true,
    label: "操作",
    type: "btn",
    width: 60,
    fixed: 'right',
    btns: [
      {
        label: "删除", value: "remove", click: (scope) => {
          let index = scope.$index;
          proxy.$openMessageBox("此操作将永久删除, 是否继续?", () => {
            productData.value.splice(index, 1);
            productTableInfo.value.data = productData.value;
            proxy.$ElMessage.success('产品删除成功');
          }, () => {
            proxy.$ElMessage.info("已取消");
          });
        }
      },
    ]
  },
  loading: false
});

/** 给表格添加一行入参定义。 */
const addProduct = () => {
  productData.value.push({ dataProductId: '' });
  productTableInfo.value.data = productData.value;
  nextTick(() => {
    scrollLastRowToView(productTableRef.value?.tableRef, productData.value.length);
  })
}

/** 根据下拉选择的产品带出产品相关信息 */
const hanldeTableSelectChange = (val, scope, item) => {
  let productItem = val && productList.value.find(p => p.productId == val);
  scope.row.dataProductId = val;
  scope.row.dataProductCode = val;
  scope.row.dataProductName = productItem?.productName;
  scope.row.dataProductEntityId = productItem?.enterpriseCode;
  scope.row.dataProductAbstract = productItem?.description;
  scope.row.dataProductEntityName = productItem?.enterpriseName;
  let nodeInfo = nodeInfoFormRef.value.formInline;
  if (scope.$index == 0) {
    nodeInfoFormItems.value.forEach((item, index) => {
      item.default = nodeInfo[item.field];
      if (index == 1) {
        item.default = tenantList.value.find(t => t.socialCreditCode == scope.row.dataProductEntityId)?.guid || scope.row.dataProductEntityName;
      } else if (index == 2) {
        item.default = scope.row.dataProductEntityId || '';
      }
    })
  }
}

/** ---------------- 合约策略执行者相关表单信息  ----------------------------------- */

/** 策略执行者下拉列表 */
const tenantList: any = ref([]);

const nodeInfoFormRef = ref();

// 策略执行者类型列表
const executorTypeList: any = ref([]);

const nodeInfoFormItems = ref([{
  label: '策略执行者类型',
  type: 'input',
  placeholder: '-',
  field: 'dataProviderType',
  default: '',
  disabled: true,
  visible: true
}, {
  label: '策略执行者名称',
  type: 'select',
  placeholder: '请选择',
  field: 'dataProviderGuid',
  default: '',
  options: tenantList.value, //先禁用,选择产品后自动带出
  props: {
    value: 'guid',
    label: 'tenantName'
  },
  filterable: true,
  clearable: true,
  disabled: true,
  required: true,
  visible: true
}, {
  label: '策略执行者标识',
  type: 'input',
  placeholder: '-',
  field: 'dataProviderId',
  default: '',
  disabled: true,
  visible: true
}, {
  label: '策略执行者类型',
  type: 'input',
  placeholder: '-',
  field: 'dataUserType',
  default: '',
  disabled: true,
  visible: true
}, {
  label: '策略执行者名称',
  type: 'select',
  placeholder: '请选择',
  field: 'dataUserGuid',
  default: '',
  options: tenantList.value,
  props: {
    value: 'guid',
    label: 'tenantName'
  },
  filterable: true,
  clearable: true,
  required: true,
  visible: true
}, {
  label: '策略执行者标识',
  type: 'input',
  placeholder: '-',
  field: 'dataUserId',
  default: '',
  disabled: true,
  visible: true
}])

const nodeInfoFormRules = ref({
  // dataProviderGuid: [required('请选择数据供给方策略执行者名称')],
  dataUserGuid: [required('请选择数据使用方策略执行者名称')],
});

const handleNodeSelectChange = (val, row, info) => {
  if (row.field == 'dataUserGuid') {
    let tenantItem = tenantList.value.find(t => t.guid == val);
    info.dataUserId = tenantItem?.socialCreditCode || '';
    nodeInfoFormItems.value.forEach(item => {
      item.default = info[item.field];
    });
  }
}

const strategyTableRef = ref();

/** 约束运算符字典下拉 */
const operatorOptionList: any = ref([]);

/** 约束行为下拉列表 */
const constraintOptionsList: any = ref([]);

/** 策略操作行为下拉列表 */
const actionOptionsList: any = ref([]);

const getSubmitInfo = () => {
  let baseInfo = baseInfoFormRef.value.formInline;
  let nodeInfo = nodeInfoFormRef.value.formInline;
  let params = { ...baseInfo };
  params.contractExpansions = extendData.value;
  params.contractSubjects = productData.value;
  params.executionNodes = [{
    executionerTypeCode: executorTypeList.value[0]?.value,
    executionerGuid: nodeInfo.dataProviderGuid,
    executionerId: nodeInfo.dataProviderId,
    executionerName: tenantList.value.find(t => t.guid == nodeInfo.dataProviderGuid)?.tenantName
  }, {
    executionerTypeCode: executorTypeList.value[1]?.value,
    executionerGuid: nodeInfo.dataUserGuid,
    executionerId: nodeInfo.dataUserId,
    executionerName: tenantList.value.find(t => t.guid == nodeInfo.dataUserGuid)?.tenantName
  }];
  params.policys = strategyTableRef.value.strategyData?.map((d, index) => {
    return Object.assign({}, d, { orderNum: index + 1 })
  }) || [];
  return params;
}

const saveDraft = () => {
  if (isDataUse.value) {
    proxy.$ElMessage.error('数据使用方不能新建合约');
    return;
  }
  let params: any = getSubmitInfo();
  params.isResubmit = false;
  fullscreenLoading.value = true;
  if (!route.query.guid) {
    saveContract(params).then((res: any) => {
      fullscreenLoading.value = false;
      if (res?.code == proxy.$passCode) {
        proxy.$ElMessage.success('合约保存成功');
        userStore.setTabbar(userStore.tabbar.filter((tab: any) => tab.fullPath !== fullPath));
        router.push({
          name: "smartContractManagement",
        });
        dataSmartContract.set(true);
      } else {
        res?.msg && proxy.$ElMessage.error(res?.msg)
      }
    })
  } else {
    params.guid = route.query.guid;
    params.isResubmit = false;
    updateContract(params).then((res: any) => {
      fullscreenLoading.value = false;
      if (res?.code == proxy.$passCode) {
        proxy.$ElMessage.success('合约编辑保存成功');
        userStore.setTabbar(userStore.tabbar.filter((tab: any) => tab.fullPath !== fullPath));
        router.push({
          name: "smartContractManagement",
        });
        dataSmartContract.set(true);
      } else {
        res?.msg && proxy.$ElMessage.error(res?.msg)
      }
    })
  }
}

const submit = () => {
  if (isDataUse.value) {
    proxy.$ElMessage.error('数据使用方不能新建合约');
    return;
  }
  baseInfoFormRef.value.ruleFormRef?.validate((valid, errorItem) => {
    if (valid) {
      for (const data of extendData.value) {
        if (!data.expansionFieldName) {
          proxy.$ElMessage.error('扩展信息中的扩展字段名称不能为空');
          handleLeft('base-info');
          expandBase.value = true;
          return;
        }
        if (!data.fieldType) {
          proxy.$ElMessage.error('扩展信息中的字段类型不能为空');
          handleLeft('base-info');
          expandBase.value = true;
          return;
        }
      }
      if (!productData.value?.length) {
        proxy.$ElMessage.error('合约标的的数据产品不能为空');
        expandInfo.value = true;
        handleLeft('product-info');
        return;
      }
      let index = 0;
      for (const pd of productData.value) {
        if (!pd.dataProductId) {
          proxy.$ElMessage.error('合约标的的数据产品不能为空');
          expandInfo.value = true;
          handleLeft('product-info');
          return;
        }
        if (userData.superTubeFlag == 'Y') { //只有主平台模式下需判断
          if (baseInfoFormRef.value.formInline.signModeCode == '02' && index > 0 && productData.value[index].dataProductEntityId != pd.dataProductEntityId) {
            proxy.$ElMessage.error('合约标的的数据产品不能来自不同的企业主体');
            expandInfo.value = true;
            handleLeft('product-info');
            return;
          } else {
            if (pd.dataProductEntityId != nodeInfoFormRef.value?.formInline?.dataProviderId) {
              proxy.$ElMessage.error('合约标的的数据产品所属主体与数据提供方的策略执行者不一致,请检查!');
              expandInfo.value = true;
              handleLeft('product-info');
              return;
            }
          }
        }
        index++;
      }
      nodeInfoFormRef.value.ruleFormRef?.validate((valid1, errorItem1) => {
        if (valid1) {
          let nodeInfo = nodeInfoFormRef.value.formInline;
          if (nodeInfo.dataProviderGuid == nodeInfo.dataUserGuid) {
            proxy.$ElMessage.error(`${executorTypeList.value[0].label}${executorTypeList.value[1].label}的策略执行者不能选择同一个`);
            expandPolicy.value = true;
            handleLeft('policy-info');
            return;
          }
          if (!strategyTableRef.value.validateValue()) {
            expandPolicy.value = true;
            handleLeft('policy-info');
            return;
          }
          let params: any = getSubmitInfo();
          params.isResubmit = detailInfo.value?.contractStatus == '00';
          params.contractStatus = '02';
          fullscreenLoading.value = true;
          if (!route.query.guid) {
            saveContract(params).then((res: any) => {
              fullscreenLoading.value = false;
              if (res?.code == proxy.$passCode) {
                proxy.$ElMessage.success('合约协商成功');
                userStore.setTabbar(userStore.tabbar.filter((tab: any) => tab.fullPath !== fullPath));
                router.push({
                  name: "smartContractManagement",
                });
                dataSmartContract.set(true);
              } else {
                res?.msg && proxy.$ElMessage.error(res?.msg)
              }
            })
          } else {
            params.guid = route.query.guid;
            updateContract(params).then((res: any) => {
              fullscreenLoading.value = false;
              if (res?.code == proxy.$passCode) {
                proxy.$ElMessage.success('合约协商成功');
                userStore.setTabbar(userStore.tabbar.filter((tab: any) => tab.fullPath !== fullPath));
                router.push({
                  name: "smartContractManagement",
                });
                dataSmartContract.set(true);
              } else {
                res?.msg && proxy.$ElMessage.error(res?.msg)
              }
            })
          }
        } else {
          expandPolicy.value = true;
          var obj = Object.keys(errorItem1);
          nodeInfoFormRef.value.ruleFormRef?.scrollToField(obj[0]);
        }
      })
    } else {
      expandBase.value = true;
      var obj = Object.keys(errorItem);
      baseInfoFormRef.value.ruleFormRef?.scrollToField(obj[0]);
      nodeInfoFormRef.value.validate();
    }
  });
}

const handleLeft = (id) => {
  let dom = document.getElementById(id);
  dom && dom.scrollIntoView({
    behavior: "smooth", // 平滑过渡
    block: "start", // 上边框与视窗顶部平齐。默认值
  });
}

const cancel = () => {
  proxy.$openMessageBox("当前页面尚未保存,确定放弃修改吗?", () => {
    userStore.setTabbar(userStore.tabbar.filter((tab: any) => tab.fullPath !== fullPath));
    router.push({
      name: "smartContractManagement",
    });
  }, () => {
    proxy.$ElMessage.info("已取消");
  });
}

const detailInfo: any = ref({});

/** 当前会员是否认证信息 */
const currTenantDetailInfo: any = ref({});

const psLogon = ref();

onBeforeMount(() => {
  let exec = () => {
    let userRole = localStorage.getItem('userRole');
    if (userRole == USERROLE.PROVIDER) {
      baseInfoFormItems.value[1].disabled = true;
      baseInfoFormItems.value[1].default = '01';
      productTableInfo.value.editInfo.dataProductId.props.label = 'productName';
    } else { //可以选点对点。未认证时只能选择中介参与
      baseInfoFormItems.value[1].disabled = !currTenantDetailInfo.value.trustedIdentityCredential;
      baseInfoFormItems.value[1].default = !currTenantDetailInfo.value.trustedIdentityCredential ? '02' : '01';
      productTableInfo.value.editInfo.dataProductId.props.label = 'productNameDesc';
    }
    if (route.query.guid) {
      fullscreenLoading.value = true;
      getContractDetail(route.query.guid).then((res: any) => {
        fullscreenLoading.value = false;
        if (res?.code == proxy.$passCode) {
          detailInfo.value = res.data || {};
          baseInfoFormItems.value.forEach(item => {
            item.default = detailInfo.value[item.field];
          });
          // if (baseInfoFormItems.value[1].default == '01') {
          //   // 默认点对点,数据使用方可以选择
          //   nodeInfoFormItems.value[1].disabled = true;
          // } else {
          //   nodeInfoFormItems.value[1].disabled = false;
          // }
          // nodeInfoFormItems.value[1].disabled = detailInfo.value.signModeCode == '01';
          let executionNodes = detailInfo.value.executionNodes || [];
          let provider = executionNodes.find(e => e.executionerTypeCode == '01');
          let user = executionNodes.find(e => e.executionerTypeCode == '02');
          nodeInfoFormItems.value[1].default = provider.executionerGuid;
          nodeInfoFormItems.value[2].default = provider.executionerId;
          nodeInfoFormItems.value[4].default = user.executionerGuid;
          nodeInfoFormItems.value[5].default = user.executionerId;
          if (baseInfoFormItems.value[1].default == '01' && userData.superTubeFlag == 'Y') {
            productList.value = res.data?.map(d => {
              d.disabled = d.enterpriseName != userData.tenantName; //点对点,只能选择自己公司所属产品
              return d;
            }) || [];
          }
          productTableInfo.value.editInfo.dataProductId.options = productList.value;
          extendData.value = detailInfo.value.contractExpansions || [];
          extendTableInfo.value.data = extendData.value;
          productData.value = detailInfo.value.contractSubjects || [];
          productTableInfo.value.data = productData.value;
        } else {
          res?.msg && proxy.$ElMessage.error(res?.msg)
        }
      })
    } else {
      if (baseInfoFormItems.value[1].default == '01') {
        // 默认点对点,数据使用方可以选择
        //  nodeInfoFormItems.value[1].disabled = true;
        nodeInfoFormItems.value[1].default = userData.tenantGuid;
        if (tenantList.value.length) {
          let item = tenantList.value.find(t => t.guid == userData.tenantGuid);
          nodeInfoFormItems.value[2].default = item?.socialCreditCode;
        }
      } else {
        // nodeInfoFormItems.value[1].disabled = false;
        nodeInfoFormItems.value[1].default = ''; //如果是中介的话,不能选择自己吧。
      }
    }
    getContractDataProduct().then((res: any) => {
      if (res?.code == proxy.$passCode) {
        productList.value = res.data?.map(d => {
          d.productNameDesc = d.productName + '(' + d.enterpriseName + ')';
          d.disabled = userData.superTubeFlag == 'Y' && baseInfoFormItems.value[1].default == '01' && d.enterpriseName != userData.tenantName; //点对点,只能选择自己公司所属产品
          return d;
        }) || [];
        productTableInfo.value.editInfo.dataProductId.options = productList.value;
      } else {
        res?.msg && proxy.$ElMessage.error(res?.msg);
      }
    })
  }
  fullscreenLoading.value = true;
  psLogon.value = getEnterpriseData({
    logonUser: userData.tenantName == "非认证会员" ? userData.logonUser : tenantData.logonUser
  }).then((res: any) => {
    psLogon.value = null;
    fullscreenLoading.value = false;
    if (res?.code == proxy.$passCode) {
      currTenantDetailInfo.value = res.data || {};
      exec();
    } else {
      res?.msg && proxy.$ElMessage.error(res?.msg);
      exec();
    }
  }).catch(() => {
    psLogon.value = null;
    fullscreenLoading.value = false;
    exec();
  });
  getParamsList({ dictType: '合约签署模式' }).then((res: any) => {
    if (res?.code == proxy.$passCode) {
      const data = res.data || [];
      signModeList.value = data;
      baseInfoFormItems.value[1].options = signModeList.value;
    } else {
      res?.msg && proxy.$ElMessage.error(res?.msg);
    }
  })
  getParamsList({ dictType: '合约扩展字段类型' }).then((res: any) => {
    if (res?.code == proxy.$passCode) {
      const data = res.data || [];
      dataTypeList.value = data;
      extendTableInfo.value.editInfo.fieldType.options = dataTypeList.value;
    } else {
      res?.msg && proxy.$ElMessage.error(res?.msg);
    }
  })
  getParamsList({ dictType: '约束运算符' }).then((res: any) => {
    if (res?.code == proxy.$passCode) {
      const data = res.data || [];
      operatorOptionList.value = data;
    } else {
      res?.msg && proxy.$ElMessage.error(res?.msg);
    }
  })
  getActionPolicyList().then((res: any) => {
    if (res?.code == proxy.$passCode) {
      const data = res.data || [];
      actionOptionsList.value = data;
    } else {
      res?.msg && proxy.$ElMessage.error(res?.msg);
    }
  })
  getConstraintPolicyList().then((res: any) => {
    if (res?.code == proxy.$passCode) {
      const data = res.data || [];
      constraintOptionsList.value = data;
    } else {
      res?.msg && proxy.$ElMessage.error(res?.msg);
    }
  })
  getParamsList({ dictType: '策略执行者类型' }).then((res: any) => {
    if (res?.code == proxy.$passCode) {
      const data = res.data || [];
      executorTypeList.value = data;
      nodeInfoFormItems.value[0].default = executorTypeList.value[0]?.label;
      nodeInfoFormItems.value[3].default = executorTypeList.value[1]?.label;
    } else {
      res?.msg && proxy.$ElMessage.error(res?.msg);
    }
  })
  getContractTenantList().then((res: any) => {
    if (res.code == proxy.$passCode) {
      tenantList.value = res.data || [];
      nodeInfoFormItems.value[1].options = tenantList.value;
      nodeInfoFormItems.value[4].options = tenantList.value;
      if (nodeInfoFormItems.value[1].default) {
        let item = tenantList.value.find(t => t.guid == nodeInfoFormItems.value[1].default);
        nodeInfoFormItems.value[2].default = item?.socialCreditCode;
      }
    } else {
      res?.msg && proxy.$ElMessage.error(res.msg);
    }
  })
});

onActivated(() => {
  if (route.query.guid) {
    let tab: any = userStore.tabbar.find((tab: any) => tab.fullPath === fullPath);
    if (tab) {
      document.title = `编辑合约-${route.query.name}`;
      tab.meta.title = `编辑合约-${route.query.name}`;
    }
  }
})

</script>

<template>
  <div class="container_wrap full" v-loading="fullscreenLoading">
    <div class="content_main panel">
      <ContentWrap id="base-info" title="合约信息" expandSwicth style="margin-top: 15px" :isExpand="expandBase"
        @expand="(v) => (expandBase = v)" description="">
        <Form ref="baseInfoFormRef" formId="base-info-form" :itemList="baseInfoFormItems" :rules="baseInfoFormRules"
          col="col3" @select-change="handleFormSelectChange" />
        <Table ref="extendTableRef" :tableInfo="extendTableInfo" class="fiveRow-table" />
        <div class="row-add-btn">
          <el-button link @click="addExtend" :icon="CirclePlus" v-preReClick>添加扩展信息</el-button>
        </div>
      </ContentWrap>
      <ContentWrap id="product-info" title="合约标的" expandSwicth style="margin-top: 15px" :isExpand="expandInfo"
        @expand="(v) => (expandInfo = v)" description="">
        <Table ref="productTableRef" :tableInfo="productTableInfo" @table-select-change="hanldeTableSelectChange" />
        <!-- <div class="row-add-btn">
          <el-button link @click="addProduct" :icon="CirclePlus" v-preReClick>添加产品</el-button>
        </div> -->
      </ContentWrap>
      <ContentWrap id="policy-info" title="合约策略" expandSwicth style="margin-top: 15px" :isExpand="expandPolicy"
        @expand="(v) => (expandPolicy = v)" description="">
        <div class="h-title">策略执行节点</div>
        <Form ref="nodeInfoFormRef" formId="node-info-form" :itemList="nodeInfoFormItems" :rules="nodeInfoFormRules"
          @select-change="handleNodeSelectChange" col="col3" />
        <StrategyTable ref="strategyTableRef" :show-title="true" :value="detailInfo.policys || []"
          :operatorOptionList="operatorOptionList" :actionOptionsList="actionOptionsList" :productFieldList="[]"
          :constraintOptionsList="constraintOptionsList"></StrategyTable>
      </ContentWrap>
    </div>
    <div class="tool_btns">
      <div class="btns">
        <el-button @click="cancel">取消</el-button>
        <el-button @click="saveDraft" v-show="detailInfo?.contractStatus != '00'">保存</el-button>
        <el-button type="primary" @click="submit">合约协商</el-button>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.container_wrap {
  overflow: hidden;

  .content_main {
    height: calc(100% - 45px);
    overflow: hidden auto;

    &.panel {
      padding: 0 16px 16px;
    }
  }
}

.tool_btns {
  height: 44px;
  margin: 0 -8px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-top: 1px solid #d9d9d9;
}

.row-add-btn {
  .el-button--default {
    padding: 4px 0px;
    margin-top: 4px;
  }

  :deep(.el-icon) {
    width: 16px;
    height: 16px;

    svg {
      width: 16px;
      height: 16px;
    }
  }
}

.h-title {
  font-size: 14px;
  color: #212121;
  font-weight: 600;
  margin-bottom: 4px;
}
</style>