/**
 * Created by 1 at 2022-09-09 17:50:25
 * 注册事件类【行政区划管理】，参看event.defaultEvent.js
 */
window.$swEvent.setup("bpm.sys.user.area.area", {
    setup(page) {
        const {$params, $refs, $widgets, $model, $utils, $tabRouter, $api} = page || {};
        const {$$message, $$http} = $utils || {};
        const typeMap = {2: 105100, 4: 105101, 6: 105102, 9: 105103, 12: 105104};
        //
        const focusName = () => {

        };
        const changeName = (value) => {
            $model.areacard.setFormVal("ar_full_name", value);
        };

        const focusCode = () => {

        };
        const changeCode = (value) => {
            $model.areacard.setFormVal("ar_seq", value);
            //根据编码长度设置区划级别
            $model.areacard.setFormVal("ar_type", typeMap[value.length]);
            $model.areacard.setFormVal("ar_parent_id", getParentArea(value));

        };

        const getParentArea = (value) => {
            if (value.length == 12) {
                return value.substring(0, 9);
            }
            if (value.length == 9) {
                return value.substring(0, 6);
            }
            if (value.length == 6) {
                return value.substring(0, 4);
            }
            if (value.length == 4) {
                return value.substring(0, 2);
            }
            if (value.length == 2) {
                return -1;
            }
        }
        return {
            focusName, changeName, focusCode, changeCode
        }
    }
});
