<template>
  <div class="compare-view-wrap">
    <compareBasicSection
      sectionTitle="基础信息"
      headerLabel="查看表单脚本"
      :objType="objType"
      :objCode="objCode"
      :compareHData1="compareHData1"
      :compareHData2="compareHData2"
      :preVersion="preVersion"
      :curVersion="curVersion"
      :fields="basicFields"
      @reverCallback="$emit('reverCallback')"
    />
    <compareCodeSection
      sectionTitle="脚本"
      :preVersion="preVersion"
      :curVersion="curVersion"
      :leftCode="compareHData1.script || ''"
      :rightCode="compareHData2.script || ''"
      mode="java"
      enableDiff
    />
  </div>
</template>

<script>
import compareMixin from "./compareMixin";
import compareBasicSection from "./compareBasicSection.vue";
import compareCodeSection from "./compareCodeSection.vue";

export default {
  name: "formScriptCompareView",
  mixins: [compareMixin],
  components: {
    compareBasicSection,
    compareCodeSection,
  },
  computed: {
    isFormScriptType1() {
      return this.compareHData1?.scriptType === 1 || this.compareHData2?.scriptType === 1;
    },
    basicFields() {
      const commonFields = [
        { key: "scriptName", label: "脚本名称" },
        { key: "scriptCode", label: "脚本编码" },
      ];
      const type1Fields = this.isFormScriptType1
        ? [
            { key: "menuKindName", label: "表单分类" },
            {
              key: "formCode",
              label: "表单模板编码",
              formatter: (val) => this.formatFormCode(val),
            },
            {
              key: "urlPath",
              label: "Url路径",
              formatter: (val, data) => this.formatScriptUrlPath(val, data),
            },
          ]
        : [];
      return [
        ...commonFields,
        ...type1Fields,
        {
          key: "enabled",
          label: "是否启用",
          formatter: (val) => this.formatBool(val, "启用", "禁用"),
        },
        {
          key: "transactions",
          label: "开启事务",
          formatter: (val) => this.formatBool(val),
        },
        ...(this.isFormScriptType1
          ? [
              { key: "serviceName", label: "服务名" },
              { key: "uri", label: "自定义URL" },
              {
                key: "formScriptTagDTOs",
                label: "项目标签",
                formatter: (val) => this.formatTags(val),
              },
            ]
          : []),
        { key: "scriptRemark", label: "脚本说明" },
        { key: "sid", label: "唯一标识" },
        ...this.auditFields(),
      ];
    },
  },
};
</script>
