<script>
import WidgetTmp from '../_comm/WidgetTmp';
import { eventType, MOUSE_EVENT } from './constants';
export default {
    extends: WidgetTmp,
    methods: {

        /**
         * 准备滑动
         * @param {Event} evt 事件对象
         */
        _onStart (evt) {
            const _that = this;
            const _evtType = eventType[evt.type];
            if (_evtType !== MOUSE_EVENT) {
                return;
            }
            if (evt.button + '' !== '0') {
                return;
            }
            if (_that._isStart) {
                return;
            }
            _that._isStart = evt.pageX;
            _that._ismove = false;
            _that.pointX = evt.pageX;
        },
        /**
         * 准备滑动
         * @param {Event} evt 事件对象
         */
        _onMove (evt) {
            const _that = this;
            if (!_that._isStart) {
                return;
            }
            let _refs = _that.$refs || {};
            let _wrapEl = _refs.hook_wrap;
            _wrapEl.scrollLeft = _wrapEl.scrollLeft + (_that.pointX - evt.pageX);
            _that.pointX = evt.pageX;
            if (Math.abs(_that._isStart - evt.pageX) > 5) {
                _that._ismove = true;
            }
        },
        /**
         * 准备滑动
         * @param {Event} evt 事件对象
         */
        _onEnd () {
            let _that = this;
            _that._isStart = 0;
            setTimeout(() => {
                _that._ismove = false;
            }, 0);
        }
    }
};
</script>
