<template>
  <!-- 增改查弹窗 -->
  <el-dialog title="查看组织详情" :visible.sync="formVisible" class="finish-dialog" :class="mode" width="780px" append-to-body :close-on-click-modal="false">
    <el-form v-if="formVisible" ref="detailForm" :model="formData" :rules="rules" label-position="right" inline class="detail-dialog" label-width="140px">
      <el-form-item label="组织名称：" prop="parkid">
        <span>{{ formData.name || '--' }}</span>
      </el-form-item>
      <el-form-item label="上级组织：">
        <span>{{ formData.parentName || '--' }}</span>
      </el-form-item>
      <el-form-item label="备注：" prop="remark" style="width: 100%">
        <span>{{ formData.remark || '--' }}</span>
      </el-form-item>
      <el-form-item label="创建人：" prop="createName">
        <span>{{ formData.createName || '--' }}</span>
      </el-form-item>
      <el-form-item label="创建时间：" prop="createTime">
        <span>{{ formData.createTime || '--' }}</span>
      </el-form-item>
      <el-form-item label="最后修改人：" prop="createName">
        <span>{{ formData.updateName || '--' }}</span>
      </el-form-item>
      <el-form-item label="最后修改时间：" prop="loginTime">
        <span>{{ formData.updateTime || '--' }}</span>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { deepClone } from '@/utils'

export default {
  name: '',
  inject: ['global', 'refresh'],
  data() {
    return {
      labelWidth: '180px',
      mode: 'see', // 查看see / 编辑edit / 添加add
      titles: { // 弹窗标题(动态)
        see: '查看组织详情',
        add: '添加',
        edit: '编辑'
      },
      formVisible: false, // 弹窗显示
      formConfig: {}, // 表单配置
      formData: {}, // 表单数据
      rules: { }
    }
  },
  computed: {
    isEditAdd() {
      return this.mode === 'edit' || this.mode === 'add'
    }
  },
  methods: {
    showDialog({ formConfig, formData, formTitle }) {
      this.formConfig = formConfig
      this.mode = formConfig?.mode || (this.formData.id ? 'edit' : 'add')
      this.formData = deepClone(formData)
      this.initFormData()
      this.formVisible = true
    },
    initFormData() { // 表单数据初始化
    },
    close() {
      this.formVisible = false
    }
  }
}
</script>

<style scoped lang="scss">
.finish-dialog {
  /deep/ .el-dialog__body {
    padding: 10px 20px 0 20px;
    margin-top: 10px;
  }
  /deep/ .el-form-item {
    &__content  { // 内容宽度100%（默认）
      width: calc(100% - 180px); // 减去label宽
      max-width: none;
      .el-checkbox-group {
        line-height: normal;
      }
    }
    &.fit-width { // 内容宽度自适应
      .el-form-item__content {
        width: fit-content;
      }
    }
    &__label, &__content { // 统一行高
      // line-height: 2;
    }
  }
  .detail-dialog {
    padding-top: 10px;
    .el-row.mb-20 {
      margin-bottom: 10px;
    }
  }
  &.edit, &.add {
    /deep/ .el-form-item {
      margin-bottom: 22px;
    }
  }
  &.add {
    .detail-dialog {
      margin-top: 10px;
    }
  }
  &.see {
    .detail-dialog {
      // background-color: #f8f8f8;
      padding: 20px;
    }
    /deep/ .el-form-item {
      &__label, &__content { // 统一行高
        line-height: 2;
      }
      margin-bottom: 10px;
    }
  }
}
</style>
