<template>
  <div class="declare-box">
    <div
      class="step"
      v-if="!this.view"
    >
      <van-steps
        :active="active"
        active-icon="success"
        active-color="#EB4E3F"
      >
        <van-step>申报</van-step>
        <van-step>项目初审</van-step>
        <van-step>窗口复审</van-step>
        <!-- <van-step>银行卡确认</van-step> -->
        <van-step>退税办理</van-step>
        <van-step>完成</van-step>
      </van-steps>
    </div>
    <div :class="['content-box1']">
      <div class="card-box">
        <div class="top-box">
          <div class="icon"></div>
          <div class="name">申报人信息</div>
        </div>
        <div class="bottom-box">
          <van-cell-group>
            <van-field
              v-model="form.name"
              name="姓名"
              input-align="right"
              label="姓名"
              readonly
              :disabled="this.view"
              clearable
              required
              placeholder="输入您的姓名"
            >
            </van-field>
            <van-field
              v-model="form.idCard"
              name="身份证号"
              input-align="right"
              readonly
              label="身份证号"
              :disabled="this.view"
              clearable
              required
              placeholder="输入您的身份证号"
            >
            </van-field>
            <van-field
              v-model="form.phone"
              name="手机号码"
              input-align="right"
              label="手机号码"
              :disabled="this.view"
              clearable
              required
              placeholder="输入您的手机号码"
            >
            </van-field>
            <van-field
              v-model="form.userArea"
              name="辖市区"
              input-align="right"
              label="辖市区"
              :disabled="this.view"
              @click="showPicker = true"
              readonly
              clearable
              required
              placeholder="选择辖市区"
            >
            </van-field>
            <van-popup
              v-model="showPicker"
              :disabled="this.view"
              position="bottom"
              round
              v-if="!this.view"
            >
              <van-picker
                show-toolbar
                :columns="
                  columns1.map((item) => {
                    return item.label;
                  })
                "
                title="辖市区"
                @cancel="showPicker = false"
                @confirm="onConfirm"
              />
            </van-popup>
            <van-field
              v-model="form.address"
              name="详细地址"
              input-align="right"
              label="详细地址"
              :disabled="this.view"
              clearable
              required
              placeholder="输入详细地址"
            >
            </van-field>
            <van-field
              label="上传个人身份证(正、反)照"
              input-align="right"
              :disabled="this.view"
              required
            >
              <template #input>
                <van-uploader
                  :disabled="view"
                  :deletable="!view"
                  :after-read="afterRead"
                  v-model="form.idimg"
                  max-count="2"
                />
              </template>
            </van-field>
          </van-cell-group>
        </div>
      </div>
      <div class="card-box">
        <div class="top-box">
          <div class="icon"></div>
          <div
            class="name"
            @click="showDialog"
          >
            银行卡
            <span style="font-size: 12px; font-weight: 400; color: #EB4E3F;margin-left: 15px;">填写说明</span>
          </div>
        </div>
        <div class="bottom-box">
          <van-cell-group>
            <van-field
              v-model="form.bank"
              name="开户银行"
              input-align="right"
              label="开户银行"
              :disabled="this.view"
              clearable
              required
              placeholder="镇江本地本人一类储蓄卡"
            >
            </van-field>
            <van-field
              v-model="form.bankCard"
              name="银行卡号"
              input-align="right"
              label="银行卡号"
              :disabled="this.view"
              type="number"
              clearable
              required
              placeholder="输入银行卡号"
            >
            </van-field>
            <van-field
              label="上传银行卡(正、反)照"
              input-align="right"
              :disabled="this.view"
              required
            >
              <template #input>
                <van-uploader
                  :disabled="view"
                  :deletable="!view"
                  :after-read="afterRead"
                  v-model="form.bankimg"
                  max-count="2"
                />
              </template>
            </van-field>
          </van-cell-group>
        </div>
      </div>
      <div class="card-box">
        <div class="top-box">
          <div class="icon"></div>
          <div class="name">不动产信息</div>
        </div>
        <div class="bottom-box">
          <van-cell-group>
            <van-field
              input-align="right"
              label="契税发票号码-1"
              :disabled="this.view"
              required
            >
              <template #input>
                <div
                  class="box_megic"
                  style="display:flex;align-items: center;"
                >
                  <div style="display: flex">
                    <div>NO.</div>
                    <van-field
                      v-model="form.deedBillCode"
                      placeholder="输入契税发票号码-1"
                      input-align="center"
                      :disabled="view"
                      type="digit"
                      :rules="[{ required: true, message: '' }]"
                      class="megic megic3"
                    >
                    </van-field>
                  </div>
                  <van-icon
                    v-if="!showCopy && !form.secondDeedBillCode && !view"
                    @click="showCopy = true"
                    name="add-o"
                    class="add-o"
                    color="#29A400"
                  />
                </div>
              </template>
            </van-field>
            <van-field
              input-align="right"
              v-if="showCopy || form.secondDeedBillCode"
              label="契税发票号码-2"
              :disabled="this.view"
              required
            >
              <template #input>
                <div
                  class="box_megic"
                  style="display:flex;align-items: center;"
                >
                  <div style="display: flex">
                    <div>NO.</div>
                    <van-field
                      v-model="form.secondDeedBillCode"
                      placeholder="输入契税发票号码-2"
                      input-align="center"
                      :disabled="view"
                      type="digit"
                      :rules="[{ required: true, message: '' }]"
                      class="megic megic3"
                    >
                    </van-field>
                  </div>
                  <van-icon
                    v-if="!view"
                    @click="changeShowCopy"
                    name="delete-o"
                    class="delete-o"
                    color="#ED0000"
                  />
                </div>
              </template>
            </van-field>
            <van-field
              v-model="form.paymentDeedTaxAmount"
              name="缴纳契税金额(元)"
              input-align="right"
              label="缴纳契税金额(元)"
              :disabled="this.view"
              type="number"
              clearable
              required
              placeholder="输入缴纳契税金额(元)"
            >
            </van-field>
            <van-field
              v-model="form.square"
              name="房屋面积(㎡)"
              input-align="right"
              label="房屋面积(㎡)"
              :disabled="this.view"
              type="number"
              clearable
              required
              placeholder="输入房屋面积"
            >
            </van-field>
            <van-field
              v-model="form.realEstateArea"
              name="不动产权坐落辖市区"
              input-align="right"
              label="不动产权坐落辖市区"
              :disabled="this.view"
              @click="showPicker1 = true"
              readonly
              clearable
              required
              placeholder="选择辖市区"
            >
            </van-field>
            <van-popup
              v-model="showPicker1"
              position="bottom"
              round
              v-if="!this.view"
            >
              <van-picker
                show-toolbar
                :columns="
                  columns.map((item) => {
                    return item.label;
                  })
                "
                title="辖市区"
                @cancel="showPicker1 = false"
                @confirm="onConfirm1"
              />
            </van-popup>
            <van-field
              v-model="form.realEstateAddress"
              name="不动产权坐落地址"
              input-align="right"
              label="不动产权坐落地址"
              :disabled="this.view"
              clearable
              required
              placeholder="输入详细地址"
            >
            </van-field>
            <van-field
              v-model="form.netSignTime"
              input-align="right"
              label="网签时间"
              :disabled="this.view"
              required
              readonly
              placeholder="请选择网签时间"
              @click="showDatePicker = true"
            >
            </van-field>
            <van-popup
              v-model="showDatePicker"
              position="bottom"
              round
              v-if="!this.view"
            >
              <van-datetime-picker
                v-model="currentDate"
                type="date"
                title="选择网签时间"
                @confirm="(value) => oncurrentDateConfirm(value)"
                @cancel="showDatePicker = false"
              />
            </van-popup>
            <van-field
              label="不动产权证号"
              input-align="right"
              :disabled="this.view"
              required
            >
              <template #input>
                <div class="box_megic">
                  <div style="display: flex">
                    <div>苏(</div>
                    <van-field
                      v-model="front"
                      placeholder="例:2022"
                      input-align="center"
                      :disabled="view"
                      type="digit"
                      :rules="[{ required: true, message: '' }]"
                      class="megic"
                    >
                    </van-field>
                    <div>)</div>
                  </div>
                  <div style="display: flex">
                    <div>镇江市不动产权第</div>
                    <van-field
                      v-model="after"
                      placeholder="例:31515"
                      input-align="center"
                      :disabled="view"
                      type="digit"
                      :rules="[{ required: true, message: '' }]"
                      class="megic megic2"
                    ></van-field>
                    <div>号</div>
                  </div>
                </div>
              </template>
            </van-field>
            <van-field
              label="房屋属性"
              required
              :disabled="this.view"
            >
              <template #input>
                <van-radio-group
                  v-model="form.houseType"
                  direction="horizontal"
                >
                  <van-radio :name="1">商品房</van-radio>
                  <van-radio :name="2">二手房</van-radio>
                </van-radio-group>
              </template>
            </van-field>
            <van-field
              label="不动产权证书"
              input-align="right"
              :disabled="this.view"
              required
            >
              <template #input>
                <div style="display: flex;align-items: center;">
                  <van-image
                    v-if="
                      form.certificate && form.certificate.length == 0 && !view
                    "
                    src="https://www.smart-zj.cn:55901/image/e54db055-61f1-42b2-a54b-ccff2a763b34.jpg"
                    @click="preview(1)"
                    width="70"
                    height="70"
                    style=" margin-right: 10px;"
                  />
                  <van-uploader
                    :disabled="view"
                    :deletable="!view"
                    :after-read="afterRead"
                    v-model="form.certificate"
                    max-count="1"
                  />
                </div>
              </template>
            </van-field>
            <van-field
              label="网签房屋买卖合同(商品房请上传1、2、7页，二手房请上传3、4、6页)"
              input-align="right"
              :disabled="this.view"
              required
            >
              <template #input>
                <van-image
                  v-if="form.contract && form.contract.length == 0 && !view"
                  src="https://www.smart-zj.cn:55901/image/deca5b01-864e-4d28-88ae-07237d82184a.jpg"
                  @click="preview(2)"
                  width="50"
                  height="70"
                  style=" margin-right: 5px;"
                />
                <van-image
                  v-if="form.contract && form.contract.length == 0 && !view"
                  src="https://www.smart-zj.cn:55901/image/23e0d6c2-0e9a-4d27-82f4-6dbad558c88d.jpg"
                  @click="preview(3)"
                  width="50"
                  height="70"
                  style=" margin-right: 5px;"
                />
                <van-uploader
                  :disabled="view"
                  :deletable="!view"
                  :after-read="afterRead"
                  :multiple="false"
                  v-model="form.contract"
                  max-count="3"
                />
              </template>
            </van-field>
            <van-field
              label="契税完税凭证-1"
              input-align="right"
              :disabled="this.view"
              required
            >
              <template #input>
                <van-image
                  v-if="form.voucher && form.voucher.length == 0 && !view"
                  src="https://www.smart-zj.cn:55901/image/dc2de416-240a-4e05-a8ee-c1680ec97f22.png"
                  @click="preview(4)"
                  width="70"
                  height="70"
                  style=" margin-right: 10px;"
                />
                <van-uploader
                  :disabled="view"
                  :deletable="!view"
                  :after-read="afterRead"
                  v-model="form.voucher"
                  max-count="1"
                />
              </template>
            </van-field>
            <van-field
              v-if="showCopy || form.secondDeedBillCode"
              label="契税完税凭证-2"
              input-align="right"
              :disabled="this.view"
              required
            >
              <template #input>
                <van-image
                  v-if="form.voucher1 && form.voucher1.length == 0 && !view"
                  src="https://www.smart-zj.cn:55901/image/dc2de416-240a-4e05-a8ee-c1680ec97f22.png"
                  @click="preview(4)"
                  width="70"
                  height="70"
                  style=" margin-right: 10px;"
                />
                <van-uploader
                  :disabled="view"
                  :deletable="!view"
                  :after-read="afterRead"
                  v-model="form.voucher1"
                  max-count="1"
                />
              </template>
            </van-field>
          </van-cell-group>
        </div>
      </div>
    </div>
    <div
      class="submit-box"
      v-if="!this.view"
    >
      <van-button
        class="submit1-box"
        @click="go(1)"
      >提交</van-button>
    </div>
    <div
      class="submit-box"
      v-else
    >
      <van-button
        class="submit2-box"
        @click="go(2)"
      >返回上一级</van-button>
      <van-button
        class="submit2-box"
        @click="submit"
      >确认提交</van-button>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import {
  Step,
  Steps,
  CellGroup,
  Field,
  Popup,
  Picker,
  Uploader,
  Button,
  ImagePreview,
  Dialog,
  DatetimePicker,
  Icon,
  RadioGroup,
  Radio,
} from "vant";
import { Image as VanImage } from "vant";
import {
  addDeedTax,
  queryDeedTaxInfoByCode,
  updateDeedTax,
  uploadFile,
} from "@/api/deedtax.js";
import { decryptByDES } from "@/utils/utils";

Vue.use(VanImage);
Vue.use(Step)
  .use(Steps)
  .use(CellGroup)
  .use(Field)
  .use(Popup)
  .use(Picker)
  .use(Uploader)
  .use(Button)
  .use(ImagePreview)
  .use(Dialog)
  .use(DatetimePicker)
  .use(Icon)
  .use(Radio)
  .use(RadioGroup);
export default {
  data() {
    return {
      active: 0,
      form: {
        name: "",
        phone: "",
        idCard: "",
        userArea: "",
        address: "",
        idimg: [], //身份证照片
        bank: "",
        bankCard: "",
        bankimg: [], //银行卡照片
        deedBillCode: "",
        secondDeedBillCode: "",
        paymentDeedTaxAmount: "",
        square: "",
        realEstateArea: "",
        realEstateAddress: "",
        netSignTime: "",
        realEstateCard: "",
        houseType: null, // 房屋属性
        certificate: [], //不动产证书
        contract: [], //房屋买卖合同
        voucher: [], //契税完税凭证
        voucher1: [],
      },
      columns: [
        {
          id: "10001",
          label: "京口区",
        },
        {
          id: "10002",
          label: "润州区",
        },
        {
          id: "10003",
          label: "丹徒区",
        },
        {
          id: "10004",
          label: "镇江新区-大港片区",
        },
        {
          id: "10005",
          label: "镇江新区-丁卯片区",
        },
        {
          id: "10006",
          label: "镇江高新区",
        },
        {
          id: "10008",
          label: "句容市",
        },
      ],
      columns1: [
        {
          id: "10001",
          label: "京口区",
        },
        {
          id: "10002",
          label: "润州区",
        },
        {
          id: "10003",
          label: "丹徒区",
        },
        {
          id: "10004",
          label: "镇江新区",
        },
        {
          id: "10005",
          label: "镇江高新区",
        },
        {
          id: "10008",
          label: "句容市",
        },
      ],
      showPicker: false,
      showPicker1: false,
      front: "",
      after: "",
      view: false,
      userInfo: {},
      code: "",
      currentDate: new Date(),
      showDatePicker: false,
      date: "",
      showCopy: false,
    };
  },
  methods: {
    changeShowCopy() {
      this.showCopy = false;
      this.form.secondDeedBillCode = "";
      this.form.voucher1 = [];
    },
    showDialog() {
      Dialog.alert({
        title: "银行卡填写提示",
        message:
          "为避免不能正常打款，请确认是否为镇江本地银行一类银行卡账户，是否为一类卡账户请通过手机银行或银行确认。",
      });
    },
    oncurrentDateConfirm(value) {
      this.date = value;
      console.log(this.date.getTime());
      this.form.netSignTime =
        value.getFullYear() +
        "-" +
        (value.getMonth() + 1 > 9
          ? value.getMonth() + 1
          : "0" + (value.getMonth() + 1)) +
        "-" +
        (value.getDate() > 9 ? value.getDate() : "0" + value.getDate());
      this.showDatePicker = false;
    },
    onConfirm(value) {
      console.log(value);
      this.form.userArea = value;
      this.showPicker = false;
    },
    onConfirm1(value) {
      console.log(value);
      this.form.realEstateArea = value;
      this.showPicker1 = false;
    },
    afterRead(file) {
      console.log(file);
      file.status = "uploading";
      file.message = "上传中...";
      let param = new FormData();
      param.append("file", file.file);
      this.$toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: "上传图片中...",
      });
      uploadFile(param)
        .then((res) => {
          // alert(JSON.stringify(res.data))

          this.$toast.clear();
          file.status = "done";
          file.message = "上传成功";
          file.url = res.data;
        })
        .catch((err) => {
          console.log(err);
          file.status = "failed";
          file.message = "上传失败";
        });
    },
    preview(val) {
      if (val == 1) {
        ImagePreview([
          "https://www.smart-zj.cn:55901/image/e54db055-61f1-42b2-a54b-ccff2a763b34.jpg",
        ]);
      } else if (val == 2) {
        ImagePreview([
          "https://www.smart-zj.cn:55901/image/deca5b01-864e-4d28-88ae-07237d82184a.jpg",
          "https://www.smart-zj.cn:55901/image/2536f597-3779-40c5-9fa9-c91f4af69360.jpg",
          "https://www.smart-zj.cn:55901/image/98116317-64cb-4c07-903b-935dbe99c9e3.jpg",
        ]);
      } else if (val == 3) {
        ImagePreview([
          "https://www.smart-zj.cn:55901/image/23e0d6c2-0e9a-4d27-82f4-6dbad558c88d.jpg",
          "https://www.smart-zj.cn:55901/image/22489924-ae8a-40f5-9b64-cc1afa3086ad.jpg",
          "https://www.smart-zj.cn:55901/image/5e6fa793-969b-4b5c-84b3-001f058ec887.jpg",
        ]);
      } else if (val == 4) {
        ImagePreview([
          "https://www.smart-zj.cn:55901/image/dc2de416-240a-4e05-a8ee-c1680ec97f22.png",
        ]);
      }
    },
    init() {
      console.log();
      let params = {
        code: this.code,
      };
      queryDeedTaxInfoByCode(params).then((res) => {
        console.log(res);
        if (res.code == 200) {
          // this.state = res.data.state
          this.active = 0;
          this.form.name = res.data.name;
          this.form.phone = res.data.phone;
          this.form.idCard = res.data.idCard;
          this.form.userArea = res.data.userArea;
          this.form.address = res.data.address;
          this.form.bank = res.data.bank;
          this.form.bankCard = res.data.bankCard;
          this.form.square = res.data.square;
          this.form.deedBillCode = res.data.deedBillCode
            ? res.data.deedBillCode
            : "";
          this.form.secondDeedBillCode = res.data.secondDeedBillCode
            ? res.data.secondDeedBillCode
            : "";
          this.form.paymentDeedTaxAmount = res.data.paymentDeedTaxAmount;
          this.form.realEstateArea = res.data.realEstateArea;
          this.form.realEstateAddress = res.data.realEstateAddress;
          this.form.netSignTime = res.data.netSignTime;
          this.form.houseType = res.data.houseType;

          this.front = res.data.realEstateCard.substr(
            res.data.realEstateCard.indexOf("("),
            res.data.realEstateCard.indexOf(")")
          );
          this.after = res.data.realEstateCard.substr(
            res.data.realEstateCard.indexOf("第"),
            res.data.realEstateCard.indexOf("号")
          );
          res.data.pictures.forEach((item) => {
            console.log("item---", item);
            if (item.pictureType == 1) {
              this.form.idimg.push({ url: item.picture });
            } else if (item.pictureType == 2) {
              this.form.contract.push({ url: item.picture });
            } else if (item.pictureType == 3) {
              this.form.certificate.push({ url: item.picture });
            } else if (item.pictureType == 4) {
              this.form.voucher.push({ url: item.picture });
            } else if (item.pictureType == 5) {
              this.form.bankimg.push({ url: item.picture });
            } else if (item.pictureType == 6) {
              this.form.voucher1.push({ url: item.picture });
            }
          });
        }
      });
    },
    go(value) {
      if (value == 1) {
        if (this.form.name == "") {
          this.$toast("请输入姓名");
          return;
        }
        if (this.form.phone == "") {
          this.$toast("请输入手机号码");
          return;
        }
        if (!/^1[3456789]\d{9}$/.test(this.form.phone)) {
          return this.$toast("请输入正确的手机号码");
        }
        if (!this.form.idCard) {
          return this.$toast("请填写身份证号");
        }
        if (
          !/(^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)/.test(
            this.form.idCard
          )
        ) {
          return this.$toast("请输入正确的身份证");
        }
        if (this.form.userArea == "") {
          this.$toast("请选择辖市区");
          return;
        }
        if (this.form.address == "") {
          this.$toast("请输入详细地址");
          return;
        }
        if (this.form.idimg.length < 2) {
          this.$toast("请上传个人身份证(正、反)照");
          return;
        }
        if (this.form.bank == "") {
          this.$toast("请输入开户银行");
          return;
        }
        if (this.form.bankCard == "") {
          this.$toast("请输入银行卡号");
          return;
          // } else {
          //     let pattern = /^([1-9]{1})(\d{14}|\d{18})$/
          //     let str = this.form.bankCard.replace(/\s+/g, "")
          //     if (!pattern.test(str)) {
          //         this.$toast("请输入正确的银行卡号");
          //         return
          //     }
        }
        if (this.form.bankimg.length < 2) {
          this.$toast("请上传银行卡(正、反)照");
          return;
        }
        if (
          this.form.deedBillCode == "" &&
          this.form.secondDeedBillCode == ""
        ) {
          this.$toast("请输入契税发票号码");
          return;
        } else {
          if (this.form.deedBillCode.length != 18) {
            this.$toast("请输入正确的契税发票号码-1");
            return;
          } else if (this.form.voucher.length == 0) {
            this.$toast("请上传契税完税凭证-1");
            return;
          }
          if (this.form.secondDeedBillCode) {
            if (this.form.secondDeedBillCode.length != 18) {
              this.$toast("请输入正确的契税发票号码-2");
              return;
            } else if (this.form.voucher1.length == 0) {
              this.$toast("请上传契税完税凭证-2");
              return;
            }
          }
        }

        if (this.form.paymentDeedTaxAmount == "") {
          this.$toast("请输入缴纳契税金额");
          return;
        }
        if (this.form.square == "") {
          this.$toast("请输入房屋面积");
          return;
        }
        if (this.form.realEstateArea == "") {
          this.$toast("请选择辖市区");
          return;
        }
        if (this.form.realEstateAddress == "") {
          this.$toast("请输入不动产权坐落地址");
          return;
        }
        if (this.form.netSignTime == "") {
          this.$toast("请选择网签时间");
          return;
        } else {
          if (this.date) {
            if (this.date.getTime() < 1651161600000) {
              Dialog.alert({
                title: "提示",
                message:
                  "此申报适用于自2022年4月29日(含当日)至2025年4月29日网签的商品房。",
              });
              return;
            }
          }
        }
        if (!this.form.houseType) {
          this.$toast("请选择房屋属性");
          return;
        }
        if (this.front == "" || this.after == "") {
          this.$toast("请输入正确格式的不动产权证");
          return;
        } else {
          // if (Number(this.front) < 2022) {
          //     this.$toast("请输入2022年以后(含2022年)的不动产权证");
          //     return;
          // }
          this.form.realEstateCard =
            "苏(" + this.front + ")镇江市不动产权第" + this.after + "号";
        }
        if (this.form.certificate.length < 1) {
          this.$toast("请上传不动产权证书");
          return;
        }
        if (this.form.contract.length < 3) {
          this.$toast("请上传房屋买卖合同图片");
          return;
        }
        if (this.form.voucher.length == 0) {
          this.$toast("请上传契税完税凭证-1");
          return;
        }
        for (let i = 0; i < this.form.idimg.length; i++) {
          const element = this.form.idimg[i];
          if (!element.url) {
            this.form.idimg = [];
            this.$toast("请重新上传身份证");
            return;
          }
        }
        for (let i = 0; i < this.form.bankimg.length; i++) {
          const element = this.form.bankimg[i];
          if (!element.url) {
            this.form.bankimg = [];
            this.$toast("请重新上传银行卡照片");
            return;
          }
        }
        for (let i = 0; i < this.form.certificate.length; i++) {
          const element = this.form.certificate[i];
          if (!element.url) {
            this.form.certificate = [];
            this.$toast("请重新上传不动产权证书");
            return;
          }
        }
        for (let i = 0; i < this.form.contract.length; i++) {
          const element = this.form.contract[i];
          if (!element.url) {
            this.form.contract = [];
            this.$toast("请重新上传房屋买卖合同");
            return;
          }
        }
        for (let i = 0; i < this.form.voucher.length; i++) {
          const element = this.form.voucher[i];
          if (!element.url) {
            this.form.voucher = [];
            this.$toast("请重新上传契税完税凭证");
            return;
          }
        }
        this.view = true;
        this.$router.replace({ name: "DeedtaxDeclare1" });
      } else {
        this.showPicker = false;
        this.showPicker1 = false;
        this.view = false;
        this.$router.replace({ name: "DeedtaxDeclare" });
      }
    },
    submit() {
      let params = JSON.parse(JSON.stringify(this.form));
      if (params.voucher1.length == 1) {
        params.pictures = [
          {
            pictureType: 1,
            picture: params.idimg[0].url,
          },
          {
            pictureType: 1,
            picture: params.idimg[1].url,
          },
          {
            pictureType: 2,
            picture: params.contract[0].url,
          },
          {
            pictureType: 2,
            picture: params.contract[1].url,
          },
          {
            pictureType: 2,
            picture: params.contract[2].url,
          },
          {
            pictureType: 3,
            picture: params.certificate[0].url,
          },
          {
            pictureType: 4,
            picture: params.voucher[0].url,
          },
          {
            pictureType: 6,
            picture: params.voucher1[0].url,
          },
          {
            pictureType: 5,
            picture: params.bankimg[0].url,
          },
          {
            pictureType: 5,
            picture: params.bankimg[1].url,
          },
        ];
      } else {
        params.pictures = [
          {
            pictureType: 1,
            picture: params.idimg[0].url,
          },
          {
            pictureType: 1,
            picture: params.idimg[1].url,
          },
          {
            pictureType: 2,
            picture: params.contract[0].url,
          },
          {
            pictureType: 2,
            picture: params.contract[1].url,
          },
          {
            pictureType: 2,
            picture: params.contract[2].url,
          },
          {
            pictureType: 3,
            picture: params.certificate[0].url,
          },
          {
            pictureType: 4,
            picture: params.voucher[0].url,
          },
          {
            pictureType: 5,
            picture: params.bankimg[0].url,
          },
          {
            pictureType: 5,
            picture: params.bankimg[1].url,
          },
        ];
      }
      // params.userId = this.userInfo.userId ? this.userInfo.userId : "37393";
      delete params.idimg;
      delete params.bankimg;
      delete params.certificate;
      delete params.contract;
      delete params.voucher;
      console.log(params);
      this.$toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: "提交中...",
      });
      console.log(this.code);
      if (this.code) {
        params.code = this.code;
        updateDeedTax(params)
          .then((res) => {
            // alert(JSON.stringify(res))
            if (res.code == 200) {
              this.$toast.clear();
              // this.$toast('修改成功');
              this.$router.replace({
                name: "DeedtaxDeclared",
                query: { code: this.code },
              });
            }
            if (res.code == 1004011003) {
              this.$toast.clear();

              this.$dialog
                .alert({
                  message: res.msg,
                })
               
            }
          })
          .catch(() => {
            this.$toast.clear();
            this.$toast("修改失败");
          });
      } else {
        addDeedTax(params)
          .then((res) => {
            console.log(res);
            if (res.code == 200) {
              this.$toast.clear();
              // this.$toast('提交成功');
              this.$router.replace({
                name: "DeedtaxDeclared",
                query: { code: res.data },
              });
            }
            if (res.code == 1004011003) {
              this.$toast.clear();
              this.$dialog
                .alert({
                  message: res.msg,
                })
                
            }
          })
          .catch(() => {
            this.$toast.clear();
            this.$toast("提交失败");
          });
      }
    },
    // 初始化获取userInfo
    JSBgetUserInfo() {
      if (window.android !== undefined) {
        const res = window.android.getUserInfo(); // 这是一个json字符串
        sessionStorage.setItem("ZJCD-UserInfo", res);
        this.userInfo = JSON.parse(res);
      } else if (window.webkit) {
        window.webkit &&
          window.webkit.messageHandlers.getUserInfo.postMessage("getUserInfo");
      }
    },
    getUserInfo(res) {
      sessionStorage.setItem("ZJCD-UserInfo", res);
      this.userInfo = JSON.parse(res);
      this.form.name = this.userInfo.realName;
      this.form.phone = this.userInfo.mobileNo;
      this.form.idCard = decryptByDES(this.userInfo.idCardNo, "MnuYbhGv");
      // alert(JSON.stringify(this.userInfo))
    },
  },
  created() {
    this.JSBgetUserInfo();

    if (this.userInfo) {
      this.form.name = this.userInfo.realName;
      this.form.phone = this.userInfo.mobileNo;
      this.form.idCard = decryptByDES(this.userInfo.idCardNo, "MnuYbhGv");
    }
    if (this.$route.query.code) {
      this.code = this.$route.query.code;
      console.log(this.code);
      this.init();
    }
  },
  mounted() {
    window.getUserInfo = this.getUserInfo;
  },
};
</script>

<style lang="stylus" scoped>
.box_megic {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;

  .megic {
    width: 100px;
    padding: 0;
    margin: 0;
    border-bottom: 1px solid #888;
  }

  .megic2 {
    width: 150px;
  }

  .megic3 {
    width: 300px;
  }
}

.declare-box {
  height: 100vh;
  overflow: auto;

  .content-box1 {
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
    flex-direction: column;
    align-items: center;

    .card-box {
      background: #FFFFFF;
      box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.06);
      border-radius: 8px;
      margin-bottom: 20px;
      padding: 20px;
      box-sizing: border-box;

      .top-box {
        display: flex;
        align-items: center;
        margin: 15px 0;

        .icon {
          width: 4px;
          height: 24px;
          background: #EB4E3F;
          box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.06);
          border-radius: 2px;
        }

        .name {
          font-size: 28px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #333333;
          text-shadow: 0px 2px 12px rgba(0, 0, 0, 0.06);
          margin-left: 15px;
        }
      }

      .bottom-box {
        // display: flex;
        // flex-direction: column;
        // height: 500px;
      }
    }
  }

  .submit-box {
    width: 100%;
    padding: 20px 40px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-around;

    .submit1-box {
      width: 80%;
      height: 88px;
      background: linear-gradient(311deg, #EB4E3F 0%, #FF8138 100%);
      box-shadow: 0px 15px 18px -2px rgba(235, 78, 63, 0.2);
      border-radius: 49px;
      color: #fff;
    }

    .submit2-box {
      width: 40%;
      height: 88px;
      background: linear-gradient(311deg, #EB4E3F 0%, #FF8138 100%);
      box-shadow: 0px 15px 18px -2px rgba(235, 78, 63, 0.2);
      border-radius: 49px;
      color: #fff;
    }
  }
}
</style>
