<template>
  <div>
    <div class="dialog-mask" @click="$emit('close-dialog')" v-show="dialogVisible"></div>
    <div class="dialog" v-show="dialogVisible">
      <div class="dialog-content">
        <div class="dialog-title">询价条</div>
        <div class="dialog-body">
         <div id="copy-container" class="textarea">
                     <div>物业名称：{{inquiryDetail.basic_info.building_name+inquiryDetail.basic_info.building_no+inquiryDetail.basic_info.unit_no}}</div>
                           <div>面积：{{inquiryDetail.basic_info.size}}m&sup2;</div>
                           <div>房屋用途：{{inquiryDetail.basic_info.usage_str}}</div>
                           <div>①评估价：</div>
                           <div>评估单价：{{number_format(inquiryDetail.basic_info.eva_unit_price)}} 元/m²</div>
                           <div>总值：{{number_format(inquiryDetail.basic_info.eva_total_value)}} 元</div>
             
             
                           <!-- 净值1、净值2 -->
                          <!-- <div v-if='inquiryDetail.bank_name === "中国建设银行" || inquiryDetail.bank_name === "珠海华润银行"'>-->
                           <div v-if='inquiryDetail.bank_name === "中国建设银行"'> 
                             <div v-if='inquiryDetail.basic_info.eva_net_value !== 0 && inquiryDetail.basic_info.eva_net_value !== "0.00" && inquiryDetail.eva_purpose !== "了解市场价值"'>净值1{{ (inquiryDetail.bank_name === "珠海华润银行")?"（扣全税）":""}}：{{number_format(inquiryDetail.basic_info.eva_net_value)}} 元</div>
                             <div v-if='inquiryDetail.basic_info.eva_net_value2 !== 0 && inquiryDetail.basic_info.eva_net_value2 !== "0.00" && inquiryDetail.eva_purpose !== "了解市场价值"' class='mb-10'>净值2{{ (inquiryDetail.bank_name === "珠海华润银行")?"（仅扣个税）":""}}：{{number_format(inquiryDetail.basic_info.eva_net_value2)}} 元</div>
                           </div>
             
                           <div v-if='inquiryDetail.bank_name === "珠海华润银行"'>
                             <div>主动交易净值：{{number_format(inquiryDetail.basic_info.eva_total_value)}} 元</div>
                             <div v-if='inquiryDetail.basic_info.eva_net_value !== 0 && inquiryDetail.basic_info.eva_net_value !== "0.00" && inquiryDetail.eva_purpose !== "了解市场价值"'>主动评估净值{{ (inquiryDetail.bank_name === "珠海华润银行")?"（扣全税）":""}} ：{{number_format(inquiryDetail.basic_info.eva_net_value)}} 元</div>
                             <div v-if='inquiryDetail.basic_info.eva_net_value2 !== 0 && inquiryDetail.basic_info.eva_net_value2 !== "0.00" && inquiryDetail.eva_purpose !== "了解市场价值"' class='mb-10'>被动动评估净值{{ (inquiryDetail.bank_name === "珠海华润银行")?"（仅扣个税）":""}} ：{{number_format(inquiryDetail.basic_info.eva_net_value2)}} 元</div>
                           </div>
             
                           <div
                             v-else-if='inquiryDetail.bank_name !== "中国建设银行" &&
                             inquiryDetail.basic_info.eva_net_value !== 0 &&
                             inquiryDetail.basic_info.eva_net_value !== "0.00" &&
                             inquiryDetail.eva_purpose !== "了解市场价值"'
                           >净值：{{number_format(inquiryDetail.basic_info.eva_net_value)}} 元</div>
             
                           <!-- 贷款金额 -->
                           <div v-if='inquiryDetail.eva_purpose !== "了解市场价值"'>贷款金额：{{number_format(inquiryDetail.basic_info.gross_value, 0)}} 元 {{inquiryDetail.returnPrices[0].tips !== '' && inquiryDetail.returnPrices[0].tips !== null && inquiryDetail.bank_name !== '北京银行' ? `(${inquiryDetail.returnPrices[0].tips})` : ''}}</div>
                           <div v-if='inquiryDetail.type == 1'>②二手房参考价：</div>
                           <div v-if='inquiryDetail.type == 1'>参考单价：{{number_format(inquiryDetail.returnPrices[0].guide_price)}} 元/m²</div>
                           <div v-if='inquiryDetail.type == 1'>参考总值：{{number_format((inquiryDetail.returnPrices[0].guide_price)*(inquiryDetail.returnPrices[0].size))}} 元</div>
                            <div v-if='(inquiryDetail.bank_name === "中国银行" && inquiryDetail.type == 1)|| inquiryDetail.bank_name === "珠海华润银行"'>参考净值：{{number_format(getGuideNetWorth())}} 元</div>
                           <div class='mb-10'>{{inquiryDetail.eva_purpose}}</div>
                           <div>（{{inquiryDetail.bank_name}}{{inquiryDetail.branch_bank_name}}）</div>
                           <div class='mb-10'>估价人员：{{inquiryDetail.appraiser_name}}</div>
                           <div>{{inquiryDetail.external_remarks}}</div>
           </div>
          <button class="copy-button" @click="copyToClipboard">复制到粘贴板</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    inquiryDetail: {
      type: Object,
      default: ''
    }
  },
  

  
  methods: {
	  
	  // 获取指导价净值
	  getGuideNetWorth()
	  {
		  let guideTotal = this.inquiryDetail.returnPrices[0].guide_price * this.inquiryDetail.basic_info.size; //参考净值总值
		  return guideTotal - this.inquiryDetail.returnPrices[0].total_guide_tax; // 指导价净值 = 指导价总值 - 指导价总税
	  },
	  
  	number_format( n ){
		const formatter = new Intl.NumberFormat('zh-CN', {
		//  style: 'currency',
		 // currency: 'CNY',
		});
		return formatter.format(n);
  	},
	
	 // 将cpoy-container的纯文本内容复制到手机剪贴板上
	  copyToClipboard() {
		  
		 let txt =  document.getElementById('copy-container').innerText;
		 console.log(txt)
		 this.$emit('close-dialog');
		 uni.setClipboardData({
		  data: txt,
		  success() {			 
			uni.showToast({
			  title: '已复制到剪贴板',
			  duration: 2000
			})
		  }
		})
	  }
	}
};
</script>

<style scoped>
.dialog-mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 999;
}

.dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 80%;
  height: 80%;
  transform: translate(-50%, -50%);
  background-color: #fff;
  border-radius: 10px;
  z-index: 1000;
}

.dialog-content {
  padding: 20px;
  box-sizing: border-box;
}

.dialog-title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 10px;
  text-align: center;
}

.dialog-body {
  display: flex;
  flex-direction: column;
}

.textarea {
  width: 100%;
  height: 100%;
  margin-bottom: 10px;
  padding: 10px;
  box-sizing: border-box;
  border: 1px solid #ccc;
  border-radius: 5px;
}

.copy-button {
  width: 180px;
  height: 45px;
  margin-left: auto;
  background-color: #409eff;
  vertical-align: bottom;
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}
</style>