import { Prop, Provide, Emit, Model } from 'vue-property-decorator';
import { Subject, Subscription } from 'rxjs';
import { Watch, EditFormControlBase } from '@/studio-core';
import HRContractService from '@/service/hrcontract/hrcontract-service';
import MainService from './main-form-service';
import HRContractUIService from '@/uiservice/hrcontract/hrcontract-ui-service';
import { FormButtonModel, FormPageModel, FormItemModel, FormDRUIPartModel, FormPartModel, FormGroupPanelModel, FormIFrameModel, FormRowItemModel, FormTabPageModel, FormTabPanelModel, FormUserControlModel } from '@/model/form-detail';


/**
 * form部件基类
 *
 * @export
 * @class EditFormControlBase
 * @extends {MainEditFormBase}
 */
export class MainEditFormBase extends EditFormControlBase {

    /**
     * 获取部件类型
     *
     * @protected
     * @type {string}
     * @memberof MainEditFormBase
     */
    protected controlType: string = 'FORM';

    /**
     * 建构部件服务对象
     *
     * @type {MainService}
     * @memberof MainEditFormBase
     */
    public service: MainService = new MainService({ $store: this.$store });

    /**
     * 实体服务对象
     *
     * @type {HRContractService}
     * @memberof MainEditFormBase
     */
    public appEntityService: HRContractService = new HRContractService({ $store: this.$store });

    /**
     * 应用实体名称
     *
     * @protected
     * @type {string}
     * @memberof MainEditFormBase
     */
    protected appDeName: string = 'hrcontract';

    /**
     * 应用实体中文名称
     *
     * @protected
     * @type {string}
     * @memberof MainEditFormBase
     */
    protected appDeLogicName: string = '合同信息';
    /**
     * 界面UI服务对象
     *
     * @type {HRContractUIService}
     * @memberof MainEditFormBase
     */  
    public appUIService:HRContractUIService = new HRContractUIService(this.$store);


    /**
     * 表单数据对象
     *
     * @type {*}
     * @memberof MainEditFormBase
     */
    public data: any = {
        srfupdatedate: null,
        srforikey: null,
        srfkey: null,
        srfmajortext: null,
        srftempmode: null,
        srfuf: null,
        srfdeid: null,
        srfsourcekey: null,
        hremployeename: null,
        contractcode: null,
        contractmode: null,
        contracttype: null,
        begintime: null,
        endtime: null,
        mgrorganizationname: null,
        signorganizationname: null,
        contractsigntype: null,
        contractstate: null,
        probationtime: null,
        workcontent: null,
        memo: null,
        attachment: null,
        signorganizationid: null,
        hremployeeid: null,
        mgrorganizationid: null,
        hrcontractid: null,
        hrcontract:null,
    };

    /**
     * 属性值规则
     *
     * @type {*}
     * @memberof MainEditFormBase
     */
    public rules: any = {
        hremployeename: [
            { required: true, type: 'string', message: '员工姓名 值不能为空', trigger: 'change' },
            { required: true, type: 'string', message: '员工姓名 值不能为空', trigger: 'blur' },
        ],
        contractcode: [
            { required: true, type: 'string', message: '合同编号 值不能为空', trigger: 'change' },
            { required: true, type: 'string', message: '合同编号 值不能为空', trigger: 'blur' },
        ],
        contractmode: [
            { required: true, type: 'string', message: '合同类别 值不能为空', trigger: 'change' },
            { required: true, type: 'string', message: '合同类别 值不能为空', trigger: 'blur' },
        ],
        contracttype: [
            { required: true, type: 'string', message: '合同类型 值不能为空', trigger: 'change' },
            { required: true, type: 'string', message: '合同类型 值不能为空', trigger: 'blur' },
        ],
        begintime: [
            { required: true, type: 'string', message: '开始日期 值不能为空', trigger: 'change' },
            { required: true, type: 'string', message: '开始日期 值不能为空', trigger: 'blur' },
        ],
        endtime: [
            { required: true, type: 'string', message: '结束日期 值不能为空', trigger: 'change' },
            { required: true, type: 'string', message: '结束日期 值不能为空', trigger: 'blur' },
        ],
        mgrorganizationname: [
            { required: true, type: 'string', message: '合同管理单位 值不能为空', trigger: 'change' },
            { required: true, type: 'string', message: '合同管理单位 值不能为空', trigger: 'blur' },
        ],
        contractsigntype: [
            { required: true, type: 'string', message: '签订类型 值不能为空', trigger: 'change' },
            { required: true, type: 'string', message: '签订类型 值不能为空', trigger: 'blur' },
        ],
        contractstate: [
            { required: true, type: 'string', message: '合同状态 值不能为空', trigger: 'change' },
            { required: true, type: 'string', message: '合同状态 值不能为空', trigger: 'blur' },
        ],
    }

    /**
     * 属性值规则
     *
     * @type {*}
     * @memberof MainBase
     */
    public deRules:any = {
    };

    /**
     * 详情模型集合
     *
     * @type {*}
     * @memberof MainEditFormBase
     */
    public detailsModel: any = {
        group1: new FormGroupPanelModel({ caption: '合同信息', detailType: 'GROUPPANEL', name: 'group1', visible: true, isShowCaption: false, form: this, showMoreMode: 0, uiActionGroup: { caption: '', langbase: 'entities.hrcontract.main_form', extractMode: 'ITEM', details: [] } }),

        formpage1: new FormPageModel({ caption: '基本信息', detailType: 'FORMPAGE', name: 'formpage1', visible: true, isShowCaption: true, form: this, showMoreMode: 0 }),

        srfupdatedate: new FormItemModel({ caption: '更新时间', detailType: 'FORMITEM', name: 'srfupdatedate', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        srforikey: new FormItemModel({ caption: '', detailType: 'FORMITEM', name: 'srforikey', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        srfkey: new FormItemModel({ caption: '合同信息标识', detailType: 'FORMITEM', name: 'srfkey', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        srfmajortext: new FormItemModel({ caption: '合同信息名称', detailType: 'FORMITEM', name: 'srfmajortext', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        srftempmode: new FormItemModel({ caption: '', detailType: 'FORMITEM', name: 'srftempmode', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        srfuf: new FormItemModel({ caption: '', detailType: 'FORMITEM', name: 'srfuf', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        srfdeid: new FormItemModel({ caption: '', detailType: 'FORMITEM', name: 'srfdeid', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        srfsourcekey: new FormItemModel({ caption: '', detailType: 'FORMITEM', name: 'srfsourcekey', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        hremployeename: new FormItemModel({ caption: '员工姓名', detailType: 'FORMITEM', name: 'hremployeename', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        contractcode: new FormItemModel({ caption: '合同编号', detailType: 'FORMITEM', name: 'contractcode', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        contractmode: new FormItemModel({ caption: '合同类别', detailType: 'FORMITEM', name: 'contractmode', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        contracttype: new FormItemModel({ caption: '合同类型', detailType: 'FORMITEM', name: 'contracttype', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        begintime: new FormItemModel({ caption: '开始日期', detailType: 'FORMITEM', name: 'begintime', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        endtime: new FormItemModel({ caption: '结束日期', detailType: 'FORMITEM', name: 'endtime', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        mgrorganizationname: new FormItemModel({ caption: '合同管理单位', detailType: 'FORMITEM', name: 'mgrorganizationname', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        signorganizationname: new FormItemModel({ caption: '合同签约单位', detailType: 'FORMITEM', name: 'signorganizationname', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        contractsigntype: new FormItemModel({ caption: '签订类型', detailType: 'FORMITEM', name: 'contractsigntype', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        contractstate: new FormItemModel({ caption: '合同状态', detailType: 'FORMITEM', name: 'contractstate', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        probationtime: new FormItemModel({ caption: '试用期', detailType: 'FORMITEM', name: 'probationtime', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        workcontent: new FormItemModel({ caption: '工作内容', detailType: 'FORMITEM', name: 'workcontent', visible: false, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        memo: new FormItemModel({ caption: '备注', detailType: 'FORMITEM', name: 'memo', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        attachment: new FormItemModel({ caption: '附件', detailType: 'FORMITEM', name: 'attachment', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        signorganizationid: new FormItemModel({ caption: '合同签约单位ID', detailType: 'FORMITEM', name: 'signorganizationid', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        hremployeeid: new FormItemModel({ caption: '员工标识', detailType: 'FORMITEM', name: 'hremployeeid', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        mgrorganizationid: new FormItemModel({ caption: '合同管理单位ID', detailType: 'FORMITEM', name: 'mgrorganizationid', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

        hrcontractid: new FormItemModel({ caption: '合同信息标识', detailType: 'FORMITEM', name: 'hrcontractid', visible: true, isShowCaption: true, form: this, showMoreMode: 0, disabled: false, enableCond: 3 }),

    };

    /**
     * 表单项逻辑
     *
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
     * @returns {Promise<void>}
     * @memberof MainEditFormBase
     */
    public async formLogic({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): Promise<void> {
                















        if (Object.is(name, '') || Object.is(name, 'contracttype')) {
            let ret = true;
            const _contracttype = this.data.contracttype;
            if (this.$verify.testCond(_contracttype, 'EQ', '10')) {
                ret = false;
            }
            this.rules.endtime.some((rule: any) => {
                if (rule.hasOwnProperty('required')) {
                    rule.required = ret;
                }
                return false;
            });
        }






        if (Object.is(name, '') || Object.is(name, 'contracttype')) {
            let ret = false;
            const _contracttype = this.data.contracttype;
            if (this.$verify.testCond(_contracttype, 'EQ', '30')) {
                ret = true;
            }
            this.detailsModel.workcontent.setVisible(ret);
        }







    }
}