<template>
  <div>
    <el-dialog
      id="custom-dialog-wuliao"
      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 v-loading="loading">
          <div
            v-for="(item, index) in materielListData"
            :key="index"
            class="item-container"
          >
            <div>
              <div class="item-header">
                {{ item?.materialName }}
                <!--                {{ item?.materialCode }}-->
                <!--                {{ item?.batchCode }}-->
              </div>
              <div class="item-mCode">{{ item?.materialCode }}</div>
              <div class="item-describe">{{ item?.spec }}</div>
            </div>
            <div>
              <span class="item-count">{{ item?.num }}</span>
              <span class="item-unit">
                {{ dictS.getLableByValue("danwei_type", 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>
import { outSuitBox } from "@/api/process/callMateriel";
import { useDictionaryStore } from "@/store";

const dictS = useDictionaryStore();
const visible = ref(false);

let callBack: Function | null = null;

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

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

const loading = ref(false);

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

const sure = async () => {
  loading.value = true;
  const res = await outSuitBox({ vehicleOperationId: boxObj.value.id });
  ElMessage.success(res?.data ?? "操作成功");
  loading.value = false;
  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-wuliao {
  background: #f1f3f5;
  box-shadow: 0px 0px 80px 10px rgba(0, 0, 0, 0.25);
  border-radius: 16px 16px 16px 16px;
  width: 924px;
  height: 600px;

  .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: 300px;

    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: 10px 20px;
  //height: 96px;
  //margin-top: px;
  //border: 1px solid red;
}

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

.item-mCode {
  font-weight: 500;
  font-size: 16px;
  color: rgba(0, 0, 0, 0.6);
  text-align: left;
}

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

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

  text-align: right;
}

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

  text-align: right;
}
</style>
