Newer
Older
xc-business-system / src / components / DetailPage / DetailBlock.vue
dutingting on 12 Apr 2024 2 KB 设备收发、交接单新需求
<script lang="ts" setup name="DetailBlock">
const props = defineProps({
  title: {
    type: String,
    required: true,
  },
  titleMenus: {
    type: Array as () => string[],
    // required: true,
    default: () => [],
  },
})
const emits = defineEmits(['handleChangeRadio'])

const slots = useSlots()

const current = ref('') // radio绑定值

// 监听radio绑定值变化
watch(() => current.value, (newValue) => {
  emits('handleChangeRadio', newValue)
}, { immediate: true })

watch(() => props.titleMenus, (newValue) => {
  if (newValue.length) {
    current.value = newValue[newValue.length - 1]
  }
}, { deep: true, immediate: true })
</script>

<template>
  <div class="detail-main">
    <div v-if="title" class="header">
      <div style="display: flex;align-items: center;">
        <div class="title">
          {{ title }}
        </div>
        <div>
          <slot name="subhead" />
        </div>
      </div>

      <div v-if="props.titleMenus.length > 1" style="display: flex;justify-content: space-between;">
        <el-radio-group v-model="current" style="margin-bottom: 20px;">
          <el-radio-button v-for="item in titleMenus" :key="item" :label="item">
            {{ item }}
          </el-radio-button>
        </el-radio-group>
      </div>
      <div class="btns">
        <slot name="btns" />
      </div>
    </div>
    <div v-if="slots.default" :class="title ? 'content' : 'special-content'">
      <slot />
    </div>
  </div>
</template>

<style lang="scss" scoped>
.detail-main {
  background-color: #fff;
  border-radius: 8px;
  margin-top: 10px;
  padding-top: 10px;
  box-sizing: border-box;

  .header {
    position: relative;
    height: 40px;
    // align-items: center;
    padding-left: 20px;
    flex-direction: column;
    justify-content: center;
    display: flex;

    .title {
      font-weight: 500;
    }

    .btns {
      position: absolute;
      right: 10px;
      top: 50%;
      transform: translateY(-50%);
    }
  }

  .content {
    background-color: #fff;
    padding: 0 10px 20px;
    margin-top: 10px;
  }

  .special-content {
    background-color: #fff;
    padding: 0 10px;
    padding-right: 20px;
    padding-bottom: 10px;
    margin-top: 10px;
    border-radius: 8px;
  }
}
</style>