<template>
  <div>
    <!-- 表单 -->
    <u-form
      labelPosition="left"
      :model="formData"
      ref="addressForm"
      labelWidth="130"
      :labelStyle="{ fontWeight: 400, fontSize: '12px', color: 'rgba(15, 39, 75, 0.6)' }"
    >
      <!-- 工程名称 -->
      <u-form-item :label="label" borderBottom>
        <u-input
          v-model="formData.consName"
          disabled
          disabledColor="#fff"
          border="none"
          inputAlign="right"
          fontSize="12"
          style="font-weight: 500"
        />
      </u-form-item>
      <!-- 公司地址 -->
      <u-form-item label="单位地址" borderBottom>
        <u-input
          v-model="formData.address"
          disabled
          disabledColor="#fff"
          border="none"
          inputAlign="right"
          fontSize="12"
          style="font-weight: 500"
        />
      </u-form-item>
      <!-- 法定代表人 -->
      <u-form-item label="法人姓名" borderBottom>
        <u-input
          v-model="formData.corporateName"
          disabled
          disabledColor="#fff"
          border="none"
          inputAlign="right"
          fontSize="12"
          style="font-weight: 500"
        />
      </u-form-item>
      <!-- 项目负责人 -->
      <!-- <u-form-item label="项目负责人" borderBottom>
        <u-input
          v-model="formData.projectLeader"
          disabled
          disabledColor="#fff"
          border="none"
          inputAlign="right"
          fontSize="12"
          style="font-weight: 500"
        />
      </u-form-item> -->
      <!-- 联系方式 -->
      <u-form-item label="法人联系方式" borderBottom>
        <u-input
          v-model="formData.corporatePhone"
          disabled
          disabledColor="#fff"
          border="none"
          inputAlign="right"
          fontSize="12"
          style="font-weight: 500"
        />
      </u-form-item>
      <!-- 征信代码 -->
      <u-form-item label="社会统一征信征信代码" borderBottom>
        <u-input
          v-model="formData.socialUnifiedCreditCode"
          disabled
          disabledColor="#fff"
          border="none"
          inputAlign="right"
          fontSize="12"
          style="font-weight: 500"
        />
      </u-form-item>
    </u-form>

    <div v-if="isLeave">
      <Title title="离场原因" />
      <u--textarea v-model="formData.reason" height="105" disabled count/>
    </div>
  </div>
</template>

<script>
import Steps from 'pages/component/Steps'
import config from '@/config'
import { encryptCBC, decryptCBC } from '@/utils/aescbc'

export default {
  props: {
    isDetail: {
      type: Boolean,
      default: false
    },
    isLeave: {
      type: Boolean,
      default: false
    },
    isSubcontractor: {
      type: Boolean,
      default: false
    },
    params: {
      type: Object,
      default: () => {}
    }
  },
  components: { Steps },
  data() {
    return {
      label: '承包商单位名称',
      formData: {
        // 承包商名称
        consName: '',
        // 法定代表人
        corporateName: '',
        // 征信代码
        socialUnifiedCreditCode: '',
        // 项目负责人
        // projectLeader: '',
        // 联系方式
        corporatePhone: '',
        // 公司地址
        address: ''
      },
      // 企业资质
      enterpriseQualification: [],
      // 其他材料
      otherMaterials: [],
      // 离场原因
      leaveValue: '',
      // 审批记录
      ApprovalRecordList: []
    }
  },
  mounted() {
    if (this.isSubcontractor) {
      this.label = '分包商单位名称'
      this.getSubcontractorInfo()
    } else {
      this.label = '承包商单位名称'
      this.getContractorInfo()
    }
  },
  methods: {
    // 获取承包商详情
    getContractorInfo() {
      let params = {
        proId: this.params.proId,
        consUuid: this.params.consUuid
      }
      // console.log('🚀 ~ getContractorInfo ~ params:', params)

      // 加密
      params = encryptCBC(JSON.stringify(params))
      // const res = await getConsDetailsInfo(params)
      // console.log('🚀 ~ getContractorInfo ~ res:', res)
      uni.request({
        url: config.baseUrl + '/project/outsourcingPro/getConsDetailsInfo',
        data: params,
        method: 'post',
        header: {
          'Content-Type': 'application/json',
          Authorization: uni.getStorageSync('App-Token'),
          tokenType: 'APP'
        },
        success: res => {
          // console.log('🚀 ~ getContractorInfo ~ res:', decryptCBC(res.data.data))
          const data = JSON.parse(decryptCBC(res.data.data))
          // console.log('🚀 ~ getContractorInfo ~ data:', data)
          if (data) {
            this.formData = data
          }
        }
      })
    },
    // 获取分包商详情
    async getSubcontractorInfo() {
      let params = {
        proId: this.params.proId,
        consUuid: this.params.consUuid,
        supUuid: this.params.supUuid,
        subUuid: this.params.subUuid,
        uuid: this.params.uuid,
        taskId: this.params.taskId,
        procInstId: this.params.procInsId,
        finalCheck: this.params.finalCheck
      }
      console.log('🚀 ~ getContractorInfo ~ params:', params)
      // 加密
      params = encryptCBC(JSON.stringify(params))
      uni.request({
        url: config.baseUrl + '/project/outsourcingPro/getSubDetailsInfo',
        data: params,
        method: 'post',
        header: {
          'Content-Type': 'application/json',
          Authorization: uni.getStorageSync('App-Token'),
          tokenType: 'APP'
        },
        success: res => {
          const data = JSON.parse(decryptCBC(res.data.data))
          console.log('🚀 ~ getContractorInfo ~ data:', data)
          if (data) {
            this.formData = data
            this.formData.consName = data.subName
          }
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
