<template>
    <div class="repairAcceptance">
      <div class="whiteBoard">
        <div class="addRepair" @tap="addRepair">新增报修 <van-icon name="add" style="margin-left: 8rpx"/></div>
        <div class="repairItem" v-for="item in recordList" @click="toDetail(item)">
          <div class="repairItemTitleRow">
            <span class="titleName">{{item.description}}</span>
            <span class="titleTag" :class="item.statusName==='已受理'?'titleTag2':item.type==='已处理'?'titleTag3':'titleTag'">{{item.statusName}}</span>
          </div>
          <div class="companyBox">
            <img src="https://www.idea-co-sf.com/gardenProduct/image/gs.svg" class="gsIcon">
            <span class="companyName">{{item.companyName}}</span>
          </div>
          <div class="upTimeBox">上报时间：{{ item.createdAt }}</div>
        </div>
      </div>
    </div>
</template>

<script>
import { repairList,getUserLocalStorageInfo,getByCodes } from "@/js_sdk/http";
export default {
  name: "repairAcceptance",
  data(){
    return{
      dc_key: ['REPAIR_STATUS'],
      getUserLocalStorageInfo: getUserLocalStorageInfo(),
      recordList:[
        // {name:'上月水费不太对，怀疑水表异常',type:'待受理'},
        // {name:'空调坏了，不能使用',type:'待处理'},
        // {name:'空调坏了，不能使用',type:'已处理'},
      ],
      params: {
        pageNum: 1,
        pageSize: 10,
        dispatchUserId: getUserLocalStorageInfo().userId,
        handleUserId: getUserLocalStorageInfo().userId,
      },
      checkList:[]
    }
  },
  onShow(){
    this.getByCodes()
  },
  mounted(){
  },
  methods:{
    onPullDownRefresh() {
      this.getByCodes()
      setTimeout(function () {
        uni.stopPullDownRefresh();
      }, 1000);
    },
    async getByCodes() {
      let data = await getByCodes(JSON.stringify(this.dc_key));
      this.dic_SelectList = this.$common.handleDicList(data);
      this.checkList = this.dic_SelectList.REPAIR_STATUS
      this.getList()
    },
    getList(){
      this.recordList = []
      const _this = this
      repairList(this.params).then((res) => {
        if (res.code=='409'){
          uni.clearStorageSync();
          uni.reLaunch({
            url: "/pages/login/login",
          });
        }
        if (res.data) {
          res.data.forEach(function(item) {
            const jsonMap = _this.getItemJson(item)
            _this.recordList.push(jsonMap)
          })
        }
      })
    },
    addRepair(){
      uni.navigateTo({
        url:'/pages/subPackages/todo/addRepair'
      })
    },
    toDetail(item) {
      uni.navigateTo({
        url:'/pages/subPackages/todo/dispatch?item=' + JSON.stringify(item)
      })
    },
    getItemJson: function(item) {
      item.createdAt = this.$common.transServDate(item.createdAt)
      let transformedObject = this.checkList.reduce((acc, obj) => {
        acc[obj.value] = obj.label;
        return acc;
      }, {});

      item.statusName = transformedObject[item.status]
      return item
    },
  }
}
</script>

<style lang="scss">
    .repairAcceptance{
      .whiteBoard{
        background: white;
        margin-top: 24rpx;
        box-sizing: border-box;
        padding: 32rpx;
        min-height: 1424rpx;
        .addRepair{
          display: flex;
          justify-content: flex-end;
          align-items: center;
          color: rgba(3, 101, 249, 1);

        }
        .repairItem{
          background: rgba(245, 247, 250, 1);
          border-radius: 16rpx;
          width: 686rpx;
          height: 224rpx;
          padding: 32rpx 0 24rpx 0;
          box-sizing: border-box;
          margin-top: 24rpx;
          .repairItemTitleRow{
            display: flex;
            justify-content: space-between;
            padding: 0 32rpx;
            .titleName{
              color: rgba(34, 34, 34, 1);
              font-size: 32rpx;
              font-weight: 600;
            }
            .titleTag{
              width: 112rpx;
              height: 48rpx;
              display: flex;
              align-items: center;
              justify-content: center;
              border-radius: 4rpx;
              color: rgba(242, 25, 18, 1);
              font-size: 28rpx;
              background: rgba(242, 25, 18, 0.20);
            }
            .titleTag2{
              width: 112rpx;
              height: 48rpx;
              display: flex;
              align-items: center;
              justify-content: center;
              border-radius: 4rpx;
              color: rgba(255, 107, 24, 1);
              font-size: 28rpx;
              background: rgba(255, 107, 24, 0.20);
            }
            .titleTag3{
              width: 112rpx;
              height: 48rpx;
              display: flex;
              align-items: center;
              justify-content: center;
              border-radius: 4rpx;
              color: rgba(34, 181, 101, 1);
              font-size: 28rpx;
              background: rgba(34, 181, 101, 0.20);
            }
          }
          .companyBox{
            display: flex;
            align-items: center;
            padding: 8rpx 32rpx 24rpx 32rpx;
            .gsIcon{
              width: 32rpx;
              height: 32rpx;
            }
            .companyName{
              font-size: 28rpx;
              color: rgba(102, 102, 102, 1);
              margin-left: 8rpx;
            }
          }
          .upTimeBox{
            padding: 16rpx 32rpx 0 32rpx;
            border-top: 1px solid rgba(230, 230, 230, 1);
            color: rgba(102, 102, 102, 1);
            font-size: 28rpx;
          }
        }
      }
    }
</style>
