<script setup name="AssetLibrary">
import { ref, toRefs, reactive, getCurrentInstance } from 'vue'
import QueryForm from './QueryForm.vue'
import FormGroup from './modules/formGroup.vue'
const emit = defineEmits(['page'])

const { proxy } = getCurrentInstance()

const data = reactive({
  form: {
    name: ''
  },
  queryParams: {
    customerName: null
  },
  rules: {
  }
})

const { queryParams, form, rules } = toRefs(data)

const modalData = reactive({
  show: false,
  text: ''
})

// 新增
const handleAdd = () => {
  emit('page', 'add')
}

// 筛选查询
const onQuery = () => {
  console.log('onQuery')
  // handleQuery()
}
// 查询组件事件重置
const onReset = (formQuery) => {
  console.log('onReset')
  formQuery.resetFields()
}

// 预览
const onPreview = () => {
  console.log('onPreview')
}

// 删除
const onDelete = () => {
  console.log('onPreview')
  modalData.show = true
  modalData.text = '删除后无法恢复，是否确认删除[若依配测系统]？'
}

// 确认删除回调
const modalConfirm = () => {
  modalData.show = false
}

// 编辑成功回调
const onConfirm = () => {
  console.log('编辑成功')
}
</script>

<template>
  <div class="app-container scroller">
    <PageTitle>
      <template #title>
        资产库
      </template>
      <template #buttons>
        <el-button type="primary" icon="Plus" @click="handleAdd">新增数据源</el-button>
      </template>
    </PageTitle>
    <div class="app-container__body">
      <query-form ref="QueryFormRef" v-model="queryParams" @query="onQuery" @reset="onReset" />
      <el-scrollbar>
        <div class="flex-content">
          <el-card class="box-card" :body-style="{ padding: '0px !important' }">
            <img class="img" src="https://172.19.1.166:9005/static/img/MYSQL.535270a.png" alt="">
            <div class="title">
              <div class="title-content">若依配测系统</div>
            </div>
            <div class="mask">
              <div class="maskbutton">
                <div class="maskbutton-item" @click="onDelete">
                  <el-icon :size="18">
                    <delete />
                  </el-icon>
                  <br>
                  <span>删除</span>
                </div>
                <div class="maskbutton-item" @click="onPreview">
                  <el-icon :size="18">
                    <View />
                  </el-icon>
                  <br>
                  <span>预览</span>
                </div>
              </div>
            </div>
          </el-card>
        </div>
      </el-scrollbar>
      <div class="mt20">
        <div class="mb20">数据源明细：{{ form.name }}</div>
        <FormGroup :id="'1111'" page="edit" @confirm="onConfirm"  />
      </div>
    </div>
    <Modal v-model="modalData.show" icon="error" :cancel="true" :text="modalData.text" @confirm="modalConfirm"></Modal>
  </div>
</template>

<style lang="scss" scoped>
.flex-content {
  display: flex;
  height: 190px;
  .box-card {
    position: relative;
    flex-shrink: 0;
    margin-right: 20px;
    height: 138px;
    width: 188px;
    border-radius: 10px;
    -webkit-transform: translateY(0);
    transform: translateY(0);
    -webkit-transition: all 0.1s;
    transition: all 0.1s;
    :deep(.el-card__body) {
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
    }
    .img {
      width: 100%;
      border-radius: 10px 10px 0 0;
    }

    .title {
      width: 100%;
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #7a8495;
      &-content {
        padding-left: 16px;
        padding-right: 16px;
        font-size: 14px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
    .mask {
      position: absolute;
      z-index: -1;
      opacity: 0;
      -webkit-transition: all 0.1s;
      transition: all 0.1s;
      width: 100%;
      height: 104px;
      left: 0;
      top: 0;
      background: #191919;
      display: flex;
      -webkit-box-align: center;
      -ms-flex-align: center;
      align-items: center;
      justify-content: center;
      border-radius: 10px 10px 0 0;
      .maskbutton {
        color: #fff;
        width: 100%;
        position: absolute;
        top: 50%;
        -webkit-transform: translateY(-50%);
        transform: translateY(-50%);
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
        -ms-flex-pack: distribute;
        justify-content: space-around;
        &-item {
          width: 70px;
          font-size: 14px;
          cursor: pointer;
          text-align: center;
          color: #fff;
        }
      }
    }
  }
  .box-card:hover {
    width: 250px;
    height: 190px;
    margin: 0 16px;
    .mask {
      opacity: 1;
      width: 100%;
      height: 140px;
      display: block;
      position: absolute;
      z-index: 50;
    }
    .title {
      &-content {
        font-size: 18px;
      }
    }
  }
  .box-card:last-child {
    margin-right: 0;
  }
}
</style>