<template>
  <audit-form-top-banner :form-data="mode">
    <sd-detail-form
      ref="docform"
      form-id="iamFinDataTransformLog"
      page-id="dm/datatransLog/iamFinDataTransformLog"
      :record-id="this.$route.query.record ? parseInt(this.$route.query.record) : null"
      :class="$style.form"
      :read-only="true"
      @close="close(true)"
      @sdFormReady="sdFormReady"
    >
      <template v-slot="{ model, fields }">
        <table>
          <tr>
            <td style="padding-left:5px;border:none">
              <audit-advanced-group
                :expand="basicExpand"
                :expand-str="'basicExpand'"
                :group-label="'基本信息'"
                tablestyle="''"
                @changedClick="changedClick"
              ></audit-advanced-group>
            </td>
          </tr>
        </table>

        <table v-show="basicExpand">
          <tr>
            <!-- 任务编号 -->
            <sd-form-item-td name="taskId" />
            <sd-form-item-td name="ftpFileName" />
          </tr>

          <tr>
            <!-- 最后采集的XX平台单位编码 -->
            <sd-form-item-td name="lastUnitCode" label="XX单位编码" />
            <!-- 任务执行状态 -->
            <sd-form-item-td name="taskStatus" label="任务执行状态" />
          </tr>
          <tr>
            <!-- 任务开始时间 -->
            <sd-form-item-td name="beginTime" />
            <!-- 任务结束时间 -->
            <sd-form-item-td name="endTime" />
          </tr>
          <tr>
            <!-- 转换过程中是否发生错误 -->
            <sd-form-item-td
              name="hasError"
              :colspan="3"
              label="是否发生错误"
              :input-props="{ defaultValue: model.hasError === 1 ? '是' : '否' }"
            />
          </tr>
          <tr>
            <!-- 请求参数 -->
            <sd-form-item-td name="urlParameters" :colspan="3" />
          </tr>
          <tr>
            <!-- 定时管理ID -->
            <sd-form-item-td name="jobId" :colspan="3" />
          </tr>
        </table>

        <table>
          <tr
            ><td :colspan="4">
              <sd-form-item name="iamFinDataTransDetailLogEntities" :label="null">
                <template v-slot:read-and-edit="{ editable }">
                  <audit-advanced-group
                    :expand="contactExpand"
                    :expand-str="'contactExpand'"
                    :group-label="'日志详情'"
                    @changedClick="changedClick"
                  >
                    <template>
                      <xm-child-table
                        v-if="contactExpand"
                        ref="tabaData"
                        v-model="model.iamFinDataTransDetailLogEntities"
                        :class="$style.deptPlanChild"
                        label="日志详情"
                        :read-only="!editable"
                        :fields="Array.from(fields.iamFinDataTransDetailLogEntities.attr.dync)"
                        :columns="contactColumns"
                      >
                        <!-- input-form 表示这部分是子表组件的form插槽 -->
                        <template v-slot:input-form="{ model }"> </template>
                      </xm-child-table>
                    </template>
                  </audit-advanced-group>
                </template> </sd-form-item
            ></td>
          </tr>
        </table>
      </template>
    </sd-detail-form>
  </audit-form-top-banner>
</template>

<script>
import axios from '@/common/services/axios-instance'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import { message } from '@/common/one-ui'
import auditFormTopBanner from '@product/iam/components/audit-form-top-banner'
import auditAdvancedGroup from '@product/iam/components/audit-advanced-group'
import auditAdvancedGroupMixins from '@product/iam/components/audit-advanced-group-mixins'
import components from './_import-components/iam-dm-datatranslog-form-import'
import 'element-ui/lib/theme-chalk/index.css'

export default {
  name: 'IamDmDatatranslogForm',
  metaInfo: {
    title: '定时采集配置',
  },
  components: {
    ...components,
    auditAdvancedGroup,
    auditFormTopBanner,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return {
      configOptions: [], // 转换配置列表
      croninput: '',
      showCron: false,
      mode: null,
      saveFlag: true,
      basicExpand: true,
      contactExpand: true,
      etlConfigOptions: [],
      contactColumns: [
        {
          title: '序号',
          dataIndex: 'taskIndex',
          width: '80px',
          customRender: (text, record, index) => `${index + 1}`,
        },
      ],
    }
  },
  mounted() {},
  methods: {
    fnShowCron() {
      this.showCron = true
    },
    handleCancel(e) {
      this.showCron = !this.showCron
    },
    crontabFill(value) {
      // 确定后回传的值
      this.croninput = value
      this.$refs.docform.setFieldValue('jobCron', value)
    },
    configChange(val, option) {
      this.$refs.docform.setFieldValue('configId', Number(option.data.key))
    },
    // 页面加载完成后
    sdFormReady() {
      this.mode = this.$refs.docform.formData.mode
      this.croninput = this.$refs.docform.getFieldValue('jobCron')
    },
    // 保存
    saveForm() {
      this.$refs.docform.validateFields().then(() => {
        message.success('保存成功').then(() => {
          this.$refs.docform.saveBtnClick()
        })
      })
      // this.$refs.docform.saveBtnClick()
    },
    saved() {
      this.close(true)
    },
    close(flag) {
      crossWindowWatcher.notifyChange(this.$route.fullPath, flag)
      window.close()
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
@import '@/webflow/sd-flow-form.scss';
.connect-btn {
  float: right;
  font-weight: 400;
  font-size: 16px;
  top: 8px;
  cursor: pointer;
  margin-right: 10px;
}
.first-td {
  border: none !important;
  padding: 0;
}
</style>
