<template>
  <div>
    <el-dialog
      id="custom-dialog"
      v-model="visible"
      :close-on-click-modal="false"
      :title="null"
      close-icon="null"
    >
      <div class="top-title">{{ boxObj?.vehicleName }}</div>
      <div class="desc-title">{{ boxObj?.vehicleCode }}</div>
      <div class="center-content">
        <el-scrollbar>
          <div
            v-for="(item, index) in materielListData"
            :key="index"
            class="item-container"
          >
            <div>
              <div class="item-header">{{ item?.materialName }}</div>
              <div class="item-describe">{{ item?.spec }}</div>
            </div>
            <div>
              <span class="item-count">{{ item?.num }}</span>
              <span class="item-unit">{{ item?.unit }}个</span>
            </div>
          </div>
        </el-scrollbar>
      </div>

      <div class="bottom-btns">
        <el-button class="cancelBtn" @click="visible = false">取消</el-button>
        <el-button class="sureBtn" type="primary" @click="sure"
          >确认取出
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
const visible = ref(false);

let callBack: Function | null = null;

const materielListData = ref<any[]>([]);

const boxObj = ref<any>({});

const showDialog = (
  box: object,
  listData: any[],
  callback: Function | null
) => {
  boxObj.value = box;
  visible.value = true;
  materielListData.value = listData;
  callBack = callback;
};

const sure = () => {
  callBack && callBack();
  visible.value = false;
};

defineExpose({
  showDialog,
});
</script>

<style lang="scss" scoped>
:deep(.el-dialog) {
  background: #f1f3f5;
  box-shadow: 0px 0px 80px 10px rgba(0, 0, 0, 0.25);
  border-radius: 16px;
}

#custom-dialog {
  background: #f1f3f5;
  box-shadow: 0px 0px 80px 10px rgba(0, 0, 0, 0.25);
  border-radius: 16px 16px 16px 16px;
  width: 924px;
  max-height: 80vh;

  .top-title {
    width: 100%;

    font-weight: 500;
    font-size: 38px;
    color: rgba(0, 0, 0, 0.9);
    text-align: center;
  }

  .desc-title {
    font-weight: 400;
    font-size: 20px;
    color: rgba(0, 0, 0, 0.6);
    text-align: center;
  }

  .center-content {
    margin-top: 24px;
    width: 100%;
    height: 500px;

    font-size: 24px;
    overflow-y: auto;
    color: rgba(0, 0, 0, 0.9);
    border-radius: 16px 16px 16px 16px;
    border: 1px solid rgba(0, 0, 0, 0.2);
  }

  .bottom-btns {
    display: flex;
    justify-content: center;
    margin-top: 20px;
    margin-bottom: 20px;

    .button {
      margin-right: 20px;
    }

    .cancelBtn {
      width: 292px;
      height: 80px;
      background: rgba(0, 0, 0, 0.06);
      border-radius: 76px 76px 76px 76px;
    }

    .sureBtn {
      width: 292px;
      height: 80px;
      background: #0a59f7;
      border-radius: 76px 76px 76px 76px;
    }
  }
}

.item-container {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-left: 30px;
  padding-right: 20px;
  height: 80px;
}

.item-header {
  font-weight: 500;
  font-size: 24px;
  color: rgba(0, 0, 0, 0.9);
  text-align: left;
}

.item-describe {
  font-weight: 400;
  font-size: 20px;
  color: rgba(0, 0, 0, 0.6);
  text-align: left;
}

.item-count {
  font-weight: bold;
  font-size: 38px;
  color: rgba(0, 0, 0, 0.9);

  text-align: right;
}

.item-unit {
  font-weight: 500;
  font-size: 20px;
  color: rgba(0, 0, 0, 0.6);

  text-align: right;
}
</style>
