<template>
  <div class="modifysend">
    <van-tabs :active="active" @change="getSelectedLoudong">
      <van-tab title="全部" name="null"> </van-tab>
      <van-tab
        v-for="(
          item, index
        ) in dic_SelectList.rectification_management_update_type"
        :title="item.label"
        :name="item.value"
        :key="index"
      >
      </van-tab>
    </van-tabs>
    <!-- 
    <div class="top-add" @click="goNavigator()">
      <i class="iconfont icon-xinzeng"></i>
      <span class="txt">新增整改</span>
    </div> -->

    <div class="info-findRectificationManagementInOutList">
      <div class="info-item" v-for="item in recordList" :key="item.id">
        <div class="info-bottom" v-if="item.recheckId">
          <div class="left"></div>
          <div class="right">
            <span class="normal-tip yd h-bg"> 多次整改 </span>
          </div>
        </div>
        <div class="info-top">
          <div class="left" @click="jumpPageDetails(item.finishType, item.id)">
            <img
              :src="
                item.infoMorePictureUrl != null &&
                item.infoMorePictureUrl.length > 0
                  ? BASE_URI +
                    '/FileController/download/' +
                    item.infoMorePictureUrl[0]
                  : ''
              "
              alt=""
            />
          </div>
          <div class="right" @click="jumpPageDetails(item.finishType, item.id)">
            <p class="tit">
              {{ item.info }}
            </p>
            <p class="txt">
              处理时间：{{ !item.finishTime ? "暂无" : item.finishTime }}
            </p>
            <p class="txt">
              确认时间：{{
                !item.checkTime || item.checkTime == "null"
                  ? "暂无"
                  : item.checkTime
              }}
            </p>
            <p class="txt" v-if="item.finishState == 1 && item.finishType == 4">
              确认结果：已完成整改
            </p>
            <p class="txt" v-if="item.finishState != 1 && item.finishType == 4">
              确认结果：未完成整改
            </p>

            <!-- <p class="txt">确认时间：{{ item.checkTime }}</p> -->
          </div>
        </div>
        <div class="info-bottom">
          <div class="left">
            <i class="iconfont icon-shijian"></i>
            <span>
              {{ item.updateAddress }}
            </span>
          </div>
          <div class="right">
            <span
              v-if="item.finishType == 2"
              class="normal-tip yd h-bg pending-btn"
            >
              待处理
            </span>
            <span
              v-if="item.finishType == 3"
              class="normal-tip yd h-bg accepted-btn"
            >
              待确认
            </span>
            <span
              v-if="item.finishType == 4"
              class="normal-tip yd h-bg processed-btn"
            >
              已完成
            </span>
          </div>
        </div>
      </div>
    </div>
    <select-dengjiyuan
      ref="selectDengjiyuan"
      :multiple="false"
      :range="range"
      :selectParent="false"
      :foldAll="true"
      rangeKey="name"
      idKey="id"
      @selectDengjiyuan="selectDengjiyuan"
    />
  </div>
</template>
      <script>
import {
  findRectificationManagementInOutList,
  getByCodes,
  getUserLocalStorageInfo,
  getSelectUserTwo,
} from "@/js_sdk/http.js";
import tools from "../../subPackages/components/tkitree/tools.js";
import selectDengjiyuan from "../../subPackages/components/select_dengjiyuan/tkitree.vue";

// import Base from "@/pages/base/base";
export default {
  data() {
    return {
      active: "",
      finishStateList: [
        { value: 2, text: "待处理" },
        { value: 3, text: "待确认" },
        { value: 4, text: "已完成" },
      ],
      range: [],
      isCheckList: [],
      loudongList: [
        { name: "1", title: "待派单" },
        { name: "2,3,4", title: "已派单" },
      ],
      BASE_URI: this.$constant.BASE_URI,
      dic_key: ["rectification_management_update_type"],
      dic_SelectList: {},
      recordList: [],
      params: {
        openUser: getUserLocalStorageInfo().user.id,
        updatedBy: getUserLocalStorageInfo().user.id,
        pageNum: 1,
        pageSize: 10,
        finishTypeMore: 2,
        // updateType: 1,
      },
      totalPage: 1,
      allData: [],
      findRectificationManagementInOutList: [
        {
          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",
        },
      ],
    };
  },
  components: {
    selectDengjiyuan,
  },
  mounted() {
    // if (window.history && window.history.pushState) {
    //   // 向历史记录中插入了当前页
    //   history.pushState(null, null, document.URL);
    //   window.addEventListener("popstate", this.goBack, false);
    // }
  },
  onLoad() {},
  onShow() {
    this.getByCodes();
  },

  methods: {
    bindDateChange(e) {
      let that = this;
      that.params.needFinishTime = e.detail.value;
    },
    getIsCheckList(e) {
      let that = this;
      that.isCheckList = e.detail.value;
    },
    selectDengjiyuan(e) {
      this.form.finishUserName = e[e.length - 1].name;
      this.form.finishUser = e[e.length - 1].id;
      this.$forceUpdate();
    },
    async getSelectUserTwo(key) {
      let that = this;
      console.log(that.isCheckList);
      if (that.isCheckList.length == 0) {
        that.$showToast("请先选择要派发的整改");
        return;
      }
      let departmentList = await getSelectUserTwo("");
      that.range = tools.transData(
        departmentList.data,
        "id",
        "parentid",
        "children"
      );
      that.$refs[key]._show();
      that.$forceUpdate();
    },
    selectDengjiyuan(e) {
      var names = [];
      var ids = [];

      for (var p in e) {
        if (e[p].type == "u") {
          names.push(e[p].name);
          ids.push(e[p].id);
        }
      }

      this.form.xinxidengji = names.join(",");
      this.form.manageMessengerId = ids.join(",");
    },
    getSelectedLoudong(event) {
      let that = this;
      that.active = event.detail.name;
      that.params.updateType =
        event.detail.name == "null" ? "" : event.detail.name;
      that.selectData();
    },
    goNavigator(id) {
      uni.navigateTo({
        url: "/pages/subPackages/modifyReport/add",
      });
    },
    jumpPageDetails(type, id) {
      console.log(id);
      if (type == 3) {
        uni.navigateTo({
          url: "/pages/subPackages/modifySend/confirm?id=" + id,
        });
      } else {
        uni.navigateTo({
          url: "/pages/subPackages/modifyHandle/handle?id=" + id,
        });
      }
    },
    async getByCodes() {
      let that = this;
      let data = await getByCodes(JSON.stringify(this.dic_key));

      that.dic_SelectList = that.$common.handleDicList(data);
      that.active = "null";
      console.log("that.activethat.activethat.active", that.active);
      that.selectData();
      that.$forceUpdate();
    },
    // auth.currUser().id
    selectData() {
      const _this = this;
      findRectificationManagementInOutList(this.params).then((res) => {
        if (res) {
          res.rows.forEach((e) => {
            e.needFinishTime = this.$common.transServDay(e.needFinishTime);
            e.checkTime = !e.checkTime
              ? "暂无"
              : this.$common.transServDay(e.checkTime);
            e.updateAddress =
              e.updateAddress && e.updateAddress.length > 0
                ? e.updateAddress.replace("江苏省无锡市", "")
                : e.updateAddress;
            e.infoMorePictureUrl =
              e.infoMorePictureUrl && e.infoMorePictureUrl.length > 0
                ? e.infoMorePictureUrl.split(",")
                : [];
            console.log(e.infoMorePictureUrl);
          });

          this.recordList = res.rows;
        }
      });
    },
    getItemJson: function (item) {
      const fileUrls = item.fileUrl !== "" ? JSON.parse(item.fileUrl) : [];
      console.log(fileUrls);
      item.fileUrl = fileUrls;
      item.createdAt = this.$common.transServDate(item.createdAt);
      //   console.log(item.status);
      //   console.log(this.dic_SelectList.REPAIR_STATUS);
      //   let index = this.dic_SelectList.REPAIR_STATUS.findIdex((e)=>e.value==item.status)
      //   item.statusName = this.dic_SelectList.REPAIR_STATUS[index];
      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>
.modifysend {
  .pending-btn {
    color: $fc;
    background-color: $red;
  }
  .accepted-btn {
    color: $fc;
    background-color: $color2;
  }
  .processed-btn {
    color: $fc;
    background-color: $orange;
  }
  .evaluated-btn {
    color: $fc;
    background-color: $green;
  }
  .btn-view {
    width: 100%;
    height: 100rpx;
    padding: 20rpx 10%;
    background-color: #ffffff;
    position: fixed;
    bottom: 0;
    left: 0;
  }
  .uni-select_2 {
    font-size: 22rpx;
    border: 2px solid #e5e5e5;
    box-sizing: border-box;
    border-radius: 8rpx;
    padding: 0 10rpx;
    padding-left: 20rpx;
    position: relative;
    display: flex;
    -webkit-user-select: none;
    user-select: none;
    flex-direction: row;
    align-items: center;
    border-bottom: solid 2px #e5e5e5;
    width: 100%;
    flex: 1;
    height: 70rpx;
    color: #6a6a6a;
  }
  .btn {
    border-radius: 8rpx 8rpx 8rpx 8rpx;
    width: 80%;
    height: 90rpx;
    //  border-radius: 50rpx 50rpx 50rpx 50rpx;
    background: #1d18bc;
    line-height: 90rpx;
    color: white;
  }
  .top-add {
    background-color: #fff;
    padding: 30rpx;
    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-findRectificationManagementInOutList {
    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 {
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: hidden;
            text-overflow: ellipsis;
            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>
      