<template>
  <view class="container">
    <Navbar title="报修工单详情" canBack></Navbar>
    <view class="basisCardCss mr10">
      <basisCellCard title="报修信息" :list="repairInfoList"></basisCellCard>
    </view>
    <view class="otherCardCss mr10">
      <basisCellCard title="下单信息" :list="orderInfoList"></basisCellCard>
    </view>
    <view class="otherCardCss mr10" v-if="pageType == '已处理'">
      <basisCellCard title="维修结果" :list="repairResultList"></basisCellCard>
    </view>
    <view class="otherCardCss mr10" v-if="pageType == '已处理'">
      <basisCellCard title="维修人员信息" :list="repairPeopleInfoList"></basisCellCard>
    </view>
  </view>
</template>

<script>
import basisCellCard from '@/components/basisCellCard/basisCellCard'
export default {
  name:'repairDetailInfo',
  components: {
    basisCellCard
  },
  data() {
    return {
      repairInfoList: [{
        name: '报修类型',
        value: 'QP5465641',
        key: 'fBxlx',
      }, {
        name: '问题描述',
        value: '',
        key: 'fWtms',
      },{
        name: '问题图片',
        type:'photoList',
        value: [],
        key: 'fWttp',
      }, {
          name: '状态',
          value: '',
          key: 'fZt',
      },{
          name: '上报时间',
          value: '',
          key: 'fXdsj',
      },{
        name: '处理时间',
        value: '',
        key: 'fWxsj',
      }],
      orderInfoList: [{
        name: '工单号',
        value: '无异常',
        key: 'fGdh',
      }, {
        name: '订单类型',
        value: '无异常',
        key: 'fGdlx',
      }, {
        name: '下单时间',
        value: '无异常',
        key: 'fXdsj',
      }, {
        name: '联系人',
        value: '无异常',
        key: 'fLxr',
      }, {
        name: '联系方式',
        value: 'QYYG-20240301009',
        key: 'fLxrdh',
      }, {
        name: '联系地址',
        value: '',
        key: 'fLxdz',
      }],
      repairResultList: [{
        name: '事件情况',
        value: '未泄露',
        key: 'fWxjgms',
      }, {
        name: '上报时间',
        value: '正常',
        key: 'fWxsj',
      }, {
        name: '问题描述',
        value: '20L',
        key: 'fWxjgbz',
      }, {
        name: '问题照片',
        value:[],
        type:'photoList',
        key: 'fWxjgtp',
      }],
      repairPeopleInfoList:[{
        name: '姓名',
        value: '无',
        key: 'fWxrxm',
      },{
        name: '联系',
        value: '无',
        key: 'fWxrlxdh',
      }],
      qpData: {},
      repairOrderId: "",
      query: {},
      pageType:'待处理'
    };
  },
  onLoad(data) {
    if(data.id){
      this.repairOrderId = data.id
    }
    if(data.type){
      this.pageType = data.type
    }
    this.getQpxxData();
  },
  methods: {
    async getQpxxData() {
      let query = {
        id:this.repairOrderId
      }
      const result = await this.$api.repairOrderApi.getRepairDetail(query);
      let {code, value} = result;
      if (code === 200) {
        let photoList = JSON.parse(value.fWttp);
        let photoArray = [];
        photoList.map( async (item)=>{
          let photoItem = await this.$getPhotoUrl(item.response.fileId);
          photoArray.push({
            type:'photoList',
            url:photoItem,
            fileId:item.response.fileId
          })
        })
        value.fWttp = photoArray;
        value.fLxdz= value.fLxdzsf +' '+ value.fLxdzs +' '+value.fLxdzq+' '+ value.fLxdzjd +' ' + value.fLxdzxxdz;
        this.repairInfoList = await this.$assignValues(value,this.repairInfoList);
        this.orderInfoList = await  this.$assignValues(value,this.orderInfoList);
        if(this.pageType == '已处理'){
          let clphotoList = JSON.parse(value.fWxjgtp);
          let clphotoArray = [];
          clphotoList.map( async (item)=>{
            let photoItem = await this.$getPhotoUrl(item.response.fileId);
            clphotoArray.push({
              type:'photoList',
              url:photoItem,
              fileId:item.response.fileId
            })
          });
          value.fWxjgtp = clphotoArray;
          this.repairResultList = await this.$assignValues(value,this.repairResultList);
          this.repairPeopleInfoList = await this.$assignValues(value,this.repairPeopleInfoList);
        }else{
          this.repairInfoList=this.repairInfoList.filter(item=>{
            return item.name != '处理时间'
          })
        }
        console.log('打印this.repairInfoList',this.repairInfoList)
      }
    }
  }
}
</script>

<style lang="scss">
.container {
  padding-bottom: 10px;
}

.mr10 {
  margin: 10px;
}
</style>
