<template>
  <div>
    <van-form @submit="onSubmit">
      <table>
        <tr>
          <td>
            <mobile-input :formatter="formatter" :rules="[{ validator: testFloat, message: '必须为正整数或者小数' }]" :required="true" type="number" format-trigger="reset" v-model="noManufacturingObject.GPM"
                          label="销售毛利率(%)" size="small" />
          </td>
          <td>
            <mobile-input :formatter="formatter" :rules="[{ validator: testFloat, message: '必须为正整数或者小数' }]" :required="true" format-trigger="reset" v-model="noManufacturingObject.ROE" type="number" label="净资产收益率(%)"
                          size="small" />
          </td>
        </tr>
        <tr>
          <td>
            <mobile-input :formatter="formatter" :rules="[{ validator: testFloat, message: '必须为正整数或者小数' }]" :required="true" type="number" format-trigger="reset" v-model="noManufacturingObject.ASSET"
                          label="资产负债率(%)" size="small" />
          </td>
          <td>
            <mobile-input :formatter="formatter" :rules="[{ validator: testFloat, message: '必须为正整数或者小数' }]" :required="true" format-trigger="reset"
                          v-model="noManufacturingObject.EARNED" label="已获利息倍数" type="number" size="small" />
          </td>
        </tr>
        <tr>
          <td>
            <mobile-input :formatter="formatter" :rules="[{ validator: testFloat, message: '必须为正整数或者小数' }]" :required="true" format-trigger="reset"
                          v-model="noManufacturingObject.InterBearing" type="number" label="有息负债率(%)" size="small" />
          </td>
          <td>
            <mobile-input :formatter="formatter" :rules="[{ validator: testFloat, message: '必须为正整数或者小数' }]" :required="true" format-trigger="reset"
                          v-model="noManufacturingObject.ACCRECETRUN" type="number" label="应收账款周转率(%)" size="small" />
          </td>
        </tr>
        <tr>
          <td>
            <mobile-input :formatter="formatter" :rules="[{ validator: testFloat, message: '必须为正整数或者小数' }]" :required="true" format-trigger="reset" v-model="noManufacturingObject.DEPTURN"
                          label="存款周转率(%)" type="number" size="small" />
          </td>
          <td>
            <mobile-input :formatter="formatter" :rules="[{ validator: testFloat, message: '必须为正整数或者小数' }]" :required="true" format-trigger="reset"
                          v-model="noManufacturingObject.FAT" type="number" label="固定资产周转率(%)" size="small" />
          </td>
        </tr>
        <tr>
          <td>
            <mobile-input :formatter="formatter" :rules="[{ validator: testFloat, message: '必须为正整数或者小数' }]" :required="true" format-trigger="reset" v-model="noManufacturingObject.ITR"
                          label="存货周转率(%)" type="number" size="small" />
          </td>
          <td>
            <mobile-input :formatter="formatter" :required="true" type="number" format-trigger="reset" v-model="noManufacturingObject.SARE"
                          label="销售收入(元)" size="small" />
          </td>
        </tr>
        <tr>
          <td>
            <mobile-input :formatter="formatter" :rules="[{ pattern, message: '年限为整数' }]" :required="true" format-trigger="reset" v-model="noManufacturingObject.ESYEAR"
                          label="成立年限" type="digit" size="small" />
          </td>
          <td>
            <mobile-input :formatter="formatter" :rules="[{ validator: testFloat, message: floatMsg }]" :required="true" format-trigger="reset" v-model="noManufacturingObject.TASS"
                          label="总资产(元)" type="digit" size="small" />
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <mobile-input :required="true" :rules="[{ validator: testFloat, message: floatMsg }]" :formatter="formatter" format-trigger="reset" v-model="noManufacturingObject.NASS"
                          label="净资产(元)" type="number" size="small" />
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <div style="margin: 16px; display: flex; justify-content: space-around">
              <van-button @click="reset" style="width: 25%" round color="#999999" native-type="button" plain>重置</van-button>
              <van-button style="width: 25%" round type="info" native-type="submit">试算</van-button>
            </div>
          </td>
        </tr>
      </table>
    </van-form>
    <van-dialog
      :show-cancel-button="false"
      :show-confirm-button="false"
      :close-on-click-overlay="true"
      v-model="showDialogReject"
    >
      <div class="dialog-box" style="position: relative">
        <div class="dialog-title">测算结果</div>
        <div class="score-box">{{ totalScore }}</div>
        <svg class="icon icon-img" aria-hidden="true">
          <use xlink:href="#icon-a-cepingjieguo110x110ziyuan40"></use>
        </svg>
        <van-button class="submitstyle3" block native-type="button" @click="showDialogReject = false">
          知道了
        </van-button>
      </div>
    </van-dialog>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import systemApi from "@/constants/api/ms-system/system.api.ts";
import IF from "@/public/factory/InterFaceFactory";
import { NativeUI } from "@/public/ts/NativeUI";

/**
 * @Description 非制造业试算
 * @Author 王航
 * @Date 2022-2-23 下午 04:32
 */
@Component({
  name: "NoManufacturingTrial"
})
export default class NoManufacturingTrial extends Vue {
  noManufacturingObject:any = {
    //非制造业对象
    GPM: '', //销售毛利率
    ROE: '', //净资产收益率
    ASSET: '', //资产负债率
    EARNED: '', //已获息倍数
    InterBearing: '', //有息负债率
    ACCRECETRUN: '', //应收账款周转率
    DEPTURN: '', //存款周转率
    FAT: '', //固定资产周转率
    ITR: '', //存货周转率
    SARE: '', //销售收入
    ESYEAR: '', //成立年限
    TASS: '', //总资产
    NASS: '' //净资产
  };
  pattern = /^[1-9]\d*$/; //整数校验
  totalScore:any= ''; //总分数
  showDialogReject= false;
  floatMsg= ''; //浮点数验证信息

  formatter() {
  }

  onSubmit(values: any) {
    // console.log("submit", values);
    this.selectCompanyComputeInfo();
  }
  selectCompanyComputeInfo() {
    let param = {
      GPM: this.noManufacturingObject.GPM, //销售毛利率
      ROE: this.noManufacturingObject.ROE, //净资产收益率
      ASSET: this.noManufacturingObject.ASSET, //资产负债率
      EARNED: this.noManufacturingObject.EARNED, //已获息倍数
      InterBearing: this.noManufacturingObject.InterBearing, //有息负债率
      ACCRECETRUN: this.noManufacturingObject.ACCRECETRUN, //应收账款周转率
      DEPTURN: this.noManufacturingObject.DEPTURN, //存款周转率
      FAT: this.noManufacturingObject.FAT, //固定资产周转率
      ITR: this.noManufacturingObject.ITR, //存货周转率
      SARE: this.noManufacturingObject.SARE, //销售收入
      ESYEAR: this.noManufacturingObject.ESYEAR, //成立年限
      TASS: this.noManufacturingObject.TASS, //总资产
      NASS: this.noManufacturingObject.NASS, //净资产
      COMTYPE: '1' //0表示制造业企业，1表示非制造业
    };
    NativeUI.showWaiting('正在查询...');
    return IF.transferDataInter(systemApi.companyMoneyComputed, param).then((res:any) => {
      NativeUI.closeWaiting();
      if (res.code == 1) {
        this.totalScore = res.data.totalAch; //总分
        console.log(this.totalScore);
        this.showDialogReject = true;
      } else {
        NativeUI.toast(res.message);
      }
    });
  }

  formatDate(date: any) {
    return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
  }

  reset() {
    this.noManufacturingObject.GPM = '';
    this.noManufacturingObject.ROE = '';
    this.noManufacturingObject.ASSET = '';
    this.noManufacturingObject.EARNED = '';
    this.noManufacturingObject.InterBearing = '';
    this.noManufacturingObject.ACCRECETRUN = '';
    this.noManufacturingObject.DEPTURN = '';
    this.noManufacturingObject.FAT = '';
    this.noManufacturingObject.ITR = '';
    this.noManufacturingObject.SARE = '';
    this.noManufacturingObject.ESYEAR = '';
    this.noManufacturingObject.TASS = '';
    this.noManufacturingObject.NASS = '';
  }
  testFloat(val:any) {
    if (parseFloat(val) < 0) {
      // this.floatMsg = '必须为正数';
      return false;
    } else {
      // this.floatMsg = '必须为整数或者小数';
      return /^(-?\d+)(\.\d+)?$/.test(val);
    }
  }
}
</script>

<style scoped>
table {
  width: 90%;
  margin: 0 auto;
}

::v-deep .van-button--info {
  background-color: #fd5065;
  border: 1px solid #fd5065;
}

::v-deep .van-button__text {
  font-size: 16px;
}
.dialog-box {
  margin: 0 auto;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 300px;
  height: 306px;
}
.icon-img {
  width: 120px;
  height: 120px;
  margin-top: 20px;
  margin-bottom: 20px;
  color: rgb(17, 167, 30);
}
.dialog-title {
  font-weight: bold;
  margin-top: 10%;
  font-size: 16px;
  color: #333;
}
.score-box {
  position: absolute;
  font-size: 36px;
  font-weight: 400;
  top: 105px;
  z-index: 999;
  color: #f59a23;
}
.submitstyle3 {
  width: 268px;
  height: 36px;
  border-radius: 6px;
  margin-top: 30px;
  color: #fff;
  background-color: #ff574c;
  border-color: #ff574c;
  font-size: 16px;
  text-align: center;
  font-weight: 400;
}
</style>
