<template>
  <a-card>
    <sd-data-table-ex
      ref="table"
      form-id="weRemoteCallLog"
      page-id="extracirc/log/weRemoteCallLog"
      :columns="columns"
      :actions="actions"
      show-selection
      :modal-props="{ class: $style.table }"
      :search-fields="['sysName', 'title']"
    >
      <template v-slot:form="{ model, fields }">
        <sd-form-item name="id" hidden />
        <sd-form-item name="sysCode" />
        <sd-form-item name="sysName" />
        <sd-form-item name="instId" />
        <sd-form-item name="moduleBeanId" />
        <sd-form-item name="logId" />
        <sd-form-item name="formId" />
        <sd-form-item name="title" />
        <sd-form-item name="param1">
          <a-textarea v-model="model.param1"></a-textarea>
        </sd-form-item>
        <sd-form-item name="param2">
          <a-textarea v-model="model.param2"></a-textarea>
        </sd-form-item>
        <sd-form-item name="param3">
          <a-textarea v-model="model.param3"></a-textarea>
        </sd-form-item>
        <div>
          <sd-form-item name="weRemoteCallLogChildEntityList" :label="null">
            <template v-slot:read-and-edit="{ editable }">
              <sd-child-table
                ref="childForm"
                v-model="model.weRemoteCallLogChildEntityList"
                :columns="[
                  { dataIndex: 'param1', sdHidden: true },
                  { dataIndex: 'param2', sdHidden: true },
                  { dataIndex: 'param3', sdHidden: true },
                  { dataIndex: 'param4', sdHidden: true },
                  { dataIndex: 'param5', sdHidden: true },
                ]"
                :label="fields.weRemoteCallLogChildEntityList.caption"
                :read-only="!editable"
                :fields="Array.from(fields.weRemoteCallLogChildEntityList.attr.dync)"
              >
                <template v-slot:form="scope">
                  <sd-form-item v-for="(val, key) in scope.fields" :key="key" :name="key">
                    <a-textarea
                      v-if="key.includes('param')"
                      v-model="scope.model[key]"
                    ></a-textarea>
                  </sd-form-item>
                </template>
              </sd-child-table>
            </template>
          </sd-form-item>
        </div>
      </template>
    </sd-data-table-ex>
  </a-card>
</template>

<script>
import TableColumnTypes from '@/common/services/table-column-types'
import TableActionTypes from '@/common/services/table-action-types'
import workbenchService from './workbench-service'
import components from './_import-components/sd-log-record-import'

export default {
  name: 'SdLogRecord',
  metaInfo: {
    title: '日志记录',
  },
  components,
  data() {
    return {
      columns: [
        {
          title: '系统的名称',
          sdClickable: true,
          dataIndex: 'sysName',
        },
        {
          title: '标题',
          dataIndex: 'title',
        },
        {
          title: '创建时间',
          dataIndex: 'creationTime',
          sorter: true,
          sdRender: TableColumnTypes.dateTime,
        },
      ],
      actions: [
        {
          label: '新建',
          id: 'new',
          type: TableActionTypes.ex.create,
        },
        {
          label: '删除',
          id: 'delete',
          type: TableActionTypes.batch,
          permission: 'delete',
          callback: (keys, records) => {
            workbenchService.delLogRecord(keys).then((res) => {
              this.$refs.table.refresh()
            })
          },
        },
      ],
    }
  },
  methods: {},
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.table {
  /* stylelint-disable selector-class-pattern */
  :global .header_sd-child-table_common {
    > span,
    > :global(.ant-btn):nth-child(2) {
      display: none;
    }
  }
  :global .ant-modal-footer {
    display: none;
  }
}
</style>
