const _Http = getApp().globalData.http,
  currency = require("../../utils/currency");
let downCount = null;

Page({
  data: {
    "content": {
      "nocache": true,
      "pageNumber": 1,
      "pageSize": 20,
      "pageTotal": 1,
      containssub: true,
      sa_saleareaids: [],
      where: {
        status: ""
      },
      list: [],
    },
    navList: [{
      label: "排序",
      icon: "icon-jiangxu1",
      color: "",
      width: "",
      id: "sort"
    }, {
      label: "筛选",
      icon: "icon-shaixuan",
      color: "",
      width: "",
      id: "2"
    }],
    filtratelist: [{
      label: "状态",
      index: 0,
      showName: "name", //显示字段
      valueKey: "status", //返回Key
      selectKey: "value", //传参 代表选着字段 不传参返回整个选择对象
      value: "", //选中值
      required: true,
      list: [{
        name: "全部",
        value: ""
      }, {
        name: "启用",
        value: "ACTIVE"
      }, {
        name: "停用",
        value: "INACTIVE"
      }]
    }]
  },
  onLoad(options) {
    _Http.basic({
      "classname": "webmanage.sale.salearea.salearea",
      "method": "query_area_qyjl",
      content: {
        "nocache": true,
        "pageNumber": 1,
        "pageSize": 9999,
      }
    }).then(res => {
      console.log("获取区域列表", res)
      if (res.msg == '成功' && res.data.length) {
        this.setData({
          "filtratelist[1]": {
            label: "区域",
            index: 0,
            showName: "areaname", //显示字段
            valueKey: "sa_saleareaids", //返回Key
            selectKey: "sa_saleareaid", //传参 代表选着字段 不传参返回整个选择对象
            value: res.data[0].sa_saleareaid, //选中值
            required: true,
            list: res.data
          }
        });
        this.data.content.sa_saleareaids = [res.data[0].sa_saleareaid];
        this.getList()
      }
    })
  },
  getList(init = false) {
    if (init.detail != undefined) init = init.detail;
    let content = this.data.content;
    if (init) content.pageNumber = 1;
    if (content.pageNumber > content.pageTotal) return;
    _Http.basic({
      id: 20221011144903,
      content
    }).then(res => {
      console.log("经销商", res)
      this.selectComponent('#ListBox').RefreshToComplete();
      this.setData({
        list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
        "content.pageNumber": res.pageNumber + 1,
        "content.pageTotal": res.pageTotal,
        "content.sort": res.sort,
        "content.total": res.total,
        loading: false
      })
    })
  },
  /* 搜索 */
  onSearch({
    detail
  }) {
    this.setData({
      "content.where.condition": detail
    });
    this.getList(true)
  },
  onReady() {
    this.selectComponent("#ListBox").setHeight(".total", this);
  },
  showModal(e) {
    this.setData({
      modalName: e.currentTarget.dataset.target
    })
  },
  hideModal(e) {
    this.setData({
      modalName: null
    })
  },
  handleFiltrate({
    detail
  }) {
    this.data.content.where.status = detail.status;
    this.data.content.sa_saleareaids = detail.sa_saleareaids ? [detail.sa_saleareaids] : [];
    downCount = setTimeout(() => {
      this.getList(true);
    }, 300);
  },
})