<template>
  <div class="g-p20 main g-h">
    <base-search @on-search="search" @reset="reset"></base-search>
    <div class="content g-br-10 g-bg-fff g-p20">
      <el-table
        :data="allData.items"
        header-cell-class-name="table-head"
        row-class-name="table-row"
        style="width: 100%"
        v-loading="allData.loading"
      >
        <el-table-column prop="date" label="备件图片" width="150">
          <template #default="{ row }">
            <el-image
              :preview-src-list="[row.imageSource]"
              :initial-index="1"
              hide-on-click-modal
              :preview-teleported="true"
              style="width: 85px; height: 85px; border-radius: 15px"
              :src="row.imageSource"
              fit="contain"
            />
          </template>
        </el-table-column>
        <el-table-column prop="name" label="备件名称" width="120">
          <template #default="{ row }">
            <div class="second">
              {{ row.name }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="address" width="120" label="物料型号">
          <template #default="{ row }">
            <div class="second">{{ row.model }}</div>
          </template>
        </el-table-column>
        <el-table-column width="260" prop="address1" label="供应商">
          <template #default="{ row }">
            <div class="second">{{ row.supplier }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="address1" label="备注">
          <template #default="{ row }">
            <div class="remark">{{ row.remark }}</div>
          </template>
        </el-table-column>
        <el-table-column width="200" align="center" prop="address1" label="库存">
          <template #default="{ row }">
            <div class="last-row">{{ row.quantity }}</div>
          </template>
        </el-table-column>
      </el-table>
      <pro-pagination
        v-if="allData.data.totalCount"
        class="pagination"
        :total="allData.data.totalCount"
        :pageObj="pageObj"
      ></pro-pagination>
    </div>
  </div>
</template>

<script setup lang="ts" name="备品备件">
  import { getSpareParts } from '@/api'
  const pageObj = reactive({
    MaxResultCount: 10,
    SkipCount: 1
  })
  // onMounted(async () => {
  //
  //   await allData.getData()
  //
  // })

  let iptValue = ref('')
  const allData = useRequest(() =>
    getSpareParts({
      MaxResultCount: pageObj.MaxResultCount,
      SkipCount: (pageObj.SkipCount - 1) * pageObj.MaxResultCount,
      DeviceId: useQuery('id'),
      Filter: iptValue.value
    })
  )
  watchEffect(() => {
    allData?.getData()
  })
  const search = (v: any) => {
    iptValue.value = v
    if (!v) {
      allData?.getData()
    }
  }
  const reset = () => {
    iptValue.value = ''
  }
</script>

<style lang="less" scoped>
  .main {
    background: #c8cfdf;
    margin-bottom: 40px;
  }
  .content {
    min-height: calc(100vh - 200px);
    padding-bottom: 100px;
    position: relative;
    .first {
      width: 63px;
      height: 20px;
      background: #a6a9af;
      border-bottom-left-radius: 10px;
      border-top-right-radius: 10px;
      font-size: 12px;
      color: #fff;
      text-align: center;
    }
    .second {
      font-weight: bold;
    }
    .remark {
      border-right: 1px solid #efefef;
      padding-right: 15px;
      font-weight: bold;
    }
    .three {
      color: #7d7d86;
    }
    .last-row {
      height: 100%;
      font-size: 20px;
      color: #597fda;
    }

    .pagination {
      position: absolute;
      bottom: 20px;
      right: 30px;
    }
  }
  :deep(.content) {
    .table-head {
      background: #f6f6f6;
      .cell {
        color: #333;
      }
    }
    .table-head {
      height: 40px;
      font-size: 12px;
    }
    .table-row {
      color: #333;
      .el-table__cell {
        padding: 16px 0;
      }
    }
    .el-icon {
      width: 20px;
      height: 20px;
      font-size: 16px;
      font-weight: bold;
    }
    .fs-16 {
      font-size: 18px;
    }
  }
</style>
