const app = getApp();
const api = require('@/utils/api.js');
const Constants = require('@/utils/Constants.js')
const mixins = require('@/mixins/index.js')
Page({
  mixins: [mixins],
  /**
   * 页面的初始数据
   */
  data: {
    showPop: false,
    gradeCode: app.globalData.company.gradeCode,
    active: 0,
    // 选择数据
    choosedData: [],
    // // 是否显示tab
    // tabFlag: false,
    // 页签默认在第一个 
    // 查询条件
    searchContent: null,
    // 路由
    routeObjName: 'common',
    // pop使用
    routeObjNamePop: '',
    // 列表区（内容）
    contentList: null,
    // 方法名
    method: null,
    // 字典类型
    dictCode: null,
    // 标题
    title: null,
    // 弹出pop的标题
    popTitle: null,
    // 需要调到的新建路由
    addUrl: null,
    // 是否多选
    chooseFlag: false,
    // 提示信息
    placeholder: [],
    // tab页签
    tagList: [],
    // 用于多选
    valueKey: null,
    labelKey: null,
    // 多选时是否允许重复
    repeatFlag: false,
    // 简单标识
    simpleFlag: false,
    // 弹出新建
    popContent: null,
    // 是否有默认值
    defaultFlag: false,
    // 状态
    status: null,
    // 控制是否显示状态
    statusFlag: false,
    // 确定按钮
    buttonList: [{
      name: 'confirm',
      title: '确定'
    }],
    // 新加的数据
    addItem: null,
  },
  /**
   * @desc : 调到新建
   * @author : 姜永辉
   * @date : 2022/5/23 15:16
   */
  toAdd() {
    let addUrl = this.data.addUrl
    // 如果链接有值，跳转
    if (addUrl) {
      let _this = this
      wx.navigateTo({
        url: this.data.addUrl,
        events: {
          // 保存成功后刷新页面
          refresh: function (data) {
            // 刷新一览界面
            _this.searchData();
          }
        },
        success: function (res) {
          // 通过eventChannel向被打开页面传送数据 TODO 测试例子url是写死的，实际中，需要从route中读取
          res.eventChannel.emit('params', { formType: _this.data.chooseRoute.type, backFlag: true })
        }
      })
    } else if (this.data.popContent && this.data.popContent.length > 0) {
      this.setData({
        showPop: true
      })
    }
  },
  /**
   * @desc : 选择数据
   * @author : 周兴
   * @date : 2024/3/25 15:16
   */
  chooseData(e) {
    console.log('eerere', e);
    let list = e.detail.list;
    let item = e.detail.item;
    let valueKey = this.data.valueKey;
    if (!valueKey) {
      this.setData({
        choosedData: list
      })
    } else {
      let choosedData = this.data.choosedData
      // 不允许重复
      if (!this.data.repeatFlag) {
        if (e.detail.checked) { // 勾选
          let filters = choosedData.filter(it => it[valueKey] == item[valueKey])
          if (!filters || filters.length == 0) {
            choosedData.push(item);
          }
        } else { // 取消勾选
          choosedData = choosedData.filter(it => it[valueKey] != item[valueKey])
        }
      } else {
        if (e.detail.checked) { // 勾选
          // 可以重复
          choosedData.push(item);
        }
      }
      this.setData({
        choosedData: choosedData
      })
    }
  },
  /**
   * @desc : 确定事件-返回数据
   * @author : 周兴
   * @date : 2024/3/25 15:16
   */
  confirm() {
    let list = [...this.data.choosedData]
    let id = list.map(it => it[this.data.valueKey])
    let name = list.map(it => it[this.data.labelKey])
    const eventChannel = this.getOpenerEventChannel();
    eventChannel.emit('bindData', {
      data: {
        list,
        id,
        name
      }
    })
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * @desc : 点击事件-返回数据
   * @author : 周兴
   * @date : 2024/5/8 15:16
   */
  choose(e) {
    // 如果选择框开启就走确定模式
    if (this.data.chooseFlag) {
      return;
    }
    let item = e.currentTarget.dataset.item
    let index = e.currentTarget.dataset.index
    let tableData = this.data.tableData
    tableData.forEach(res => {
      res.checked = false
    })
    tableData[index].checked = true
    this.setData({
      tableData: tableData
    })
    // 执行点击事件
    this._toDetail(item);
  },
  /**
   * @desc : 点击事件-返回数据
   * @author : 姜永辉
   * @date : 2022/5/23 15:16
   */
  toDetail(e) {
    // 如果选择框开启就走确定模式
    if (this.data.chooseFlag) {
      return;
    }
    let item = e.detail.item
    let tableData = this.data.tableData
    tableData.forEach(res => {
      res.checked = false
    })
    tableData[e.detail.index].checked = true
    this.setData({
      tableData: tableData
    })
    // 执行点击事件
    this._toDetail(item);
  },
  /**
   * @desc :  执行点击事件（私有方法）
   * @author : 周兴
   * @date : 2024/5/9 15:16
   */
  _toDetail(item) {
    // 读取传入的单据类型
    let route = this.data.chooseRoute
    console.log('dddf', route);
    let data = {}
    switch (route.type) {
      // 部门
      case Constants.chooseType.org:
        data = {
          id: item.orgId,
          name: item.orgName
        }
        break;
      // 员工
      case Constants.chooseType.staff:
        data = {
          id: item.staffId,
          name: item.staffName,
          orgId: item.orgId,
          orgName: item.orgName,
          staffPhone: item.staffPhone,
        }
        break;
      // 角色
      case Constants.chooseType.role:
        data = {
          id: item.roleId,
          name: item.roleName,
        }
        break;
      //渠道
      case Constants.chooseType.saleChannel:
        data = {
          id: item.channelId,
          name: item.channelName,
          code: item.channelCode
        }
        break;
      //资金账户
      case Constants.chooseType.moneyAccount:
        data = {
          id: item.macId,
          name: item.macName,
          code: item.macCode
        }
        break;
      //客户来源
      case Constants.chooseType.cusFrom:
        data = {
          id: item.dataId,
          name: item.dataValue,
          code: item.dataCode
        }
        break;
      // 供应商
      case Constants.chooseType.supplier:
      case Constants.chooseType.outSupplier:
        data = {
          id: item.supId,
          name: item.supName,
          item: item
        }
        break;
      // 对象类型
      case Constants.chooseType.objectType:
        data = {
          id: item.objId,
          name: item.objName,
          objType: item.objType
        }
        break;

      // 仓库
      case Constants.chooseType.warehouse:
        data = {
          id: item.whId,
          name: item.whName
        }
        break;
      case Constants.chooseType.inventorySku:
        data = {
          id: item.whId,
          name: item.whName,
          item: item
        }
        break;
      // 品牌
      case Constants.chooseType.brand:
        data = {
          id: item.brandId,
          name: item.brandName
        }
        break;
      // 系列 刘尧 2024.05.29
      case Constants.chooseType.series:
        data = {
          id: item.seriesId,
          name: item.seriesName
        }
        break;
      // 计量单位 刘尧 2024.05.29
      case Constants.chooseType.unit:
        data = {
          id: item.unitId,
          name: item.unitName,
          decimalPlaces: item.decimalPlaces
        }
        break;
      // 系统数据
      case Constants.chooseType.kindData:
        data = {
          id: item.kindCode,
          name: item.kindName
        }
        break;
      // 数据字典
      case Constants.chooseType.dictionary:
        data = {
          id: item.dataId,
          name: item.dataValue,
          dictCode: item.dictCode,
          dataCode: item.dataCode,
          flgDefault: item.flgDefault,
        }
        break;
      // 系统数据
      case Constants.chooseType.kindType:
        data = {
          id: item.id,
          name: item.kindName,
          kindType: item.kindType,
          kindCode: item.kindCode,
          flgDefault: item.flgDefault,
        }
        break;
      default:
        data = {}
        break;
    }
    const eventChannel = this.getOpenerEventChannel();
    eventChannel.emit('bindData', {
      data: data
    })
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * @desc :   设置查询参数
   * @date : 2024/3/25 15:49
   * @author : 周兴
   */
  setSearchParams(params) {
    params.flgValid = true
    // 字典类别
    if (this.data.dictCode) {
      params.dictCode = this.data.dictCode
    }
    // 系统数据
    if (this.data.kindType) {
      params.kindType = this.data.kindType
    }
    console.log('eee', this.data.chooseRoute);
    let chooseType = this.data.chooseRoute.type;
    // 供应商
    if (chooseType == Constants.chooseType.supplier) {
      params.supType = "";
      let active = this.data.active
      params.supType = Constants.kindCode.supplierPur;

      if (active == 1) { //采购供应商
        params.supType = Constants.kindCode.supplierPur;
      } else if (active == 2) { //服务供应商
        params.supType = Constants.kindCode.supplierService;
      }
    }
    // 外协供应商
    if (chooseType == Constants.chooseType.outSupplier) {
      params.supType = Constants.kindCode.supplierOutsourcing;
    }
    //跟据色号公司skuid判断库存
    if (chooseType == Constants.chooseType.inventorySku) {
      console.log('globalData', app.globalData)

      params.skuId = this.data.item.skuId
      params.nonStdCode = this.data.item.nonStdCode
      params.cpId = app.globalData.company.cpId
    }
    if (chooseType == Constants.chooseType.saleChannel) {
      params.dataSourceCode = Constants.chooseType.saleChannel
    }
    if (chooseType == Constants.chooseType.cusFrom) {
      params.dataSourceCode = Constants.chooseType.cusFrom
    }
    if (chooseType == Constants.chooseType.inventorySku) {
      params.flgValid = true
    }
    if (chooseType == Constants.chooseType.warehouse) {
      params.flgValid = true
    }
    return params
  },
  /** 
   * @desc : 删除已选
   * @date : 2024年3月26日
   * @author : 周兴
   */
  delChoosed(e) {
    let choosedData = this.data.choosedData;
    choosedData = choosedData.filter((it, index) => index != e.detail.index)
    this.setData({
      choosedData: choosedData
    })
  },
  /** 
   * @desc : 查询数据
   * @date : 2024年3月23日
   * @author : 周兴
   */
  getData(params) {
    console.log('this.data.routeObjName', this.data.method)
    let service = app.globalData[this.data.routeObjName + 'Service'];
    return this.excute(service, service[this.data.method], params);
  },
  /** 
   * @desc : 保存数据
   * @date : 2024年5月9日
   * @author : 周兴
   */
  editItems(e) {
    let data = e.detail.form
    // 基础资料的传值 
    data.dictCode = this.data.dictCode
    this.setData({
      formData: JSON.stringify(data)
    })
    //执行保存编辑操作
    this.save({})
  },
  /** 
   * @desc : 执行保存
   * @date : 2024年5月9日
   * @author : 周兴
   */
  saveData(params) {
    let routeObjNamePop = this.data.routeObjNamePop
    if (!routeObjNamePop) return;
    this.setData({
      addItem: null
    })
    let service = app.globalData[routeObjNamePop + 'Service']
    let defaultFlag = this.data.defaultFlag;
    // 没有默认值就直接保存
    if (!defaultFlag) {
      return this.excute(service, service.insert, params).then(res => {
        if (res.data.code === Constants.SUCESS_CODE) {
          wx.showToast({
            title: '保存成功',
            image: '/static/image/success.png',
            duration: 2000
          })
          if (res.data.data) {
            setTimeout(() => {
              // 多选就选中
              if (this.data.chooseFlag) {
                this.setData({
                  addItem: res.data.data
                })
                this.searchData();
              } else {
                // 执行点击事件
                this._toDetail(res.data.data)
              }
            }, 2000)
          }
        }
      })
    } else {
      this.isFlgDefaultSave(service).then(it => {
        //存在默认
        Dialog.confirm({
          message: mixins.$t('defaultInfo'),
        }).then(() => {
          return this.excute(service, service.insert, params).then(res => {
            if (res.data.code === Constants.SUCESS_CODE) {
              wx.showToast({
                title: '保存成功',
                image: '/static/image/success.png',
                duration: 2000
              })
              if (res.data.data) {
                setTimeout(() => {
                  // 执行点击事件
                  this._toDetail(res.data.data)
                }, 2000)
              }
            }
          })
        }).catch(() => {
          // this.setData({
          //   dataItem: null
          // })
          // //清除组件数据
          // this.selectComponent('#popup').setFormNull()
          return
        });
      })
    }
  },
  /**
   * @desc : 新建默认设置提示
   * @author : 于继渤
   * @date : 2022/5/26 20:16
   */
  isFlgDefaultSave(service) {
    return new Promise((resolve, reject) => {
      this.excute(service, service.selectByCond, {
        flgDefault: true
      }).then(res => {
        if (res.data.data.list && res.data.data.list.length > 0) {
          resolve(false)
        } else {
          resolve(true)
        }
      })
    })
  },
  /**
   * @desc : tab切换（列表和已选）
   * @date : 2024/3/25 15:49
   * @author : 周兴
   */
  changeTag(e) {
    this.setData({
      active: e.detail.index
    })
  },
  /**
   * @desc : 切换tab
   * @date : 2024/2/1 15:49
   * @author : 周兴
   */
  onChangeTabs(e) {
    let index = e.detail.detail.index
    this.setData({
      active: index,
    })
    // 查询
    this.searchData()
  },

  /** 
   * @desc : stickyView的高度
   * @date : 2024年3月23日
   * @author : 周兴
   */
  queryHeight() {
    let _this = this
    var query = wx.createSelectorQuery();
    query.select('#stickyView').boundingClientRect(function (rect) {
      var height = rect.height; // 获取元素的高度
      console.log('元素的高度: ' + height + 'px');
      _this.setData({
        heightList: height + 20
      })
    }).exec();
  },

  /** 
   * @desc : 生命周期函数（初始加载）
   * @date : 2024年3月23日
   * @author : 周兴
   */
  loadInit(e) {
    // // stickyView的高度
    // this.queryHeight()

    let route = this.data.chooseRoute;
    if (!route || !route.type) {
      return;
    }
    let title;
    // 读取传入的单据类型
    let chooseType = route.type
    switch (chooseType) {
      // 角色
      case Constants.chooseType.role:
        title = "角色"
        this.setData({
          addUrl: '/package-basic-data/pages/role/add/add',
          routeObjName: 'common',
          method: 'getRole',
          valueKey: 'roleId',
          title: 'roleName',
          chooseFlag: route.chooseFlag,
          contentList: [{
            name: 'roleCode',
            title: '编码'
          },],
          placeholder: ['roleName']
        })
        break;
      // 部门
      case Constants.chooseType.org:
        title = "部门"
        this.setData({
          addUrl: app.globalData.company.gradeCode == Constants.gradeCode.STD ? null : '/package-basic-data/pages/org/org',
          routeObjName: 'common',
          method: 'getOrg',
          valueKey: 'orgId',
          title: 'orgName',
          contentList: [{
            name: 'orgCode',
            title: '部门编码'
          },],
          placeholder: ['orgName']
        })
        break;
      // 员工
      case Constants.chooseType.staff:
        title = "员工"
        this.setData({
          addUrl: '/package-basic-data/pages/staff/add/add',
          routeObjName: 'common',
          method: 'getStaff',
          valueKey: 'staffId',
          title: 'staffName',
          contentList: [{
            name: 'staffCode',
            title: '员工工号'
          },
          {
            name: 'orgName',
            title: '部门'
          },
          ],
          placeholder: ['staffName']
        })
        break;

      //客户来源
      case Constants.chooseType.cusFrom:
        title = "客户来源"
        this.setData({
          routeObjName: 'common',
          method: 'getInitData',
          valueKey: 'dataId',
          title: 'dataValue',
          contentList: [{
            name: 'dataCode',
            title: '来源编码'
          },
          {
            name: 'dataValue',
            title: '来源名称'
          },
          ],
          placeholder: ['sourceName']
        })
        break;

      // 资金账户
      case Constants.chooseType.moneyAccount:
        title = "资金账户"
        this.setData({
          routeObjName: 'common',
          pageFlag: false,
          method: 'getMac',
          valueKey: 'macId',
          title: 'macName',
          contentList: [{
            name: 'macCode',
            title: '账户编码'
          },
          {
            name: 'macName',
            title: '账户名称'
          },

          ],
          placeholder: ['moneyAccount']
        })
        break;

      //销售渠道
      case Constants.chooseType.saleChannel:
        title = "销售渠道"
        this.setData({
          routeObjName: 'common',
          method: 'getInitData',
          valueKey: 'channelId',
          title: 'channelName',
          simpleFlag: true,
          placeholder: ['channelName']
        })
        break;
      // 供应商
      case Constants.chooseType.supplier:
      case Constants.chooseType.outSupplier:
        title = "供应商"
        this.setData({
          addUrl: '/package-purchase/pages/supplier-list/add/add',
          routeObjName: 'supplier',
          method: 'selectByCond',
          title: 'supName',
          valueKey: 'supId',
          labelKey: 'supName',
          chooseFlag: route.chooseFlag,
          contentList: [{
            name: 'supTypeName',
            title: '供应商类别'
          },
          {
            name: 'returnAddress',
            title: '供应商地址'
          },
          {
            name: 'payableResidue',
            title: '剩余应付'
          },
          {
            name: 'paymentResidue',
            title: '预付金额'
          },
          ],
          placeholder: ['supplier']
        })
        // 多选时就不要有其他的tag标签
        // if (!route.chooseFlag) {
        //   this.setData({
        //     tagList: [{
        //       title: mixins.$t("all") //全部
        //     }, {
        //       title: mixins.$t("procurementSupplier") //采购供应商
        //     }, {
        //       title: mixins.$t("serviceProvider") // 服务供应商
        //     }],
        //   })
        // }
        break;
      // 仓库
      case Constants.chooseType.warehouse:
        title = "仓库"
        let dataItemData = {}
        dataItemData['supervisor'] = app.globalData.user.staffName
        dataItemData['contactPhone'] = app.globalData.user.userPhone

        this.setData({
          routeObjName: 'common',
          routeObjNamePop: 'warehouse',
          method: 'getWarehouseListBy',
          valueKey: 'whId',
          title: 'whName',
          contentList: [{
            name: 'supervisor',
            title: '仓库主管'
          },
          {
            name: 'contactPhone',
            title: '联系电话'
          },
          ],
          placeholder: ['whName'],
          popContent:
            [
              // { code: 'whCode', type: 'str', title: mixins.$t('whCode'), required: false, readonly: true, },
              { code: 'whName', type: 'str', title: mixins.$t('whName'), required: true },
              {
                name: 'supervisor',
                code: 'supervisor',
                title: mixins.$t("supervisor"),
                type: 'choose',
                required: true,
                urlKey: 'chooseStaff'
              },
              { code: 'contactPhone', type: 'str', title: mixins.$t('contactPhone'), required: true },
              { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
            ],
          //设置默认主管
          dataItem: JSON.stringify(dataItemData)
        })
        break;
      case Constants.chooseType.inventorySku:
        title = "库存"
        this.setData({
          routeObjName: 'common',
          method: 'getInventory',
          title: 'skuName',
          contentList: [
            {
              name: 'skuCode',
              title: '商品编码'
            },
            {
              name: 'whName',
              title: '库区'
            },
            {
              name: 'nonStdCode',
              title: '色号'
            },
            {
              name: 'usableQty',
              title: '可售量'
            },
            {
              name: 'invQty',
              title: '库存量'
            },
            {
              name: 'outingQty',
              title: '占库量'
            },
            {
              name: 'freezeQty',
              title: '冻结量'
            },
          ],
          placeholder: ['whName']
        })
        break;
      // 品牌
      case Constants.chooseType.brand:
        title = "品牌"
        this.setData({
          routeObjName: 'common',
          routeObjNamePop: 'goodsBrand',
          method: 'goodsBrandListNoPage',
          chooseFlag: route.chooseFlag,
          repeatFlag: route.repeatFlag,
          valueKey: 'brandId',
          pageFlag: false,
          popTitle: mixins.$t('add') + title,
          title: 'brandName',
          simpleFlag: true,
          // contentList: [{
          //   name: 'brandCode',
          //   title: '品牌编码'
          // },
          // {
          //   name: 'brandName',
          //   title: '品牌名称'
          // },
          // ],
          placeholder: ['brandName']
        })
        // 标准版没有供应商
        if (this.data.gradeCode == Constants.gradeCode.STD) {
          this.setData({
            popContent: [
              { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
              { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
            ],
          })
        } else {
          this.setData({
            popContent: [
              { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
              { code: 'supplierIds', name: 'supplierNames', title: 'supplier', type: 'choose', dropType: 'supplier', urlKey: '', code: 'supplierIds', formMode: 'index', idKey: 'roleId', title: mixins.$t('supplier') },
              { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
            ],
          })
        }
        break;
      // 系列 刘尧 2024.05.29
      case Constants.chooseType.series:
        title = "系列"
        this.setData({
          routeObjName: 'common',
          routeObjNamePop: 'goodsSeries',
          method: 'getGoodsSeriesNoPage',
          chooseFlag: route.chooseFlag,
          repeatFlag: route.repeatFlag,
          valueKey: 'seriesId',
          pageFlag: false,
          popTitle: mixins.$t('add') + title,
          title: 'seriesName',
          simpleFlag: true,
          placeholder: ['seriesName'],
          popContent: [
            { code: 'seriesName', type: 'str', title: mixins.$t('seriesName'), required: true },
            { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
          ]
        })
        break;
      // 计量单位 刘尧 2024.05.29
      case Constants.chooseType.unit:
        title = "单位"
        this.setData({
          routeObjName: 'common',
          routeObjNamePop: 'unit',
          method: 'getUnitNoPage',
          status: 'decimalPlacesStr',
          chooseFlag: route.chooseFlag,
          repeatFlag: route.repeatFlag,
          statusFlag: true,
          valueKey: 'unitId',
          pageFlag: false,
          popTitle: mixins.$t('add') + title,
          title: 'unitName',
          simpleFlag: true,
          placeholder: ['unitName'],
          popContent: [
            { code: 'unitName', type: 'str', title: mixins.$t('unitName'), required: true },
            { code: 'decimalPlaces', max: 6, type: 'number', sign: "", digits: 0, title: mixins.$t('decimalPlaces'), required: true, formatThousandth: false },
            { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
          ]
        })
        break;
      // 数据字典
      case Constants.chooseType.dictionary:
        title = "数据字典"
        let dictCode = route.dictCode
        this.setData({
          addUrl: '/package-basic-data/pages/basic-data/basic-data',
          routeObjName: 'common',
          method: 'getDictionaryData',
          routeObjNamePop: 'basicData',
          dictCode: route.dictCode,
          chooseFlag: route.chooseFlag,
          repeatFlag: route.repeatFlag,
          pageFlag: false,
          valueKey: 'dataId',
          title: 'dataValue',
          contentList: [{
            name: 'dataCode',
            title: '数据编码'
          },
          {
            name: 'dictCode',
            title: '字典项目'
          },
          ],
          placeholder: ['orgName'],

        })
        if (dictCode == mixins.$t('reasonStorageSys')) {
          let popContent =
            [
              { code: 'dataValue', type: 'str', title: mixins.$t('reasonName'), required: true },
              { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false, },
            ]
          this.setData({
            popContent
          })
        }
        break;
      // 系统数据
      case Constants.chooseType.kindData:
        title = "系统数据"
        this.setData({
          pageFlag:false,
          routeObjName: 'common',
          method: 'getDataKind',
          kindType: route.kindType,
          valueKey: 'kindCode',
          title: 'kindName',
          chooseFlag: route.chooseFlag,
          repeatFlag: route.repeatFlag,
          contentList: [{
            name: 'kindCode',
            title: '数据代码'
          },
          {
            name: 'kindName',
            title: '数据名称'
          },
          ],
          placeholder: ['sensitiveName']
        })
        break;
      // 对象类型
      case Constants.chooseType.objectType:
        title = "对象类型"
        this.setData({
          routeObjName: 'common',
          method: 'getSupplierAndCustomerData',
          title: 'objName',
          contentList: [{
            name: 'objCode',
            title: '对象编码'
          },
          {
            name: 'objTypeName',
            title: '对象'
          },
          {
            name: 'addressFull',
            title: '地址'
          },

          {
            name: 'phone',
            title: '电话'
          },
          ],
          searchContent: [{
            code: 'supplier-customer',
            title: '选择对象',
            searchType: Constants.searchType.switch,
            list: [{
              code: 'supplier',
              title: '供应商',
              value: 1,
            },
            {
              code: 'customer',
              title: '客户',
              value: 2
            }
            ]
          },

          ],
          placeholder: ['customerName', 'supplierName', 'address', 'telephone']
        })

        break;

      default:
        break;
    }
    // 多选，数据回显到已选列表
    if (this.data.chooseFlag && this.data.item && this.data.item.data) {
      this.setData({
        choosedData: this.data.item.data
      })
    }
    wx.setNavigationBarTitle({
      title: '选择' + title,
    })
    // 调取查询
    this.searchData();
  },

  /** 
 * @desc : 对获取到的数据进行处理
 * @date : 2024年5月29日
 * @author : 刘尧
 */
  handleSearchData(tableData) {
    let addItem = this.data.addItem
    let valueKey = this.data.valueKey
    let choosedData = this.data.choosedData
    tableData.forEach(item => {
      if (addItem && valueKey) {
        if (item[valueKey] == addItem[valueKey]) {
          item.checked = true;
          choosedData.push({ ...item });
        }
      }
      // 判断数据中是否存在计量单位的小数位数字段
      if (item && (item.decimalPlaces || item.decimalPlaces === 0)) {
        item.decimalPlacesStr = '小数：' + item.decimalPlaces
      }
    })
    this.setData({
      tableData: tableData,
      choosedData: choosedData
    })
  }
})