<template>
  <u-sticky class="shadow-default" bgColor="#fff" style="top: 0">
    <u-tabs
      :list="tabsList"
      :current="tabsCurrent"
      @click="tabsClick"
      lineColor="#333"
      :activeStyle="{ color: '#333', fontSize: '14px' }"
      :inactiveStyle="{ color: '#909399', fontSize: '14px' }"
      :scrollable="false"
    ></u-tabs>
  </u-sticky>

  <oa-scroll
    customClass="repairManage-container scroll-height"
    :pageSize="pageSize"
    :total="total"
    :isSticky="true"
    :refresherLoad="true"
    :refresherEnabled="true"
    :refresherDefaultStyle="'none'"
    :refresherThreshold="44"
    :refresherBackground="'#f5f6f7'"
    @load="load"
    @refresh="refresh"
    :data-theme="'theme-' + proxy.$settingStore.themeColor.name"
  >
    <template #default>
      <view class="menu-list m0">
        <view class="list-cell list-cell-arrow" style="color: #666666; line-height: 25px" v-for="(base, index) in dataList" :key="index" @click="handleToDetails(base)">
          <view class="content-area-top menu-item">
            <view class="content-area-top-time">
              {{ base.repairStatus == 1 ? (base.createTime ? base.createTime.replace("T", " ") : "") : base.handleTime ? base.handleTime.replace("T", " ") : "" }}
            </view>
            <view class="content-area-top-status" v-if="base.repairStatus == 1" style="background-color: #23dedc"> 受理中 </view>
            <view class="content-area-top-status" v-if="base.repairStatus == 2" style="background-color: #16bf00"> 处理完成 </view>
          </view>
          <view class="content-area-row_wrap menu-item">
            <view class="content-area-row_wrap-view"> 项目名称：{{ base.projectName }} </view>
            <view class="content-area-row_wrap-view"> 报修人：{{ base.reflectName }} </view>
            <view class="content-area-row_wrap-view"> 报修人电话：{{ base.reflectPhone }} </view>
            <view class="content-area-row_wrap-view"> 报修内容：{{ base.repairContent }} </view>
            <view class="content-area-row_wrap-view"> 报修地址：{{ base.projectAddress }} </view>
          </view>
        </view>
      </view>
    </template>
  </oa-scroll>
</template>

<script setup>
/*----------------------------------依赖引入-----------------------------------*/
import { onLoad, onShow, onReady, onHide, onLaunch, onNavigationBarButtonTap, onPageScroll } from "@dcloudio/uni-app";
import { ref, reactive, computed, getCurrentInstance, toRefs, inject } from "vue";
/*----------------------------------接口引入-----------------------------------*/
import { page } from "@/api/business/fireIot/repairManage.js";
/*----------------------------------组件引入-----------------------------------*/
/*----------------------------------store引入-----------------------------------*/
import { useStores, commonStores } from "@/store/modules/index";
/*----------------------------------公共方法引入-----------------------------------*/
/*----------------------------------公共变量-----------------------------------*/
const { proxy } = getCurrentInstance();
const commonStore = commonStores(); //全局公共Store
/*----------------------------------变量声明-----------------------------------*/
const state = reactive({
  tabsList: [
    { name: "全部", value: "" },
    { name: "受理中", value: 1 },
    { name: "处理完成", value: 2 },
  ],
  tabsCurrent: 1,

  dataList: [],
  pageSize: 20,
  current: 1,
  total: 0,
});

const { tabsList, tabsCurrent, dataList, pageSize, current, total } = toRefs(state);

/**
 * @页面初始化
 */
function init() {
  selectListApi();
}

/**
 * @列表查询
 * @api接口查询
 */
function selectListApi() {
  page({
    repairStatus: state.tabsList[state.tabsCurrent].value,
    current: state.current,
    size: state.pageSize,
  }).then((requset) => {
    if (requset.status === "SUCCESS") {
      state.dataList = requset.data.records;
      state.total = requset.data.total;
    }
  });
}

/**
 * @跳转详情事件
 */
function handleToDetails(e) {
  proxy.$tab.navigateTo(`/pages/business/fireIot/repairManage/repairDetails?repairCode=${e.repairCode}`);
}

/**
 * @scrollView加载数据
 */
function load() {
  state.pageSize += 10;
  init();
}

/**
 * @scrollView刷新数据
 */
function refresh() {
  state.pageSize = 20;
  init();
}

/**
 * @tabs点击事件
 */
function tabsClick(e) {
  state.tabsCurrent = e.index;
  init();
}

onReady(() => {});

onShow(() => {
  //调用系统主题颜色
  proxy.$settingStore.systemThemeColor([1]);
});

onLoad((options) => {
  init();
});
</script>

<style lang="scss" scoped>
.repairManage-container {
  .content-area {
    &-top {
      padding-right: 10px;
      font-size: 16px;
      font-weight: 600;
      color: #000000;

      &-time {
        max-width: 70%;
        margin: auto 0;
        font-size: 14px;
        color: rgb(102, 102, 102);
      }

      &-name {
        max-width: 70%;
        color: #000;
      }

      &-status {
        max-width: 30%;
        margin: auto 0 auto auto;
        font-size: 12px;
        color: #ffffff;
        padding: 0 5px;
        border-radius: 20px;
        line-height: 20px;
      }
    }

    &-row_wrap {
      padding-right: 10px;
      font-size: 13px;
      flex-flow: row wrap;

      &-view {
        display: flex;
        min-width: 50%;
        > .iconfont {
          font-size: 14px;
          color: #909399;
          margin-left: 5px;
        }
      }
    }
  }
}
</style>
