<template>
  <div ref="list">
    <p style="margin: 10px 0; border-bottom: 1px solid #eee; padding-bottom: 5px;">经纪人</p>

    <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch" label-width="100px" @submit.native.prevent>
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          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"
          :disabled="!brokerId && !userId"
          v-hasPermi="['product:info:add']"
        >选择
        </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>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="infoList" @sort-change="handleSortChange" :height="tableHeight - 150"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="产品归属" prop="brokerName" fixed="left" />
      <el-table-column label="产品名称" prop="productName" sortable='custom' fixed="left" />
      <!-- <el-table-column label="备注" align="center" prop="remark" sortable='custom' show-overflow-tooltip/> -->
      <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-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"
      :pager-count="3"
      @pagination="getList"
    />
<!--    <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="brokerId">
              <treeselect v-model="form.brokerId" :options="brokerList" props="lable" :show-count="true"
                          :disabled="readonly"
                          :defaultExpandLevel="Infinity"  disabled
                          placeholder="请选择归属部门" :normalizer="tenantIdnormalizer"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品名称" prop="id">
              <el-select style="width: 100%;" filterable v-model="form.id" placeholder="请选择产品名称" @change="handleChange"
                         :disabled="readonly"
                         clearable>
                <el-option v-for="info in infoListAll" :key="info.id" :label="info.productName"
                           :value="info.id"/>
              </el-select>
              <!--              <el-input v-model="form.productName" placeholder="请输入产品名称"/>-->
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品简称" prop="simpleName">
              <el-input v-model="form.simpleName" placeholder="请输入产品简称" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="产品类型" prop="productType">
              <el-select style="width: 100%;" v-model="form.productType" placeholder="选择产品类型" clearable disabled>
                <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-col :span="8">
            <el-form-item label="产品细类" prop="productSubtype">
              <el-input v-model="form.productSubtype" placeholder="请输入产品细类" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="最高额度(万)" prop="maxAmount">
              <el-input-number v-model="form.maxAmount" placeholder="请输入最高额度(万)" style="width: 100%;" :min="0"
                               disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="还款周期" prop="repaymentCycle">
              <el-input v-model="form.repaymentCycle" placeholder="请输入还款周期" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="还款方式" prop="repaymentMethod">
              <el-input v-model="form.repaymentMethod" placeholder="请输入还款方式" disabled/>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="综合费率" prop="combinedRates">
              <el-input v-model="form.combinedRates" placeholder="请输入综合费率" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="上架时间起" prop="listBegin">
              <el-date-picker clearable
                              disabled
                              v-model="form.listBegin"
                              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="listEnd">
              <el-date-picker clearable
                              disabled
                              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="status">
              <el-select style="width: 100%;" v-model="form.status" placeholder="选择状态" clearable disabled>
                <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="12">
            <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="12">
            <el-form-item label="年利率(单利%)" prop="interestRateBegin">
              <el-input-number v-model="form.interestRateBegin" style="width: 150px;" :min="0" :precision="2" disabled/>
              -
              <el-input-number v-model="form.interestRateEnd" style="width: 150px;" :min="0" :precision="2" disabled/>
            </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" disabled/>
              <!--                <el-input v-model="form.productIntro" type="textarea" placeholder="请输入内容"/>-->
            </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" disabled/>
              <!--                <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/>
            </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 :title="title" :visible.sync="openByAdd" 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" v-show="brokerId">
            <el-form-item label="所属代理商" prop="brokerId" >
              <treeselect v-model="form.brokerId" :options="brokerList" props="lable" :show-count="true"
                          :disabled="readonly"
                          :defaultExpandLevel="Infinity"  disabled
                          placeholder="请选择归属部门" :normalizer="tenantIdnormalizer"/>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-show="userId">
            <el-form-item label="所属经纪人" prop="userId" >
              <el-select style="width: 100%;" v-model="form.userId"  clearable disabled>
                <el-option v-for="info in userInfoList" :key="info.userId" :label="info.userName"
                           :value="info.userId"/>
              </el-select>
<!--              <el-input v-model="form.userId" placeholder="请输入所属经纪人" disabled/>-->
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品名称" prop="ids">
<!--              <el-select multiple  v-model='form.ids' @change='changeSelect' placeholder='请选择' filterable>-->
<!--                <el-checkbox v-model="checked" @change='selectAll'>全选</el-checkbox>-->
<!--                <el-option v-for="info in infoListAll" :key="info.id" :label="info.productName"-->
<!--                           :value="info.id"/>-->
<!--                <el-option v-for='(item, index) in options' :key='index' :label='item.name' :value='item.name'></el-option>-->
<!--              </el-select>-->
              <el-select
                multiple
                v-model="form.ids"
                @change="changeSelect"
                placeholder="请选择"
                filterable
                reserve-keyword="true"
                :remote="true"
                :remote-method="filterMethod"
                :loading="loading"
              >
                <!-- 全选 checkbox -->
                <el-checkbox
                  v-model="checked"
                  @change="selectAll"
                >全选</el-checkbox>

                <!-- 循环 infoListAll 数据 -->
                <el-option
                  v-for="info in filteredList"
                  :key="info.id"
                  :label="info.productName"
                  :value="info.id"
                />

                <!-- 循环 options 数据 -->
                <el-option
                  v-for="(item, index) in filteredOptions"
                  :key="index"
                  :label="item.name"
                  :value="item.name"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormByAdd" 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">添加</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">移除</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 AutoTableHeight from '@/views/broker/AutoTableHeight';
import {
  pageListInfo,
  getInfo,
  delInfo,
  addInfo,
  updateInfo,
  listInfo,
  editByBroker,
  editByBrokers,
  delInfoByBroker,
  listByBroker,
  getInfoByBroker,
  listByUserId,
} from "@/api/product/info";
import {listArea} from "@/api/system/area";
import {listBrokerByTree} from "@/api/broker/broker";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {getUser} from "@/api/system/user";
import {
  listUserAll
} from "@/api/system/user";

export default {
  name: "BrokerUser",
  mixins: [AutoTableHeight],
  dicts: ['product_type', "product_status"],
  components: {Treeselect},
  props: {
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      checked: false,  // 控制是否全选
      options: [],      // 存储其他选项
      filteredList: [], // 存储过滤后的产品列表
      filteredOptions: [], // 存储过滤后的其他选项
      openByAddAndUser: false,
      readonly:false,
      // isReadOnly: false,
      brokerList: [],
      userInfoList: [],
      infoListAll: [],
      brokerId: null,
      userId: null,
      // 日期范围
      dateRange: [],
      rowDataNew: {},
      defaultProps: {
        children: "children",
        label: "name"
      },
      searchText: '',
      showModal: false,
      selectedCities: [],
      cityList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中名字
      names: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openByAdd: 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: {
        id: [
          {required: true, message: "产品名称不能为空", trigger: "blur"}
        ],
        ids: [
          {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"}
        ],
        // remark: [
        //   {required: true, message: "备注不能为空", trigger: "blur"}
        // ],
      }
    };
  },
  mounted() {
    // 初始化时将 rowData 的值赋给 row
    this.rowDataNew = this.rowData;
  },
  watch: {
    // 监听 rowData 的变化
    rowData: function (newVal, oldVal) {
      this.rowDataNew = newVal;
      this.brokerId = this.rowDataNew.id;
      this.userId = this.rowDataNew.userId;
      this.queryParams.brokerIds = this.brokerId;
      this.queryParams.userId = this.rowDataNew.userId;
      this.getList();
    },
  },
  computed: {
    filteredCities() {
      // 根据搜索文本过滤城市列表
      return this.cityList.filter(city => city.name.includes(this.searchText));
    },
  },
  created() {
    this.getList();
    this.getAreaList();
  },
  methods: {
    // 过滤方法，更新 filteredList 和 filteredOptions
    filterMethod(query) {
      this.loading = true;
      // 根据 query 过滤 infoListAll 和 options
      this.filteredList = this.infoListAll.filter(info => info.productName.includes(query));
      this.filteredOptions = this.options.filter(item => item.name.includes(query));
      this.loading = false;
    },
    // 全选方法，只选中过滤出来的选项
    selectAll() {
      if (this.checked) {
        // 获取过滤后的所有选项并将它们添加到 form.ids 中
        const allSelectedIds = [
          ...this.form.ids, // 保留已有的选中项
          ...this.filteredList.map(info => info.id), // 添加过滤后的选项
        ];
        this.form.ids = Array.from(new Set(allSelectedIds)); // 使用 Set 去重
      } else {
        // 取消全选：从 form.ids 中剔除过滤后的选项
        this.form.ids = this.form.ids.filter(id => !this.filteredList.some(info => info.id === id));
      }
      this.filteredList = this.infoListAll;
    },
    // selectAll() {
    //   if (this.checked) {
    //     // 获取过滤后的所有选项并将它们添加到 form.ids 中
    //     const allSelectedIds = [
    //       ...this.form.ids, // 保留已有的选中项
    //       ...this.filteredList.map(info => info.id), // 添加过滤后的选项
    //     ];
    //     this.form.ids = Array.from(new Set(allSelectedIds)); // 使用 Set 去重
    //   } else {
    //     // 取消全选：从 form.ids 中剔除过滤后的选项
    //     this.form.ids = this.form.ids.filter(id => !this.filteredList.some(info => info.id === id));
    //   }
    //   this.filteredList = this.infoListAll;
    // },
    changeSelect(val) {
      if (val.length === this.infoListAll.length) {
        this.checked = true
      } else {
        this.checked = false
      }
    },
    tenantIdnormalizer(node, instanceId) {
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.id,
        label: node.brokerName,
        children: node.children
      }
    },
    getbrokerList() {
      listBrokerByTree().then(response => {
        this.brokerList = response.data;
      });
    },
    handleChange() {
      getInfo(this.form.id).then(response => {
        var brokerId = this.form.brokerId;
        this.form = response.data;
        this.form.brokerId = brokerId;
        this.getAllInfo();
        this.getList();
      });
    },
    getUserInfoList() {
      var params = {
        userType:"jj"
      }
      listUserAll(params).then(response => {
        this.userInfoList = response.data;
      });
    },
    getAllInfo(id) {
      var params = {
        selectByBroker: "1",
        brokerId: this.rowData.id,
        id: id
      }
      listByBroker(params).then(response => {
        this.infoListAll = response.data;
      });
    },
    getAllInfoByUser(id) {
      // selectByBroker: "1",
      var params = {
        selectByBroker: "1",
        userId: this.rowData.userId,
        id: id
      }
      listByUserId(params).then(response => {
        this.infoListAll = response.data;
        this.filteredList = this.infoListAll;
      });
    },
    getAllIds(data) {
      let ids = [];
      ids.push(data.id);
      if (data.children && Array.isArray(data.children)) {
        // 遍历 children 数组
        data.children.forEach(child => {
          // 递归调用 getAllIds 函数，获取当前子对象及其子对象的 id，并添加到 ids 数组中
          ids = ids.concat(this.getAllIds(child));
        });
      }
      return ids.join(',');
    },
    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);
        this.$message.success('成功添加城市！');
      }
    },
    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;
      this.queryParams.selectByBroker = "1";
      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.openByAdd = 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: null,
        remark: null,
        userId: null,
        maxAmountBegin: null,
        maxAmountEnd: 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();
      if (this.brokerId) {
        this.getAllInfo();
        this.getbrokerList();
        this.readonly = false;
        this.form.brokerId = this.brokerId;
        this.openByAdd = true;
        // this.isReadOnly = false;
        this.title = "添加产品信息";
      } else {
        this.getAllInfoByUser();
        this.getUserInfoList();
        this.readonly = false;
        this.form.userId = this.userId;
        // this.form.brokerId = this.brokerId;
        this.openByAdd = true;
        // this.isReadOnly = false;
        this.title = "添加产品信息";
      }
    },
    handleRead(row) {
      this.reset();
      this.getbrokerList();
      const id = row.id || this.ids;
      var param = {
        id: id,
        brokerId: this.brokerId
      };
      getInfoByBroker(param).then(response => {
        this.form = response.data;
        if (this.userId) {
          this.getAllInfoByUser(id);
        } else {
          this.getAllInfo(id);
        }
        this.open = true;
        this.readonly = true;
        this.title = "查看产品信息";
        // this.isReadOnly = true;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getbrokerList();
      const id = row.id || this.ids;
      var param = {
        id: id,
        brokerId: this.brokerId,
        userId: this.userId
      };
      getInfoByBroker(param).then(response => {
        this.form = response.data;
        if (this.userId) {
          this.getAllInfoByUser(id);
        } else {
          this.getAllInfo(id);
        }
        this.open = true;
        this.readonly = false;
        this.title = "修改产品信息";
        // this.isReadOnly = true;
      });
      // getInfo(id).then(response => {
      //   this.form = response.data;
      //   this.form.brokerId = this.brokerId;
      //   this.getAllInfo(id);
      //   this.open = true;
      //   this.title = "修改产品信息";
      // });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          editByBroker(this.form).then(response => {
            if (response.code === 200) {
              this.$modal.msgSuccess("保存成功");
              this.open = false;
              this.openByAdd = false;
              this.getList();
            } else {
              this.$modal.msgError(response.msg);
            }
          });
        }
      });
    },
    submitFormByAdd() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          editByBrokers(this.form).then(response => {
            if (response.code === 200) {
              this.$modal.msgSuccess("保存成功");
              this.open = false;
              this.openByAdd = false;
              this.getList();
            } else {
              this.$modal.msgError(response.msg);
            }
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const rowIds = Array.isArray(row.id) ? row.id : [row.id];
      const ids = [...rowIds, ...this.ids];
      const names = row.id || this.names;
      var param = {
        ids: ids,
        brokerId: this.brokerId,
        userId: this.userId
      };
      this.$modal.confirm('是否确认移除产品信息为"' + names + '"的数据项？').then(function () {
        return delInfoByBroker(param);
      }).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>
