<template>
  <view class="">
    <view class="service-object-wrap">

      <view class="service-object-list" >

        <view v-for="item in serviceObjectList" class="store-content">
          <view class="store-img">
            <image v-if="item.facePhotoUrl" :src="item.facePhotoUrl" mode=""></image>
            <image v-else src="../../static/logo.png" mode=""></image>
          </view>
          <view class="content">
            <view class="title-price">
              <view class="title">
                <text v-if="item.nickName">{{item.nickName}}</text>
                <text v-else>未填写</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">关系：{{item.blood}}</view>
              <view class="completed" >
                备注：<text>{{item.remark || '无'}}</text>
              </view>
            </view>
          </view>
        </view>
      </view>

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

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

<script>
  export default {
    data() {
      return {
        reqParm: {
          auth: true
        },
        serviceObjectList: [],
        images: [],
      };
    },
    mounted() {
    },
    onLoad() {

    },
    onShow(){
      // 查询服务对象列表
      this.listServiceObject();
    },
    methods: {
      // 查询服务对接信息列表
      listServiceObject(){
        this.$api.listServiceObject(this.reqParm).then((res)=>{
          console.log(res)
          this.serviceObjectList = res.data.data
           this.getImgUrlByBannerOssId(this.serviceObjectList);
        }).catch(() =>{
          uni.showToast({
            title: "操作失败"
          })
        });
      },
      // 获取图片
      getImgUrlByBannerOssId(items){
        for(let i = 0; i <items.length; i++) {
          if (items[i].facePhoto){
            this.$api.getImgUrlByOssId({ossId:items[i].facePhoto}).then(res=>{
              items[i].facePhotoUrl = res.data.data[0].url.replace(/^http:/, "https:")
            })
          }
        }
      },


      /* 添加服务对象 */
      gotoAddServiceObject(){
        uni.navigateTo({
          url: '/myPages/serviceObjectFaceAuth/index',
        })
      },
      // 去修改服务对象
      gotoUpdateServiceObject(item){
        item.facePhotoUrl = item.imgUrl;
        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>
  .service-object-wrap{
    margin-left: 12px;
    margin-right: 12px;
    .add{
      position: fixed;
      bottom: 12px;
      right: 12px;
      left: 12px;
      margin-top: 20px;
      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-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: 36px;
                width: 36px;
              }
            }
          }

          .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{
            }
          }

        }

      }

    }
  }
</style>
