<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品简称" prop="simpleName">
        <el-input
          v-model="queryParams.simpleName"
          placeholder="请输入产品简称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品类型" prop="productType">
        <el-select v-model="queryParams.productType" placeholder="选择产品类型" clearable @keyup.enter.native="handleQuery">
          <el-option v-for="dict in dict.type.product_type" :key="dict.value" :label="dict.label"
                     :value="dict.value"/>
        </el-select>
      </el-form-item>
      <!--      <el-form-item label="还款周期" prop="repaymentCycle">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.repaymentCycle"-->
      <!--          placeholder="请输入还款周期"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="还款方式" prop="repaymentMethod">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.repaymentMethod"-->
      <!--          placeholder="请输入还款方式"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="展业城市" prop="businessCity">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.businessCity"-->
      <!--          placeholder="请输入展业城市"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="综合费率" prop="combinedRates">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.combinedRates"-->
      <!--          placeholder="请输入综合费率"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="选择状态" clearable @keyup.enter.native="handleQuery">
          <el-option v-for="dict in dict.type.product_status" :key="dict.value" :label="dict.label"
                     :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="上架时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 200px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="年利率(单利)" prop="interestRateBegin">
        <el-input-number
          :min="0"
          :precision="2"
          style="width: 150px"
          v-model="queryParams.interestRateBegin"
          clearable
          @keyup.enter.native="handleQuery"
        />
        -
        <el-input-number
          :min="0"
          :precision="2"
          style="width: 150px"
          v-model="queryParams.interestRateEnd"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最高额度(万)" prop="maxAmount">
        <el-input-number
          :min="0"
          v-model="queryParams.maxAmountBegin"
          style="width: 150px"
          clearable
          @keyup.enter.native="handleQuery"
        />
        -
        <el-input-number
          :min="0"
          style="width: 150px"
          v-model="queryParams.maxAmountEnd"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['product:info:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['product:info:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['product:info:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['product:info:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          size="mini"
          @click="shelves"
          :disabled="multiple"
          v-hasPermi="['product:info:shelves']"
        >上架
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          size="mini"
          @click="offShelves"
          :disabled="multiple"
          v-hasPermi="['product:info:offShelves']"
        >下架
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @sort-change="handleSortChange"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="排序" width="80"  prop="serialNumber" sortable='custom' fixed="left"/>
      <el-table-column label="产品名称" align="center" prop="productName" sortable='custom' fixed="left" min-width="100"/>
      <!-- <el-table-column label="产品简称" align="center" prop="simpleName" sortable='custom' min-width="100"/> -->
      <el-table-column label="产品类型" align="center" prop="productType" sortable='custom' min-width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.product_type" :value="scope.row.productType"/>
        </template>
      </el-table-column>
      <!-- <el-table-column label="产品细类" align="center" prop="productSubtype" sortable='custom' min-width="100"/> -->
      <el-table-column label="最高额度(万)" align="center" prop="maxAmount" sortable='custom' min-width="120"/>
      <el-table-column label="年利率(单利)" align="center" prop="interestRate"  min-width="120"/>
      <!-- <el-table-column label="产品简介" align="center" prop="productIntro" sortable='custom' show-overflow-tooltip
      min-width="100"/> -->
      <!-- <el-table-column label="产品详情" align="center" prop="productDetail" sortable='custom' show-overflow-tooltip
      min-width="100"/> -->
      <!-- <el-table-column label="还款周期" align="center" prop="repaymentCycle" sortable='custom' min-width="100"/> -->
      <!-- <el-table-column label="还款方式" align="center" prop="repaymentMethod" sortable='custom' min-width="100"/> -->
      <el-table-column label="展业城市" align="center" prop="businessCity"  min-width="150" show-overflow-tooltip/>
      <el-table-column label="综合费率" align="center" prop="combinedRates" sortable='custom' min-width="100"/>
      <el-table-column label="上架时间起" align="center" prop="listBegin" min-width="120" sortable='custom'>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.listBegin, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="上架时间止" align="center" prop="listEnd" min-width="120" sortable='custom'>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.listEnd, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="备注" align="center" prop="remark" sortable='custom' show-overflow-tooltip/> -->
      <el-table-column label="状态" align="center" prop="status" sortable='custom' fixed="right">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.product_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleRead(scope.row)"
          >查看
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['product:info:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['product:info:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改产品信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="115px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="产品名称" prop="productName" >
              <el-input v-model="form.productName" placeholder="请输入产品名称" :disabled="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品简称" prop="simpleName" >
              <el-input v-model="form.simpleName" placeholder="请输入产品简称" :disabled="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品类型" prop="productType">
              <el-select style="width: 100%;" v-model="form.productType" placeholder="选择产品类型" clearable :disabled="readonly">
                <el-option v-for="dict in dict.type.product_type" :key="dict.value" :label="dict.label"
                           :value="dict.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="产品细类" prop="productSubtype">
              <el-input v-model="form.productSubtype" placeholder="请输入产品细类" :disabled="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年利率(单利%)" prop="interestRateBegin">
              <el-input-number v-model="form.interestRateBegin" style="width: 160px;" :min="0" :precision="2" :disabled="readonly"/>
              -
              <el-input-number v-model="form.interestRateEnd" style="width: 160px;" :min="0" :precision="2" :disabled="readonly"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="最高额度(万)" prop="maxAmount">
              <el-input-number v-model="form.maxAmount" placeholder="请输入最高额度(万)" style="width: 100%;" :min="0" :disabled="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="还款周期" prop="repaymentCycle">
              <el-input v-model="form.repaymentCycle" placeholder="请输入还款周期" :disabled="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="还款方式" prop="repaymentMethod">
              <el-input v-model="form.repaymentMethod" placeholder="请输入还款方式" :disabled="readonly"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="展业城市" prop="businessCityByName">
              <el-input v-model="form.businessCityByName" placeholder="选择展业城市" style="width: 100%;" readonly >
                <el-button slot="append" icon="el-icon-arrow-down" @click="openModal"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="综合费率" prop="combinedRates">
              <el-input v-model="form.combinedRates" placeholder="请输入综合费率" :disabled="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="上架时间起" prop="listBegin">
              <el-date-picker clearable
                              :disabled="readonly"
                              v-model="form.listBegin"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择上架时间起"
                              style="width: 100%;">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="上架时间止" prop="listEnd">
              <el-date-picker clearable
                              :disabled="readonly"
                              v-model="form.listEnd"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择上架时间止"
                              style="width: 100%;">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="贷款期限" prop="loanTerm">
              <el-input v-model="form.loanTerm" placeholder="请输入贷款期限" :disabled="readonly" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="状态" prop="status">
              <el-select style="width: 100%;" v-model="form.status" placeholder="选择状态" clearable :disabled="readonly">
                <el-option v-for="dict in dict.type.product_status" :key="dict.value" :label="dict.label"
                           :value="dict.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
        <el-col :span="8">
          <el-form-item label="排序" prop="serialNumber">
            <el-input-number v-model="form.serialNumber" placeholder="请输入排序" :disabled="readonly" :min="0" style="width: 100%;"/>
          </el-form-item>
        </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="申请链接" prop="applicationLink" >
<!--              <editor v-model="form.productIntro" :min-height="92" />-->
                  <el-input v-model="form.applicationLink"  placeholder="请输入内容" :disabled="readonly"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="产品简介（展示给客户）" prop="productIntro" >
              <editor v-model="form.productIntro" :min-height="92" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="产品详情（展示给经纪人）" prop="productDetail" >
              <editor v-model="form.productDetail" :min-height="152" />
              <!--                <el-input v-model="form.productDetail" type="textarea" placeholder="请输入内容"/>-->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :disabled="readonly"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="!readonly">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="showModal" title="选择城市" @close="closeModal">
      <el-row>
        <el-col :span="12">
          <h3 class="section-title">城市列表</h3>
          <el-input v-model="searchText" placeholder="请输入城市名称" clearable></el-input>
          <div class="city-tree-container">
            <el-tree
              :data="filteredCities"
              :props="defaultProps"
              :expand-on-click-node="false"
              :filter-node-method="filterNode"
              ref="tree"
              node-key="id"
              :default-expand-all="false"
              highlight-current
            >
              <template v-slot="{ node, data }">
                <div class="city-item">
                  <span>{{ node.label }}</span>
                  <el-button @click="selectCity(data)" type="text" size="mini" class="add-button" v-if="!readonly">添加</el-button>
                </div>

              </template>
            </el-tree>
          </div>
        </el-col>
        <el-col :span="12">
          <h3 class="section-title">已选择城市</h3>
          <ul class="selected-city-list">
            <li v-for="(city, index) in selectedCities" :key="index">
              <div class="selected-city-item">
                {{ city.name }}
                <el-button @click="removeCity(index)" type="text" size="mini" v-if="!readonly">移除</el-button>
              </div>
            </li>
          </ul>
        </el-col>
      </el-row>
      <div slot="footer">
        <el-button @click="confirmSelection">确认</el-button>
      </div>
    </el-dialog>

  </div>
</template>
<script>
import {pageListInfo, getInfo, delInfo, addInfo, updateInfo, changeStatus, getBrokerNum} from "@/api/product/info";
import {listArea} from "@/api/system/area";
import {changeStatusByPoster} from "@/api/poster/poster";
// import Treeselect from "@riophae/vue-treeselect";

export default {
  name: "Info",
  dicts: ['product_type', "product_status"],
  data() {
    return {
      dateRange: [],
      defaultProps: {
        children: "children",
        label: "name"
      },
      searchText: '',
      showModal: false,
      selectedCities: [],
      cityList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中名字
      names: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      readonly: false,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productName: null,
        simpleName: null,
        productType: null,
        productSubtype: null,
        maxAmount: null,
        interestRate: null,
        productIntro: null,
        productDetail: null,
        listBegin: null,
        listEnd: null,
        status: null,
        maxAmountBegin: undefined,
        maxAmountEnd: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        productName: [
          {required: true, message: "产品名称不能为空", trigger: "blur"}
        ],
        simpleName: [
          {required: true, message: "产品简称不能为空", trigger: "blur"}
        ],
        productType: [
          {required: true, message: "产品类型不能为空", trigger: "change"}
        ],
        // productSubtype: [
        //   {required: true, message: "产品细类不能为空", trigger: "change"}
        // ],
        maxAmount: [
          {required: true, message: "最高额度(万)不能为空", trigger: "blur"}
        ],
        interestRateBegin: [
          {required: true, message: "年利率(单利)不能为空", trigger: "blur"}
        ],
        // productIntro: [
        //   {required: true, message: "产品简介不能为空", trigger: "blur"}
        // ],
        // productDetail: [
        //   {required: true, message: "产品详情不能为空", trigger: "blur"}
        // ],
        // listBegin: [
        //   {required: true, message: "上架时间起不能为空", trigger: "blur"}
        // ],
        // listEnd: [
        //   {required: true, message: "上架时间止不能为空", trigger: "blur"}
        // ],
        status: [
          {required: true, message: "状态不能为空", trigger: "change"}
        ],
        // serialNumber: [
        //   {required: true, message: "序号不能为空", trigger: "change"}
        // ],
      }
    };
  },
  computed: {
    filteredCities() {
      // 根据搜索文本过滤城市列表
      return this.cityList.filter(city => city.name.includes(this.searchText));
    }
  },
  created() {
    this.getList();
    this.getAreaList();
  },
  methods: {
    offShelves(){
      const ids = this.ids;
      let param = {
        ids: ids,
        status: "0"
      }
      this.$modal.confirm('是否确认下架数据？').then(function () {
        return    changeStatus(param)
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("下架成功");
      }).catch(() => {
      });
      // changeStatus(param).then(response => {
      //   this.getList();
      //   this.$modal.msgSuccess("修改成功");
      // });
    },
    shelves(){
      const ids = this.ids;
      let param = {
        ids: ids,
        status: "1"
      }
      getBrokerNum(ids).then(response => {
        if(response.data > 0){
          this.$modal.confirm('代理产品权限是否也随之上架？').then(function () {
            let paramVo = {
              ids: ids,
              status: "1",
              isBroker: "1"
            }
            return changeStatus(paramVo);
          }).then(() => {
            this.getList();
            this.$modal.msgSuccess("修改成功");
          }).catch(() => {
            changeStatus(param).then(response => {
              this.getList();
              this.$modal.msgSuccess("修改成功");
            });
          });
        }else{
          changeStatus(param).then(response => {
            this.getList();
            this.$modal.msgSuccess("修改成功");
          });
        }
      });
    },
    filterNode(value, data) {
      if (!value) return true;
      return data.name.indexOf(value) !== -1;
    },
    openModal() {
      this.showModal = true;
      let selectedCities = [];
      let businessCities = this.form.businessCity.split(',');
      businessCities.forEach(cityId => {
        let matchedCity = this.cityList.find(city => city.areaId == cityId);
        if (matchedCity) {
          selectedCities.push({
            areaId: matchedCity.areaId,
            name: matchedCity.name
          });
        }
      });
      this.selectedCities = selectedCities;
    },
    closeModal() {
      // 关闭模态窗口
      this.showModal = false;
      this.searchText = '';
      this.selectedCities = [];
    },
    selectCity(city) {
      // 检查城市是否已经添加
      if (this.isCitySelected(city)) {
        this.$message.warning('该城市已经添加过了！');
      } else {
        this.selectedCities.push(city);
      }
    },
    isCitySelected(city) {
      // 检查城市是否已经添加
      return this.selectedCities.some(selectedCity => selectedCity.areaId == city.areaId);
    },
    removeCity(index) {
      // 移除已选择的城市
      this.selectedCities.splice(index, 1);
    },
    confirmSelection() {
      // 确认选择并关闭模态窗口
      this.form.businessCity = this.selectedCities.map(city => city.areaId).join(',');
      this.form.businessCityByName = this.selectedCities.map(city => city.name).join(',');
      this.showModal = false;
    },
    getAreaList() {
      listArea().then(response => {
        this.cityList = this.buildTree(response.data);
      });
    },
    buildTree(data) {
      let tree = [];
      let map = {};
      data.forEach(node => {
        map[node.areaId] = node;
        node.children = [];
      });
      // 将 全国 的节点移到最前面
      if (map[0]) {
        tree.push(map[0]);
        delete map[0];
      }
      data.forEach(node => {
        if (node.parentId != 0) {
          const parent = map[node.parentId];
          if (parent) {
            parent.children.push(node);
          }
        } else if (node.areaId != 0) {
          tree.push(node);
        }
      });
      return tree;
    },
    /** 查询产品信息列表 */
    getList() {
      this.loading = true;
      pageListInfo(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      }).catch(e => {
        this.loading = false;
      });
    }
    ,
// 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    }
    ,
// 表单重置
    reset() {
      this.form = {
        id: null,
        productName: null,
        simpleName: null,
        productType: null,
        productSubtype: null,
        maxAmount: null,
        interestRateBegin: null,
        interestRateEnd: null,
        productIntro: null,
        productDetail: null,
        listBegin: null,
        listEnd: null,
        status: "0",
        remark: null,
        maxAmountBegin: null,
        maxAmountEnd: null,
        applicationLink: null,
      };
      this.resetForm("form");
    }
    ,
//排序
    handleSortChange(col) {
      this.$sortBy(col, this.queryParams);
      this.getList();
    }
    ,
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    }
    ,
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.maxAmountBegin = undefined;
      this.queryParams.maxAmountEnd = undefined;
      this.queryParams.interestRateEnd = undefined;
      this.handleQuery();
    }
    ,
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.names = selection.map(item => item.productName);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    }
    ,
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.readonly = false;
      this.title = "添加产品信息";
    },
    handleRead(row) {
      this.reset();
      const id = row.id || this.ids;
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.readonly = true;
        this.title = "查看产品信息";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.readonly = false
        this.title = "修改产品信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.interestRateBegin > this.form.interestRateEnd) {
            this.$modal.msgError("最低利率不能大于最高利率");
            return;

          }
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      const names = row.id || this.names;
      this.$modal.confirm('是否确认删除产品名称为"' + names + '"的数据项？').then(function () {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('product/info/export', {
        ...this.queryParams
      }, `产品信息数据_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
.add-button {
  margin-left: 10px; /* 将添加按钮向右移动 */
}

.section-title {
  font-size: 16px;
  margin-bottom: 10px;
}

.city-tree-container {
  flex: 1;
  overflow-y: auto;
  max-height: 400px; /* 设置最大高度 */
}

.city-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-right: 10px;
}

.city-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
}

.selected-city-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 440px; /* 设置最大高度 */
  flex: 1;
  overflow-y: auto;
}

.selected-city-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
}
</style>
