<template>
  <div>
    <EasyDataList ref="EasyDataList" :action-props="{ showExportBtn: false, showAddBtn: false }"
                  :data-source-name="dataSourceName">
      <template v-slot:tableSlot="{ row, $index }">
        <el-tooltip class="item" content="业务编号为一个随机字符串，提交后，可去数据源中查看数据是否正常新增" effect="dark" placement="top">
          <el-button size="small" type="text" @click="addView(row)">新增</el-button>
        </el-tooltip>
        <el-tooltip class="item" content="业务编号为当前数据的业务ID" effect="dark" placement="top">
          <el-button size="small" type="text" @click="editView(row)">编辑</el-button>
        </el-tooltip>
        <el-tooltip class="item" content="业务编号为当前数据的业务ID" effect="dark" placement="top">
          <el-button size="small" type="text" @click="showView(row)">查看</el-button>
        </el-tooltip>
      </template>
    </EasyDataList>
    <ed-dialog :fullscreen="true" :show-footer="false" :title="title" :visible="visibleView" @close="close">
      <EasyDataTemplate :biz-params="bizParam" :template-id="templateId" @submitOk="submitOk"></EasyDataTemplate>
    </ed-dialog>
  </div>
</template>

<script>
import {randomUUID} from "../../../lib/utils/utils"

export default {
  name: "TemplateDemo",
  data() {
    return {
      visible: false,
      visibleView: false,
      title: '',
      templateId: '',
      bizParam: {busi_id: ''},
      dataSourceName: 'tmp_demo',
    }
  },
  methods: {
    addView(row) {
      if (row.keyInfoObject.templateId) {
        this.visibleView = true
        this.$nextTick(() => {
          this.title = row.keyInfoObject.name + "-查询"
          this.bizParam.busi_id = randomUUID()
          this.templateId = row.keyInfoObject.templateId
        })
      } else {
        this.$message.warning("不存在新增模板ID")
      }
    },
    editView(row) {
      if (row.keyInfoObject.templateIdEdit) {
        this.visibleView = true
        this.$nextTick(() => {
          this.title = row.keyInfoObject.name + "-编辑"
          this.bizParam.busi_id = row.keyInfoObject.busi_id
          this.templateId = row.keyInfoObject.templateIdEdit
        })
      } else {
        this.$message.warning("不存在编辑模板ID")
      }
    },
    showView(row) {
      if (row.keyInfoObject.templateIdQuery) {
        this.visibleView = true
        this.$nextTick(() => {
          this.title = row.keyInfoObject.name + "-查看"
          this.bizParam.busi_id = row.keyInfoObject.busi_id
          this.templateId = row.keyInfoObject.templateIdQuery
        })
      } else {
        this.$message.warning("不存在查询模板ID")
      }
    },
    close() {
      this.templateId = ""
      this.visibleView = false
      this.bizParam.busi_id = ""
    },
    submitOk(formData, isSupper) {
      if (isSupper) {
        this.close()
      }
    }
  }
}
</script>

<style scoped></style>
