<template>
  <div class="modifysend">
    <div class="top-add" @click="goNavigator()">
      <i class="iconfont icon-xinzeng"></i>
      <span class="txt">新增整改</span>
    </div>
    <van-tabs
      id="tabs"
      @change="getSelectedLoudong"
      @before-change="onBeforeChange"
      line-width="80rpx"
      title-active-color="#1D18BC"
    >
      <van-tab
        v-for="(item, index) in loudongList"
        :title="item.title"
        :name="item.name"
        :key="index"
      >
      </van-tab>
    </van-tabs>
    <div
      style="background: white; padding-top: 32rpx; padding: 0 32rpx"
      v-if="params.finishTypeMore == 2"
    >
      <uni-row>
        <uni-col :span="8">
          <div style="height: 70rpx; line-height: 70rpx">处理状态：</div>
        </uni-col>
        <uni-col :span="16">
          <picker
            @change="getFinishType"
            :value="params.finishTypeIndex"
            :range="finishStateList"
            range-key="text"
          >
            <view class="uni-select_2">
              {{
                params.finishTypeIndex === 0 || params.finishTypeIndex
                  ? finishStateList[params.finishTypeIndex].text
                  : "请选择"
              }}
            </view>
          </picker>
        </uni-col>
      </uni-row>
      <div style="margin-top: 16rpx">
        <uni-row>
          <uni-col :span="8">
            <div style="height: 70rpx; line-height: 70rpx">处理日期：</div>
          </uni-col>
          <uni-col :span="16">
            <uni-datetime-picker
              type="date"
              v-model="params.needFinishTime"
              @change="bindDateChange"
              :clear-icon="true"
            />
            <!-- <picker mode="date" @change="bindDateChange" style="float: left">
              <view class="uni-select_2">
                {{ !params.finishTime ? "请选择" : params.finishTime }}
              </view>
              finishTime
            </picker> -->
          </uni-col>
        </uni-row>
      </div>
    </div>
    <div class="info-findRectificationManagementInOutList">
      <checkbox-group @change="getIsCheckList">
        <div class="info-item" v-for="item in recordList" :key="item.id">
          <div class="info-top">
            <checkbox
              :value="item.id"
              :checked="item.isCheck"
              v-if="params.finishTypeMore == 1"
            />
            <div
              class="left"
              @click="jumpPageDetails(item.finishType, item.id)"
            >
              <img
                style="width: 90%; height: 90%; border-radius: 0.5rem"
                :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.createdAt }}</p>

              <!-- <p class="txt">{{ item.createdAt }}</p> -->
              <!-- <p class="txt">处理时间：{{ item.finishTime }}</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 == 1" class="normal-tip yd h-bg">
                待派单
              </span>
              <span v-if="item.finishType == 2" class="normal-tip yd h-bg">
                待处理
              </span>

              <span v-if="item.finishType == 3" class="normal-tip yd h-bg">
                待确认
              </span>

              <span v-if="item.finishType == 4" class="normal-tip yd h-bg">
                已完成
              </span>
            </div>
          </div>
        </div>
      </checkbox-group>
      <view class="‘btn-view‘" v-if="params.finishTypeMore == 1">
        <button class="btn" @click="modifysend()">任务派单</button>
      </view>
    </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,
  updateListRectificationManagement,
} 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 {
      finishStateList: [
        { value: "", text: "全部" },
        { value: 2, text: "待处理" },
        { value: 3, text: "待确认" },
        { value: 4, text: "已完成" },
      ],
      range: [],
      isCheckList: [],
      loudongList: [
        { name: "1", title: "待派单" },
        { name: "2", title: "已派单" },
      ],
      BASE_URI: this.$constant.BASE_URI,
      dic_key: ["REPAIR_STATUS"],
      dic_SelectList: {},
      recordList: [],
      params: {
        openUser: getUserLocalStorageInfo().user.id,
        pageNum: 1,
        pageSize: 10,
        finishTypeMore: 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() {
    this.getByCodes();
  },
  onShow() {
    this.selectData();
  },

  methods: {
    getFinishType(e) {
      let that = this;

      that.params.finishType = that.finishStateList[e.detail.value].value;
      that.params.finishTypeIndex = e.detail.value;
      that.selectData();
      that.$forceUpdate();
    },

    bindDateChange(e) {
      let that = this;
      console.log(e);
      that.params.needFinishTime = e ? e : e;
      that.selectData();
    },
    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 modifysend() {
      let that = this;
      if (that.isCheckList.length == 0) {
        that.$showToast("请先选择要派发的整改");
        return;
      }
      let form = that.isCheckList.map((e) => {
        return {
          id: e,
          finishType: "2",
          updatedBy: getUserLocalStorageInfo().user.id,
        };
      });
      console.log(form);
      let data = await updateListRectificationManagement({
        entities: JSON.stringify(form),
      });
      if (data.code == 200) {
        that.$showToast("派单成功");
        that.selectData();
      }
    },

    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.params = {
        openUser: getUserLocalStorageInfo().user.id,
        pageNum: 1,
        pageSize: 10,
        finishTypeMore: event.detail.name,
      };
      that.selectData();
    },
    goNavigator(id) {
      uni.navigateTo({
        url: "/pages/subPackages/modifyReport/add?isReport=" + 1,
      });
    },
    jumpPageDetails(type, id) {
      console.log(id);
      if (type == 4) {
        uni.navigateTo({
          url: "/pages/subPackages/modifyHandle/handle?id=" + id,
        });
      } else if (type == 3) {
        uni.navigateTo({
          url:
            "/pages/subPackages/modifySend/confirm?id=" +
            id +
            "&btnStatus=" +
            1,
        });
      } else {
        uni.navigateTo({
          url:
            "/pages/subPackages/modifyReport/detail?id=" +
            id +
            "&pdStatus=" +
            1,
        });
      }
    },
    async getByCodes() {
      let that = this;
      let data = await getByCodes(JSON.stringify(this.dic_key));
      that.dic_SelectList = that.$common.handleDicList(data);
      that.selectData();
    },
    // auth.currUser().id
    selectData() {
      const _this = this;
      findRectificationManagementInOutList(this.params).then((res) => {
        if (res) {
          res.rows.forEach((e) => {
            e.finishTime = this.$common.transServDay(e.finishTime);
            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(",")
                : [];
            e.createdAt = this.$common.transServDate(e.createdAt);
            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 {
  .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 {
    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 {
            width: 380rpx;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: hidden;
            text-overflow: ellipsis;
            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>
    