<template>
  <div class="repair">
    <!--    <div class="top-add" @click="goNavigator('repairprocessing-add-app')">-->
    <!--      <i class="iconfont icon-xinzeng"></i>-->
    <!--      <span class="txt">新增报修</span>-->
    <!--    </div>-->
    <div class="info-list">
      <div class="info-item" v-for="item in recordList" :key="item.id" @click="goNavigator(item.id)">
        <div class="info-top">
          <div class="left">
            <img :src="item.fileUrl != null ? item.fileUrl.url : ''" alt="" />
          </div>
          <div class="right">
            <p class="tit">
              {{ item.description }}
            </p>
            <p class="txt">{{ item.companyName }}</p>
          </div>
        </div>
        <div class="info-bottom">
          <div class="left">
            <i class="iconfont icon-shijian"></i>
            <span>
              {{ item.createdAt }}
            </span>
          </div>
          <div class="right">
            <span v-if="item.status == '1'" class="normal-tip yd h-bg">待处理</span>
            <span v-if="item.status == '2'" class="normal-tip yd z-bg">已处理 </span>
            <span v-if="item.status == '3'" class="normal-tip yd z-bg">已确认 </span>
            <span v-if="item.status == '4'" class="normal-tip yd z-bg">已退回 </span>
            <span v-if="item.status == '5'" class="normal-tip yd z-bg">确认退回 </span>

          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
// import { list } from "@/service/api_repair";
import {
  getByCodes,
  getUserLocalStorageInfo,
  getRepairList,
} from "@/js_sdk/http";
// import Base from "@/pages/base/base";
// import auth from "@/service/auth";
export default {
  data() {
    return {
      dic_key: ["REPAIR_STATUS"],
      dic_SelectList: {},
      recordList: [],
      dic_SelectList: {},
      BASE_URI: this.$constant.BASE_URI,
      params: {
        pageNum: 1,
        pageSize: 10,
        // status: 'acceptance',
        // groupId: '870261874875170816',
        // handleUserId: getUserLocalStorageInfo().user.id,
      },
      totalPage: 1,
      allData: [],
      list: [
        {
          title: "关于组织2020年无锡市服务业提质增效资金项目申报的通知",
          name: "无锡 XXXX有限公司",
          date: "2020-09-18 19:34:06",
          type: "1",
        },
        {
          title:
            "关于组织2020年无锡市服务业提质增效资金项目申报的通知关于组织2020年无锡市服务业提质增效资金项目申报的通知",
          name: "无锡 XXXX有限公司",
          date: "2020-09-18 19:34:06",
          type: "2",
        },
      ],
    };
  },
  onShow() {
    this.parmas =
      getUserLocalStorageInfo().user.id +
      getUserLocalStorageInfo().user.truename +
      getUserLocalStorageInfo().user.phone;
    this.getByCodes();
    this.params.handleUserId = getUserLocalStorageInfo().user.id;
  },

  methods: {
    goNavigator(id) {
      uni.navigateTo({
        url: "/pages/subPackages/repairprocessing-app/detail?id=" + id,
        fail: (fail) => {
          console.log(fail);
        },
      });
    },
    async getByCodes() {
      let data = await getByCodes(JSON.stringify(this.dic_key));
      this.dic_SelectList = this.$common.handleDicList(data);
      this.selectData();
    },
    goBack() {
      this.$router.push({ path: "/home-app" });
    },
    selectData() {
      const _this = this;
      _this.recordList = [];
      _this.params;
      getRepairList(this.params).then((res) => {
        console.log(res.data);
        if (res.data) {
          res.data.rows.forEach(function (item) {
            const jsonMap = _this.getItemJson(item);
            _this.recordList.push(jsonMap);
          });
        }
      });
    },
    getItemJson: function (item) {
      item.createdAt = this.$common.transServDate(item.createdAt);
      console.log(item.status)
      // let index = this.dic_SelectList.REPAIR_STATUS.findIndex((e) => {
      //   console.log('e.value, item.status', e.value == item.status)
      //   console.log('e.value, item.status', e.value, item.status)
      //   return e.value == item.status
      // }
      // );
      // console.log(index)
      const fileUrls =
        item.fileUrl && item.fileUrl.length > 0 ? item.fileUrl.split(",") : [];
      console.log(fileUrls);
      const fileUrl = {
        url:
          this.$constant.BASE_URI +
          "/wx/fileController/download/" +
          fileUrls[0],
      };
      item.fileUrl = fileUrl;
      console.log(this.dic_SelectList.REPAIR_STATUS);
      // item.statusName = this.dic_SelectList.REPAIR_STATUS[index].label;
      return item;
    },
    /**
     *
     */
    quickSelect(item) {
      if (this.quickSleced.val && this.quickSleced.val === item.val) {
        this.quickSleced = {};
      } else {
        this.quickSleced = item;
      }
    },
    /**
     * 上传文件
     */
    afterRead(file) {
      console.log(file);
    },
    /**
     * 设置状态样式
     */
    setStatusStyle(status) {
      let statusClass = null;
      switch (status) {
        case "unAcceptance":
          statusClass = "pending-btn";
          break;
        case "acceptance":
          statusClass = "accepted-btn";
          break;
        case "processed":
          statusClass = "processed-btn";
          break;
        case "evaluated":
          statusClass = "evaluated-btn";
          break;
      }
      return statusClass;
    },
  },
  /**
   * 过滤器
   */
  filters: {
    /**
     * 状态：0、待受理 1、已受理 2、已处理  3、已评价
     */
    statusFilter(val) {
      let res = null;
      switch (val) {
        case "unAcceptance":
          res = "待处理";
          break;
        case "acceptance":
          res = "已受理";
          break;
        case "processed":
          res = "已处理";
          break;
        case "evaluated":
          res = "已评价";
          break;
      }
      return res;
    },
  },
};
</script>
<style lang="scss" type="text/scss" scoped>
.repair {
  .top-add {
    background-color: #fff;
    padding: 30rpx;
    margin-bottom: 20rpx;
    text-align: right;
    box-shadow: 0rpx 5rpx 10rpx 0rpx rgba(0, 0, 0, 0.05);

    i {
      font-size: 36rpx;
      color: $text6;
      margin-right: 15rpx;
    }

    .txt {
      font-size: 32rpx;
      color: $text6;
    }
  }

  .info-list {
    height: calc(100vh - 124rpx);
    overflow-y: auto;

    .info-item {
      background-color: #fff;
      padding: 20rpx 30rpx;
      margin-bottom: 20rpx;

      .info-top {
        @include flex;

        .left {
          width: 286rpx;
          height: 168rpx;
          font-size: 0;
          border-radius: 10rpx;
          overflow: hidden;

          img {
            width: 100%;
            height: 100%;
          }
        }

        .right {
          align-self: flex-start;
          width: 380rpx;

          .tit {
            width: 380rpx;
            font-size: 32rpx;
            line-height: 1.4;
            font-weight: bold;
            color: #333333;
            @include line-clamp;
            margin-bottom: 20rpx;
          }

          .txt {
            font-size: 28rpx;
            color: #666;
          }
        }
      }

      .info-bottom {
        margin-top: 20rpx;
        padding-top: 20rpx;
        border-top: 1rpx dashed #dbdbdb;
        @include flex;

        .left {
          i {
            font-size: 30rpx;
            color: #999999;
            margin-left: 10rpx;
          }

          span {
            font-size: 28rpx;
            color: #999999;
          }
        }

        .right {}
      }
    }
  }
}
</style>
