<template>
  <div class="pointrent">
    <!-- 合同信息 -->
    <div class="layout-content">
      <div class="step">
        <!-- step -->
        <el-steps :active="active" finish-status="success" :align-center="true" class="fx_step">
          <el-step title="合同基本信息" class="first_title"></el-step>
          <el-step title="款项信息" class="second_title"></el-step>
          <el-step title="附件" class="third_title"></el-step>
        </el-steps>
        <div v-if="active==0">
          <el-form ref="form" :model="form" :rules="rules" label-width="130px">
            <!-- 选择信息 -->
            <div class="shopBox_choose" v-show="shopshow==false">
              <!-- <div class="shopBtn_choose" @click="!editIf?buluopenShopDialog():''">选择商户</div> -->
              <div class="shopBtn_choose" @click="buluopenShopDialog">选择商户</div>
            </div>
            <!-- <div class="shopBox" v-show="shopshow" @click="!editIf?buluopenShopDialog():''"> -->
            <div class="shopBox" v-show="shopshow" @click="buluopenShopDialog">
              <!-- <div class="shopBtn">{{!editIf?'切换商户':''}}</div> -->
              <div class="shopBtn">切换商户</div>
              <div class="shopContent">
                <div class="shoplist">
                  <div>
                    <i class="iconfont icon-iconshangpuguanli iconBox"></i>
                    {{ this.newshopTableData.shopNumber}}
                  </div>
                  <div>{{ this.newshopTableData.building}}</div>
                  <div>{{ this.newshopTableData.floor}}</div>
                  <div
                    :style="'color:'+[this.newshopTableData.status=='未出租'?'#EE7653':'#555']+' !important'"
                  >{{changeStatus(this.newshopTableData.status)}}</div>
                  <div>{{ this.newshopTableData.buildArea}} ㎡</div>
                  <div>{{getRent(this.newshopTableData)}}</div>
                </div>
                <div class="jiaojiao">
                  <img src="../../../static/images/jiaojiao.png" alt>
                </div>
              </div>
            </div>

            <!-- 合同信息 -->
            <div class="public_part">
              <div class="public_part_title">合同信息</div>
              <div class="public_part_Box">
                <el-form-item label="合同状态" prop="status" class="fx_send">
                  <el-select
                    v-if="!fromBulu"
                    :disabled="formdisabled"
                    v-model="form.status"
                    placeholder="请选择"
                    class="select-method"
                  >
                    <el-option
                      v-for="item in options"
                      :key="item.value"
                      :value="item.value"
                      :label="item.label"
                    ></el-option>
                  </el-select>
                  <el-input
                    v-else
                    disabled
                    value="合同补录"
                    style="width:211px;"
                  ></el-input>
                </el-form-item>
                <el-form-item label="合同编号" prop="contractNumber" class="fx_title">
                  <el-input
                    v-model="form.contractNumber"
                    placeholder="请输入合同编号"
                    class="edit-item-input"
                    maxlength="50"
                    clearable
                  ></el-input>
                </el-form-item>
                <el-form-item label="合同签约日" prop="signDate">
                  <el-date-picker
                    type="date"
                    placeholder="选择日期"
                    v-model="form.signDate"
                    :picker-options="pickerAfterdata"
                  ></el-date-picker>
                </el-form-item>
              </div>
            </div>

            <!-- 商户信息 -->
            <div class="public_part">
              <div class="public_part_title">商户信息</div>
              <div class="public_part_Box">
                <el-form-item label="商户名称" prop="merchantName" class="fx_title">
                  <el-input
                    :disabled="formdisabled"
                    v-model="form.merchantName "
                    placeholder="请输入商户名称"
                    class="edit-item-input"
                    maxlength="50"
                    clearable
                  ></el-input>
                </el-form-item>
                    <el-form-item label="合同主体名称" prop="" class="fx_title">
                <el-input
                  v-model="form.subjectName "
                  placeholder="合同中乙方主体名称"
                  maxlength="50"
                  clearable
                ></el-input>
              </el-form-item>
                <el-form-item label="经营品牌" prop="brand" class="fx_send">
                  <el-select
                    :disabled="form.brand==''?false:formdisabled"
                    v-model="form.brand"
                    placeholder="请先选择品牌"
                    class="select-method"
                  >
                    <el-option
                      v-for="(item,index) in brands"
                      :key="index"
                      :value="item.id"
                      :label="item.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="经营业态" prop="businessId" class="fx_send">
                  <el-select
                    :disabled="form.businessId==''?false:formdisabled"
                    v-model="form.businessId"
                    placeholder="请先选择经营业态"
                    class="select-method"
                  >
                    <el-option
                      v-for="(item,index) in businessIds"
                      :key="index"
                      :value="item.id"
                      :label="item.title"
                    ></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="店面类型" prop="shopType" class="fx_send">
                  <el-select
                    :disabled="form.shopType==''?false:formdisabled"
                    v-model="form.shopType	"
                    placeholder="请先选择店铺类型"
                    class="select-method"
                  >
                    <el-option
                      v-for="index in shopTypes"
                      :key="index.value"
                      :value="index.value"
                      :label="index.label"
                    ></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="联系人" prop="linkPerson" class="fx_title">
                  <el-input
                    :disabled="formdisabled"
                    v-model="form.linkPerson"
                    placeholder="请输入联系人"
                    class="edit-item-input"
                    maxlength="10"
                    clearable
                  ></el-input>
                </el-form-item>
                <el-form-item label="联系电话" prop="linkPhone" class="fx_title">
                  <el-input
                    :disabled="formdisabled"
                    type="text"
                    v-model="form.linkPhone"
                    placeholder="请输入手机号或座机号"
                    class="edit-item-input"
                    clearable
                    maxlength="20"
                  ></el-input>
                </el-form-item>
              </div>
            </div>
            <!-- 租赁信息 -->
            <div class="public_part">
              <div class="public_part_title">租赁信息</div>
              <div class="public_part_Box">
                <el-form-item label="租赁开始日期" prop="rentalStartDate">
                  <el-date-picker
                    type="date"
                    placeholder="选择日期"
                    v-model="form.rentalStartDate"
                    :picker-options="pickerOptions0"
                    @change="(value) => changeDates(value, 'rentalStartDate')"
                  ></el-date-picker>
                </el-form-item>
                <el-form-item label="租赁截止日期" prop="rentalEndDate">
                  <el-date-picker
                    type="date"
                    placeholder="选择日期"
                    v-model="form.rentalEndDate"
                    :picker-options="pickerOptions1"
                    @change="(value) => changeDates(value, 'rentalEndDate')"
                  ></el-date-picker>
                </el-form-item>
                <el-form-item label="总租期" class="width">
                  <span>{{form.totalPeriodMonth}}</span>个月
                  <span>{{form.totalPeriodDay}}</span>天
                </el-form-item>
                <el-form-item label="装修日期" prop="fixDate">
                  <el-date-picker
                    v-model="form.fixDate"
                    type="daterange"
                    style="width:400px!important;"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                  ></el-date-picker>
                </el-form-item>
                <el-form-item label="计租开始日期" prop="startDate">
                  <el-date-picker
                    type="date"
                    placeholder="选择日期"
                    v-model="form.startDate"
                    @change="comperData"
                  ></el-date-picker>
                </el-form-item>
                <el-form-item label="账单生成方式" prop="adjustPeriod">
                  <el-radio-group
                    v-model="form.adjustPeriod"
                    @change="setAdjustPeriod"
                    size="small"
                    style="margin-left:20px;"
                  >
                    <el-radio-button label="2" value="2">按计租日期</el-radio-button>
                    <el-radio-button label="3" value="3">按自然月</el-radio-button>
                  </el-radio-group>
                </el-form-item>
              </div>
            </div>
          </el-form>
        </div>
      </div>
    </div>
    <shop-list-dgnew
      :ref="tKeynew"
      :t-keynew="tKeynew"
      :shops-type="shopsType"
      :cbnew="getShopCbNew"
    ></shop-list-dgnew>
    <!-- 款项信息 -->
    <div v-if="active==1" class="layout-content">
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <div class="public_part">
          <div class="public_part_title">租金信息</div>
          <div class="public_part_Box">
            <el-form-item label="选择计算方式" prop="type" class="fx_send">
              <el-select
                :value="form.type"
                @input="changeFormData('type', $event)"
                placeholder="请先选择计算方式"
                class="select-method"
              >
                <el-option
                  v-for="index in computedTypes"
                  :key="index.value"
                  :value="index.value"
                  :label="index.label"
                ></el-option>
              </el-select>
            </el-form-item>
            <div>
              <el-form-item label="计租面积" prop="rentArea" class="fx_title numberInputBox">
                <el-input
                  type="number"
                  :value="form.rentArea"
                  @input="changeArea('rentArea', $event)"
                  placeholder="请输入计租面积"
                  maxlength="8"
                  clearable
                ></el-input>
                <span class="per">㎡</span>
              </el-form-item>
              <el-form-item label="租赁单价" prop="rentPrice" class="fx_title" v-if="this.form.type!=2">
                <el-radio-group
                  :value="form.priceUnit"
                  @input="changeFormData('priceUnit', $event)"
                  size="small"
                >
                  <el-radio-button
                    v-for="(item,index) in priceUnitOption"
                    :key="index"
                    :label="item.value"
                  >{{item.name}}</el-radio-button>
                </el-radio-group>
              </el-form-item>
              <el-form-item label prop="rentPrice" class="fx_title" v-if="this.form.type!=2">
                <el-input
                  :value="form.rentPrice"
                  @input="changeArea('rentPrice', $event)"
                  placeholder="请输入租赁单价"
                  maxlength="10"
                  clearable
                ></el-input>
                <span class="per">元/㎡</span>
              </el-form-item>
              <el-form-item label="租金" prop="price" class="fx_title" v-if="this.form.type!=2">
                <el-input v-model="form.price" placeholder="请输入租金金额" maxlength="10" clearable></el-input>
                <span class="per">元/{{changeUnitType}}</span>
              </el-form-item>
              <el-form-item label="保底营业额" prop="revenue" class="fx_title" v-if="this.form.type==2">
                <el-input v-model="form.revenue" placeholder="请输入保底营业额金额" maxlength="10" clearable></el-input>
                <span class="per">元/{{changeUnitType}}</span>
              </el-form-item>
              <!-- prop="payRatio" -->
              <el-form-item
                label="联营扣点率"
                v-if="this.form.type!=1"
                prop="payRatio"
                class="fx_title numberInputBox"
              >
                <el-input
                  type="number"
                  v-if="form.busDiscountRatio==''"
                  v-model="form.payRatio"
                  placeholder="请输入"
                  maxlength="10"
                  clearable
                ></el-input>
                <span v-if="form.busDiscountRatio==''" class="per" style="margin-right:30px;">%</span>
                <el-button @click="jumpRateSet" size="small" class="jump-rate-set" type="primary">跳点设置</el-button>
                <!-- ul -->
                <show-rate-list v-show="form.busDiscountRatio!=''"></show-rate-list>
                
              </el-form-item>
              <!-- <el-form-item label="联营扣点率" prop="payRatio" class="fx_title" v-if="this.form.type!=1">
                <el-input v-model="form.payRatio" placeholder="请输入" maxlength="10" clearable></el-input>
                <span class="per">%</span>
              </el-form-item> -->
              <el-form-item label="押金" prop="deposit" class="fx_title">
                <el-input v-model="form.deposit" placeholder="请输入押金金额" maxlength="10" clearable></el-input>
                <span class="per">元</span>
              </el-form-item>
              <el-form-item label="付款周期" prop="receivePeriod" class="paydata">
                <el-select
                  v-model="form.receivePeriod"
                  filterable
                  class="select-method innerinput"
                  style="width:150px"
                >
                  <el-option
                    v-for="index in cycles"
                    :key="index.value"
                    :value="index.value"
                    :label="index.label"
                  ></el-option>
                </el-select>
                <!-- <el-input-number
                  v-if="form.priceUnit==1"
                  :value="form.receivePeriod"
                  @input="changeFormData('receivePeriod', $event)"
                  controls-position="right"
                  :min="1"
                  :max="365"
                ></el-input-number> -->
                <span class="per">月</span>
              </el-form-item>
         <div v-if="isshowYear">
               <el-form-item v-if="months.length>0" label="年租金调整" class="fx_title" style="display:inline-block;">
               <el-radio-group
                   :value="form.adjustRatioWay"
                  @input="changeFormData('adjustRatioWay', $event)"
                  size="small"
                  style="margin-left:20px;" >
                  <el-radio-button label="1" value="1">比例上调</el-radio-button>
                  <el-radio-button label="2" value="2">固定上调</el-radio-button>
                  <el-radio-button label="3" value="3">自定义</el-radio-button>
                </el-radio-group>
                 <!-- <help title="" content="年租金调整为固定上调，请在输入框中输入需要上调的比例或金额"></help> -->
            </el-form-item>
            <div v-if="form.adjustRatioWay==1" class="per-list">
               <el-form-item
              v-for="index in months" :key="index" label="" :value="index" :prop="`adjustRatio[${index}]`" :rules="formvail.adjustRatio"  class="fx_title" style="display:inline-block;width:400px;">
              <el-input v-model="form.adjustRatio[index]" placeholder="调整比例" clearable >
                <template slot="prepend">第{{index+2}}年</template>
              </el-input>
              <span class="per">%</span>
              </el-form-item>
              </div>
              <div v-else class="per-list">
            <el-form-item 
              v-for="index in months" :key="index" label="" :value="index" :prop="`adjustRatio[${index}]`" :rules="formvail.adjustRatio1"  class="fx_title" style="display:inline-block;width:400px;">
              <el-input v-model="form.adjustRatio[index]" placeholder="调整金额" clearable>
                <template slot="prepend">第{{index+2}}年</template>
              </el-input>
             <span class="per">元/{{changeUnitType}}</span>
              </el-form-item>
               </div>
              </div>
            </div>
          </div>
          <el-row>
              <el-col :span="8">
                <el-form-item
                  label="滞纳金费率"
                  label-width="160px"
                  prop='latePayRatio'
                >
                  <el-input
                    style="width:150px"
                    v-model="form.latePayRatio"
                    placeholder="请输入"
                    maxlength="10"
                    clearable
                  ></el-input>
                  %
                </el-form-item>
              </el-col>
              <el-col :span="14">
                <el-form-item
                  label="欠缴后"
                  prop='latePayDay'
                >
                  <el-input
                    style="width:150px"
                    v-model="form.latePayDay"
                    placeholder="请输入"
                    maxlength="10"
                    clearable
                  ></el-input>
                  日开始计费
                  <help title content="例如：“0”为欠缴当天开始计滞纳金"></help>
                </el-form-item>
              </el-col>
            </el-row>
        </div>
        <div class="public_part">
          <div class="public_part_title">账户信息</div>
          <div class="public_part_Box">
            <el-form-item label="甲方接收账户" prop="payAccount" class="fx_title">
              <el-input v-model="form.payAccount " placeholder="请输入接收账户" maxlength="20" clearable></el-input>
            </el-form-item>
            <el-form-item label="开户行" prop="bankName" class="fx_title">
              <el-input v-model="form.bankName " placeholder="请输入开户行" maxlength="20" clearable></el-input>
            </el-form-item>
          </div>
        </div>
      </el-form>
    </div>
    <!-- 附件 -->
    <div class="layout-content" v-show="active==2">
      <!-- 合同上传 -->
      <el-form ref="form02" :model="form" :rules="rules" label-width="130px">
        <div class="public_part">
          <div class="public_part_title">合同租金明细</div>
          <div class="public_part_Box">
            <el-radio-group v-model="form.rentStartType" @change="submitMoney()" style="margin-bottom:20px;">
              <el-radio :label="1" border>按租赁开始日生成</el-radio>
              <el-radio :label="2" border>按计租日生成</el-radio>
            </el-radio-group>
            <rent-bill :data="billData" :id="form.id" :type='1' :ref="billTk"></rent-bill>
          </div>
        </div>
        <div class="public_part">
          <div class="public_part_title">附件</div>
          <div class="public_part_Box" style="width:800px;">
            <el-form-item label="合同文件：">
              <el-upload
                class="upload-demo fx_upload"
                drag
                action="/api/upload/awsFileUpload"
                :on-error="importError"
                :on-success="importSuccess"
                :on-remove="handleRemove"
                :file-list="fileNames"
                :beforeUpload="beforeUpload"
              >
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">
                  将文件拖到此处，或
                  <em>点击上传</em>
                </div>
              </el-upload>
            </el-form-item>
          </div>
          <div class="public_part_title" v-if="processData.length>0">合同审批</div>
          <div class="public_part_Box" style="width:800px;" v-if="processData.length>0">
            <el-form-item label="审批流程">
              <process-template :processData="processData"></process-template>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
              <el-input
                type="textarea"
                maxlength="150"
                v-model="form.remark"
                placeholder="请填写备注！"
                class="edit-item-input"
              ></el-input>
            </el-form-item>
          </div>
        </div>
      </el-form>
    </div>
    <div class="group-btn">
      <el-button class="quxiaoBtn" @click="goback" v-if="active!=0">返回上一步</el-button>
      <el-button class="quxiaoBtn" @click="cancel" v-show="iscancel">取消</el-button>
      <el-button class="baocunBtn" :loading="loading" @click="submit('form02')" v-if="active==2">保存</el-button>
      <el-button class="nextBtn" @click="next('form')" v-if="active!=2">下一步</el-button>
    </div>
    <!--  -->
    <jump-rate-set ref="jumpRateSetDialog"></jump-rate-set>
  </div>
</template>

<script>
import help from "../../help.vue";
import commonUtil from "../../../core/tool/commonUtil";

import shopListDgnew from "../contractComp/shopListDgnew.vue"; //补录合同
import moment from "moment";
import { mapState, mapActions } from "vuex";
import { deepcopy } from "../../../utils/validate";
import rentBill from "../contractutil/rentbill.vue";
import { ContractUrl } from "../businessComp/UrlEnum.js";
import { ContractData } from "../../../service/contract/data.js";
import processTemplate from "../contractutil/processTemplate.vue";
import jumpRateSet from '../rent/jumpRateSet.vue';
import showRateList from '../rent/showRateList.vue';
import { promissionUrl } from "../../../urlconfig/promission/url.js";
import Vue from "vue";
export default {
  components: {
    shopListDgnew,
    rentBill,
    processTemplate,
    help,
    jumpRateSet,
    showRateList,
  },
  name: "pointrentBulu",
  data() {
    return {
      ...mapActions(["setRentInfo", "setNavData", "setFormData"]),
      processData: [],
      loading: false,
      billTk: "rentbill",
      billData: null,
      editIf: false,
      pickerAfterdata: {
        // disabledDate(time) {
        //   return time.getTime() < Date.now() - 8.64e7; //限制只能选今天以后的日期
        // }
      },
      brands: [],
      fileNames: [],
      months: [],
      copelease: "", //总租期备份
      shopsType: "2",
      dateType: "月",
      isshowYear: true,
      tKey: "shopListDg",
      tKeynew: "shopListDgnew",
      active: 0,
      formdisabled: false,
      shopshow: false,
      iscancel: true,
      businessIds: [], //经营业态列表
      newshopTableData: {},
      priceUnitOption: ContractData.priceUnitOption,
      //来自补录还是编辑补录
      fromBulu: false,
      form: {
         adjustRatioWay:'1',//年物业费调整方式1、比例上调2、按固定上调
        operationType:1,
        rentStartType:1,
        rentPrice: 0,
        fixDate: [],
        rentShopType: 2,
        signDate: "", //合同签约日
        startDate: "", //起租日
        rentalStartDate: "", //租赁开始日期
        rentalEndDate: "", //租賃截止日期
        totalPeriodMonth: 0, //总租期（月）
        totalPeriodDay: 0, //总租期（天）
        priceUnit: "2",
        lease: "",
        shopTableData: [], //商铺信息列表
        brand: "", //商铺经营品牌
        subjectName:"",//合同主体名称
        merchantName: "", //商户名称
        contractNumber: "", //合同编号
        status: "", //合同状态
        linkPerson: "", //联系人
        linkPhone: "", //联系人电话
        rentArea: "", //计租面积
        shopType: "", //店铺类型
        zuqi: "", //计租日期
        price: "", //租金
        deposit: "", //押金
        receivePeriod: "", //付款周期
        payAccount: "", //支付账号
        payDate: "", //支付规则
        shopId: "", //商铺id
        filepath: "", //文件路径
        filename: "", //文件名称
        merchantId: "", //商户id
        businessId: "", //经营业态
        id: "",
        type: 1, //计算方式
        revenue: "", //营业额
        payRatio: "", //支付比例

        busDiscountRatio: "", //跳点信息
        busDiscountTime: 1, //时间计算类型123年月日
        adjustRatio: [], //上浮比例
        adjustPeriod: "2", //周期按天还是按月
        monthHandleType: "2",
        accountType: "", //支付账号类型
        bankName: "", //开户行
        latePayRatio:"",
        latePayDay:""
      },

      //合同状态
      options: [
        {
          value: 0,
          label: "意向"
        },
        {
          value: 1,
          label: "待签约"
        },
        {
          value: 8,
          label: "合同补录"
        }
      ],
      // 店铺类型
      shopTypes: ContractData.shopTypes,
      //计租计算方式
      computedTypes: ContractData.computedTypes,
      //周期浮动比例
      changeScale: [
        {
          value: 3,
          label: "3"
        },
        {
          value: 6,
          label: "6"
        },
        {
          value: 12,
          label: "12"
        }
      ],
      cycles: ContractData.cycles,
      formvail: {
        adjustRatio: [
          {
            required: true,
            message: "抱歉，不能识别您输入的浮动比例",
            trigger: "blur"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
              if (!reg.test(value)) {
                callback("抱歉，浮动比例限制为数字");
              } else if (value > 50) {
                callback("抱歉，浮动比例不能大于50%");
              }
              callback(errors);
            }
          }
        ],
        adjustRatio1:[
           {
            required: true,
            message: "抱歉，此项为必填项！",
            trigger: "blur"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
              console.log(value)
              if (!reg.test(value)||Number(value)>=10000000) {
                callback("抱歉，金额限制为大于0且小于9999999.99的最多保留两位小数的数字！");
              } 
              callback(errors);
            }
          }
        ]
      },
      rules: {
        latePayRatio: [
          {
            required: false,
            trigger: "blur"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
              if (!reg.test(value)&&value!='') {
                callback("抱歉，滞纳金费率限制为大于0且最多保留两位小数的数字");
              } else {
                if (typeof value == "string") {
                  if (Number(value)>100) {
                    callback("滞纳金费率最大值为100%");
                  }
                }
              }
              callback(errors);
            }
          }
        ],
        latePayDay: [
          {
            required: false,
            trigger: "blur"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              const reg = /^[0-9]+$/;
              if (!reg.test(value)&&value!='') {
                callback("抱歉，限制为0~1000的整数！");
              } else {
                if (typeof value == "string") {
                  if (Number(value)>1000) {
                    callback("抱歉，限制为0~1000的整数！");
                  }
                }
              }
              callback(errors);
            }
          }
        ],
        adjustPeriod: [
          {
            required: true,
            trigger: "change",
            message: "抱歉，请选择账单生成方式"
          }
        ],
        monthHandleType: [
          {
            required: true,
            trigger: "change",
            message: "抱歉，不能识别您选择的账单生成方式"
          }
        ],
        rentalStartDate: [
          {
            required: true,
            trigger: "change",
            message: "抱歉，不能识别您选择的租赁开始日期"
          }
        ],
        rentalEndDate: [
          {
            required: true,
            trigger: "change",
            message: "抱歉，不能识别您选择的租赁结束日期"
          }
        ],
        startDate: [
          {
            required: true,
            trigger: "change",
            message: "抱歉，不能识别您选择的计租开始日期"
          }
        ],
        signDate: [
          {
            required: true,
            trigger: "change",
            message: "抱歉，不能识别您选择的合同签约日"
          }
        ],
        revenue: [
          {
            required: true,
            pattern: /.+/,
            message: "抱歉，不能识别您输入的营业额",
            trigger: "blur"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              const reg = /(^[0-9]\d*(\.\d{1,2})?$)|(^1(\.\d{1,2})?$)/;
              if (!reg.test(value)) {
                callback("抱歉，营业额限制为数字");
              } else {
                if (typeof value == "string") {
                  if (value.split(".")[0].length > 7) {
                    callback("最大金额为9999999.99");
                  }
                }
              }
              callback(errors);
            }
          }
        ],
        lease: [
          {
            required: true,
            trigger: "blur",
            message: "抱歉，不能识别您输入的总租期"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              const reg = /^[0-9]*[1-9][0-9]*$/;
              if (value && !reg.test(value)) {
                callback("抱歉，总租期必须是正整数");
              }
              callback(errors);
            }
          }
        ],
        status: [
          {
            required: true,
            trigger: "change",
            message: "抱歉，不能识别您选择的合同状态"
          }
        ],
        businessId: [
          {
            required: true,
            trigger: "change",
            message: "抱歉，不能识别您选择的经营业态"
          }
        ],
        contractNumber: [
          {
            required: true,
            trigger: "blur",
            message: "抱歉，不能识别您输入的合同编号"
          }
        ],
        merchantName: [
          {
            required: true,
            trigger: "blur",
            message: "抱歉，不能识别您输入的商铺名称"
          }
        ],
        zuqi: [
          {
            required: true,
            trigger: "blur",
            message: "抱歉，不能识别您输入的总租期"
          }
        ],
        receivePeriod: [
          {
            required: true,
            trigger: "blur",
            message: "抱歉，不能识别您输入的付款周期"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              if (value < 1) {
                callback("抱歉，付款周期不能小于1");
              }
              callback(errors);
            }
          }
        ],
        payDate: [
          {
            required: true,
            trigger: "blur",
            message: "抱歉，不能识别您输入的支付规定"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              if (value > 31 || value < 1) {
                callback("抱歉，支付日期只能是1-31");
              }
              callback(errors);
            }
          }
        ],
        rentdata: [
          {
            required: true,
            trigger: "blur",
            message: "抱歉，不能识别您输入的交租日"
          }
        ],
        firstrentdata: [
          {
            required: true,
            trigger: "blur",
            message: "抱歉，不能识别您输入的首期款缴日期"
          }
        ],
        linkPhone: [
          {
            required: true,
            message: "抱歉，不能识别您输入的手机号哦!",
            trigger: "blur"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              var mobile = /^1[0|1|2|3|4|5|6|7|8|9]\d{9}$/,
                phone = /^0\d{2,3}-?\d{7,8}$/;
              if (value && !mobile.test(value) && !phone.test(value)) {
                callback("抱歉，请输入正确的手机号和座机号");
              }
              if (value && !mobile.test(value) && !phone.test(value)) {
                callback("抱歉，请输入正确的手机号和座机号");
              }
              callback(errors);
            }
          }
        ],
        // addr: [{
        //         required: true,
        //         message: '地址不能不能为空...',
        //         trigger: 'blur'
        // }],
        linkPerson: [
          {
            required: true,
            message: "抱歉，不能识别您输入的联系人",
            trigger: "blur"
          }
        ],
        buildArea: [
          {
            required: true,
            pattern: /.+/,
            message: "抱歉，不能识别您输入的建筑面积",
            trigger: "blur"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^1(\.\d{1,2})?$)/;
              if (!reg.test(value)) {
                callback("抱歉，建筑面积限制为大于0的数字");
              }
              callback(errors);
            }
          }
        ],
        rentArea: [
          {
            required: true,
            pattern: /.+/,
            message: "抱歉，不能识别您输入的计租面积",
            trigger: "blur"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
              if (!reg.test(value)) {
                callback("抱歉，计租面积限制为大于等于0的且最多保留两位小数");
              }else {
                if (typeof value == "string") {
                  if (value.split(".")[0].length > 7) {
                    callback("最大值为9999999.99");
                  }
                }
              }
              callback(errors);
            }
          }
        ],
        price: [
          {
            required: true,
            pattern: /.+/,
            message: "抱歉，不能识别您输入的租金金额",
            trigger: "blur"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              const reg = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
              if (!reg.test(value)) {
                callback("抱歉，租金金额限制为大于0的数字");
              } else {
                if (typeof value == "string") {
                  if (value.split(".")[0].length > 7) {
                    callback("最大金额为9999999.99");
                  }
                }
              }
              callback(errors);
            }
          }
        ],
        rentPrice: [
          {
            required: true,
            pattern: /.+/,
            message: "抱歉，不能识别您输入的租金单价",
            trigger: "blur"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              const reg = /(^[0-9]\d*(\.\d{1,2})?$)|(^1(\.\d{1,2})?$)/;
              if (!reg.test(value)) {
                callback("抱歉，租金单价限制为大于等于0保留两位小数数字");
              } else {
                if (typeof value == "string") {
                  if (value.split(".")[0].length > 7) {
                    callback("最大金额为9999999.99");
                  }
                }
              }
              callback(errors);
            }
          }
        ],
        deposit: [
          {
            required: true,
            pattern: /.+/,
            message: "抱歉，不能识别您输入的押金金额",
            trigger: "blur"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              const reg = /(^[0-9]\d*(\.\d{1,2})?$)|(^1(\.\d{1,2})?$)/;
              if (!reg.test(value)) {
                callback("抱歉，押金金额限制为大于0的数字");
              } else {
                if (typeof value == "string") {
                  if (value.split(".")[0].length > 7) {
                    callback("最大金额为9999999.99");
                  }
                }
              }
              callback(errors);
            }
          }
        ],
        type: [
          {
            required: true,
            message: "抱歉，不能识别您选择的计算方式",
            trigger: "change"
          }
        ],

        payRatio: [
          {
            required: true,
            message: "抱歉，不能识别您输入的支付比例",
            trigger: "blur"
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              /* const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^1(\.\d{1,2})?$)/;
              if (!reg.test(value)) {
                callback("抱歉，最多只能保留两位小数");
              } else if (value < 0 || value > 100) {
                callback("抱歉，支付比例不能小于0或大于100%");
              } */
              const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
              if (!reg.test(value) || value < 0 || value > 100) {
                callback(
                  "抱歉，联营扣点数值限制为大于0%~100%且最多保留两位小数！"
                );
              }
              
              callback(errors);
            }
          }
        ],
        adjustPeriod: [
          {
            required: true,
            message: "抱歉，不能识别您选择的周期",
            trigger: "change"
          }
        ]
      }
    };
  },

  watch: {
    formData: {
      handler(newVal, oldVal) {
        this.form.busDiscountRatio = newVal.busDiscountRatio;
        this.form.payRatio = newVal.payRatio;
        this.form.busDiscountTime = newVal.busDiscountTime;
      },
      deep: true,
      immediate: true
    }
  },
  computed: {
    ...mapState({
      rentInfo: state => state.setRentInfo.rentInfo,
      formData: state => state.setRentInfo.formData
    }),
    getFreceveperiodUnit() {
      return this.form.priceUnit == 1 ? "日" : "月";
    },
    changeUnitType() {
      return this.priceUnitOption.filter(e => e.value == this.form.priceUnit)[0]
        .name;
    },
    pickerOptions0: function() {
      return {
        disabledDate: time => {
          let endDate = moment(this.form.rentalEndDate);
          if (endDate) {
            return moment(time) > endDate;
          }
        }
      };
    },
    pickerOptions1: function() {
      return {
        disabledDate: time => {
          let beginDateVal = moment(this.form.rentalStartDate);
          if (beginDateVal) {
            return moment(time) < beginDateVal;
          }
        }
      };
    }
  },
  methods: {
    // 打开jumpRateSet 跳点设置弹框组件
    jumpRateSet() {
      this.$refs['jumpRateSetDialog'].openDialog();
    },
    getRent(item){
      return item.rent?item.rent+' 元/㎡/'+this.priceUnitOption.filter(e=>e.value==item.rent_unit)[0].name:'未设置';
    },
    /**
     * 修改租赁面积及单价改变租金
     */
    changeArea(type, val) {
      this.form[type] = val;
      this.form.price =
        ((Number(this.form["rentPrice"] * 100) *
          Number(this.form["rentArea"] * 100)) /
        10000).toFixed(2);
    },
    changeFormData(type, val) {
      this.form[type] = val;
      if(type=='type'&&val==2){
        this.form.priceUnit=2;
      }
    },
    //
    setAdjustPeriod(e) {
      this.form.adjustPeriod = e;
      // this.form.adjustRatio = [];
    },
    //修改租赁开始时间及租赁结束日期
    changeDates(e, type) {
      this.form[type] = e;
      this.getDateDiff(this.form.rentalStartDate, this.form.rentalEndDate);
    },
    getDateDiff(rentalStartDate, rentalEndDate) {
      if (rentalStartDate && rentalEndDate) {
        this.getFetch(
          `${ContractUrl.getDateDiff}?startDate=${moment(
            this.form.rentalStartDate
          ).format("YYYY-MM-DD")}&endDate=${moment(this.form.rentalEndDate)
            .add(1, "days")
            .format("YYYY-MM-DD")}`
        ).then(res => {
          this.form.totalPeriodMonth = res.data.month;
          this.form.totalPeriodDay = res.data.day;
          this.form.lease =
            Number(res.data.month) + (Number(res.data.day) > 0 ? 1 : 0);
          this.lease();
        });
      }
    },
    changeStatus(value) {
      return value == 1 ? "已出租" : "未出租";
    },
    next(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.lease();
          if (this.form.shopTableData.length == 0) {
            this.$message.error("抱歉，请先选择点位商铺");
            return;
          }
          if(this.form.lease>600){
            this.$message.error("抱歉，总租期最大限制为600个月");
            return;
          }
          for (let shopItem of this.form.shopTableData) {
            this.form.shopId = shopItem.id;
            this.form.merchantId = shopItem.merchantId;
          }
          if (this.form.startDate && this.form.rentalStartDate) {
            //计租开始时间
            let startDate = moment(this.form.startDate).format("YYYY-MM-DD");
            //租赁开始日期
            let rentalStartDate = moment(this.form.rentalStartDate).format(
              "YYYY-MM-DD"
            );
            if (moment(startDate).isBefore(rentalStartDate)) {
              this.$message.error("计租开始日期不能早于租赁开始日期");
              return;
            }
          }
          if(moment(this.form.startDate).valueOf()>moment(this.form.rentalEndDate).valueOf()){
            this.$message.error("计租开始日期不能大于租赁结束日期");
            return;
          }
          if (this.active != 0) {
            this.submitOn();
          } else {
            this.active += 1;
            this.iscancel = false;
          }
        } else {
          return false;
        }
      });
    },
    //合同基本信息提交
    submit(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.submitOn();
        } else {
          return false;
        }
      });
    },
    //保存第一步
    saveFirst(url, param) {
            this.loading = true;
      this.postFetch(url, param)
        .then(d => {
          this.iscancel = false;
          if (this.active == 2) {
            if (this.processData.length<=0) {
              this.updateRentContractStatus();
            }else{
              this.$message.success("提交成功");
              this.loading = false;
              this.$router.back(-1);
            }
          } else {
            this.form.id = d.data.id;
            this.active += 1;
            this.loading = false;
            this.$refs[this.billTk].setData(d.data.previewBillRentList,this.form.receivePeriod);
          }
          //
          /* if (d.data.busDiscountRatio == undefined) {
            d.data.busDiscountRatio = '';
          } */
          let myObj = Object.assign({},this.formData);
          myObj.busDiscountRatio = d.data.busDiscountRatio;
          myObj.busDiscountTime = d.data.busDiscountTime;
          myObj.payRatio = Number(d.data.payRatio) / 100;
          this.setFormData(myObj);
          
          // this.form.busDiscountRatio = d.data.busDiscountRatio;
          // _this.submitApproval(d.data.contractNumber);
        })
        .catch(err => {
          this.$message.error(err.data);
           this.loading = false;
        });
    },
    updateRentContractStatus(){
      let param = {
        id:this.form.id
      }
      this.postFetch(ContractUrl.updateRentContractStatus,param)
      .then(d=>{
        this.$message.success("保存成功！");
        this.loading = false;
        this.$router.back(-1);
        //
        this.formData.busDiscountRatio = '';
        this.formData.busDiscountTime = 1;
        this.formData.payRatio = 0;
        this.setFormData(this.formData);
      })
      .catch(err=>{
        this.$message.error(err.data);
      })
    },
    submitMoney() {
      let param = {
        id: this.form.id,
        rentStartType: this.form.rentStartType,
        rentalStartDate:moment(this.form.rentalStartDate).format('YYYY-MM-DD')+' 00:00:00'
      };
      let _this = this;
      _this
        .postFetch("/api/wxRentContract/updateRentStartTime", param)
        .then(d => {
          _this.$message.success("预账单生成成功!");
          _this.$refs[_this.billTk].setData(d.data.previewBillRentList,this.form.receivePeriod);
        })
        .catch(err => {
          _this.form.rentStartType = _this.form.rentStartType==1?2:1;
          _this.$message.error(err.data);
        });
    },
    checkcontractNum(url, param) {
      this.$confirm(
        "抱歉,此合同编号已存在,取消请返回上一步修改合同编号, 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(() => {
          this.saveFirst(url, param);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    makeSure(url,param){
      this.$confirm('为确保合同有效生成，请联系管理员添加审批流程!', '提示', {
        confirmButtonText: '坚持提交',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.saveFirst(url,param);
      }).catch(() => {
        this.loading = false;
        this.$message({
          type: 'info',
          message: '已取消'
        });          
      });
    },
    submitOn: function() {
      let _this=this;
      //账单生成方式未自然月时付款周期处理
      this.form.receivePeriod=this.form.adjustPeriod==3?(this.cycles.filter(e=>e.value==this.form.receivePeriod).length>0?this.form.receivePeriod:1):this.form.receivePeriod;
      let param = deepcopy(this.form);
      if (param.adjustPeriod == 1) {
        param.monthHandleType = "";
      }
      param.rentalStartDate =
        commonUtil.date.date(this.form.rentalStartDate) + " 00:00:00";
      param.rentalEndDate =
        commonUtil.date.date(this.form.rentalEndDate) + " 23:59:59";
      param.startDate = commonUtil.date.date(this.form.startDate) + " 00:00:00";
      param.signDate = commonUtil.date.date(this.form.signDate) + " 00:00:00";
      if (this.form.fixDate&&this.form.fixDate[0] != undefined) {
        param.fixStartDate =
          moment(this.form.fixDate[0]).format("YYYY-MM-DD") + " 00:00:00";
        param.fixEndDate =
          moment(this.form.fixDate[1]).format("YYYY-MM-DD") + " 23:59:59";
      }else{
        param.fixStartDate = ''
        param.fixEndDate = ''
      }
      param.depositStr = this.form.deposit;
      param.priceStr = this.form.price;
      param.deposit = Number(Number(this.form.deposit * 100).toFixed(2));
      param.price = Number(Number(this.form.price * 100).toFixed(2));
      param.revenue = Number(Number(this.form.revenue * 100).toFixed(2));
      param.payRatio = Number(Number(this.form.payRatio * 100).toFixed(2));
      //aaaa  合同补录
      param.status = 8;
      param.fileNames = JSON.stringify(this.fileNames);
      let adjustRatios01 = this.form.adjustRatio.filter(
        (item, index) => param.lease / 12 - 1 > index
      );
      let adjustRatios02 = adjustRatios01.map(item => Number(Number(item * 100).toFixed(2)));
      param.adjustRatio = JSON.stringify(adjustRatios02);
      if (this.form.id) {
        if (this.active == 2) {
          if(this.processData.length > 0){
            param.flowParams = {
              variables: [
                {
                  key: "contractType",
                  value: "2"
                },
                {
                  key: "contractNumber",
                  value: this.form.contractNumber
                }
              ],
              businessType: 5,
              remark: this.form.remark
            };
          }
          let previewBillRentList = [];
          if (
            this.$refs[this.billTk].getData() != false &&
            this.$refs[this.billTk].getData().length > 0
          ) {
            let haveCommentsError = false;
            let message = "";
            this.$refs[this.billTk].getData().map((item, index) => {
              let a = {};
              a.id = item.id;
              a.receivePay = item.receivePay;
              a.needPay = item.needPay;
              a.receiveDate = item.receiveDate;
              a.starttime = moment(item.starttime).format('YYYY-MM-DD')+' 00:00:00';
              a.endtime = moment(item.endtime).format('YYYY-MM-DD')+' 23:59:59';
              a.comments = item.comments;
              previewBillRentList.push(a);
              if(item.receivePay!=item.needPay&&!item.comments){
                haveCommentsError = true;
                message = "建议账单金额调整后,补充金额调整原因！";
              }
            });
            param.previewBillRentList = previewBillRentList;
            //aaa 合同补录的状态是8不能选择  第二步保存的时候如果是来自补录，需要将status重置为8
            if (this.fromBulu) {
              param.status = 8;
            }
            if(haveCommentsError){
              this.$confirm(message, '有金额变更原因未填写', {
                confirmButtonText: '去补充',
                cancelButtonText: '继续提交',
                type: 'warning'
              }).then(() => {
                return false;
              }).catch(() => {
                if (_this.processData.length > 0) {
                  this.saveFirst("/api/wxRentContract/update", param); 
                }else{
                  this.makeSure("/api/wxRentContract/update", param);
                }   
              });
            }else{
              if (_this.processData.length > 0) {
                this.saveFirst("/api/wxRentContract/update", param); 
              }else{
                this.makeSure("/api/wxRentContract/update", param);
              }    
            }
          } else {
            return;
          }
        }
        if (this.active == "1") {
          this.getFetch(
            `/api/wxRentContract/hasContractNumber?contractNumber=${
              this.form.contractNumber
            }&id=${this.form.id}`
          )
            .then(d => {
              //如果合同编号重复
              if (d.data) {
                this.checkcontractNum("/api/wxRentContract/update", param);
              } else {
                this.saveFirst("/api/wxRentContract/update", param);
              }
            })
            .catch(err => {
              this.$message.error(err.data);
            });
        }
      } else {
        //如果没有id走到这一步代表补录进来的 aaa
        param.status = 8;
        this.getFetch(
          `/api/wxRentContract/hasContractNumber?contractNumber=${
            this.form.contractNumber
          }&id=${this.form.id}`
        )
          .then(d => {
            //如果合同编号重复
            if (d.data) {
              this.checkcontractNum("/api/wxRentContract/add", param);
            } else {
              this.saveFirst("/api/wxRentContract/add", param);
            }
          })
          .catch(err => {
            this.$message.error(err.data);
          });
      }
    },
    goback() {
      if (this.active-- < 0) {
        this.active = 0;
      }
    },
    cancel() {
      this.$router.back(-1);
    },
    // 店铺弹框
    openShopDialog() {
      this.$refs[this.tKey].openDialog();
    },
    getShopCb(items) {
      this.form.shopTableData = items.data;
      this.form.rentArea = items.data[0].operationArea;
      this.shopshow = true;
      this.newshopTableData = this.form.shopTableData[0];
    },
    //文件上传
    beforeUpload: function(file) {
      let type = file.name.split(".")[1];
      const extension =
        type === "doc" ||
        type === "docx" ||
        type === "pdf" ||
        type === "png" ||
        type === "jpg" ||
        type === "jpeg";
      const isLt2M = file.size / 1024 / 1024 < 20;
      if (!extension) {
        this.$message.warning(
          "抱歉，上传文件只能是doc、docx、pdf、png、jpg、jpeg格式"
        );
      }
      if (!isLt2M) {
        this.$message.warning("抱歉，上传文件大小不能超过 20MB");
      }
      return extension && isLt2M;
    },
    importSuccess: function(response, file, fileList) {
      this.$message.success("上传成功");
      let a = {
        name: file.name,
        url: response.data.url
      };
      this.fileNames.push(a);
    },
    importError: function(response, file, fileList) {
      this.$message.error("抱歉，上传失败");
      console.log("error:" + response + "--" + file + "---" + fileList);
    },
    downloadPr(file) {
      window.open(file.url);
    },
    handleRemove: function(file, filelist) {
      this.fileNames.map((item, index) => {
        if (item.url == file.url) {
          this.fileNames.splice(index, 1);
        }
      });
    },
    //按计租和联营扣点显示不同内容
    computedChange(item) {
      this.form.type = item;
    },
    comperData() {
      if (this.form.startDate && this.form.rentalStartDate) {
        //计租开始问题
        let startDate = moment(this.form.startDate).format("YYYY-MM-DD");
        //租赁开始日期
        let rentalStartDate = moment(this.form.rentalStartDate).format(
          "YYYY-MM-DD"
        );
        if (moment(startDate).isBefore(rentalStartDate)) {
          this.$message.error("计租开始日期不能早于租赁开始日期");
          return;
        }
      }
    },
    // 店铺弹框
    buluopenShopDialog() {
      this.$refs[this.tKeynew].openDialog();
    },

    // 商铺选中之后的操作
    getShopCbNew(items) {
      console.log(items)
      this.form.shopTableData = items.data;
      this.form.shopTableData.status = "已出租";
      if (items.data[0].linkPerson) {
        this.form.linkPerson = items.data[0].linkPerson;
      } else {
        this.form.linkPerson = "";
      }
      if (items.data[0].linkPhone) {
        this.form.linkPhone = items.data[0].linkPhone;
      } else {
        this.form.linkPhone = "";
      }
      if (items.data[0].merchantName) {
        this.form.merchantName = items.data[0].merchantName;
      } else {
        this.form.merchantName = "";
      }
      this.form.merchantId = items.data[0].merchantId;
      if (items.data[0].brand) {
        this.form.brand = items.data[0].brand;
      } else {
        this.form.brand = "";
      }
      if (items.data[0].shopType) {
        this.form.shopType = items.data[0].shopType;
      } else {
        this.form.shopType = "";
      }
      if (items.data[0].businessId) {
        this.form.businessId = items.data[0].businessId;
      } else {
        this.form.businessId = "";
      }
      this.form.rentArea = items.data[0].operationArea;
      this.formdisabled = true;
      //aaaa  合同补录
      this.form.status = 8;
      this.isShow = true;
      this.shopshow = true;
      this.newshopTableData = this.form.shopTableData[0];
    },
    lease() {
      this.months = [];
      if (this.form.lease > 12) {
        let j = this.form.lease / 12;
        if (j % 1 === 0) {
          //判断是不是整数
          j = j - 1;
        } else {
          j = Math.floor(j);
        }
        for (var i = 0; i < j; i++) {
          this.months.push(i);
        }
        this.form.adjustRatio.length = this.months.length;
        for (var q = 0; q < this.form.adjustRatio.length; q++) {
          if (this.form.adjustRatio[q] == undefined) {
            this.form.adjustRatio[q] = 0;
          }
        }
      } else {
        this.months = [];
      }
      this.copelease = this.form.lease;
    },
    getAdjustRatio(item) {
      let arr = [];
      for (let i of item) {
        arr.push(i / 100);
      }
      return arr;
    },
    /**
     * 获取默认收银信息
     */
    getPayAccountInfo() {
      this.getFetch(ContractUrl.getPayAccountInfo)
        .then(d => {
          this.form.payAccount = d.data.bankCardId;
          this.form.bankName = d.data.bankAccountName;
        })
        .catch(err => {
          this.$message.error(err.data);
        });
    },
    /**
     * 根据业务查询模板
     */
    getModelBybusiness(){
      this.getFetch(`${promissionUrl.getModelBybusiness}?flowType=5`)
      .then(d=>{
        if(d.data.length>0){
          this.processData = JSON.parse(d.data[0].flow).lists;
        }
      })
      .catch(err=>{
        this.$message.error(err.data);
      })
    },
    dealInfoFromMerchant() {
      let {curMerchantId} = this.$route.query;
      if (curMerchantId != undefined && curMerchantId) {
        //相当于来自编辑，不可切换商户
        this.fromBulu = true;
        this.editIf = true;
        this.shopshow = false;
        this.getFetch('/api/wxMerchant/findById?id='+curMerchantId)
          .then(d=>{
            let curMerchantObj = d.data.shoplist[0];
            curMerchantObj.businessId = d.data.businessId;
            //和普通合同的存储不一样，多经的补录取得是merchantId不是id，merchantName不是name
            // curMerchantObj.merchantId = curMerchantObj.id;
            // curMerchantObj.merchantName = curMerchantObj.name;
            let arr01 = [];
            let arr02 = [];
            arr01.push(curMerchantObj)
            arr02.push(curMerchantObj.id)
            let obj = {
              data: arr01,
              vals: arr02
            }
            // 执行商铺选中之后的操作
            this.getShopCbNew(obj);
          })
          .catch(err=>{
            this.$message.error(err.data);
          })

      }
    },

  },
  mounted() {
    //来自商户管理的补录跳转操作  属于补录不属于编辑补录
    this.dealInfoFromMerchant();
  },
  created() {
    let _this = this;
    let datastr = moment(new Date()).format("YYYYMMDDhhmmss");
    this.form.contractNumber = datastr;
    this.setNavData(["合同管理", "多经点位", "租金合同", "补录"]);
    this.getFetch(ContractUrl.businessList)
      .then(d => {
        this.businessIds = d.data;
      })
      .catch(err => {
        this.$message.error(err.data);
      });

    //获取品牌列表
    this.getFetch("/api/wxBrand/queryBrand")
      .then(d => {
        this.brands = d.data;
      })
      .catch(err => {
        this.$message.error(err.data);
      });
    this.getModelBybusiness();
    if (this.$route.query.id) {
      this.fromBulu = false;
      this.setNavData(["合同管理", "多经点位", "租金合同", "补录编辑"]);
      this.getFetch("/api/wxRentContract/findById?id=" + this.$route.query.id)
        .then(d => {
          this.formdisabled = true;
          _this.shopshow = true;
          _this.editIf = true;
          if (d.data.wxRentContract.adjustPeriod == 1) {
            d.data.wxRentContract = "2";
          }
          this.form = Object.assign(this.form, d.data.wxRentContract);
          if (d.data.wxRentContract.fileNames) {
            this.fileNames = JSON.parse(d.data.wxRentContract.fileNames);
          }
          if (d.data.wxRentContract.filename) {
            this.fileName = d.data.wxRentContract.filename;
          }
          if (d.data.wxRentContract.adjustRatio) {
            this.form.adjustRatio = this.getAdjustRatio(
              eval("(" + d.data.wxRentContract.adjustRatio + ")")
            );
          }
          this.form.rentalStartDate = moment(this.form.rentalStartDate).format(
            "YYYY-MM-DD"
          );
          this.form.rentalEndDate = moment(this.form.rentalEndDate).format(
            "YYYY-MM-DD"
          );
          this.getDateDiff(this.form.rentalStartDate, this.form.rentalEndDate);
          if (d.data.wxShops) {
            this.form.merchantId = d.data.wxShops[0].merchantId;
            this.form.shopTableData = d.data.wxShops;
            this.newshopTableData = d.data.wxShops[0];
          }

          if (d.data.wxRentContract.lease) {
            this.copelease = d.data.wxRentContract.lease;
          }
          this.form.price = Number(d.data.wxRentContract.price) / 100;
          this.form.deposit = Number(d.data.wxRentContract.deposit) / 100;
          this.form.revenue = Number(d.data.wxRentContract.revenue) / 100;
          Vue.set(this.form, "fixDate", [
            d.data.wxRentContract.fixStartDate,
            d.data.wxRentContract.fixEndDate
          ]);
          if (d.data.wxRentContract.payRatio == undefined) {
            this.form.payRatio = 0;
          } else {
            this.form.payRatio = Number(d.data.wxRentContract.payRatio) / 100;
          }
          this.form.shopTableData = d.data.wxShops;
          //
          let curObj = Object.assign({},this.formData);
          curObj.busDiscountRatio = d.data.wxRentContract.busDiscountRatio;
          curObj.busDiscountTime = d.data.wxRentContract.busDiscountTime;
          curObj.payRatio = Number(d.data.wxRentContract.payRatio)/100;
          this.setFormData(curObj);
          
          if (this.form.adjustPeriod == 1) {
            this.dateType = "日";
            this.isshowYear = false;
          } else {
            this.dateType = "月";
            this.isshowYear = true;
          }
          //根据总租期限时调整比例
          if (this.form.lease > 12) {
            let j = this.form.lease / 12;
            if (j % 1 === 0) {
              //判断是不是整数
              j = j - 1;
            } else {
              j = Math.floor(j);
            }
            for (var i = 0; i < j; i++) {
              this.months.push(i);
            }
            this.form.adjustRatio.length = this.months.length;
            for (var q = 0; q < this.form.adjustRatio.length; q++) {
              if (this.form.adjustRatio[q] == undefined) {
                this.form.adjustRatio[q] = 0;
              }
            }
          } else {
            this.months = [];
          }
        })
        .catch(err => {
          this.$message.error(err.data);
        });
    } else {
      this.setNavData(["合同管理", "多经点位", "租金合同", "补录"]);
      //aaa
      this.fromBulu = true;
      this.getPayAccountInfo();
    }
  }
};
</script>
<style scoped>
.fx_step .el-step.is-center .el-step__line {
  left: 0;
  right: -100%;
}
.layout-content {
  width: 100%;
  background: #141e29;
  height: auto;
  border-radius: 2px;
  /* min-height: 300px; */
  padding: 0 20px;
  overflow: hidden;
  text-align: left;
}
form {
  text-align: left;
  width: 100%;
}
.shopBox {
  width: 100%;
  background: #3fc496;
  height: 40px;
  overflow: hidden;
  border-bottom-left-radius: 2px;
  border-top-left-radius: 2px;
}
.shopBox .shopBtn {
  width: 110px;
  height: 40px;
  float: left;
  text-align: center;
  line-height: 40px;
  color: #fefefe;
  font-size: 14px;
  cursor: pointer;
  background: RGBA(63, 196, 150, 1);
  border-radius: 4px;
}
.shopBox .shopBtn:hover {
  background: RGBA(63, 196, 150, 0.88);
}
.shopBox_choose {
  width: 100%;
  height: 40px;
  overflow: hidden;
}
.shopBox_choose .shopBtn_choose {
  width: 110px;
  height: 40px;
  float: left;
  text-align: center;
  line-height: 40px;
  color: #fefefe;
  font-size: 14px;
  cursor: pointer;
  background: RGBA(63, 196, 150, 1);
  border-radius: 4px;
}
.shopBox_choose .shopBtn_choose:hover {
  background: RGBA(63, 196, 150, 0.88);
}
.shopBox .shopContent {
  width: calc(100% - 110px);
  background: #ffffff;
  position: relative;
  float: right;
  height: 40px;
  border-top: 5px solid #3fc496;
  border-bottom: 5px solid #3fc496;
  border-right: 5px solid #3fc496;
  padding-right: 10px;
}
.shoplist div {
  width: 16%;
  float: left;
  text-align: center;
  line-height: 30px;
  color: #555;
  font-size: 14px;
}
.jiaojiao {
  width: 27px;
  position: absolute;
  right: 5px;
}
.iconBox {
  font-size: 18px !important;
  color: #3fc496 !important;
  margin-right: 6px !important;
}

.public_part {
  background: #fff;
  margin-top: 20px;
}
.public_part_title {
  height: 40px;
  padding: 11px 0 11px 21px;
  background: #5976bf;
  font-size: 14px;
  color: #fff;
}
.public_part_Box {
  padding: 30px;
}

.baocun {
  background: #5976bf;
  border: 0;
}
.baocun:hover {
  background: #7a6ce1;
}
.text {
  width: 100%;
}
.edit-item-input {
  width: 59%;
}
.payDate {
  width: 80px;
}
.download-file {
  position: relative;
  overflow: hidden;
  text-align: center;
  display: inline-block;
  width: 120px;
  border: 1px #dcdfe6 solid;
  background-color: #409eff;
  border-radius: 4px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: normal;
  line-height: 24px;
  color: #fff;
  text-decoration: none;
}
.el-form-item .el-form-item__content,
.el-form-item .el-form-item__content .el-date-editor,
.el-form-item .el-form-item__content .el-date-editor .el-input__inner {
  width: 211px;
}
.fx_send .el-form-item__content .el-select {
  width: 211px !important;
}
.fx_title .el-input {
  width: 211px;
}

/* 按钮处理 */
.addBtn {
  height: 40px;
  /* margin: 20px 0 0 20px; */
  background: RGBA(81, 169, 201, 1);
  color: #ffffff;
  font-size: 14px;
  border: 0;
}
.addBtn:hover {
  background: RGBA(81, 169, 201, 0.88);
}
.group-btn {
  margin: 20px 0;
  text-align: center;
}
.group-btn .quxiaoBtn,
.group-btn .baocunBtn {
  height: 40px;
  font-size: 14px;
  border-radius: 3px;
  border: 0;
}
.group-btn .quxiaoBtn {
  /* width:83px; */
  color: #555;
  margin-right: 9px;
  background: RGBA(255, 255, 255, 1);
}
.group-btn .baocunBtn,
.group-btn .nextBtn {
  /* width:130px; */
  color: #ffffff;
  margin-left: 9px;
  border: 0;
  background: rgba(81, 169, 201, 1);
}
.group-btn .quxiaoBtn:hover {
  background: rgba(255, 255, 255, 0.88);
}
.group-btn .baocunBtn:hover,
.group-btn .nextBtn:hover {
  background: rgba(81, 169, 201, 0.88);
}
.innerinput {
  width: 120px;
}
</style>
<style>
input[type="file"] {
  display: none;
}
.el-table th > .cell {
  text-align: center !important;
}
/* .pointrent .el-radio-button__orig-radio:checked + .el-radio-button__inner {
  background-color: #5976bf !important;
  border-color: #5976bf !important;
} */
.per-list .el-form-item__content{
  margin-left: 0 !important;
  width: auto !important;
}
.per-list .el-form-item{
  width: auto !important;
  margin-right: 50px;
  margin-bottom: 40px;
}
.per-list{
  margin-left: 150px;
}
</style>