<template>
  <div class="detail-wrap">
    <el-form ref="editForm" :model="formTemplate">
      <div class="d-header clearfix">
        <div class="fl">
          <i class="el-icon-info" />
          {{ dataId ? $t1("查看表单模板") : $t1("新增表单模板") }}
        </div>
        <div class="fr">
          <formVersionButton
            v-if="!hData && formTemplate.id && !readonly"
            objType="FormTemplate"
            :objCode="formTemplate.formCode"
            @reverCallback="$baseReload()"
          ></formVersionButton>
          <reverButton
            v-if="!!hData"
            objType="FormTemplate"
            :objCode="formTemplate.formCode"
            :hData="hData"
            @reverCallback="$emit('reverCallback')"
          ></reverButton>
          <el-button
            type="primary"
            plain
            class="button-sty"
            icon="el-icon-set-up"
            @click="openOtherAuthDialog"
            v-if="
              isDev && !!dataId && menuKindAuth.editAuth === 1 && !readonly && !otherFlag
            "
          >
            {{ $t1("分派") }}
          </el-button>
          <el-button
            type="success"
            class="button-sty"
            @click="openDesignDialog"
            icon="iconfont icon-liuchengguanli-shejiqi_liucheng"
            v-if="!!dataId"
            >{{ $t1("表单设计") }}
          </el-button>
          <el-button
            type="primary"
            plain
            class="button-sty"
            @click="$baseReload()"
            icon="el-icon-refresh-right"
          >
            {{ $t1("重置") }}
          </el-button>
          <el-button
            type="primary"
            class="button-sty"
            icon="el-icon-check"
            @click="saveData"
            v-if="!readonly && isDev && menuKindAuth.editAuth === 1"
          >
            {{ $t1("保存") }}
          </el-button>
        </div>
      </div>
      <baseTabs>
        <baseTabPane :label="$t1('基本信息')">
          <template #default>
            <table class="table-detail">
              <tbody>
                <tr>
                  <th>
                    <em class="f-red">*</em>
                    {{ $t1("模板名称") }}
                  </th>
                  <td colspan="3">
                    <el-form-item
                      prop="formName"
                      :rules="[{ required: true, trigger: 'blur' }]"
                    >
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormTemplate.formName"
                        :newVal="formTemplate.formName"
                      >
                        <el-input
                          type="text"
                          autocomplete="off"
                          v-model="formTemplate.formName"
                          clearable
                        />
                      </fieldCompare>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <th>{{ $t1("模板编码") }}</th>
                  <td colspan="3">
                    <el-form-item
                      prop="formCode"
                      :rules="[{ required: true, trigger: 'blur' }]"
                      v-if="!formTemplate.id"
                    >
                      <el-input
                        type="text"
                        autocomplete="off"
                        v-model="formTemplate.formCode"
                        clearable
                      />
                    </el-form-item>
                    <template v-else>
                      {{ formTemplate.formCode }}
                    </template>
                  </td>
                </tr>
                <tr>
                  <th>{{ $t1("是否启用") }}</th>
                  <td>
                    <el-form-item
                      prop="enabled"
                      :rules="[{ required: false, trigger: 'blur' }]"
                    >
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormTemplate.enabled"
                        :newVal="formTemplate.enabled"
                      >
                        <el-radio-group v-model="formTemplate.enabled">
                          <el-radio :label="true">{{ $t1("启用") }}</el-radio>
                          <el-radio :label="false">{{ $t1("禁用") }}</el-radio>
                        </el-radio-group>
                      </fieldCompare>
                    </el-form-item>
                  </td>
                  <th>{{ $t1("启用流程") }}</th>
                  <td>
                    <el-form-item>
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormTemplate.hasWf"
                        :newVal="formTemplate.hasWf"
                      >
                        {{ formTemplate.hasWf ? $t1("是") : $t1("否") }}
                      </fieldCompare>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <th>
                    <em class="f-red">*</em>
                    {{ $t1("表单分类") }}
                  </th>
                  <td colspan="5">
                    <el-form-item
                      prop="menuKindName"
                      :rules="[{ required: true, trigger: ['blur', 'change'] }]"
                    >
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormTemplate.menuKindName"
                        :newVal="formTemplate.menuKindName"
                      >
                        <el-input
                          class="search-input"
                          max="200"
                          v-model="formTemplate.menuKindName"
                          @clear="
                            formTemplate.menuKindCode = '';
                            $forceUpdate();
                          "
                          v-el-readonly
                          clearable
                          :disabled="otherFlag"
                        >
                          <i
                            slot="suffix"
                            class="el-input__icon el-icon-search"
                            @click="showMenuKindDialog = true"
                          ></i>
                        </el-input>
                      </fieldCompare>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <th>{{ $t1("备注") }}</th>
                  <td colspan="5">
                    <el-form-item>
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormTemplate.remark"
                        :newVal="formTemplate.remark"
                      >
                        <el-input
                          type="textarea"
                          :rows="2"
                          :placeholder="$t1('请输入内容')"
                          size="small"
                          v-model="formTemplate.remark"
                          clearable
                        ></el-input>
                      </fieldCompare>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <th>
                    {{ $t1("项目标签") }}
                  </th>
                  <td colspan="7">
                    <projectTagView
                      v-model="formTemplate.formTemplateTagDTOs"
                    ></projectTagView>
                  </td>
                </tr>
                <tr>
                  <th>{{ $t1("版本号") }}</th>
                  <td>{{ formTemplate.version }}</td>
                  <th>{{ $t1("服务名") }}</th>
                  <td>{{ formTemplate.serviceName }}</td>
                  <th>
                    {{ $t1("唯一标识") }}
                  </th>
                  <td colspan="3">
                    {{ formTemplate.sid }}
                  </td>
                </tr>
                <tr v-if="!!hData">
                  <th>{{ $t1("表单模板JSON") }}</th>
                  <td colspan="7">
                    <el-form-item>
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormTemplate.formViewContent"
                        :newVal="formTemplate.formViewContent"
                      >
                        <el-input
                          type="textarea"
                          :rows="12"
                          :placeholder="$t1('请输入内容')"
                          size="small"
                          v-model="formTemplate.formViewContent"
                          :disabled="true"
                        ></el-input>
                      </fieldCompare>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <th>{{ $t1("创建人") }}</th>
                  <td>{{ formTemplate.createBy }}</td>
                  <th>{{ $t1("创建时间") }}</th>
                  <td>{{ formTemplate.createDate }}</td>
                  <th>{{ $t1("更新人") }}</th>
                  <td>{{ formTemplate.modifyBy }}</td>
                  <th>{{ $t1("更新时间") }}</th>
                  <td>{{ formTemplate.modifyDate }}</td>
                </tr>
                <tr>
                  <th>
                    <span class="tips">{{ $t1("URL说明") }}</span>
                  </th>
                  <td colspan="7">
                    <span class="fl tips">
                      <div>{{ $t1("一、表单模板嵌入第三方系统URL配置") }}</div>
                      <div style="padding-left: 20px">
                        <p>
                          {{
                            $t1(
                              "1、列表URL:   /#/form_outLinkView?url=/user/form/view/list&formCode=xx&tp=&i18nLang=&access_token=xx"
                            )
                          }}
                        </p>
                        <p>
                          {{
                            $t1(
                              "2、详情URL:   /#/form_outLinkView?url=/user/form/view/edit&formCode=xx&dataId=1&tp=&i18nLang=&access_token=xx"
                            )
                          }}
                        </p>
                      </div>
                      <div>{{ $t1("二、表单模板嵌入本地系统菜单URL配置") }}</div>
                      <div style="padding-left: 20px">
                        <p>
                          {{
                            $t1(
                              "1、菜单URL:   /user/form/view/list/xxx；xx为表单模板编码；菜单类型：动态表单"
                            )
                          }}
                        </p>
                      </div>
                      <div>{{ $t1("三、参数说明") }}</div>
                      <div style="padding-left: 20px">
                        <p>
                          {{
                            $t1(
                              "1、url:详情页面固定为/user/form/view/edit，列表页面固定为/user/form/view/list；"
                            )
                          }}
                        </p>
                        <p>{{ $t1("2、formCode:表单编码；") }}</p>
                        <p>{{ $t1("3、dataId：单据ID,详情页面才需要传；") }}</p>
                        <p>{{ $t1("4、i18nLang：国际化编码，不传默认中文；") }}</p>
                        <p>{{ $t1("5、tp:第三方登录秘钥；") }}</p>
                        <p>{{ $t1("6、access_token：用户信息token；") }}</p>
                        <p>{{ $t1("7、tp与access_token只需要传其中一个即可；") }}</p>
                      </div>
                    </span>
                  </td>
                </tr>
              </tbody>
            </table>
          </template>
        </baseTabPane>
        <baseTabPane :label="$t1('操作日志')">
          <template #default>
            <formOplogTable :parent-target="_self" ref="oplogTable"></formOplogTable>
          </template>
        </baseTabPane>
      </baseTabs>
    </el-form>
    <MenuKindDialog
      v-if="showMenuKindDialog"
      :visiable.sync="showMenuKindDialog"
      :serviceName="formTemplate.serviceName"
      @confirm="confirmInsertMenuKind"
      :param="{ taType: 0 }"
      :multi="false"
    />
    <preformDialog
      v-if="showPreformDialog"
      :visiable.sync="showPreformDialog"
      @confirm="confirmPreformDialog"
    ></preformDialog>
    <otherAuthDialog
      v-if="showOtherAuthDialog"
      :visiable.sync="showOtherAuthDialog"
      :sid="sid"
      @confirm="confirmOtherAuthDialog"
    ></otherAuthDialog>
  </div>
</template>

<script>
import mixin from "./mixins/edit";
import formVersionButton from "@base/views/bd/setting/formVersion/button.vue";
import reverButton from "@base/views/bd/setting/formVersion/reverButton.vue";
import fieldCompare from "@base/views/bd/setting/formVersion/fieldCompare.vue";
export default {
  name: "bd_form_templateEdit",
  mixins: [mixin],
  components: {
    formVersionButton,
    reverButton,
    fieldCompare,
  },
};
</script>
