<template>
  <div class="g-p20" style="margin-bottom: 40px">
    <div class="g-fx">
      <!-- <pro-select
        type="1"
        placeholder="全部公司"
        v-model:selectValue="companyId"
        style="margin-right: 20px"
        :width="350"
      ></pro-select> -->
      <!-- <pro-select
        placeholder="工单状态"
        v-model:selectValue="stateVale"
        :options="options"
        style="margin-right: 20px"
        :width="350"
      ></pro-select> -->
      <base-search @on-search="search" @reset="reset"></base-search>
    </div>
    <div class="g-fx-j content">
      <div class="table">
        <el-table
          v-loading="allData.loading"
          header-cell-class-name="table-head"
          row-class-name="table-row"
          :data="allData.items"
          @cell-click="toSend"
        >
          <el-table-column width="420" label="设备信息">
            <template #default="{ row }">
              <div class="first">
                <div class="company">
                  <span>{{ row.deviceName }}</span>
                </div>
                <div>故障描述：{{ row.description }}</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="派单信息">
            <template #default="{ row }">
              <div class="g-fx-j person">
                <div>
                  <div style="color: #999">派单人</div>
                  <div style="width: 100px">{{ row.customer }}</div>
                </div>
                <div>
                  <div style="color: #999">派单时间</div>
                  <div style="width: 150px">{{ row.time }}</div>
                </div>
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column label="派单信息">
            <template #default="{ row }">
              {{ '-' }}
            </template>
          </el-table-column>
          <el-table-column label="维修信息">
            <template #default="{ row }">
              {{ '-' }}
            </template>
          </el-table-column>
          <el-table-column label="审核信息">
            <template #default="{ row }">
              {{ '-' }}
            </template>
          </el-table-column> -->
          <base-order-state></base-order-state>
        </el-table>
      </div>
      <pro-pagination
        class="pagination"
        v-if="allData.data.totalCount !== 0"
        :total="allData.data.totalCount"
        :pageObj="pageObj"
      ></pro-pagination>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { getTodoRepairList } from '@/api'
  import { getRepairForAllDevices } from '@/api/repair'
  import { useRequest } from '@/utils/hooks'
  const orderState: any = {
    1: '待派单',
    2: '待接单',
    3: '维修中',
    4: '待审核',
    5: '已完成'
  }
  const options = [
    {
      label: '待派单',
      value: '1'
    },
    {
      label: '待接单',
      value: '2'
    },
    {
      label: '维修中',
      value: '3'
    },
    {
      label: '待审核',
      value: '4'
    },
    {
      label: '已完成',
      value: '5'
    }
  ]
  const orderStateClass: any = {
    1: 'state1',
    2: 'state2',
    3: 'state3',
    4: 'state4',
    5: 'state5'
  }
  const companyName = ref('')
  const companyId = ref('')
  const stateVale = ref('')
  let pageObj: any = ref({
    MaxResultCount: 10,
    SkipCount: 1
  })
  onMounted(async () => {
    await allData.getData()
  })
  let iptValue = ref('')
  const allData = useRequest(() =>
    getTodoRepairList({
      MaxResultCount: pageObj.value.MaxResultCount,
      SkipCount: (pageObj.value.SkipCount - 1) * pageObj.value.MaxResultCount,
      State: 3,
      Keyword: iptValue.value
    })
  )
  watch(
    [pageObj.value],
    () => {
      allData?.getData()
    },
    {
      deep: true
    }
  )
  const search = (v: string) => {
    pageObj.value = {
      MaxResultCount: 10,
      SkipCount: 1
    }
    iptValue.value = v
    allData?.getData()
  }
  const router = useRouter()
  const toSend = (row: any) => {
    router.push(`/order-center/my-order/details?orderId=${row.id}&faultType=${row.faultType}`)
  }
  const reset = () => {
    pageObj.value = {
      MaxResultCount: 10,
      SkipCount: 1
    }
    companyId.value = ''
    stateVale.value = ''
    iptValue.value = ''
    allData?.getData()
  }
</script>

<style lang="less" scoped>
  .content {
    position: relative;
    padding: 20px;
    background-color: #fff;
    border-radius: 10px;
    min-height: 200px;
    padding-bottom: 100px;
    .pagination {
      position: absolute;
      bottom: 10px;
      right: 50px;
    }
  }
  .person {
    font-weight: 400;
    width: 120px;
  }
  .state {
    width: 70px;
    height: 26px;
    line-height: 26px;
    text-align: center;
    border-radius: 7px;
    font-weight: 400;
  }
  .state1 {
    color: #ec615a;
    background-color: rgba(236, 97, 90, 0.2);
  }
  .state2 {
    color: rgba(206, 117, 236, 1);
    background-color: rgba(206, 117, 236, 0.2);
  }
  .state3 {
    color: #ec615a;
    background-color: rgba(236, 97, 90, 0.2);
  }
  .state4 {
    color: rgba(85, 113, 180, 1);
    background-color: rgba(85, 113, 180, 0.2);
  }
  .state5 {
    color: rgba(62, 201, 98, 1);
    background-color: rgba(62, 201, 98, 0.2);
  }
  .table {
    width: 100%;
    .first {
      height: 90px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      position: relative;
    }
    .prefix {
      height: 100%;
      position: absolute;
      left: -10px;
      top: 50%;
      transform: translateY(-50%);
      width: 5px;
      height: 69px;
      background: #fe5656;
      border-radius: 3px;
    }
  }
  :deep(.el-table) {
    .table-head {
      background: #f6f6f6;
      .cell {
        color: #333;
      }
    }
    .table-head {
      height: 40px;
      font-size: 12px;
    }
    .table-row {
      height: 60px;
      font-weight: bold;
    }
  }
</style>
