<template>
  <view>
    <Navbar title="用户拜访/收费详情" canBack></Navbar>
    <view class="bg-white">
      <u-tabs :list="list" :current="current" :itemStyle="itemStyle" @click="onchange" lineColor="#EC1E19"
        lineWidth="25"></u-tabs>
    </view>
    <basisCellCard class="margin-sm" title="基本信息" :list="dataList" v-if="current === 0"></basisCellCard>
    <basisCellCard class="margin-sm" title="拜访信息" :list="bfDataList" v-if="current === 1"></basisCellCard>
    <basisCellCard class="margin-sm" title="决策人信息" :list="jcrDataList" v-if="current === 2"></basisCellCard>
    <basisCellCard class="margin-sm" title="收费信息" :list="sfDataList" v-if="current === 3"></basisCellCard>
    <basisCellCard class="margin-sm" title="附件" v-if="current === 0 && fileList.length">
      <view class="attachmentCss" v-if="fileList.length">
        <view class="flexCss" v-for="(item,index) in fileList" :key="index">
          <view class="leftCss overflow-one-lines">
            <view class="textCss overflow-one-lines">{{item.fileName}}</view>
          </view>
          <view class="rightCss">
            <view @click="viewAttachments(item.url)">查看</view>
          </view>
        </view>
      </view>
    </basisCellCard>
  </view>
</template>

<script>
  import {
    getMcFileList
  } from '@/api/charge.js'
  import basisCellCard from '@/components/basisCellCard/basisCellCard.vue'
  export default {
    components: {
      basisCellCard,
    },
    props: {

    },
    data() {
      return {
        current: 0,
        list: [{
          name: '基本信息',
        }, {
          name: '拜访信息',
        }, {
          name: '决策人信息'
        }, {
          name: '收费信息'
        }],
        itemStyle: {
          padding: '0',
          marginBottom: '5px',
          fontSize: '12rpx',
          width: '25%',
          height: '30px',
        },
        objData: {},
        dataList: [{
          name: "财年",
          value: "",
          key: "fiscalYear"
        }, {
          name: "收费人员",
          value: "",
          key: "billingPersonName"
        }, {
          name: "兼职/全职",
          value: "— —",
          key: "jobNature",
          dict:"sys_mc_job_nature"
        }, {
          name: "入户时间",
          value: "— —",
          key: "entryTime",
          mode:'time',
        }, {
          name: "项目公司/部门",
          value: "— —",
          key: "companyName"
        }, {
          name: "村(小区)",
          value: "— —",
          key: "vlgOrCmty"
        }, {
          name: "户名",
          value: "— —",
          key: "userName"
        }, {
          name: "联系方式",
          value: "— —",
          key: "userPhone"
        }, {
          name: "省/市/区/街道",
          value: "— —",
          key: "address"
        }, {
          name: "详细地址",
          value: "— —",
          key: "userDetailedAddress"
        }, {
          name: "备注",
          value: "— —",
          key: "remark"
        }],
        bfDataList:[
          {
            name: "是否有意向",
            value: "",
            key: "isIntent",
            dict:'sys_yes_no'
          },{
            name: "房屋情况",
            value: "",
            key: "houseCondition"
          },{
            name: "现用做饭能源",
            value: "",
            key: "currentCookingEnergy"
          },{
            name: "现用取暖能源",
            value: "",
            key: "currentHeatingEnergy"
          },{
            name: "家庭人口情况",
            value: "",
            key: "familyMembers"
          },{
            name: "电冰箱",
            value: "",
            key: "fridgeStatus"
          },{
            name: "空调",
            value: "",
            key: "acStatus"
          },{
            name: "电视",
            value: "",
            key: "tvStatus"
          },{
            name: "洗衣机",
            value: "",
            key: "washerStatus"
          },{
            name: "热水器",
            value: "",
            key: "waterHeaterStatus"
          },{
            name: "光伏",
            value: "",
            key: "pvSystemStatus"
          },
        ],
        jcrDataList:[
          {
            name: "决策人年龄",
            value: "",
            key: "dmAge"
          },{
            name: "决策人收入来源",
            value: "",
            key: "dmIncomeSrc",
            dict:"sys_mc_visit_dm_income",
          },{
            name: "决策人联系方式",
            value: "",
            key: "dmPhone"
          }
        ],
        sfDataList:[
          {
            name: "用户编号",
            value: "",
            key: "userCode"
          },{
            name: "身份证号",
            value: "",
            key: "userIdCard"
          },{
            name: "票据单号",
            value: "",
            key: "invoiceNo"
          },{
            name: "收费金额(元)",
            value: "",
            key: "chargeAmt"
          },{
            name: "缴费方式",
            value: "",
            key: "paymentMeth",
            dict:"sys_mc_payment_meth",
          },{
            name: "收费类型",
            value: "",
            key: "chargeType",
            dict:"sys_mc_charge_type",
          },
        ],
        fileList: []
      }
    },
    computed: {

    },
    onLoad(data) {
      if (data.objData) {
        this.objData = JSON.parse(data.objData);
        console.log('传递data', JSON.parse(JSON.stringify(this.objData)));
        this.dataList = this.$assignValues(this.objData, this.dataList);
        this.bfDataList = this.$assignValues(this.objData, this.bfDataList);
        this.jcrDataList = this.$assignValues(this.objData, this.jcrDataList);
        this.sfDataList = this.$assignValues(this.objData, this.sfDataList);
        console.log("收费信息", this.sfDataList);
        this.dataList.map(item => {
          if (item.key === 'address') {
            item.value =
              `${this.objData.userProvince}${this.objData.userCity}${this.objData.userDistrict}${this.objData.userStreet}`
          }
        })
      }
      this.initData()
    },
    methods: {
      onchange(e) {
        console.log(e);
        this.current = e.index;
      },
      initData() {
        let uuid = this.objData.attachmentFile;
        console.log(uuid);
        if (uuid) {
          let uuids = uuid.split(",");
          let data = {
            uuids: uuids
          }
          getMcFileList(data).then(res => {
            if (res.code === 200) {
              this.fileList = res.data
            }
          })
        }
      },
      viewAttachments(urls) {
        console.log(urls);
        uni.getSystemInfo({
          success: function(res) {
            var platform = res.platform.toLowerCase();
            console.log(platform);
            // 如果是安卓设备
            if (platform === 'android' || platform === 'windows') {
              window.open(urls, '_blank');
            }
            // 如果是 iOS 设备
            else if (platform === 'ios') {
              window.location.href = urls
            }
          }
        });
      }
    }
  }
</script>

<style lang="scss" scoped>
  .attachmentCss {
    margin-top: 38rpx;
    padding: 20rpx;
    border-radius: 10px;
    background-color: #f8f9fd;
    box-sizing: border-box;
  }

  .flexCss {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 32rpx 0;
  }

  .leftCss {
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }

  .textCss {
    width: 466rpx;
    height: 35rpx;
    margin: 0 4px;
    background-color: rgba(255, 255, 255, 0);
    box-sizing: border-box;
    font-family: '苹方 中等', '苹方', sans-serif;
    color: #999db0;
    text-align: left;
    line-height: normal;
    font-size: 26rpx;
  }

  .rightCss {
    width: 60rpx;
    height: 35rpx;
    display: flex;
    background-color: rgba(255, 255, 255, 0);
    box-sizing: border-box;
    font-family: '苹方 中等', '苹方', sans-serif;
    color: #ff5630;
    text-align: left;
    font-size: 26rpx;
  }
</style>
