<template>
  <div style="margin-left: 20px">
    <h3>放弃承诺书信息填写：</h3>
    <br />

    本人：
    <!-- <el-input v-model="form.waiverOfAgreementJson.boxA"></el-input> -->
    <el-select v-model="person" @change="handleChange">
      <el-option
        v-for="item in persons"
        :key="item.idCard"
        :value="item"
        :label="item.name"
      ></el-option>
    </el-select>
    ，性别：<el-select v-model="form.waiverOfAgreementJson.boxB">
      <el-option label="男" value="男">男</el-option>
      <el-option label="女" value="女">女</el-option>
    </el-select>
    身份证：<el-input
      disabled
      v-model="form.waiverOfAgreementJson.boxC"
      style="width: 200px"
    ></el-input
    >，在本次<el-input v-model="form.waiverOfAgreementJson.boxD"></el-input
    >街道<el-select
      v-model="form.waiverOfAgreementJson.boxE"
      style="width: 200px"
    >
      <el-option
        v-for="item in projectOptions"
        :key="item.id"
        :value="item.name"
      ></el-option> </el-select
    >项目房票安置中，房票安置转换协议（编号：<el-input
      v-model="form.waiverOfAgreementJson.boxF"
    ></el-input
    >）中约定总安置补偿款总计为<el-input
      v-model="form.waiverOfAgreementJson.boxG"
      @blur="formatChinese(form.waiverOfAgreementJson.boxG, 'boxH')"
    ></el-input
    >元（大写：<el-input
      disabled
      v-model="form.waiverOfAgreementJson.boxH"
      class="daxie"
    ></el-input
    >元整）。根据房票安置转换协议中第四款第3条之约定：为确保乙方依法得到房屋安置，不因房屋拆迁影响居住条件，乙方获得的安置补偿款须用于购买商品房，且选购的商品房价款不因房源户型限制而低于安置补偿款的90%。安置补偿款监管使用协议中选购商品房（含车位）的总价款为<el-input
      v-model="form.waiverOfAgreementJson.boxI"
      @blur="formatChinese(form.waiverOfAgreementJson.boxI, 'boxJ')"
    ></el-input
    >元（大写：<el-input
      disabled
      v-model="form.waiverOfAgreementJson.boxJ"
      class="daxie"
    ></el-input
    >元整），低于房票安置协议约定的90%，差价部分<el-input
      v-model="form.waiverOfAgreementJson.boxK"
      @blur="formatChinese(form.waiverOfAgreementJson.boxK, 'boxL')"
    ></el-input
    >元（大写：<el-input
      disabled
      v-model="form.waiverOfAgreementJson.boxL"
      class="daxie"
    ></el-input
    >元整）未使用，本户自愿放弃，对差价部分不再提出任何主张。 承诺人：
    <!-- <el-input
      v-model="form.waiverOfAgreementJson.boxM"
    ></el-input> -->
    日期：<el-input v-model="form.waiverOfAgreementJson.boxN"></el-input
    >年<el-input v-model="form.waiverOfAgreementJson.boxO"></el-input
    >月<el-input v-model="form.waiverOfAgreementJson.boxP"></el-input>日
    <!-- <el-select v-model="form.applicationJson.boxA">
      <el-option value="胜利" label="胜利"></el-option>
      <el-option value="高桥" label="高桥"></el-option>
    </el-select>
    街道办事处： 本人<el-input v-model="form.applicationJson.boxB"></el-input
    >（身份证号<el-input
      style="width: 180px"
      v-model="form.applicationJson.boxC"
    ></el-input
    >）是内江市东兴<el-input v-model="form.applicationJson.boxD"></el-input
    >街道<el-input v-model="form.applicationJson.boxE"></el-input>社区<el-input
      v-model="form.applicationJson.boxF"
    ></el-input
    >组在
    <el-input v-model="form.applicationJson.boxG"></el-input
    >项目的被安置对象的户主。我户与内江<el-input
      v-model="form.applicationJson.boxH"
    ></el-input
    >区<el-input v-model="form.applicationJson.boxI"></el-input
    >街道办事处于<el-input v-model="form.applicationJson.boxJ"></el-input
    >年<el-input v-model="form.applicationJson.boxK"></el-input>月
    <el-input v-model="form.applicationJson.boxL"></el-input
    >日签订《统一建房拆迁安置协议》，现我户<el-input
      v-model="form.applicationJson.boxM"
    ></el-input
    >人（分别是<el-input v-model="form.applicationJson.boxN"></el-input>
    ），自愿申请整户参加房票安置，并配合有关部门办理以下事项：
    一、我户自愿按照《内江高新区房票安置实施办法》的规定选择房票安置方式，并签订相关协议，以替换原签订的《统一建房拆迁安置协议》。
    二、我户自愿申请并到指定办理点签订《房票安置转换协议》，在内江市住房城乡建设局审核通过后，并在“甜城房产超市”网上“房票安置房源专栏”公布的高新区范围内房源库中自主选购商品房，并与商品房销售商签订《商品房买卖合同》。
    三、我户选购的商品房的总价不低于安置补偿款（不含超期过渡费）的90%。
    <br />
    申请人（签字按手印）：<el-input
      v-model="form.applicationJson.boxO"
    ></el-input>
    <br />
    <el-input v-model="form.applicationJson.boxP"></el-input>年<el-input
      v-model="form.applicationJson.boxQ"
    ></el-input
    >月<el-input v-model="form.applicationJson.boxR"></el-input>日
    <br /> -->
    <br />
    <el-button @click="preView">预览申请书</el-button>
  </div>
</template>

<script>
import { list } from "@/api/project";
import { info } from "@/api/ticket";
import { phase321 } from "@/api/housingTicket";
export default {
  data() {
    return {
      form: {
        id: undefined,
        waiverOfAgreementContent: undefined,
        waiverOfAgreementJson: {
          boxA: undefined,
          boxB: undefined,
          boxC: undefined,
          boxD: undefined,
          boxE: undefined,
          boxF: undefined,
          boxG: undefined,
          boxH: undefined,
          boxI: undefined,
          boxJ: undefined,
          boxK: undefined,
          boxL: undefined,
          boxM: undefined,
          boxN: undefined,
          boxO: undefined,
          boxP: undefined,
        },
      },
      projectOptions: [],
      person: undefined,
      persons: [],
    };
  },
  created() {
    this.getInfo();
    let info = JSON.parse(sessionStorage.getItem("fqcnsInfo"));
    this.form.id = this.$route.query.id;
    this.getList();
  },
  methods: {
    preView() {
      //   this.$router.push("preStepPreview");
      localStorage.setItem("fqcns", JSON.stringify(this.form));
      //   this.form = JSON.parse(localStorage.getItem("ticket"));
      let routeData = this.$router.resolve({ path: "/fqcns" });
      window.open(routeData.href, "_blank");
    },
    getInfo() {
      info({ id: this.$route.query.id }).then((res) => {
        this.persons = res.d.jiaFContent;
      });
      phase321({ ticketId: this.$route.query.id }).then((res) => {
        console.log(res);
        this.form.waiverOfAgreementJson = res.d;
      });
    },
    handleChange(item) {
      console.log(item);
      this.form.waiverOfAgreementJson.boxA = item.name;
      this.form.waiverOfAgreementJson.boxC = item.idCard;
    },
    getList() {
      list({ current: 1, size: 999999 }).then((res) => {
        this.projectOptions = res.d.records;
      });
    },
    formatChinese(val, key) {
      console.log(val, key);
      this.form.waiverOfAgreementJson[key] = this.numberParseChina(val);
    },
    numberParseChina(money) {
      //汉字的数字
      var cnNums = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
      //基本单位
      var cnIntRadice = ["", "拾", "佰", "仟"];
      //对应整数部分扩展单位
      var cnIntUnits = ["", "万", "亿", "兆"];
      //对应小数部分单位
      var cnDecUnits = ["角", "分", "毫", "厘"];
      //整数金额时后面跟的字符
      var cnInteger = "整";
      //整型完以后的单位
      var cnIntLast = "圆";
      //最大处理的数字
      var maxNum = 999999999999999.9999;
      //金额整数部分
      var integerNum;
      //金额小数部分
      var decimalNum;
      //输出的中文金额字符串
      var chineseStr = "";
      //分离金额后用的数组，预定义
      var parts;
      if (money == "") {
        return "";
      }
      money = parseFloat(money);
      if (money >= maxNum) {
        //超出最大处理数字
        return "";
      }
      if (money == 0) {
        chineseStr = cnNums[0] + cnIntLast + cnInteger;
        return chineseStr;
      }
      //转换为字符串
      money = money.toString();
      if (money.indexOf(".") == -1) {
        integerNum = money;
        decimalNum = "";
      } else {
        parts = money.split(".");
        integerNum = parts[0];
        decimalNum = parts[1].substr(0, 4);
      }
      //获取整型部分转换
      if (parseInt(integerNum, 10) > 0) {
        var zeroCount = 0;
        var IntLen = integerNum.length;
        for (var i = 0; i < IntLen; i++) {
          var n = integerNum.substr(i, 1);
          var p = IntLen - i - 1;
          var q = p / 4;
          var m = p % 4;
          if (n == "0") {
            zeroCount++;
          } else {
            if (zeroCount > 0) {
              chineseStr += cnNums[0];
            }
            //归零
            zeroCount = 0;
            chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
          }
          if (m == 0 && zeroCount < 4) {
            chineseStr += cnIntUnits[q];
          }
        }
        chineseStr += cnIntLast;
      }
      //小数部分
      if (decimalNum != "") {
        var decLen = decimalNum.length;
        for (var i = 0; i < decLen; i++) {
          var n = decimalNum.substr(i, 1);
          if (n != "0") {
            chineseStr += cnNums[Number(n)] + cnDecUnits[i];
          }
        }
      }
      if (chineseStr == "") {
        chineseStr += cnNums[0] + cnIntLast + cnInteger;
      } else if (decimalNum == "") {
        chineseStr += cnInteger;
      }
      return chineseStr;
    },
  },
};
</script>

<style lang="scss" scoped>
.el-input {
  width: 100px;
  margin: 10px;
}
.el-select {
  width: 100px;
  margin: 10px;
}
.daxie {
  width: 200px;
}
</style>
