<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="rowTags" :class="getStatus(item)==='已评价'?'yclTags':getStatus(item)==='暂存'?'zcTags':getStatus(item)==='待评价'?'dpjTags':''">{{getStatus(item)}}</span>
          </div>
          <div class="companyBox">
            <img src="https://www.idea-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 { repairHandleList,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:{
    getStatus(item){
      if (item.userType === '1') {
        if (item.statusName === '已处理') {
          return item.evaluateStatus === 1 ? '待评价' : '已评价';
        }
      }
      // 如果不满足上述条件，则直接返回 item.statusName
      return item.statusName;
    },
    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
      repairHandleList(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;
            }
            .rowTags{
              display: flex;
              align-items: center;
              justify-content: center;
              color: #0365F9;
              font-size: 28rpx;
              width: 112rpx;
              height: 48rpx;
              background: rgba(3, 101, 249, 0.20);
              border-radius: 4rpx;
            }
            .yclTags{
              color: rgba(34, 181, 101, 1);
              background: rgba(34, 181, 101, 0.20);
            }
            .zcTags{
              color: rgba(255, 107, 24, 1);
              background: rgba(254, 134, 67, 0.20);
            }
            .dpjTags{
              color: rgb(151, 24, 255);
              background: rgba(151, 24, 255, 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>
