<template>
  <view>
    <custom-nav-bar position="fixed" color="black" left-text="我的调解" left-arrow border />

    <scroll-view :scroll-y="true" :style="'height:' + (windowHeight + 'px')" @scrolltolower="headleTopLower">
      <view class="myAppeal" v-if="List.length > 0">
        <!-- 内容部分 -->
        <view class="myAppeal-conent" @tap="details" :data-item="item" v-for="(item, index) in List" :key="index">
          <view class="godd-replay-head">
            <text class="myAppeal-head-title" style="color: #333333">{{ item.title }}</text>
          </view>

          <view class="myAppeal-flex">
            <block v-for="(type, index1) in typeList" :key="index1">
              <view v-if="item.caseType + '' === type.value" class="myAppeal-type"
                :style="'background-color: ' + type.cssClass + ';'">{{ type.label }}</view>
            </block>
            <view>
              <text class="myAppeal-conent-block">{{ getDateTime(item.createTime, 2) }}</text>
              <block v-for="(state, index1) in statusList" :key="index1">
                <text v-if="item.status + '' === state.value" class="myAppeal-conent-bg myAppeal-conent-block"
                  :style="'background-color: ' + state.cssClass + ';'">
                  {{ state.label }}
                </text>
              </block>
            </view>
          </view>

          <view class="myAppeal-subheading multi-line">{{ item.descInfo }}</view>

          <view class="myAppeal-imgage" v-if="item.pics">
            <image  mode="aspectFill" :src="url" v-for="(url, key) in item.pics" :key="key"></image>
          </view>

          <view class="myAppeal-conent-block mt-21 uniline" v-if="item.address !== null">{{ item.address }}</view>

          <view class="border"></view>
        </view>
      </view>
      <view v-else>
        <van-empty description="暂无数据" />
      </view>
    </scroll-view>
  </view>
</template>
<!-- <script module="toods" lang="wxs" src="@/wxs/util.wxs"></script> -->
<script>
  // TODO: 企业-我的诉求列表 + 民生-我的调解列表此页面复用
  // const app = getApp();
  // const {
  //   enterprise,
  //   peopleApi,
  //   publicApi
  // } = app.globalData.api;
  import * as peopleApi from '@/api/peopleApi';
  import * as publicApi from '@/api/publicApi';
  import * as enterprise from '@/api/enterprise';
  import utils from '@/utils/util.map.js';
  export default {
    data() {
      return {
        windowHeight: null,
        option: {},

        type: {
          value: '',
          cssClass: '',
          label: ''
        },

        status: 'people_cases_status',
        typeList: [],
        statusList: [],
        List: [],

        params: {
          userId: uni.getStorageSync('userInfoData').userId,
          pageNo: 1,
          pageSize: 15
        },

        state: {
          value: '',
          cssClass: '',
          label: ''
        },

        url: ''
      };
    },
    async onLoad(option) {
      const res = uni.getSystemInfoSync();
      this.windowHeight = res.windowHeight
      this.option = option
      await this.getAppealList();
      await this.getTypeList();
      await this.getStateList();
    },
    methods: {
      getDateTime(time,index){
        return utils.getDateTime(time,index)
      },
      // 详情页跳转
      details(event) {
        const {
          item
        } = event.currentTarget.dataset;
        uni.navigateTo({
          url: `/packages/people/pages/mediate-my-details/mediate-my-details?id=${item.id}`
        });
      },

      // 获取我的调解列表
      async getAppealList() {
        let res = await peopleApi.casesListApi(this.params);
        if (res.data && res.data.list.length === 0) {
          uni.showToast({
            title: '已经加载底部了',
            icon: 'none'
          });
          return;
        }
        if (res.data) {
          this.List = this.List.concat(res.data.list)
        }
      },

      // 获取类型字典
      async getTypeList() {
        const res = await publicApi.getDictDataApi({
          dictType: this.type
        });
        if (res.data) {
          this.typeList = res.data.list
        }
      },

      // 获取状态字典
      async getStateList() {
        const res = await publicApi.getDictDataApi({
          dictType: this.status
        });
        if (res.data) {
          this.statusList = res.data.list
        }
      },

      // 分页加载
      headleTopLower() {
        const {
          userId,
          pageNo,
          pageSize
        } = this.params;
        this.params = {
          userId: userId,
          pageNo: pageNo + 1,
          pageSize: pageSize
        }
        this.getAppealList();
      }
    }
  };
</script>
<style lang="less">
  page {
    background-color: #fff;
  }

  .mt-20 {
    margin-top: 40rpx;
  }

  .mt-21 {
    margin-top: 21rpx;
  }

  .myAppeal {
    padding: 0rpx 40rpx 40rpx 40rpx;
  }

  .myAppeal>.myAppeal-title {
    position: relative;
    width: 175rpx;
    height: 10rpx;
    background: #ffe5e9;
    border-radius: 2rpx;
    line-height: 0;
    margin-top: 10px;

    text {
      position: absolute;
      top: -5px;
      text-align: center;
      width: 100%;
      font-size: 36rpx;

      font-weight: 500;
      color: #000000;
    }
  }

  .myAppeal-conent {
    margin-top: 37rpx;

    .godd-replay-head {
      display: flex;

      .myAppeal-head-title {
        font-size: 32rpx;
        font-weight: 500;
        color: #fe3b53;
      }

      image {
        width: 44rpx;
        height: 44rpx;
        margin-right: 24rpx;
      }
    }

    .myAppeal-flex {
      margin-top: 32rpx;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .myAppeal-type {
        width: 88rpx;
        height: 38rpx;
        line-height: 38rpx;
        text-align: center;
        color: #fff;
        box-shadow: 2px 2px 2px 0px rgba(12, 181, 207, 0.1);
        border-radius: 8rpx;
      }

      .myAppeal-conent-title {
        font-size: 32rpx;

        font-weight: 400;
        color: #fe3b53;
      }

      .myAppeal-conent-bg {
        padding: 5rpx 20rpx;
        height: 38rpx;
        text-align: center;
        color: #fff;
        line-height: 38rpx;
        box-shadow: 2px 2px 2px 0px rgba(254, 61, 85, 0.1);
        border-radius: 500rpx;
        margin-left: 39rpx;
      }
    }
  }

  .border {
    padding: 16rpx 0 18rpx 0;
    border-bottom: 1px solid #efefef;
  }

  .myAppeal-conent-block {
    font-size: 24rpx;
    font-weight: 400;
    color: #999999;
  }

  .myAppeal-title {
    font-size: 32rpx;
    font-weight: 500;
    color: #000000;
  }

  .myAppeal-subheading {
    font-size: 28rpx;
    font-weight: 400;
    color: #333333;
    margin-top: 24rpx;
  }

  .myAppeal-imgage {
    margin-top: 24rpx;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;

    image {
      width: 222rpx;
      height: 222rpx;
      border-radius: 10rpx;
      margin-right: 10rpx;
    }
  }

  .myAppeal-bg {
    width: 678rpx;
    height: 232rpx;
    background: #f7f7f7;
    border-radius: 8px;
    margin-top: 32rpx;
    padding: 28rpx 20rpx;

    view {
      display: flex;
      align-items: center;
      justify-content: space-between;

      image {
        width: 32rpx;
        height: 32rpx;
        margin-right: 8rpx;
      }

      text {
        font-size: 28rpx;

        font-weight: 400;
        color: #fe3b53;
      }
    }

    .myAppeal-bg-conent {
      padding: 16rpx 0 0 40rpx;
      font-size: 28rpx;

      font-weight: 400;
      color: #333333;
    }
  }
</style>