/*! bxs-vue-ui v3.3.0 */
import '../utils/entry-virtual.js';
import { C as create, _ as __vue_normalize__ } from '../utils/normalize-component.js';
import '../utils/object-create.js';
import '../utils/html.js';
import '../utils/es.number.constructor.js';
import '../utils/array-iteration.js';
import '../utils/sloppy-array-method.js';
import { _ as _forEachInstanceProperty } from '../utils/for-each.js';
import { _ as _indexOfInstanceProperty } from '../utils/index-of.js';
import '../utils/string-trim.js';
import '../utils/parse-int.js';
import '../utils/filter.js';
import { _ as _sliceInstanceProperty } from '../utils/slice.js';
import { _ as _extends } from '../utils/extends.js';
import { P as Popup } from '../utils/index.js';
import { _ as _someInstanceProperty } from '../utils/some.js';
import 'vue';
import '../utils/env.js';
import '../safe-area-patch/index.js';
import Icon from '../icon/index.js';
import '../utils/trim.js';
import '../utils/splice.js';
import '../utils/keys.js';
import '../utils/a-function.js';
import '../utils/species-constructor.js';
import '../utils/es.string.split.js';
import { _ as _JSON$stringify } from '../utils/stringify.js';
import DefaultPage from '../default-page/index.js';
import { _ as _reduceInstanceProperty } from '../utils/reduce.js';
import '../utils/set-timeout.js';
import { _ as _parseFloat } from '../utils/parse-float.js';
import Search from '../search/index.js';

var _components;
var script = create({
  name: 'profession-list',
  components: (_components = {}, _components[Search.name] = Search, _components[DefaultPage.view.name] = DefaultPage.view, _components[Icon.name] = Icon, _components),
  mixins: [Popup],
  data: function data() {
    return {
      totalLevels: 1,
      // 判断数据层级，共有几层筛选逻辑，默认1层
      isLeafLevel: false,
      // 最后一层
      isComplaint: false,
      // 是否符合
      selected: [],
      // 历史选择项
      // 当前项信息
      currSelect: {},
      // 当前选择项
      professionType: '',
      // 当前职业类别
      professionObj: null,
      // 当前项列表值
      // 搜索相关项
      isShowSearch: false,
      // 搜索开关
      searchValue: '',
      // 搜索key
      searchs: [],
      // 搜索数据源
      menuList: [{
        des: '一级'
      }],
      // tab数据
      digit: ['一级', '二级', '三级', '四级', '五级', '六级', '七级', '八级', '九级', '十级'],
      // 转大写字典
      listStyle: '',
      searchListStyle: ''
    };
  },
  props: {
    // 检索key
    childrenKeyName: {
      type: String,
      default: function _default() {
        return 'children';
      }
    },
    // 职业列表集
    columns: {
      type: Array,
      default: function _default() {
        return [];
      }
    },
    // 初始化值
    initialSelection: {
      type: Object,
      default: function _default() {
        return null;
      }
    },
    // 校验函数
    verifyProfess: {
      type: Function,
      default: function _default() {
        return true;
      }
    },
    // 只读属性
    readonly: {
      type: Boolean,
      default: function _default() {
        return false;
      }
    }
  },
  computed: {
    selectedStr: function selectedStr() {
      var str = '';

      if (this.selected && this.selected.length) {
        var _context;

        str = _reduceInstanceProperty(_context = this.selected).call(_context, function (preVal, currVal, idx) {
          return "" + preVal + (currVal.des && idx > 0 ? '-' : '') + currVal.des;
        }, '');
      }

      return str;
    }
  },
  methods: {
    // 动态样式计算
    calculateListStyle: function calculateListStyle() {
      if (this.$refs.bxContainerHead) this.listStyle = {
        height: window.innerHeight - this.$refs.bxContainerHead.offsetHeight + "px"
      };
    },
    // 选择层级
    onClickMenu: function onClickMenu(idx) {
      var vm = this;

      if (vm.selected.length > idx) {
        vm.isLeafLevel = false;
        vm.isComplaint = false;

        if (vm.selected.length !== vm.menuList.length) {
          var _context2;

          vm.selected = _sliceInstanceProperty(_context2 = vm.selected).call(_context2, 0, idx + 1 - vm.totalLevels);
        } else {
          var _context3;

          vm.selected = _sliceInstanceProperty(_context3 = vm.selected).call(_context3, 0, idx - vm.totalLevels);
        }

        vm.professionObj = vm.selected.length > 0 ? vm.selected[vm.selected.length - 1][vm.childrenKeyName] : vm.columns;
      }
    },
    // 职业选择功能实现
    professionChoose: function professionChoose(val) {
      var vm = this;
      vm.currSelect = val;
      vm.professionAddSelected(val);

      if (!val.code) {
        vm.professionObj = val[vm.childrenKeyName];
      } else if (vm.verifyProfess(vm.currSelect)) {
        // 最后一级职业-符合条件
        vm.isLeafLevel = true;
        vm.isComplaint = true;
        vm.professionType = val.val;

        if (!vm.readonly) {
          vm.$emit('select', vm.selected[vm.selected.length - 1]);
          vm.closeMe();
        }
      } else {
        // 最后一级职业-不符合条件
        vm.isLeafLevel = true;
        vm.isComplaint = false;
        vm.professionType = val.val;
      }
    },
    professionAddSelected: function professionAddSelected(val) {
      var _context4;

      var vm = this; // selected为0，或者 selected最后一项子项不包含当前项

      if (!vm.selected.length || vm.selected.length < vm.totalLevels && _someInstanceProperty(_context4 = vm.selected[vm.selected.length - 1][vm.childrenKeyName]).call(_context4, function (item) {
        return item.des === val.des;
      })) {
        vm.selected.push(val);
      } else {
        vm.selected.pop();
        vm.selected.push(val);
      }
    },
    back: function back() {
      var vm = this;
      vm.isLeafLevel = false;

      if (vm.selected && vm.selected.length && vm.selected.length > 0) {
        vm.selected.pop();
        vm.professionObj = vm.selected.length > 0 ? vm.selected[vm.selected.length - 1][vm.childrenKeyName] : vm.columns;
      } else {
        vm.closeMe();
      }
    },
    closeMe: function closeMe() {
      this.$emit('input', false);
    },
    enter: function enter() {
      this.totalLevels = 1;
      var targetObj = this.columns;

      while (targetObj[0] && targetObj[0][this.childrenKeyName] && typeof targetObj[0][this.childrenKeyName] === 'object') {
        this.totalLevels += 1;

        if (targetObj[0] && targetObj[0][this.childrenKeyName]) {
          targetObj = targetObj[0][this.childrenKeyName];
        }
      }

      if (this.initialSelection && this.initPreProfession(this.initialSelection)) {
        // 存在默认值
        this.professionObj = this.selected[this.selected.length - 2][this.childrenKeyName];
      } else {
        // 初始化
        this.professionObj = this.columns;
      }

      this.calculateListStyle();
    },
    beforeLeave: function beforeLeave() {
      var vm = this;
      vm.isLeafLevel = false;
      vm.isComplaint = false;
      vm.selected = [];
      vm.professionType = '';
    },
    // 搜索功能实现
    enterSearchPage: function enterSearchPage() {
      if (!this.searchListStyle && this.$refs.bxSearchBar) {
        this.searchListStyle = {
          height: window.innerHeight - this.$refs.bxSearchBar.offsetHeight + "px"
        };
      }
    },
    searchShow: function searchShow() {
      this.isShowSearch = true;
    },
    search: function search() {
      var vm = this;
      vm.searchs = [];
      var result = vm.treeTranArray(vm.columns, '', []);

      _forEachInstanceProperty(result).call(result, function (item) {
        var _context5;

        if (_indexOfInstanceProperty(_context5 = item.des).call(_context5, vm.searchValue) !== -1) {
          var temp = {};
          var desArr = item.des.split('-');
          temp.des = desArr[desArr.length - 1];
          temp.code = item.code;
          temp.val = item.val;
          temp.name = item.des;

          if (vm.verifyProfess(temp)) {
            temp.flag = 1;
          } else {
            temp.flag = 0;
          }

          vm.searchs.push(temp);
        }
      });
    },
    searchCancel: function searchCancel() {
      this.isShowSearch = false;
      this.searchClear();
    },
    searchClear: function searchClear() {
      this.searchs = [];
      this.searchValue = '';
    },
    searchAndChooseItem: function searchAndChooseItem(params) {
      var vm = this;
      var temp = params;

      if (params.flag) {
        temp.val = _parseFloat(params.val);
        vm.$emit('select', temp);

        if (!vm.readonly) {
          vm.closeMe();
          vm.searchCancel();
        } else {
          vm.$toast('符合投保条件');
        }
      } else {
        vm.$toast('该职业不符合投保条件');
      }
    },
    // 数据处理
    initPreProfession: function initPreProfession(profess) {
      var vm = this;
      var result = vm.findProfessionByCode(vm.columns, profess.code, profess.des, profess.val);
      vm.selected = result ? result.nodes : [];

      if (!vm.selected.length) {
        vm.$toast('暂无该职业或职业类别有误');
        return false;
      }

      vm.currSelect = vm.selected[vm.selected.length - 1];
      vm.isLeafLevel = true;
      vm.professionType = vm.currSelect.val;

      if (vm.verifyProfess(vm.currSelect)) {
        vm.isComplaint = true;
      } else {
        vm.isComplaint = false;
      }

      return true;
    },
    treeTranArray: function treeTranArray(list, des, params) {
      var vm = this;
      var res = params;

      for (var index = 0; index < list.length; index += 1) {
        var item = list[index];

        if (item[vm.childrenKeyName]) {
          var tempDes = des + "-" + item.des;
          vm.treeTranArray(item[vm.childrenKeyName], tempDes, res);
        } else {
          var _tempDes = des + "-" + item.des;

          res.push(_extends({}, item, {
            des: _sliceInstanceProperty(_tempDes).call(_tempDes, 1)
          }));
        }
      }

      return res;
    },
    findProfessionByCode: function findProfessionByCode(list, code, des, val, params) {
      var vm = this;

      for (var index = 0; index < list.length; index += 1) {
        var item = list[index];
        var data = JSON.parse(_JSON$stringify(params || {
          nodes: []
        }));

        if (_parseFloat(item.code) === _parseFloat(code) && item.des === des && item.val === val) {
          data.nodes.push(item);
          return data;
        }

        if (item[vm.childrenKeyName]) {
          data.nodes.push(item);
          var result = vm.findProfessionByCode(item[vm.childrenKeyName], code, des, val, data);

          if (result) {
            return result;
          }
        } else {
          data = null;
        }
      }

      return null;
    }
  },
  watch: {
    selected: function selected(val) {
      this.menuList = JSON.parse(_JSON$stringify(val));

      if (this.menuList.length < this.totalLevels) {
        this.menuList.push({
          des: this.digit[this.menuList.length]
        });
      }

      this.calculateListStyle();
    }
  }
});

var __vue_script__ = script;
/* template */

var __vue_render__ = function __vue_render__() {
  var _vm = this;

  var _h = _vm.$createElement;

  var _c = _vm._self._c || _h;

  return _c('transition', {
    attrs: {
      "name": "bx-across-slide"
    },
    on: {
      "enter": _vm.enter,
      "before-leave": _vm.beforeLeave
    }
  }, [_vm.value ? _c('div', {
    staticClass: "bx-profession"
  }, [_c('div', {
    staticClass: "bx-container"
  }, [_c('div', {
    ref: "bxContainerHead",
    staticClass: "bx-container-head"
  }, [_c('div', {
    staticClass: "bx-container-title bx-hairline--bottom"
  }, [_c('div', {
    on: {
      "click": _vm.back
    }
  }, [_c('bxs-icon', {
    attrs: {
      "size": "24px",
      "color": "#ccc",
      "name": "arrow-left"
    }
  })], 1), _c('span', {
    staticClass: "bx-container-title-center"
  }, [_vm._v("\n            职业类别\n          ")]), _c('div', {
    on: {
      "click": _vm.closeMe
    }
  }, [_c('bxs-icon', {
    attrs: {
      "size": "24px",
      "color": "#ccc",
      "name": "close"
    }
  })], 1)]), _c('div', [_c('div', {
    on: {
      "click": _vm.searchShow
    }
  }, [_c('bxs-search', {
    attrs: {
      "placeholder": "请输入关键字",
      "disabled": "",
      "background": "#f2f2f2"
    }
  })], 1)]), _c('div', {
    staticClass: "bx-container-selected"
  }, [_c('div', {
    staticClass: "bx-container-selected-sel"
  }, [_vm._v("\n            已选：\n          ")]), _vm.selected && _vm.selected.length ? _c('div', {
    staticClass: "bx-container-selected-text"
  }, [_vm._v("\n            " + _vm._s(_vm.selectedStr) + "\n          ")]) : _vm._e(), _vm.isLeafLevel && _vm.isComplaint ? _c('div', {
    staticClass: "bx-container-right"
  }, [_vm._v("\n            类别：" + _vm._s(_vm.professionType) + "类（符合投保条件）\n          ")]) : _vm._e(), _vm.isLeafLevel && !_vm.isComplaint ? _c('div', {
    staticClass: "bx-container-err"
  }, [_vm._v("\n            类别：拒保" + _vm._s(_vm.professionType) + "类（不符合投保条件）\n          ")]) : _vm._e()]), _c('ul', {
    staticClass: "bx-container-menu bx-hairline--bottom"
  }, _vm._l(_vm.menuList, function (menu, index) {
    return _c('li', {
      key: 'menu' + index,
      staticClass: "bx-container-item",
      class: {
        'active': index + 1 === _vm.menuList.length
      },
      on: {
        "click": function click($event) {
          _vm.onClickMenu(index);
        }
      }
    }, [_vm._v("\n            " + _vm._s(menu.des) + "\n          ")]);
  }))]), _c('div', {
    staticClass: "bx-container-list",
    style: _vm.listStyle
  }, [_vm.professionObj && _vm.professionObj.length > 0 ? _c('ul', _vm._l(_vm.professionObj, function (item, index) {
    return _c('li', {
      key: index,
      staticClass: "bx-container-list-li bx-hairline--bottom",
      class: {
        'bx-container-highlight': _vm.selected && _vm.selected.length && _vm.selected[_vm.selected.length - 1].des === item.des
      },
      on: {
        "click": function click($event) {
          _vm.professionChoose(item);
        }
      }
    }, [_vm._v("\n            " + _vm._s(item.des) + "\n            "), !item.code ? _c('div', [_c('bxs-icon', {
      attrs: {
        "size": "18px",
        "color": "#ccc",
        "name": "arrow-right"
      }
    })], 1) : _vm._e()]);
  })) : _vm._e()])]), _c('transition', {
    attrs: {
      "name": "bx-across-slide"
    },
    on: {
      "enter": _vm.enterSearchPage
    }
  }, [_vm.isShowSearch ? _c('div', {
    staticClass: "bx-search-container"
  }, [_c('div', {
    ref: "bxSearchBar",
    staticClass: "bx-search-bar bx-hairline--bottom"
  }, [_c('bxs-search', {
    attrs: {
      "placeholder": "请输入关键字",
      "show-action": ""
    },
    on: {
      "search": _vm.search,
      "cancel": _vm.searchCancel,
      "clear": _vm.searchClear
    },
    model: {
      value: _vm.searchValue,
      callback: function callback($$v) {
        _vm.searchValue = $$v;
      },
      expression: "searchValue"
    }
  })], 1), _c('div', {
    staticClass: "bx-search-content",
    style: _vm.searchListStyle
  }, [_vm.searchs.length > 0 ? _c('div', {
    staticClass: "bx-search-result"
  }, _vm._l(_vm.searchs, function (item, index) {
    return _c('div', {
      key: index,
      staticClass: "bx-search-item bx-hairline--bottom",
      on: {
        "click": function click($event) {
          _vm.searchAndChooseItem(item);
        }
      }
    }, [_c('div', {
      staticClass: "bx-search-name"
    }, [_vm._v("\n                " + _vm._s(item.name) + "\n              ")]), _c('div', {
      staticClass: "bx-search-job-type",
      class: {
        'bx-text-warn': !item.flag
      }
    }, [_vm._v("\n                " + _vm._s(item.val) + "类\n                " + _vm._s(item.flag ? '（符合投保条件）' : '（不符合投保条件）') + "\n              ")])]);
  })) : _c('div', [_c('bxs-default-page', {
    attrs: {
      "type": "emtpy",
      "inline": false
    }
  })], 1)])]) : _vm._e()])], 1) : _vm._e()]);
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = undefined;
/* module identifier */

var __vue_module_identifier__ = undefined;
/* functional template */

var __vue_is_functional_template__ = false;
/* style inject */

/* style inject SSR */

var index = __vue_normalize__({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);

export default index;
