<template>
  <div class="detail-wrap">
    <el-form ref="editForm" :model="formScript">
      <div class="d-header clearfix">
        <div class="fl">
          <i class="el-icon-info" />
          {{ dataId ? $t1("查看表单脚本") : $t1("新增表单脚本") }}
        </div>
        <div class="fr">
          <formVersionButton
            v-if="!hData && formScript.id && !readonly"
            objType="FormScript"
            :objCode="formScript.scriptCode"
            :relationCode="formScript.formCode"
            @reverCallback="$baseReload()"
          ></formVersionButton>
          <reverButton
            v-if="!!hData"
            objType="FormScript"
            :objCode="formScript.scriptCode"
            :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 &&
              !formTemplate
            "
          >
            {{ $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="isDev && menuKindAuth.editAuth === 1 && !readonly"
            >{{ $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>
                    <el-form-item
                      prop="scriptName"
                      :rules="[{ required: true, trigger: 'blur' }]"
                    >
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormScript.scriptName"
                        :newVal="formScript.scriptName"
                      >
                        <el-input
                          type="text"
                          autocomplete="off"
                          v-model="formScript.scriptName"
                          clearable
                        />
                      </fieldCompare>
                    </el-form-item>
                  </td>
                  <th>{{ $t1("脚本编码") }}</th>
                  <td colspan="3">
                    <el-form-item
                      prop="scriptCode"
                      :rules="[{ required: true, trigger: 'blur' }]"
                    >
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormScript.scriptCode"
                        :newVal="formScript.scriptCode"
                      >
                        <el-input
                          type="text"
                          autocomplete="off"
                          v-model="formScript.scriptCode"
                          clearable
                        />
                      </fieldCompare>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <th>
                    <em class="f-red">*</em>
                    {{ $t1("表单分类") }}
                  </th>
                  <td colspan="5">
                    <el-form-item
                      v-if="
                        formScript.formCode === 'intf' ||
                        formScript.formCode === 'busgeneral'
                      "
                      prop="menuKindName"
                      :rules="[{ required: true, trigger: ['blur', 'change'] }]"
                    >
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormScript.menuKindName"
                        :newVal="formScript.menuKindName"
                      >
                        <el-input
                          class="search-input"
                          max="200"
                          v-model="formScript.menuKindName"
                          @clear="
                            formScript.menuKindCode = null;
                            $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>
                    <template v-else>
                      <el-form-item>
                        <fieldCompare
                          :isCompare="isCompare"
                          :oldVal="oldFormScript.menuKindName"
                          :newVal="formScript.menuKindName"
                        >
                          {{ formScript.menuKindName }}
                        </fieldCompare>
                      </el-form-item>
                    </template>
                  </td>
                </tr>

                <tr>
                  <th>{{ $t1("表单模板编码") }}</th>
                  <td colspan="3">
                    <template v-if="!dataId && !formTemplate">
                      <el-radio-group v-model="formScript.formCode">
                        <el-radio label="intf">intf(接口)</el-radio>
                        <el-radio label="busgeneral">busgeneral(业务通用)</el-radio>
                      </el-radio-group>
                    </template>
                    <template v-else>
                      <span v-if="formScript.formCode === 'intf'">intf(接口)</span>
                      <span v-else-if="formScript.formCode === 'busgeneral'"
                        >busgeneral(业务通用)</span
                      >
                      <span v-else>{{ formScript.formCode }}</span>
                    </template>
                  </td>
                  <th>{{ $t1("Url路径") }}</th>
                  <td colspan="3">
                    <el-form-item>
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormScript.formCode + '/' + oldFormScript.scriptCode"
                        :newVal="formScript.formCode + '/' + formScript.scriptCode"
                      >
                        {{ formScript.formCode }}/{{ formScript.scriptCode }}
                      </fieldCompare>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <th>{{ $t1("是否启用") }}</th>
                  <td>
                    <el-form-item
                      prop="enabled"
                      :rules="[{ required: false, trigger: 'blur' }]"
                    >
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormScript.enabled"
                        :newVal="formScript.enabled"
                      >
                        <el-radio-group v-model="formScript.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="oldFormScript.transactions"
                        :newVal="formScript.transactions"
                      >
                        <el-radio-group v-model="formScript.transactions">
                          <el-radio :label="1">{{ $t1("是") }}</el-radio>
                          <el-radio :label="0">{{ $t1("否") }}</el-radio>
                        </el-radio-group>
                      </fieldCompare>
                    </el-form-item>
                  </td>
                  <th>{{ $t1("服务名") }}</th>
                  <td colspan="3">
                    <el-form-item>
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormScript.serviceName"
                        :newVal="formScript.serviceName"
                      >
                        {{ formScript.serviceName }}
                      </fieldCompare>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <th>{{ $t1("自定义URL") }}</th>
                  <td colspan="7">
                    <el-form-item
                      prop="uri"
                      :rules="[{ required: false, trigger: 'blur' }]"
                    >
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormScript.uri"
                        :newVal="formScript.uri"
                      >
                        <el-input
                          type="text"
                          autocomplete="off"
                          v-model="formScript.uri"
                          clearable
                        />
                      </fieldCompare>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <th class="no"></th>
                  <td colspan="7">
                    <span class="fl tips">
                      <div>{{ $t1("注") }}：</div>
                      <div style="padding-left: 20px">
                        <p>
                          {{
                            $t1(
                              '1.不配置"自定义URL"，默认的请求地址为：http://域名/服务前缀/bd_api/表单编码/脚本编码。'
                            )
                          }}
                        </p>
                        <p>
                          {{ $t1('2.需要特殊配置URL，"自定义URL"必须以/a_api开头。') }}
                        </p>
                        <p>
                          {{ $t1('3.第三方接口调用(DW)，"自定义URL"必须/d_api开头。') }}
                        </p>
                      </div>
                    </span>
                  </td>
                </tr>
                <tr>
                  <th>
                    {{ $t1("项目标签") }}
                  </th>
                  <td colspan="7">
                    <projectTagView
                      v-model="formScript.formScriptTagDTOs"
                    ></projectTagView>
                  </td>
                </tr>
                <tr>
                  <th>{{ $t1("脚本说明") }}</th>
                  <td colspan="7">
                    <el-form-item
                      prop="scriptRemark"
                      :rules="[{ required: false, trigger: 'blur' }]"
                    >
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormScript.scriptRemark"
                        :newVal="formScript.scriptRemark"
                      >
                        <el-input
                          type="textarea"
                          :rows="2"
                          :placeholder="$t1('请输入内容')"
                          size="small"
                          v-model="formScript.scriptRemark"
                          clearable
                        ></el-input>
                      </fieldCompare>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <th>
                    <em class="f-red">*</em>
                    {{ $t1("脚本") }}
                    <!--                <scriptDescriptionButton path="static/readme/ApiRequest.txt"></scriptDescriptionButton>-->
                    <scriptTestButton :script.sync="formScript.script"></scriptTestButton>
                  </th>
                  <td colspan="7">
                    <el-form-item
                      prop="script"
                      :rules="[{ required: true, trigger: 'blur' }]"
                    >
                      <fieldCompare
                        :isCompare="isCompare"
                        :oldVal="oldFormScript.script"
                        :newVal="formScript.script"
                      >
                        <code-editor
                          mode="java"
                          :readonly="!1"
                          v-model="formScript.script"
                          v-if="showCodeEditor"
                        ></code-editor>
                      </fieldCompare>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <th>{{ $t1("版本号") }}</th>
                  <td>{{ formScript.version }}</td>
                  <th>{{ $t1("唯一标识") }}</th>
                  <td colspan="5">{{ formScript.sid }}</td>
                </tr>
                <tr>
                  <th>{{ $t1("创建人") }}</th>
                  <td>{{ formScript.createBy }}</td>
                  <th>{{ $t1("创建时间") }}</th>
                  <td>{{ formScript.createDate }}</td>
                  <th>{{ $t1("更新人") }}</th>
                  <td>{{ formScript.modifyBy }}</td>
                  <th>{{ $t1("更新时间") }}</th>
                  <td>{{ formScript.modifyDate }}</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="formScript.serviceName"
      @confirm="confirmInsertMenuKind"
      :param="{ taType: 0 }"
      :multi="false"
    />
    <preformDialog
      v-if="showPreformDialog"
      :visiable.sync="showPreformDialog"
      :formScript="formScript"
      @confirm="confirmPreformDialog"
    ></preformDialog>
    <otherAuthDialog
      v-if="showOtherAuthDialog"
      :visiable.sync="showOtherAuthDialog"
      :sid="sid"
      @confirm="confirmOtherAuthDialog"
    ></otherAuthDialog>
  </div>
</template>

<script>
import mixin from "./mixins/edit1";
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: "user_form_scriptEdit",
  mixins: [mixin],
  components: {
    formVersionButton,
    reverButton,
    fieldCompare,
  },
};
</script>
