"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _index = _interopRequireDefault(require("../input-search/index"));

require("./style");

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

  var _h = _vm.$createElement;

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

  return _c('div', {
    staticClass: "ks-employee-input-bar"
  }, [_c('div', {
    staticClass: "ks-employee-input-content"
  }, [_vm.multiple ? _c('div', {
    ref: "userBox",
    staticClass: "user-box"
  }, [_vm._l(_vm.value, function (item, index) {
    return [_c('img', {
      key: index,
      class: {
        'photo-user': true,
        'gray-user': item._disabledUser
      },
      attrs: {
        "src": item.headUrl,
        "alt": ""
      },
      on: {
        "click": function click($event) {
          return _vm.deleteSelect(item, index);
        }
      }
    })];
  })], 2) : _vm._e(), _vm._v(" "), _c('ks-input-search', {
    ref: "ksInputSearch",
    attrs: {
      "value": _vm.searchVal,
      "clearable": false,
      "placeholder": _vm.placeholder
    },
    on: {
      "focus": _vm.focus,
      "blur": _vm.blur,
      "change": _vm.change
    },
    scopedSlots: _vm._u([_vm.clearable ? {
      key: "right-icon",
      fn: function fn() {
        return [_c('div', {
          directives: [{
            name: "show",
            rawName: "v-show",
            value: _vm.showClearVal.length > 0,
            expression: "showClearVal.length > 0"
          }],
          staticStyle: {
            "color": "#c8c9cc",
            "padding": "0 8px"
          },
          on: {
            "click": function click($event) {
              $event.stopPropagation();
              return _vm.clear($event);
            }
          }
        }, [_c('ks-icon', {
          attrs: {
            "name": "clear"
          }
        })], 1)];
      },
      proxy: true
    } : null], null, true)
  })], 1), _vm._v(" "), _vm.showCancel ? _c('div', {
    staticClass: "ks-employee-input-cancel",
    on: {
      "click": _vm.cancel
    }
  }, [_vm._v("\n    取消\n  ")]) : _vm._e()]);
};

var __vue_staticRenderFns__ = [];
var _default2 = {
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__,
  name: 'ks-employee-input',
  components: {
    ksInputSearch: _index.default
  },
  props: {
    value: {
      type: Array,
      default: function _default() {
        return [];
      }
    },
    multiple: {
      type: Boolean,
      default: false
    },
    placeholder: {
      type: String,
      default: '请搜索人名/工号'
    },
    clearable: {
      type: Boolean,
      default: true
    },
    // 是否展示取消按钮
    showCancel: {
      type: Boolean,
      default: false
    }
  },
  data: function data() {
    return {
      searchVal: '',
      showClearVal: ''
    };
  },
  methods: {
    deleteSelect: function deleteSelect(item, index) {
      this.$emit('delete', item);
      this.value.splice(index, 1);
      this.$emit('input', this.value);
    },
    clear: function clear() {
      this.searchVal = '';
      this.showClearVal = '';
      this.$refs.ksInputSearch && this.$refs.ksInputSearch.setValue('');
      this.$emit('clear', this.searchVal);
    },
    moveRight: function moveRight() {
      // 将头部的头像滚动区域平移至最后，选中需要展示最后一个
      var scrollWidth = this.$refs.userBox.scrollWidth;
      this.$refs.userBox.scrollLeft = scrollWidth;
    },
    // 删除按钮事件处理
    deleteKeyEvent: function deleteKeyEvent() {
      if (this.showClearVal === '' && this.value.length) {
        // 多选情况需要删除列表最后数据
        var lastIndex = this.value.length - 1;

        if (this.value[lastIndex] && this.value[lastIndex]._disabledUser) {
          this.deleteSelect(this.value[lastIndex], lastIndex);
        } else {
          this.$set(this.value[lastIndex], '_disabledUser', true);
        }
      }
    },
    focus: function focus() {
      this.$emit('focus');
    },
    blur: function blur() {
      this.$emit('blur');
    },
    cancel: function cancel() {
      this.$emit('cancel', false);
    },
    change: function change(val) {
      this.showClearVal = val;
      this.$emit('change', val);
    }
  }
};
exports.default = _default2;