<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="cellClick"
        >
          <el-table-column width="380" label="设备信息">
            <template #default="{ row }">
              <div class="first">
                <div class="prefix" :class="[`prefix-${row.state}`]"></div>
                <div class="company">
                  <span>{{ row.deviceName }}</span>
                </div>
                <div>故障描述：{{ row.description }}</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="报修信息" width="300">
            <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.creationTime }}</div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="派单信息">
            <template #default="{ row }">
              
              <div class="g-fx-j person" v-if="row.state>1">
                <div>
                  <div style="color: #999">派单人</div>
                  <div style="width: 100px">{{ row.assigner }}</div>
                </div>
                <div>
                  <div style="color: #999">派单时间</div>
                  <div style="width: 150px">{{ row.assignTime }}</div>
                </div>
              </div>

            </template>
          </el-table-column>
          <el-table-column label="维修信息">
            <template #default="{ row }">
              <div class="g-fx-j person" v-if="row.state>2">
                <div>
                  <div style="color: #999">维修人</div>
                  <div style="width: 100px">{{ row.repairer }}</div>
                </div>
                <div>
                  <div style="color: #999">维修时间</div>
                  <div style="width: 150px">{{ row.acceptTime }}</div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="审核信息">
            <template #default="{ row }">
              <div class="g-fx-j person" v-if="row.state>4">
                <div>
                  <div style="color: #999">审核人</div>
                  <div style="width: 100px">{{ row.auditor }}</div>
                </div>
                <div>
                  <div style="color: #999">审核时间</div>
                  <div style="width: 150px">{{ row.auditTime }}</div>
                </div>
              </div>
            </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 { getRepairForAllDevices } from '@/api/repair'
  import { useRequest } from '@/utils/hooks'

  const options = [
    {
      label: '待派单',
      value: '1'
    },
    {
      label: '待接单',
      value: '2'
    },
    {
      label: '维修中',
      value: '3'
    },
    {
      label: '待审核',
      value: '4'
    },
    {
      label: '已完成',
      value: '5'
    }
  ]

  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(() =>
    getRepairForAllDevices({
      MaxResultCount: pageObj.value.MaxResultCount,
      SkipCount: (pageObj.value.SkipCount - 1) * pageObj.value.MaxResultCount,
      State: stateVale.value,
      Keyword: iptValue.value,
      CompanyId: companyId.value
    })
  )
  watch([pageObj.value], () => {
    allData?.getData()
  })
  const router = useRouter()

  const cellClick = (row: any) => {
    router.push(`/order-center/my-order/details?orderId=${row.id}&faultType=${row.faultType}`)
  }
  const search = (v: string) => {
    pageObj.value = {
      MaxResultCount: 10,
      SkipCount: 1
    }
    iptValue.value = v
    allData?.getData()
  }
  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;
  }

  .table {
    width: 100%;
    .first {
      height: 90px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      position: relative;
      padding-left: 10px;
    }
    .prefix {
      height: 100%;
      position: absolute;
      left: -10px;
      top: 50%;
      transform: translateY(-50%);
      width: 5px;
      height: 69px;
      background: #fe5656;
      border-radius: 3px;
      &-1 {
        background-color: rgba(236, 97, 90, 1);
      }
      &-2 {
        background-color: rgba(206, 117, 236, 1);
      }
      &-3 {
        background-color: rgba(236, 97, 90, 1);
      }
      &-4 {
        background-color: rgba(85, 113, 180, 1);
      }
      &-5 {
        background-color: rgba(62, 201, 98, 1);
      }
    }
  }
  :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>
