<template>
  <view class="page" :style="{'height':windowHeight}">
    <scroll-view :style="{'height':windowHeight}" scroll-y>
      <view class="service-object-wrap">

        <view class="service-object-list" >
          <view v-for="(item,index) in serviceObjectList" class="store-content" :key="index">
            <view class="store-img">
              <image  :src="item.facePhotoUrl || '/static/logo.png'" mode="aspectFill" @click="magnify(item.facePhotoUrl)"></image>
            </view>
            <view class="content">
              <view class="title-price">
                <view class="title">
                  <text>{{item.nickName || '未填写'}}</text>
                </view>
                <view @click="gotoUpdateServiceObject(item)" class="icon-btn">
                  <image src="/static/me/u2299.png" mode=""></image>
                </view>
              </view>
              <view class="desc">
                <view class="in-progress">
                  <text>关系：{{item.blood}}</text> <text v-if="item.haveEquityCard" class="b">88卡</text>
                </view>
                <view class="completed" >
                  备注：<text>{{item.remark || '无'}}</text>
                </view>
              </view>
            </view>

          </view>
        </view>
      </view>

    </scroll-view>
    <view @click="gotoAddServiceObject()" class="add">
      +<text class="name">添加服务对象</text>
    </view>

    <uni-popup ref="popup">
      <view class="magnifyUrlView">
        <image :src="magnifyUrl" mode="widthFix"></image>
      </view>
    </uni-popup>

  </view>
</template>

<script>
  export default {
    data() {
      return {
        magnifyUrl:'',
        windowHeight:'',
        reqParm: {
          auth: true
        },
        serviceObjectList: [],
        images: [],
      };
    },
    mounted() {
    },
    onLoad() {
      let sysInfo = uni.getSystemInfoSync()
      this.windowHeight =sysInfo.windowHeight -100  +'px'//除标题栏栏外的屏幕可用高度
    },
    onShow(){
      // 查询服务对象列表
      this.listServiceObject();
    },
    methods: {

      magnify(url){
        if (!url){
          return
        }
        this.magnifyUrl = url
        this.$refs.popup.open()
      },
      // 查询服务对接信息列表
      listServiceObject(){
        this.$api.listServiceObject(this.reqParm).then((res)=>{
          console.log(res)
          this.serviceObjectList = res.data.data
           this.getImgUrlByBannerOssId(this.serviceObjectList);
        })
      },
      // 获取图片
      getImgUrlByBannerOssId(items){
        for(let i = 0; i <items.length; i++) {
          if (items[i].facePhoto){
            this.$api.getImgUrlByOssId({ossId:items[i].facePhoto}).then(res=>{
              console.log('++++++++++++facePhotoUrl+++++++++',res.data.data[0].url.replace(/^http:/, "https:"))
              items[i].facePhotoUrl = res.data.data[0].url.replace(/^http:/, "https:")
              this.$set(this.serviceObjectList,i,items[i])
            })
          }
        }
      },


      /* 添加服务对象 */
      gotoAddServiceObject(){
        uni.navigateTo({
          url: '/myPages/serviceObjectFaceAuth/index',
        })
      },
      // 去修改服务对象
      gotoUpdateServiceObject(item){
        if(item.wardship == '1'){ // 监护人
          uni.navigateTo({
            url: '/myPages/serviceObjectAllInfo/index?data=' + JSON.stringify(item),
          })
        } else { // 不是监护人
          item.opType = '2';
          uni.navigateTo({
            url: '/myPages/serviceObjectInfo/index?data=' + JSON.stringify(item) ,
          })
        }



      },
    }
  };
</script>

<style lang="scss" scoped>

  .page{
    background: #f7f7f7;
    border-top: 1px solid #f7f7f7;
  }

  .magnifyUrlView{
    border-radius: 20rpx;
    overflow: hidden;
  }

  .add{
    width: 686rpx;
    margin-left: 32rpx;
    margin-top: 30px;
    text-align: center;
    color: #333333;
    line-height: 42px;
    border-radius: 6px;
    font-size: 16px;
    height: 42px;
    background: #FFE05C;
    border-radius: 27px;
    .name{
      padding-left: 6px;
    }
  }
  .service-object-wrap{
    margin-left: 12px;
    margin-right: 12px;

    .service-object-list{
      .store-content{
        padding:10px;
        margin-top: 16px;
        background: #fff;
        display: flex;
        border-radius: 6px;
        .store-img{
          image{
            width: 90px;
            height: 90px;
            border-radius: 3px;
          }
        }
        .content{
          width: 100%;
          padding-left: 8px;
          padding-top: 4px;
          .title-price{
            display: flex;
            font-size: 20px;
            .title{
              font-size: 16px;
              color: #111111;
              width: 100%;
              font-family: "黑体", sans-serif;
              line-height: 30px;
            }
            .icon-btn{
              text-align: right;
              padding-right: 12px;
              image{
                height: 30px;
                width: 30px;
              }
            }
          }

          .desc{
            line-height: 26px;
            color: #999999;
            font-size: 12px;
            white-space: nowrap; /* Prevent line breaks */
            overflow: hidden; /* Hide overflowing content */
            text-overflow: ellipsis; /* Show ellipsis (...) for overflow */
            .teacher{
              padding-left: 6px;
            }
            .completed{
            }
          }

        }

      }

    }
  }
  .in-progress{
    display: flex;
    flex-direction: row;
    justify-content: space-between;
  }

  .b{
    font-size: 24rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    color: #9ed733;
    background: #e9f6d1;
    padding: 6rpx 16rpx;
    margin-left: 16rpx;
    border-radius: 12rpx;
  }
</style>
