<template>

  <Dialog :title="dialogTitle" v-model="dialogVisible" width="70%">

    <ContentWrap v-loading="formLoading" style="max-height:550px;min-height:550px;overflow-y: auto;border:none ;">
      <div class="left ">
        <SPuUploadImg v-model="logo" :disabled="isDetail"/>
        <el-tabs v-model="activeName" tab-position="left" class="child-tabs">
          <el-tab-pane label="基本信息" name="info" />
        </el-tabs>
      </div>
      <div class="right">
        <PickUpStoreForm :obj="userObj" ref="PickUpStoreFormRef" :isDetail="isDetail" :openType="openType" :logo="logo"
          v-if="activeName == 'info'" />
      </div>

      <div style="clear: both;"></div>

    </ContentWrap>
    <template #footer v-if="!isDetail">
      <div class="dialog-footer">
        <!-- 分配人员的保存 -->
        <el-button v-if="!isDetail" :disabled="formLoading" type="primary" @click="submitForm">保存</el-button>
      </div>
    </template>
  </Dialog>


</template>

<script lang="ts" setup>
import Dialog from '@/components/Dialog/src/Dialog.vue'
import PickUpStoreForm from './PickUpStoreForm.vue'


const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const activeName = ref('info') // Tag 激活的窗口
const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const isDetail = ref(false)
const openType = ref('view')
const userObj = ref({})
const logo = ref('logo') //头像
/** 打开弹窗 */
const open = async (type: string, obj: object) => {
  if (obj.logo == '') {
    logo.value = "默认图片"
  } else {
    logo.value = obj.logo
  }
  userObj.value = obj
  openType.value = type
  dialogTitle.value = t('action.' + type)
  if (type == "view") {
    dialogTitle.value = "查看"
  }
  // 判断打开状态，如果是view那就只能查看 否则可以编辑
  if ('view' == type) {
    isDetail.value = true
  } else {
    isDetail.value = false
    activeName.value = 'info'
  }
  dialogVisible.value = true
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
const PickUpStoreFormRef = ref() // 表单 Ref
const submitForm = async () => {
  if (await PickUpStoreFormRef.value?.submitForm()) {
    emit('success')
    dialogVisible.value = false
  }
}


</script>

<style lang="scss">
.el-dialog__body {
  padding: 0;
}

.left {
  width: 106px;
  float: left;
}

.child-tabs {
  border-top: 2px solid #e4e7ef;
  margin-top: -7px;
}

.child-tabs .el-tabs__item {
  width: 106px;
  justify-content: center;
}

.right {
  padding: 10px 0 0 10px;
  border-left: 2px solid #e4e7ee;
  margin-left: -2px;
  float: left;
  width: calc(100% - 120px);
}
</style>