<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="客户名称" prop="">
              <el-input placeholder="请输入客户名称" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="单号">
              <el-input placeholder="请输入单号" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="收货人">
              <el-input placeholder="请输入收货人" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="申请时间" prop="createTime">
              <el-date-picker type="date" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="22"> 服务工单信息列表 </el-col>
        </el-row>
      </template>

      <el-table v-loading="loading" border :data="orderServiceList" @selection-change="handleSelectionChange">
        <el-table-column label="订单时间" align="center" prop="createTime">
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单编号" align="center" prop="" />
        <el-table-column label="维保项目" align="center" prop="" />
        <el-table-column label="客户编号" align="center" prop="" />
        <el-table-column label="客户名称" align="center" prop="" />
        <el-table-column label="业务员" align="center" prop="" />
        <el-table-column label="客服" align="center" prop="" />
        <el-table-column label="归属部门" align="center" prop="" />
        <el-table-column label="技术工程师" align="center" prop="" />
        <el-table-column label="预约时间" align="center" prop="" />
        <el-table-column label="完成时间" align="center" prop="">
          <!-- <template #default="scope">
            <span>{{ parseTime(scope.row.createTime),'{y}-{m}-{d}') }}</span>
          </template> -->
        </el-table-column>
        <el-table-column label="订单状态" align="center" prop="" />

        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-button link type="primary" @click="handleReview(scope.row)" v-hasPermi="['order:orderService:edit']">查看</el-button>
            <el-button link type="primary" @click="handleFinish(scope.row)" v-hasPermi="['order:orderService:edit']">完成</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>
  </div>
</template>

<script setup name="OrderService" lang="ts">
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { sys_platform_yes_no, check_status, revenue_type } = toRefs<any>(proxy?.useDict('sys_platform_yes_no', 'check_status', 'revenue_type'));

const orderServiceList = ref<[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const router = useRouter();
const queryFormRef = ref<ElFormInstance>();
const queryParams = reactive<any>({
  pageNum: 1,
  pageSize: 10
});
const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

/** 表单重置 */
const reset = (row?: any) => {};

const handleReview = (row?: any) => {
  router.push({
    path: '/order-manage/service-detail',
    query: { id: row.id }
  });
};

const handleFinish = (row?: any) => {};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};

/** 多选框选中数据 */
const handleSelectionChange = (selection: any[]) => {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
};
const getList = () => {
  loading.value = true;
  setTimeout(() => {
    loading.value = false;
  }, 1000);
};

onMounted(() => {
  getList();
});

onActivated(() => {});
</script>
