<template>
  <view>
    <uni-popup
      ref="popup"
      type="center"
      background-color="#fff"
      :duration="2000"
      mask-background-color="rgba(10,10,10,0)"
      ><b>{{ message }}</b></uni-popup
    >
    <view class="uni-list">
      <uni-section title="银行信息" type="line">
        <view class="uni-list-cell" style="text-align: center; width: 95%">
          <!--	<text @click="handleFill" style="margin-right: 50rpx; ">上一条记录填充</text> -->
          <text
            style="
              width: 120%;
              font-size: 6rpx;
              color: gray;
              text-align: right;
              margin-right: 30rpx;
            "
            >使用 [保存本地] 按钮保存
          </text>
          <button
            class="big-button-yellow-s"
            style="width: 58%"
            @click="handleFill()"
            type="primary"
          >
            上一条记录填充
          </button>
        </view>
        <uni-card>
          <view class="uni-list-cell">
            <view class="uni-list-cell-left">
              <text class="required-label">业务归属</text>
            </view>
            <view class="uni-list-cell-db">
              <picker
                @change="handleBranchChange($event)"
                :value="selectBranchComIndex"
                :range="branchComList"
                range-key="whole_name"
              >
                <view>{{ getBranchComName(selectBranchComIndex) }}</view>
              </picker>
            </view>
          </view>
          <view class="uni-list-cell">
            <view class="uni-list-cell-left">
              <text class="required-label">报告类型</text>
            </view>
            <view class="uni-list-cell-db">
              <picker
                @change="onChangeSelect($event, 'reportObjType')"
                :value="selectReportObjTypeIndex"
                :range="reportObjTypeList"
                range-key="fullName"
              >
                <view>{{ getReportObjType(selectReportObjTypeIndex) }}</view>
              </picker>
            </view>
          </view>
          <view class="uni-list-cell">
            <view class="uni-list-cell-left">
              银行名称<text class="require">*</text>
            </view>
            <view class="uni-list-cell-db">
              <picker
                @change="onChangeSelect($event, 'bank')"
                :value="selectBankIndex"
                range-key="name"
                :range="bankList"
              >
                <view>{{
                  bankList[selectBankIndex]
                    ? bankList[selectBankIndex].name
                    : ""
                }}</view>
              </picker>
            </view>
          </view>

          <view class="uni-list-cell">
            <view class="uni-list-cell-left">
              分行名称<text class="require">*</text>
            </view>
            <view class="uni-list-cell-db" v-if="subBankIdList.length > 0">
              <picker
                @change="onChangeSelect($event, 'sub_bank')"
                :value="selectSubBankIndex"
                range-key="name"
                :range="subBankIdList"
              >
                <view>{{
                  subBankIdList[selectSubBankIndex]
                    ? subBankIdList[selectSubBankIndex].name
                    : ""
                }}</view>
              </picker>
            </view>
          </view>

          <view class="uni-list-cell">
            <view class="uni-list-cell-left">
              支行名称<text class="require">*</text>
            </view>
            <view class="uni-list-cell-db">
              <picker
                @select="handleSelect"
                :value="selectBranchBankIndex"
                range-key="name"
                :range="branchBankNameList"
              >
                <view>{{
                  branchBankNameList[selectBranchBankIndex]
                    ? branchBankNameList[selectBranchBankIndex].name
                    : ""
                }}</view>
              </picker>
            </view>
          </view>

          <view class="uni-list-cell">
            <view class="uni-list-cell-left">
              客户经理
            </view>
            <!-- <view class="uni-list-cell-db">
              <picker
                @change="onChangeSelect($event, 'bank_customer_mgr_name')"
                :value="selectCustomerIndex"
                range-key="name"
                :range="accountManagerList"
              >
                <view>{{
                  accountManagerList[selectCustomerIndex]
                    ? accountManagerList[selectCustomerIndex].name
                    : ""
                }}</view>
              </picker>
            </view> -->
            <view class="uni-list-cell-right">
              <input
                class="uni-input"
                v-model="addForm.bank_customer_mgr_name"
                maxlength="50"
                placeholder="请输入，最多50字"
                @input="handleCustomerNameInput"
              />
              <div
                v-show="accountManagerList.length > 0"
                class="property-dropdown border-1px"
              >
                <div v-if="customerLoading" class="loading-indicator">
                  <i class="el-icon-loading"></i> 加载中...
                </div>
                <ul v-else>
                  <li
                    v-for="item in accountManagerList"
                    :key="item.id"
                    @click="selectCustomer(item)"
                    class="property-option"
                  >
                    <div
                      :content="item.name"
                      placement="top"
                      :open-delay="0"
                      style="text-align: left;"
                    >
                      <span>{{ item.name }}</span>
                    </div>
                  </li>
                </ul>
              </div>
            </view>
          </view>

          <view class="uni-list-cell">
            <view class="uni-list-cell-left">
              客户经理手机
            </view>
            <view class="uni-list-cell-db">
              <input
                class="uni-input"
                v-model="addForm.bank_customer_mgr_phone"
                maxlength="50"
                placeholder="请输入"
              />
            </view>
          </view>

          <view class="uni-list-cell">
            <view class="uni-list-cell-left">
              评估目的<text class="require">*</text>
            </view>
            <view class="uni-list-cell-db">
              <picker
                @change="onChangeSelect($event, 'eva_purpose')"
                :value="selectEvaPurposeIndex"
                :range="evaluatePurposeList"
                range-key="name"
              >
                <view>{{
                  evaluatePurposeList[selectEvaPurposeIndex].name
                }}</view>
              </picker>
            </view>
          </view>
          <view class="uni-list-cell">
            <view class="uni-list-cell-left">
              业务员<text class="require">*</text>
            </view>
            <view class="uni-list-cell-db">
              <picker
                @change="onChangeSelect($event, 'select_buss_user')"
                :value="selectBussUserIndex"
                :range="userList"
                range-key="userNickName"
              >
                <view>{{
                  userList[selectBussUserIndex]
                    ? userList[selectBussUserIndex].userNickName
                    : ""
                }}</view>
              </picker>
            </view>
          </view>
          <view class="uni-list-cell">
            <view class="uni-list-cell-left">
              贷款种类<text class="require">*</text>
            </view>
            <view class="uni-list-cell-db">
              <picker
                @change="onChangeSelect($event, 'loan_type')"
                :value="selectProductIndex"
                :range="loanTypeList"
                range-key="product_name"
              >
                <view>{{
                  loanTypeList[selectProductIndex]
                    ? loanTypeList[selectProductIndex].product_name
                    : ""
                }}</view>
              </picker>
            </view>
          </view>
        </uni-card>
      </uni-section>
      <view class="line2"></view>
      <uni-section title="物业信息" type="line">
        <view v-for="(item, index) in addForm.details" :key="index">
          <uni-card>
            <view>
              <view
                class="uni-flex uni-row"
                style="justify-content: space-between"
              >
                <view style="font-size: 32rpx"> 物业 - {{ index + 1 }} </view>
                <view>
                  <button
                    v-if="addForm.details.length != 0"
                    size="mini"
                    type="warn"
                    @click="onDelPress(index)"
                  >
                    删除
                  </button>
                  <button
                    v-if="addForm.details.length != 0"
                    size="mini"
                    type="primary"
                    @click="onCopyPress(index)"
                    style="margin-left: 10rpx"
                  >
                    复制
                  </button>
                </view>
                <!-- <view>
							<button size="mini" @click="editProperty(index)">编辑</button>
						</view> -->
              </view>
            </view>
            <view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  物业名称<text class="require">*</text>
                </view>
                <view class="uni-list-cell-db">
                  <input
                    class="uni-input"
                    v-model="item.building_name"
                    maxlength="50"
                    placeholder="请输入，最多50字"
                    @input="handleBuildingNameInput"
                  />
                  <div
                    v-show="estateOptions.length > 0"
                    class="property-dropdown border-1px"
                  >
                    <div v-if="estateLoading" class="loading-indicator">
                      <i class="el-icon-loading"></i> 加载中...
                    </div>
                    <ul v-else>
                      <div style="text-align:right;margin-right: 20rpx;color:red;" @click="cancelSelect(index, 1)">取消</div>
                      <li
                        v-for="estate in estateOptions"
                        :key="estate.lp_id"
                        @click="selectEstate(estate, index)"
                        class="property-option"
                      >
                        <div
                          :content="estate.loupan_name"
                          placement="top"
                          :open-delay="0"
                        >
                          <span>{{ estate.loupan_name }}</span>
                        </div>
                      </li>
                    </ul>
                  </div>
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  栋号<text class="require">*</text>
                </view>
                <view class="uni-list-cell-db">
                  <input
                    class="uni-input"
                    v-model="item.building_no"
                    maxlength="15"
                    placeholder="请输入"
                    @input="handleBuildingInput(index)"
                  />
                  <div
                    v-show="buildingOptions.length > 0"
                    class="property-dropdown"
                  >
                    <div v-if="buildingLoading" class="loading-indicator">
                      <i class="el-icon-loading"></i> 加载中...
                    </div>
                    <ul v-else>
                      <div style="text-align:right;margin-right: 20rpx;color:red;" @click="cancelSelect(index, 2)">取消</div>
                      <li
                        v-for="building in buildingOptions"
                        :key="building.b_id"
                        @click="selectBuilding(building, index)"
                        class="property-option"
                      >
                        <div
                          :content="building.building_name"
                          placement="top"
                          :open-delay="0"
                        >
                          <span>{{ building.building_name }}</span>
                        </div>
                      </li>
                    </ul>
                  </div>
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  房号<text class="require">*</text>
                </view>
                <view class="uni-list-cell-db">
                  <input
                    class="uni-input"
                    v-model="item.unit_no"
                    maxlength="15"
                    placeholder="请输入"
                    @input="handleUnitNoInput($event, index)"
                  />
                  <div
                    v-show="unitOptions.length > 0"
                    class="property-dropdown"
                  >
                    <div v-if="unitLoading" class="loading-indicator">
                      <i class="el-icon-loading"></i> 加载中...
                    </div>
                    <ul v-else>
                      <div style="text-align:right;margin-right: 20rpx;color:red;" @click="cancelSelect(index, 3)">取消</div>
                      <li
                        v-for="unit in unitOptions"
                        :key="unit.h_id"
                        @click="selectUnit(unit, index)"
                        class="property-option"
                      >
                        <div
                          :content="unit.house_number"
                          placement="top"
                          :open-delay="0"
                        >
                          <span>{{ unit.house_number }}</span>
                        </div>
                      </li>
                    </ul>
                  </div>
                </view>
              </view>
			  <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  购买/登记日期<text class="require">*</text>
                </view>
                <view class="uni-list-cell-db">
                  <picker
                    mode="date"
                    :value="item.purchase_date"
                    :start="startDate"
                    :end="endDate"
                    placeholder="请选择日期"
                    @change="
                      onChangeSelect($event, 'RegisterTime', index, item)
                    "
                  >
                    <view class="uni-input">{{ item.purchase_date }}</view>
                  </picker>
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  购买年限
                </view>
                <view class="uni-list-cell-db">
                  <picker
                    @change="onChangeSelect($event, 'Over2year', index)"
                    :value="selectOver2YearIndex[index].index"
                    :range="isOver2yearList"
                    range-key="name"
                  >
                    <view>{{
                      isOver2yearList[selectOver2YearIndex[index].index].name
                    }}</view>
                  </picker>
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  建筑面积（m²）<text class="require">*</text>
                </view>
                <view class="uni-list-cell-db">
                  <input
                    class="uni-input"
                    style="box-sizing: border-box; height: 100%"
                    v-model="item.size"
                    placeholder="请输入"
                  />
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  登记价（元）<text class="require">*</text>
                </view>
                <view class="uni-list-cell-db">
                  <input
                    type="digit"
                    class="uni-input"
                    v-model="item.reg_price"
                    placeholder="请输入"
                  />
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  房屋用途<text class="require">*</text>
                </view>
                <!--						<div>-->
                <!--						   <FuzzyPicker :parentIndex="index" ref="searchUsageText" :list="houseUsageList" @select="handleUsageSelect"></FuzzyPicker>-->
                <!--						 </div>-->
                <view class="uni-list-cell-db">
                  <picker
                    @change="onChangeSelect($event, 'HouseUsage', index)"
                    :value="selectHouseUsageIndex[index].index"
                    :range="houseUsageList"
                    range-key="valname"
                  >
                    <view>{{
                      houseUsageList[selectHouseUsageIndex[index].index]
                        ? houseUsageList[selectHouseUsageIndex[index].index]
                            .valname
                        : ""
                    }}</view>
                  </picker>
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  产权人类型<text class="require">*</text>
                </view>
                <view class="uni-list-cell-db">
                  <picker
                    @change="onChangeSelect($event, 'TenureType', index)"
                    :value="selectTenureTypeIndex[index].index"
                    :range="tenureTypeList"
                    range-key="name"
                  >
                    <view>{{
                      tenureTypeList[selectTenureTypeIndex[index].index].name
                    }}</view>
                  </picker>
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  所在城市<text class="require">*</text>
                </view>
                <view class="uni-list-cell-db">
                  <picker
                    @change="onChangeSelect($event, 'City', index)"
                    :value="selectCityIndex[index].index"
                    :range="buildingCityList"
                    range-key="shortname"
                  >
                    <view>{{
                      buildingCityList[selectCityIndex[index].index]
                        ? buildingCityList[selectCityIndex[index].index]
                            .shortname
                        : ""
                    }}</view>
                  </picker>
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left"> 房产证号 </view>
                <view class="uni-list-cell-db">
                  <input
                    class="uni-input"
                    v-model="item.property_cert"
                    maxlength="50"
                    placeholder="请输入"
                  />
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  证载用途
                </view>
                <view class="uni-list-cell-db">
                  <input
                    class="uni-input"
                    v-model="item.cert_usage"
                    maxlength="50"
                    placeholder="请输入"
                  />
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  竣工日期
                </view>
                <view class="uni-list-cell-db">
                  <picker
                    mode="date"
                    :value="item.completion_time"
                    :start="startDate"
                    :end="endDate"
                    @change="onChangeSelect($event, 'FinishTime', index, item)"
                  >
                    <view class="uni-input">{{ item.completion_time }}</view>
                  </picker>
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  房屋性质
                </view>
                <view class="uni-list-cell-db">
                  <picker
                    @change="onChangeSelect($event, 'useRightSource', index)"
                    :value="selectUseRightSourceIndex"
                    :range="useRightSourceList"
                    range-key="name"
                  >
                    <view>{{
                      useRightSourceList[selectUseRightSourceIndex].name
                    }}</view>
                  </picker>
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left"> 土地位置 </view>
                <view class="uni-list-cell-db">
                  <input
                    class="uni-input"
                    v-model="item.land_location"
                    maxlength="150"
                    placeholder="请输入"
                  />
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left"> 权利人 </view>
                <view class="uni-list-cell-db">
                  <input
                    class="uni-input"
                    v-model="item.obligee"
                    maxlength="150"
                    placeholder="请输入"
                  />
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left"> 备注 </view>
                <view class="uni-list-cell-db">
                  <textarea
                    class="uni-input"
                    v-model="item.remark"
                    auto-height="true"
                    maxlength="150"
                    placeholder="请输入"
                  />
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  产证图片
                  <!--<text class="require">*</text>--><text
                    v-if="isBussinessInquiryType()"
                    class="require"
                    >*</text
                  >
                </view>
                <view class="uni-list-cell-db">
                  <text style="color: red" v-if="isImageUploading">上传中...</text>
                  <uni-file-picker
                    :auto-upload="false"
                    v-model="item.attachments_image"
                    file-mediatype="image"
                    mode="grid"
                    file-extname="png,jpg,jpeg"
                    :disable-preview="false"
                    @progress="progress"
                    @success="success"
                    @fail="fail"
                    @select="selectImg($event, index, item, 'image_upload')"
                    @delete="handleDelete($event, index)"
                  />
                </view>
              </view>
              <view class="uni-list-cell">
                <view class="uni-list-cell-left">
                  产证文件
                  <!--<text class="require">*</text>--><text
                    v-if="isBussinessInquiryType()"
                    class="require"
                >*</text
                >
                </view>
                <view class="uni-list-cell-db">
                  <text style="color: red" v-if="isFileUploading">上传中...</text>
                  <uni-file-picker
                      :auto-upload="false"
                      v-model="item.attachments_file"
                      file-mediatype="all"
                      mode="grid"
                      file-extname="doc,docx,xls,xlsx,pdf"
                      @progress="progress"
                      @success="success"
                      @fail="fail"
                      @select="selectImg($event, index, item, 'file_upload')"
                      @delete="handleDelete($event, index)"
                  />
                </view>
              </view>
            </view>
          </uni-card>
        </view>
      </uni-section>
      <view style="display: flex; flex-direction: row; height: 80rpx">
        <button
          class="big-button-yellow"
          size="mini"
          style="
            margin-top: 10rpx;
            text-align: center;
            width: 220rpx;
            height: 60rpx;
          "
          @click="saveInquiry()"
          type="primary"
        >
          保存本地
        </button>
        <button
          class="big-button"
          size="mini"
          style="
            margin-top: 10rpx;
            text-align: center;
            width: 220rpx;
            height: 60rpx;
          "
          @click="sumbmit()"
          type="primary"
          :loading="isLoading"
          :disabled="isLoading"
        >
          提交
        </button>
      </view>
    </view>
    <view class="uni-flex uni-row" style="position: fixed; right:0; bottom: 100rpx;z-index:99;">
      <button size="mini" type="primary" style="border-radius: 50rpx;font-size: 24rpx;" @click="newProperty()">
        添加物业
      </button>
    </view>
  </view>
</template>

<script>
import {
  getDictionaryByType,
  getUserList,
  getAccountManager,
  repeatInquirySave,
  checkExistInquiry,
  getBuildingCity,
  consultFiles,
  getProduct,
  getBranch,
  getBankForInquiry,
  save,
  getBranchCompanyList,
  getReportObjTypeList,
  getEstateListByName,
  getBuildingListByBName,
  getPropertyListByBid,
  ocrRecogniseHouseCert,
  getThreeMonthSameEstateInquiryRecord
} from "api/inquiry/inquiry";
import { uploadImg } from "@/api/common";
import { getUserID } from "../../utils/auth";
import FuzzyPicker from "../common/FuzzyPicker/FuzzyPicker.vue";
import LocalStroage from "../../plugins/localstorageManager.js";
import localstorageManager from "../../plugins/localstorageManager.js";
import constant from "../../utils/constant";
import { toast, encrypto, decrypto } from "../../utils/common";

// 个人住宅 - 非商业
const INQUERY_T_ESTATE = 1;

// 非个人-商业
const INQUERY_T_BUSSINESS = 2;

// 保存本地询价
const LOCAL_DATA_SAVE = "saveInquiry";

export default {
  name: "Index",
  components: {
    FuzzyPicker,
  },
  data() {
    const currentDate = this.getDate({
      format: true,
    });
    const USAGE_HOUSE = "1";

    return {
      isLoading: false,
      customerLoading: false,
      isUploading: false,
      isImageUploading: false,
      isFileUploading: false,
      shenzhencityIndex: 0,
      selectBussUserIndex: 0,
      selectBankIndex: 0,
      selectSubBankIndex: 0,
      selectBranchBankIndex: 0,
      selectCustomerIndex: 0,
      selectEvaPurposeIndex: 0,
      selectProductIndex: 0,
      selectOver2YearIndex: [{ index: 0 }],
      selectCityIndex: [{ index: 2 }],
      selectHouseUsageIndex: [{ index: 0 }],
      selectTenureTypeIndex: [{ index: 0 }],
      selectUseRightSourceIndex: 0, //房屋性质
      selectBranchComIndex: 1,
      selectReportObjTypeIndex: 0, // 报告类型索引
      message: "",
      showMessage: false,
      filePathsList: [],
      tempFilePaths: [],
      branchComList: [], //业务归属
      reportObjTypeList: [], //报告类型数组
      useRightSourceList: [],
      estateOptions: [],
      estateLoading: false, // 加载中
      buildingOptions: [],
      buildingLoading: false, // 加载中
      unitOptions: [], //单元
      unitLoading: false, // 加载中
      addForm: {
        buss_user_id: "",
        buss_username: "",
        type: 1, // 住宅
        product_id: "",
        bank_id: "",
        bank_branch_id: "", // 分行id
        bank_sub_id: "", //支行id
        bank_name: "",
        bank_branch_name: "", //分行名
        bank_sub_name: "", // 支行名称
        bank_customer_mgr_name: "",
        bank_customer_mgr_phone: "",
        eva_purpose: "",
        business_no: "",
        branchCom_id: 0,
        loan_type: "",
        report_obj_type: 0,
        details: [
          {
            city_id: "440300",
            usage: "1",
            ownership_type: 1,
            consult_id: "",
            tax_type: "",
            year: "",
            city: "深圳",
            building_name: "",
            property_full_name: "",
            building_no: "",
            unit_no: "",
            property_cert: "",
            reg_price: "",
            purchase_date: "",
            completion_time: "",
            obligee: "",
            land_location: "",
            is_tran_tax_free: "1",
            size: "",
            remark: "",
            attachments: [],
            attachments_obj: [],
            use_right_source: "1", //房屋性质
            cert_usage: "住宅",
            attachments_file: [],
            attachments_image: [],
          },
        ],
      },
      isOver2yearList: [
        {
          name: "已满两年",
          id: 1,
        },
        {
          name: "未满两年",
          id: 2,
        },
      ],
      tenureTypeList: [
        {
          name: "个人",
          id: 1,
        },
        {
          name: "公司",
          id: 2,
        },
      ],
      inquiryInvailList: [],
      userList: [],
      buildingCityList: [],
      houseUsageList: [],
      bankList: [],
      subBankIdList: [],
      branchBankNameList: [],
      accountManagerList: [],
      loanTypeList: [],
      evaluatePurposeList: [
        { id: 1, name: "抵押" },
        { id: 2, name: "了解市值" },
      ],
      searchParam: {}
    };
  },

  computed: {
    startDate() {
      return this.getDate("start");
    },
    endDate() {
      return this.getDate("end");
    },
  },

  async created() {
    // init bank select
    await this.initSelectBank();
    //初始化业务员
    this.initSelectUser();
    // init buildingCity select
    this.initSelectBuildingCity();
    // init initDictionaryByType select
    this.initDictionaryByType();
    // 初始化分公司选项
    this.loadBranchOptions();
    //加载报告类型
    this.initReportObjTypesOptions();
    //提取最近保存的询价
    // this.handleFill();
  },

  methods: {
    // 是商业询价类型 1-个人住宅（住宅） 2-个人非住宅（商业）
    isBussinessInquiryType() {
      // return (INQUERY_T_BUSSINESS ==  this.inquiryTypeList[ this.selectInquiryTypeIndex ].id);
      return 1 == this.addForm.details.usage;
    },

    initReportObjTypesOptions() {
      const res = getReportObjTypeList(this.addForm).then((res) => {
        if (res.code === 1) {
          this.reportObjTypeList = res.data;
          this.addForm.report_obj_type = res.data[0].id;
        } else {
          this.$Message.error(res.msg);
        }
      });
    },
    handleBranchChange(event) {
      this.selectBranchComIndex = event.detail.value;
      this.addForm.branchCom_id =
        this.branchComList[this.selectBranchComIndex].id;
    },

    loadBranchOptions() {
      try {
        const res = getBranchCompanyList(this.addForm).then((res) => {
          console.log("loalBranchOptions", res.data);
          if (res.code === 1) {
            this.branchComList = res.data.list;
            this.branchComList.forEach((item) => {
              return (item.whole_name =
                item.full_name + "(" + item.short_name + ")");
            });
            this.addForm.branchCom_id = res.data.list[0].id;
          } else {
            //this.$message.error(res.msg || '获取分公司列表失败')
          }
        });
      } catch (error) {
        console.error("获取分公司列表失败:", error);
        //this.$message.error('获取分公司列表失败')
      }
    },

    /**
			 * 获取分公司名字
			 @param {Object} index
			 */
    getBranchComName(index) {
      const item = this.branchComList[index];
      if (null != item) {
        // return (item.full_name+"("+item.short_name+")");
        return item.whole_name;
      }
      return "";
    },

    getReportObjType(index) {
      const item = this.reportObjTypeList[index];
      if (null != item) {
        return item.fullName;
      }
      return "";
    },

    getDate(type) {
      const date = new Date();
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();

      if (type === "start") {
        year = year - 100;
      } else if (type === "end") {
        year = year + 100;
      }
      month = month > 9 ? month : "0" + month;
      day = day > 9 ? day : "0" + day;
      return `${year}-${month}-${day}`;
    },
    // 保存询价数据
    saveInquiry() {
      let content = {};
      for (let key in this.$data) {
        if (this.$data.hasOwnProperty(key)) {
          if (key === 'addForm') {
            this.$data[key].details.forEach((item) => {
              item.attachments = [];
              item.attachments_obj = [];
              item.attachments_file = [];
              item.attachments_image = [];
            })
          }
          content[key] = this.$data[key];
        }
      }
      	// console.log('content:',JSON.stringify(content));
      localstorageManager.setPageStorage(
        this,
        LOCAL_DATA_SAVE,
        JSON.stringify(content)
      );
      toast("已保存本地！您可点击 [上一条记录填充] 找回。");
    },

    // 上一条填充数据
    handleFill() {
      let content = JSON.parse(
        localstorageManager.getPageStorage(this, LOCAL_DATA_SAVE)
      );
      console.log("handleFile", content);
      if (content == null) {
      	return;
      }
      for (let key in content) {
        if (this.$data.hasOwnProperty(key)) {
          //localstorageManager.setPageStorage( this, key, this.$data[key] );
          this.$data[key] = content[key];
        }
      }

      this.$refs.branchBankName.selectItem({
        id: content.addForm.bank_branch_id,
        name: content.addForm.bank_branch_name,
      });
    },

    // 检查必填字段
    checkDetailsFields() {
      let returnOK = true;
      let errMsg = "";
      let i = 0;

      if (returnOK === true && this.addForm.bank_id === "" || this.addForm.bank_name === "") {
        returnOK = false;
        errMsg = "请选择银行";
      }

      if (returnOK === true && this.addForm.bank_branch_id === "" || this.addForm.bank_branch_name === "") {
        returnOK = false;
        errMsg = "请选择分行";
      }

      if (returnOK === true && this.addForm.bank_sub_id === "" || this.addForm.bank_sub_name === "") {
        returnOK = false;
        errMsg = "请选择支行";
      }

      if (returnOK === true && this.addForm.eva_purpose === "") {
        returnOK = false;
        errMsg = "请选择评估目的";
      }

      // 检查业务员一栏是否为空
      if (returnOK === true && this.addForm.buss_username === "") {
        returnOK = false;
        errMsg = "请选择业务员";
      }

      for (let detail of this.addForm.details) {
        ++i;
        console.log("detail:", detail);

        if (returnOK === true && detail.building_name === "") {
          returnOK = false;
          errMsg = " 请填写[物业" + i + "]的物业名称";
          break;
        }
        if (returnOK === true && detail.building_no === "") {
          returnOK = false;
          errMsg = " 请填写[物业" + i + "]的栋号";
          break;
        }
        if (returnOK === true && detail.unit_no === "") {
          returnOK = false;
          errMsg = " 请填写[物业" + i + "]的房号";
          break;
        }
        console.log(111111);
        if (returnOK === true && detail.purchase_date === "") {
          returnOK = false;
          errMsg = " 请填写[物业" + i + "]的购买/登记日期";
          break;
        }
        if (returnOK === true && detail.size === "") {
          returnOK = false;
          errMsg = " 请填写[物业" + i + "]的建筑面积";
          break;
        }
        if (returnOK === true && detail.reg_price === "") {
          returnOK = false;
          errMsg = " 请填写[物业" + i + "]的登记价";
          break;
        }
  
        if (returnOK === true && detail.usage === "") {
          returnOK = false;
          errMsg = " 请填写[物业" + i + "]的房屋用途";
          break;
        }
        if (returnOK === true && detail.ownership_type === "") {
          returnOK = false;
          errMsg = " 请填写[物业" + i + "]的权利人类型";
          break;
        }
        if (returnOK === true && detail.city === "") {
          returnOK = false;
          errMsg = " 请填写[物业" + i + "]的所在城市";
          break;
        }
      }
      return {
        returnOK,
        errMsg,
      };
    },
    sumbmit() {
      // 如果已经在加载中，则直接返回，防止重复提交
      if (this.isLoading) {
        return;
      }
        
      this.isLoading = true;
      uni.showLoading({
        title: "正在提交...",
        mask: true,
      });
      
      const res = this.sumbmitInquiry();
      if (res) {
        uni.hideLoading();
      }
    },

    // 提交询价
    sumbmitInquiry() {
      // 检查字段填写并提示
      let checkRes = {returnOK: true, errMsg: ""};
      checkRes = this.checkDetailsFields();

      if (!checkRes.returnOK) {
        this.isLoading = false;
        uni.showToast({
          title: checkRes.errMsg,
          icon: "error",
          duration: 2000,
        });
        return true;
      }

      // 商业必须提交房产证
      if (this.isBussinessInquiryType()) {
        for (let i = 0; i < this.addForm.details.length; ++i) {
          if (this.addForm.details[i].attachments.length == 0) {
            this.isLoading = false;
            uni.showToast({
              title: "非个人住宅(商业)请上传房产证！",
              icon: "error",
              duration: 2000,
            });
            return true;
          }
        }
      }

      // 如果是单套物业直接保存
      if (this.addForm.details.length > 1) {
        // 没询过价，直接保存
        save(this.addForm).then((res) => {
          if (res.code === 1) {
            localstorageManager.removePageStorage(this, LOCAL_DATA_SAVE, "");
            this.$tab.navigateTo("/pages/inquiry/index");
          } else {
            this.isLoading = false;
            //	console.log('res.data:',res.data)
            uni.showToast({
              title: this.getErrorMsg(res.data),
              icon: "error",
              duration: 2000,
            });
          }
        });
        return true;
      } else {
        checkExistInquiry(this.addForm).then((res) => {
          if (res.code === 1) {
            if (res.data.repeat_type === 1) {
              // 没询过价，直接保存
              save(this.addForm).then((res) => {
                if (res.code === 1) {
                  uni.showToast({
                    title: "询价已提交，请您耐心等候回价。",
                    icon: "success",
                    duration: 2000,
                  });
                  setTimeout(() => {
                    localstorageManager.removePageStorage(
                      this,
                      LOCAL_DATA_SAVE,
                      ""
                    );
                    this.$tab.navigateTo("/pages/inquiry/index");
                  }, 2200);
                } else {
                  this.isLoading = false;
                  uni.showToast({
                    title: this.getErrorMsg(res.data),
                    icon: "error",
                    duration: 2000,
                  });
                }
              });
            } else if (res.data.repeat_type === 2) {
              repeatInquirySave(this.addForm).then((res) => {
                if (res.code === 1) {
                  uni.showToast({
                    title: "物业已回过价格，已给您自动回价。",
                    icon: "success",
                    duration: 2000,
                  });
                  setTimeout(() => {
                    localstorageManager.removePageStorage(
                      this,
                      LOCAL_DATA_SAVE,
                      ""
                    );
                    this.$tab.navigateTo("/pages/inquiry/index");
                  }, 2200);
                } else {
                  this.isLoading = false;
                  uni.showToast({
                    title: res.msg,
                    icon: "error",
                    duration: 2000,
                  });
                }
              });
            } else {
              // 没询过价，直接保存
              save(this.addForm).then((res) => {
                if (res.code === 1) {
                  uni.showToast({
                    title: "询价已提交，请您耐心等候回价。",
                    icon: "success",
                    duration: 2000,
                  });
                  setTimeout(() => {
                    localstorageManager.removePageStorage(
                      this,
                      LOCAL_DATA_SAVE,
                      ""
                    );
                    this.$tab.navigateTo("/pages/inquiry/index");
                  }, 2200);
                } else {
                  this.isLoading = false;
                  uni.showToast({
                    title: this.getErrorMsg(res.data),
                    icon: "error",
                    duration: 2000,
                  });
                }
              });
            }
          } else {
            this.isLoading = false;
            uni.showToast({ title: res.msg, icon: "error", duration: 2000 });
          }
        });
        return true;
      }
    },

    getErrorMsg(data) {
      let errMsg = "输入有误：";
      for (let i in data) {
        let item = data[i];
        for (let k in item) errMsg += item[k] + " ";
      }
      return errMsg;
    },

    // 选择文件，获取上传状态
    selectImg(e, index, item, name) {
      this.tempFilePaths = e.tempFilePaths;
      if (!this.tempFilePaths.length) return;
      // const path = this.tempFilePaths.pop();

      // this.isUploading = true;
      if (name === 'image_upload') {
        this.isImageUploading = true;
      } else {
        this.isFileUploading = true;
      }

      this.tempFilePaths.forEach((path) => {
        uploadImg({filePath: path})
            .then((response) => {
              const data = response.data;
              const id = data.id;
              if (id) {
                if (name === 'image_upload') {
                  this.addForm.details[index].attachments.unshift(id);
                  this.addForm.details[index].attachments_obj.unshift({
                    id: id,
                    path: path
                  });
                  // 判断是否最后一个文件
                  if (path === this.tempFilePaths.pop()) {
                    // 调用OCR识别
                    // this.ocrRecognise(index);
                  }
                } else {
                  this.addForm.details[index].attachments.push(id);
                  this.addForm.details[index].attachments_obj.push({
                    id: id,
                    path: path
                  });
                }
              }

              // uni.showToast({title: "上传成功", icon: "success"});
              // this.isUploading = false;
              this.isImageUploading = false;
              this.isFileUploading = false;
            })
            .catch((err) => {
              uni.showToast({title: err, icon: "error"});
              window.console.log(err);
              // this.isUploading = false;
              this.isImageUploading = false;
              this.isFileUploading = false;
            });
      });
    },
    //OCR识别
    ocrRecognise(index) {
      uni.showLoading({title: '产证OCR识别中...', mask: true});
      let fileIds = this.addForm.details[index].attachments
      ocrRecogniseHouseCert({file_ids: fileIds}).then((res) => {
        if (res.code === 1) {
          // 处理OCR识别结果
          if (this.addForm.details[index].property_cert === '') {
            this.addForm.details[index].property_cert = res.data.property_cert;//房产证号
          }
          if (this.addForm.details[index].city === '') {
            this.addForm.details[index].city = res.data.city;//城市名称
            this.addForm.details[index].city_id = res.data.city_id;//城市id
          }
          if (this.addForm.details[index].obligee === '') {
            this.addForm.details[index].obligee = res.data.obligee;//权利人名称
          }
          if (this.addForm.details[index].cert_no === '') {
            this.addForm.details[index].cert_no = res.data.cert_no;//证件号码
          }
          if (this.addForm.details[index].size === '') {
            this.addForm.details[index].size = res.data.size;//面积
          }
          if (this.addForm.details[index].reg_price === '') {
            this.addForm.details[index].reg_price = res.data.reg_price;//登记价
          }
          if (this.addForm.details[index].completion_time === '') {
            this.addForm.details[index].completion_time = res.data.completion_time;//竣工日期
          }
          if (this.addForm.details[index].purchase_date === '') {
            this.addForm.details[index].purchase_date = res.data.purchase_date;//购买日期
            if (res.data.purchase_date != '') {
              let rt = new Date(res.data.purchase_date);
              let now = new Date();
              let betweenyear = (now - rt) / 1000 / 60 / 60 / 24 / 365;

              if (betweenyear >= 2) {
                this.selectOver2YearIndex[index].index = 0;
                this.addForm.details[index].is_tran_tax_free =
                  this.isOver2yearList[this.selectOver2YearIndex[index].index].id;
              } else {
                this.selectOver2YearIndex[index].index = 1;
                this.addForm.details[index].is_tran_tax_free =
                  this.isOver2yearList[this.selectOver2YearIndex[index].index].id;
              }
            }
          }
          if (this.addForm.details[index].use_right_source === '') {
            this.addForm.details[index].use_right_source = res.data.use_right_source;//房屋性质
          }
          if (this.addForm.details[index].building_name === '') {
            this.addForm.details[index].building_name = res.data.property_full_name;//物业名称
            this.addForm.details[index].building_no = " ";//栋号
            this.addForm.details[index].unit_no = " ";//单元号
          }
          if (this.addForm.details[index].ownership_type === '') {
            this.addForm.details[index].ownership_type = res.data.ownership_type;//权利人类型
          }
          if (this.addForm.details[index].usage === '') {
            this.addForm.details[index].usage = res.data.usage;//用途
          }
          uni.hideLoading();
          uni.showToast({title: '产证OCR识别成功', icon: 'success'});
        } else {
          uni.hideLoading();
          uni.showToast({title: '产证OCR识别失败，请删除附件重新上传', icon: 'error'});
        }
      });
    },
    handleDelete(e, index) {
      this.addForm.details[index].attachments_obj.forEach((item) => {
        if (item.path === e.tempFilePath) {
          this.addForm.details[index].attachments_obj.splice(
            this.addForm.details[index].attachments_obj.indexOf(item),
            1
          );
          this.addForm.details[index].attachments.splice(
            this.addForm.details[index].attachments.indexOf(item.id),
            1
          );
        }
      }
      );
    },

    onDelPress(index) {
      if (this.addForm.details.length === 1) {
        uni.showToast({ title: "删除物业成功！", icon: "success" });
      } else {
        this.addForm.details.splice(index, 1);
        this.selectOver2YearIndex.splice(index, 1);
        this.selectHouseUsageIndex.splice(index, 1);
        this.selectCityIndex.splice(index, 1);
        uni.showToast({ title: "删除物业成功！", icon: "success" });
      }
    },
    newProperty() {
      /*   if (this.addForm.details.length === 3) {
			        return
			      }*/
				  this.addForm.details.push({
            city_id: "440300",
            usage: "1",
            ownership_type: 1,
            consult_id: "",
            tax_type: "",
            year: "",
            city: "深圳",
            building_name: "",
            property_full_name: "",
            building_no: "",
            unit_no: "",
            property_cert: "",
            reg_price: "",
            purchase_date: "",
            completion_time: "",
            obligee: "",
            land_location: "",
            is_tran_tax_free: "1",
            size: "",
            remark: "",
            attachments: [],
            attachments_obj: [],
            use_right_source: "1", //房屋性质
            cert_usage: "住宅",
            attachments_file: [],
            attachments_image: [],
      });

      let lastIndex = this.addForm.details.length - 1;
      this.initSelectBuildingCity(lastIndex);

      this.selectOver2YearIndex.push({ index: 0 });
      this.selectHouseUsageIndex.push({ index: this.getHouseUsageIndex("1") });
      this.selectCityIndex.push({ index: this.shenzhencityIndex });
      this.selectTenureTypeIndex.push({ index: 0 });

      this.usageItem = this.findUsageItem(this.houseUsageList, "住宅");
      let idx = Number(this.addForm.details.length - 1);
      //console.log('this.$refs.searchUsageText idx :'+ idx);
      uni.showToast({
        title: "添加新物业成功!",
        icon: "success",
        duration: 2000,
      });

      // 因为元素还没渲染出来，所以放到下一贞执行
      this.$nextTick(() => {
        if (this.$refs.searchUsageText.length >= 2) {
          //console.log(this.$refs.searchUsageText[1]);
          this.$refs.searchUsageText["1"].selectItem({
            id: usageItem.id,
            name: usageItem.name,
          });
        }
      });
    },

    // 获取房屋用途索引值
    getHouseUsageIndex(usageCode) {
      let idx = 0;
      for (let i = 0; i < this.houseUsageList.length; ++i) {
        if (this.houseUsageList[i].code == usageCode) {
          return i;
        }
      }
      return 0;
    },

    editProperty(index) {},
    onInitialBankFinish(res_data) {
      if (this.$route.query.business_no) {
        this.initialQueryVals();
      }
    },

    doFailed(res_code) {
      let tips = "";
      if (res_code === 0) {
        tips = "您登陆超时了，请重新登陆";
      } else {
        tips = "系统错误，提示码为[" + res_code + "] ,请跟系统管理员联系。";
      }

      // 弹出提示框
      uni.showToast({
        title: tips,
        icon: "error",
        duration: 2000,
      });

      // 跳转页面
      setTimeout(() => {
        localstorageManager.removePageStorage(this, LOCAL_DATA_SAVE, "");
        this.$tab.navigateTo("/pages/login");
      }, 2200);
    },

    initSelectBank() {
      getBankForInquiry().then((res) => {
        if (res.code === 1) {
          this.bankList = res.data;
          this.addForm.bank_id = this.bankList[0].id;
          this.addForm.bank_name = this.bankList[0].name;
          this.onInitialBankFinish(res.data);
          this.initSelectBranch(0);
        } else {
          this.doFailed(res.code);
        }
      });
    },
    initSelectBranch(type) {
      // type 0: 银行触发  1:分行触发
      const id =
        type === 0 ? this.addForm.bank_id : this.addForm.bank_branch_id;
      console.log("initSelectBranch type:" + type);
      console.log("initSelectBranch id:" + id);

      getBranch({ id }).then((res) => {
        if (res.code === 1) {
          if (type === 0) {
            this.selectSubBankIndex = 0;
            this.subBankIdList =
              res.isCrypto == true ? decrypto(res.data) : res.data;
            this.addForm.bank_branch_id =
              this.subBankIdList[this.selectSubBankIndex].id;
            this.addForm.bank_branch_name =
              this.subBankIdList[this.selectSubBankIndex].name;
            this.initSelectBranch(1);
            // 默认 深圳分行

            // 			res.data.forEach(item => {
            // 			  this.selectSubBankIndex++
            // 			  if (item.name === '深圳分行') {

            // 				this.addForm.bank_branch_id = item.id

            // 				this.addForm.bank_sub_name = item.name

            // 			  }
            //			})
          } else {
            // 支行数据填充
            this.branchBankNameList =
              res.isCrypto == true ? decrypto(res.data) : res.data;
            this.selectBranchBankIndex = 0;
            this.addForm.bank_sub_id =
              this.branchBankNameList[this.selectBranchBankIndex].id;
            this.addForm.bank_sub_name =
              this.branchBankNameList[this.selectBranchBankIndex].name;
            this.onInitialSubbankFinish(res.data);

            this.$refs.branchBankName.selectItem({
              id: this.addForm.bank_sub_id,
              name: this.addForm.bank_sub_name,
            });
          }
        }
      });
    },
    async initSelectAccountManager(id) {
      // this.addExtraForm.bank_id

      await getAccountManager({ bank_id: id }).then((res) => {
        if (res.code === 1) {
          this.selectCustomerIndex = 0;
          //this.accountManagerList = res.data;
          // console.log('getaccountmgr')
          //  console.log(res.data)
          this.addForm.bank_customer_mgr_id =
          res.data[this.selectCustomerIndex].id;
          this.addForm.bank_customer_mgr_name =
          res.data[this.selectCustomerIndex].name;

          res.data.forEach((item) => {
            if (item.id === this.addForm.bank_customer_mgr_id) {
              this.addForm.bank_customer_mgr_phone = item.mobile;
            }
          });
        }
      });
    },
    initSelectBuildingCity() {
      getBuildingCity().then((res) => {
        if (res.code === 1) {
          this.buildingCityList = res.data;

          for (let i = 0; i < this.buildingCityList.length; i++) {
            if (this.buildingCityList[i].shortname == "深圳") {
              this.shenzhencityIndex = i;
              this.selectCityIndex[0].index = this.shenzhencityIndex;
              break;
            }
          }
        } else {
          this.buildingCityList = [];
        }
      });
    },

    initSelectUser() {
      getUserList({roleCode: "Evaluation_salesman"}).then((res) => {
        if (res.code === 1) {
          const data = res.data;
          this.userList = data;
          let current_user_id = getUserID();
          for (let i = 0; i < this.userList.length; i++) {
            if (this.userList[i].userId == current_user_id) {
              this.selectBussUserIndex = i;
              break;
            }
          }
          this.addForm.buss_user_id =
            this.userList[this.selectBussUserIndex].userId;
          this.addForm.buss_username =
            this.userList[this.selectBussUserIndex].userNickName;
          this.addForm.buss_userphone =
            this.userList[this.selectBussUserIndex].phonenumber;
        } else {
          this.$Message.error(res.msg);
          this.doFailed(res.code);
        }
      });
    },

    // 转换为fuzzy控件的赋值函数
    // lst 需要转换的数组
    // id_col 作为id的字段，name_col 作为name 的字段
    transformFuzzyData(lst, id_col, name_col) {
      let arrRes = [];
      lst.forEach(function (item) {
        arrRes.push({ id: item[id_col], name: item[name_col] });
      });
      return arrRes;
    },

    // 判断是否商业物业
    isBussnissType() {
      if (null == this.addForm) {
        return false;
      }

      return this.addForm.type == 2;
    },

    findUsageItem(usageList, name) {
      let res = null;
      usageList.forEach(function (item) {
        if (item.name == name) {
          console.log(" 用途 findusage " + item.name);
          console.log(item);
          res = item;
          return res;
        }
      });
      return res;
    },

    initDictionaryByType() {
      getDictionaryByType({ type: ["HOUSE_USAGE", "USE_RIGHT_SOURCE"] }).then(
        (res) => {
          if (res.code === 1) {
            const data = res.isCrypto == true ? decrypto(res.data) : res.data;
            console.log("initDictionaryByType", data);
            // this.houseUsageList = this.transformFuzzyData(data.house_usage,'code','valname') ;
            this.houseUsageList = data.house_usage;
            this.useRightSourceList = this.transformFuzzyData(
              data.use_right_source,
              "code",
              "valname"
            );
            console.log("this.useRightSourceList", this.useRightSourceList);
            let usageItem = this.findUsageItem(this.houseUsageList, "住宅");
            console.log("-----------------");
            // console.log(this.$refs.branchBankName)
            for (let i = 0; i < this.addForm.details.length; ++i) {
              const textComponent = this.$refs.searchUsageText;
              if (null == textComponent) {
                continue;
              }

              const item = this.$refs.searchUsageText[i];
              if (null != item) {
                item.selectItem({ id: usageItem.id, name: usageItem.name });
              }
            }

            this.initProduct();
          } else {
            this.$Message.error(res.msg);
          }
        }
      );
    },

    initProduct() {
      this.addForm.eva_purpose =
        this.evaluatePurposeList[this.selectEvaPurposeIndex].name;

      getProduct({
        bank_id: this.addForm.bank_id,
        type: this.addForm.type,
      }).then((res) => {
        if (res.code === 1) {
          const data = res.data;
          this.loanTypeList = data;
          this.addForm.product_id =
            this.loanTypeList[this.selectProductIndex].id;
          this.addForm.loan_type =
            this.loanTypeList[this.selectProductIndex].product_name;
          // this.addForm.eva_purpose = this.loanTypeList[this.selectProductIndex].product_name
          //  // 默认 抵押贷款（云）
          //  data.forEach(item => {
          // if (item.product_name === '抵押贷款（云）' || item.product_name === '抵押贷款(云)') {
          //   this.addForm.product_id = item.id
          //   this.addForm.eva_purpose = item.product_name
          // }
          //  this.onInitialProductFinisth(data)
          //  })
        } else {
          this.loanTypeList = [];
        }
      });
    },

    // 获取房屋用途索引值
    getArrayIndexByID(id, lst) {
      let idx = 0;
      for (let i = 0; i < lst.length; ++i) {
        if (lst[i].id == id) {
          return i;
        }
      }
      return 0;
    },

    //
    handleUsageSelect(item, pIdx) {
      console.log("handleUsageSelect ------pid:" + pIdx + ";" + item.name);
      let indexU = this.getArrayIndexByID(item.id, this.houseUsageList);
      let index = pIdx;
      this.selectHouseUsageIndex[pIdx].index = indexU;
      this.addForm.details[pIdx].usage = this.houseUsageList[indexU].id;
    },

    handleSelect(item) {
      // 处理选中的项
      this.onchangBranchSearch(
        this.getArrayIndexByID(item.id, this.bankList),
        item.id,
        item.name
      );
    },

    // 改变支行函数
    onchangBranchSearch(index, bankId, bankName) {
      this.addForm.bank_sub_id = bankId;
      this.addForm.bank_sub_name = bankName;
      // 清空客户经理
      this.addForm.bank_customer_mgr_phone = "";
      this.initSelectAccountManager(this.addForm.bank_sub_id);
    },

    onInitialSubbankFinish(res_data) {
      this.initProduct();
      this.initSelectAccountManager(this.addForm.bank_sub_id);
    },

    onChangeSelect(event, name, index, item) {
      if (!event) {
        return;
      }
      window.console.log(event);
      window.console.log("onChangeSelect:" + name), window.console.log(index);

      switch (name) {
        case "bank":
          this.selectBankIndex = event.detail.value;
          this.addForm.bank_id = this.bankList[this.selectBankIndex].id;
          this.addForm.bank_name = this.bankList[this.selectBankIndex].name;
          // 触发 分行
          this.initSelectBranch(0);

          // 触发 客户经理
          // this.initSelectAccountManager()

          // 触发 评估目的
          this.initProduct();

          this.addForm.product_id = "";
          this.addForm.loan_type = "";

          // 清空分行
          this.addForm.bank_branch_name = "";
          this.addForm.bank_branch_id = "";

          // 清空支行
          this.addForm.bank_branch_name = "";
          this.addForm.bank_sub_id = "";
          this.branchBankNameList = [];

          // 清空客户经理
          this.addForm.bank_customer_mgr_phone = "";
          this.accountManagerList = [];
          break;
        case "eva_purpose":
          this.selectEvaPurposeIndex = event.detail.value;
          this.addForm.eva_purpose =
            this.evaluatePurposeList[this.selectEvaPurposeIndex].name;
          break;
        case "sub_bank":
          this.selectSubBankIndex = event.detail.value;
          this.addForm.bank_branch_id =
            this.subBankIdList[this.selectSubBankIndex].id;
          this.addForm.bank_sub_name =
            this.subBankIdList[this.selectSubBankIndex].name;
          this.initSelectBranch(1);

          // 清空支行
          this.addForm.bank_branch_name = "";
          this.addForm.bank_sub_id = "";
          // 清空客户经理
          this.addForm.bank_customer_mgr_phone = "";
          this.accountManagerList = [];

          break;
        case "branch_bank":
          this.selectBranchBankIndex = event.detail.value;
          this.addForm.bank_sub_id =
            this.branchBankNameList[this.selectBranchBankIndex].id;
          this.addForm.bank_branch_name =
            this.branchBankNameList[this.selectBranchBankIndex].name;
          // 清空客户经理
          this.addForm.bank_customer_mgr_phone = "";
          this.initSelectAccountManager(this.addForm.bank_sub_id);
          break;
        case "bank_customer_mgr_name":
          this.selectCustomerIndex = event.detail.value;
          this.addForm.bank_customer_mgr_id =
            this.accountManagerList[this.selectCustomerIndex].id;
          this.addForm.bank_customer_mgr_name =
            this.accountManagerList[this.selectCustomerIndex].name;
          this.accountManagerList.forEach((item) => {
            if (item.id === this.addForm.bank_customer_mgr_id) {
              this.addForm.bank_customer_mgr_phone = item.mobile;
            }
          });
          break;

        case "Over2year":
          this.selectOver2YearIndex[index].index = event.detail.value;
          this.addForm.details[index].is_tran_tax_free =
            this.isOver2yearList[this.selectOver2YearIndex[index].index].id;

          break;
        case "HouseUsage":
          this.selectHouseUsageIndex[index].index = event.detail.value;
          this.addForm.details[index].usage =
            this.houseUsageList[this.selectHouseUsageIndex[index].index].code;
          //console.log('HouseUsage this.addForm.details[index].usage ：'+  this.addForm.details[index].usage +' this.selectHouseUsageIndex[index].index ：'+this.selectHouseUsageIndex[index].index);
          break;
        case "City":
          this.selectCityIndex[index].index = event.detail.value;
          this.addForm.details[index].city_id =
            this.buildingCityList[this.selectCityIndex[index].index].id;
          this.addForm.details[index].city =
            this.buildingCityList[this.selectCityIndex[index].index].shortname;

          break;
        case "TenureType":
          this.selectTenureTypeIndex[index].index = event.detail.value;
          this.addForm.details[index].ownership_type =
            this.tenureTypeList[this.selectTenureTypeIndex[index].index].id;
          break;
        case "RegisterTime":
          item.purchase_date = event.detail.value;
          let rt = new Date(item.purchase_date);
          let now = new Date();
          let betweenyear = (now - rt) / 1000 / 60 / 60 / 24 / 365;

          if (betweenyear >= 2) {
            this.selectOver2YearIndex[index].index = 0;
            this.addForm.details[index].is_tran_tax_free =
              this.isOver2yearList[this.selectOver2YearIndex[index].index].id;
          } else {
            this.selectOver2YearIndex[index].index = 1;
            this.addForm.details[index].is_tran_tax_free =
              this.isOver2yearList[this.selectOver2YearIndex[index].index].id;
          }
          break;
        case "FinishTime":
          item.completion_time = event.detail.value;
          break;
        case "select_buss_user":
          this.selectBussUserIndex = event.detail.value;
          this.addForm.buss_user_id =
            this.userList[this.selectBussUserIndex].userId;
          this.addForm.buss_username =
            this.userList[this.selectBussUserIndex].userNickName;
          this.addForm.buss_userphone =
            this.userList[this.selectBussUserIndex].phonenumber;

          break;
        case "reportObjType":
          this.selectReportObjTypeIndex = event.detail.value;
          this.addForm.report_obj_type =
            this.reportObjTypeList[this.selectBankIndex].fullName;
          break;
        case "useRightSource":
          console.log("userightsource", event.detail.data);
          this.selectUseRightSourceIndex = event.detail.value;
          this.addForm.details[index].use_right_source =
            this.useRightSourceList[
              this.selectUseRightSourceIndex
            ].code;
          break;
        case "loan_type":
          this.selectProductIndex = event.detail.value; // 贷款种类
          this.addForm.loan_type =
            this.loanTypeList[this.selectProductIndex].product_name; // 贷款种类
          break;
      }
    },

    handleBuildingNameInput(item) {
      this.estateOptions = [];
      this.buildingOptions = [];
      const value = item.detail.value;
      if (!value) {
        this.estateOptions = [];
        return;
      }

      this.estateLoading = true;
      // 使用正确的API获取物业数据
      getEstateListByName({ name: value })
        .then((res) => {
          this.estateLoading = false;
          if (res.code === 1 && res.data && res.data.length > 0) {
            this.estateOptions = res.data;
          } else {
            this.estateOptions = [];
          }
        })
        .catch(() => {
          this.estateLoading = false;
          this.estateOptions = [];
        });
    },
    selectEstate(estate, index) {
      this.addForm.details[index].building_name = estate.loupan_name;
      this.addForm.details[index].lp_id = estate.lp_id;

      // 清空其他字段
      this.addForm.details[index].building_no = "";
      this.addForm.details[index].unit_no = "";
      // 获取栋号列表
      this.estateOptions = [];
      //获取栋号列表
      this.handleBuildingInput(index);
    },
    handleBuildingInput(index) {
      const estate = this.addForm.details[index];
      if (estate && estate.building_name) {
        this.buildingLoading = true;
        getBuildingListByBName({
          bname: estate.building_no,
          lpid: estate.lp_id,
        })
          .then((res) => {
            // 添加 500ms 延迟
            setTimeout(() => {
              this.buildingLoading = false;
              if (res.code === 1 && res.data && res.data.length > 0) {
                this.buildingOptions = res.data;
              } else {
                this.buildingOptions = [];
              }
            }, 500); // 延迟 500 毫秒
          })
          .catch(() => {
            this.buildingLoading = false;
            this.buildingOptions = [];
          });
      }
    },
    selectBuilding(building, index) {
      this.addForm.details[index].building_no = building.building_name;
      this.addForm.details[index].b_id = building.b_id;

      this.buildingOptions = [];
    },
    handleUnitNoInput(value, index) {
      console.log("value", value);
      if (!value.detail.value) {
        this.unitOptions = [];
        return;
      }
      this.unitLoading = true;
      let item = this.addForm.details[index];
      // 添加 500ms 延迟
      getPropertyListByBid({ bid: item.b_id, hno: item.unit_no })
        .then((res) => {
          setTimeout(() => {
            this.unitLoading = false;
            if (res.code === 1 && res.data && res.data.length > 0) {
              this.unitOptions = res.data;
            } else {
              this.unitOptions = [];
            }
          }, 500); // 延迟 500 毫秒
        })
        .catch(() => {
          this.unitLoading = false;
          this.unitOptions = [];
        });
    },
    selectUnit(unit, index) {
      this.addForm.details[index].unit_no = unit.house_number;
      this.unitOptions = [];

      //获取3个月内同一个物业的询价记录接口
      this.getInquiryLog(index)
    },
    cancelSelect(index, type) {
      if (type === 1) { // 楼盘
        this.estateOptions = [];
      } else if (type === 2) { // 栋号
        this.buildingOptions = [];
      } else if (type === 3) { // 房号
        this.unitOptions = [];
      }
    },
    getInquiryLog(index) {
      const params = {
        building_name: this.addForm.details[index].building_name,
        building_no: this.addForm.details[index].building_no,
        unit_no: this.addForm.details[index].unit_no,
        page: 1,
        limit: 10,
      }
      getThreeMonthSameEstateInquiryRecord(params)
        .then((res) => {
          if (res.code === 1 && res.data.data && res.data.data.length > 0) {
            uni.showModal({
              title: '浏览确认',
              content: '系统监测到该物业房号近期3个月内容共有 4 次历史询价记录，确认要浏览吗？',
              success: function (res) {
                if (res.confirm) {
                  console.log('用户点击确定');
                  uni.navigateTo({
                    url: '/pages/inquiry/historyList?params='+ encodeURIComponent(JSON.stringify(params)) 
                  });
                } else if (res.cancel) {
                  console.log('用户点击取消');
                }
              }
            });
          }
        })
    },
    handleCustomerNameInput(item) {
      const value = item.detail.value;
      if (!value) {
        this.accountManagerList = [];
        this.addForm.bank_customer_mgr_id = 0;
        this.addForm.bank_customer_mgr_phone = "";
        return;
      }

      this.customerLoading = true;

      getAccountManager({ bank_id: this.addForm.bank_sub_id, name: value }).then((res) => {
        if (res.code === 1) {
          this.customerLoading = false;

          this.selectCustomerIndex = 0;
          this.accountManagerList = res.data;
        }
      });
  },
  selectCustomer(item) {
    this.addForm.bank_customer_mgr_id = item.id;
    this.addForm.bank_customer_mgr_name = item.name;
    this.addForm.bank_customer_mgr_phone = item.mobile;
    this.accountManagerList = [];
    },
    onCopyPress(index) {
      this.addForm.details.push({
            city_id: "440300",
            usage: "1",
            ownership_type: 1,
            consult_id: "",
            tax_type: "",
            year: "",
            city: "深圳",
            building_name: this.addForm.details[index].building_name,
            property_full_name: this.addForm.details[index].building_name+this.addForm.details[index].building_no,
            building_no: this.addForm.details[index].building_no,
            b_id: this.addForm.details[index].b_id,
            unit_no: "",
            property_cert: "",
            reg_price: "",
            purchase_date: "",
            completion_time: "",
            obligee: "",
            land_location: "",
            is_tran_tax_free: "1",
            size: "",
            remark: "",
            attachments: [],
            attachments_obj: [],
            use_right_source: "1", //房屋性质
            cert_usage: "住宅",
            attachments_file: [],
            attachments_image: [],
      });

      let lastIndex = this.addForm.details.length - 1;
      this.initSelectBuildingCity(lastIndex);

      this.selectOver2YearIndex.push({ index: 0 });
      this.selectHouseUsageIndex.push({ index: this.getHouseUsageIndex("1") });
      this.selectCityIndex.push({ index: this.shenzhencityIndex });
      this.selectTenureTypeIndex.push({ index: 0 });

      this.usageItem = this.findUsageItem(this.houseUsageList, "住宅");
      let idx = Number(this.addForm.details.length - 1);
      //console.log('this.$refs.searchUsageText idx :'+ idx);
      uni.showToast({
        title: "添加新物业成功!",
        icon: "success",
        duration: 2000,
      });

      // 因为元素还没渲染出来，所以放到下一贞执行
      this.$nextTick(() => {
        if (this.$refs.searchUsageText.length >= 2) {
          //console.log(this.$refs.searchUsageText[1]);
          this.$refs.searchUsageText["1"].selectItem({
            id: usageItem.id,
            name: usageItem.name,
          });
        }
      });
    }
  },
};
</script>

<style>
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

/* 将 mask 缩小到一行 */
.uni-popup-mask {
  height: 1px;
}
/* 将 mask 演示为浅蓝色 */
.uni-popup-mask::before {
  background-color: #e6f1ff;
}
.uni-list-cell {
  line-height: 90rpx;
  display: flex;
  align-items: center;
}

.message-box {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px;
  background-color: #333;
  color: #fff;
  border-radius: 5px;
  opacity: 0;
  transition: opacity 0.5s;
}
.uni-input {
  height: 50rpx;
  padding: 0rpx 25rpx;
  line-height: 30rpx;
  font-size: 28rpx;
}

.message-box.show {
  opacity: 1;
}

.btn {
  color: #ff6a00;
  border: 1px;
  border-color: blue;
}

.big-button {
  width: 40%;
  border: 1px;
  border-color: blue;
}

.big-button-yellow {
  width: 40%;
  border: 1px;
  background-color: #ff6a00;
}

.big-button-yellow-s {
  width: 250rpx;
  border: 1px;
  text-align: right;
  background-color: #ffaa00;
  font-size: 16rpx;
}

.require {
  color: RED;
}

.line {
  width: 100%;
  height: 5rpx;
  background-color: #e6e6e6;
}

.line2 {
  width: 100%;
  height: 20rpx;
  background-color: #f5f5f5;
}
.button-sp-area {
  margin: 0 auto;
  width: 80%;
}
.property-dropdown {
	position: absolute;
	top: 100%;
	left: 0;
	width: 100%;
	max-height: 300px;
	overflow-y: auto;
	background-color: #fff;
	border: 1px solid #dcdfe6;
	border-radius: 4px;
	box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
	z-index: 2000;
	margin-top: 5px;
  }
  .uni-file-picker{
    margin-top: 40rpx;
  }
</style>
