<template>
    <div style="padding: 0px 10px;">
        <el-collapse>
            <el-collapse-item>
                <template slot="title">
                    <span class="abap-api-item-group">整型：I</span>
                </template>
                <div class="abap-api-item-2">
                    <div>显示</div>
                    <div>
                        <el-switch v-model="form.i.show"/>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>变量名</div>
                    <div>
                        <el-input v-model="form.i.paramName"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>默认值</div>
                    <div>
                        <el-input v-model="form.i.defaultValue" placeholder="默认 0"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>长度</div>
                    <div>
                        <el-input v-model="form.i.length" placeholder="默认 4"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>赋值</div>
                    <div>
                        <el-input v-model="form.i.value"></el-input>
                    </div>
                </div>
            </el-collapse-item>

            <el-collapse-item>
                <template slot="title">
                    <span class="abap-api-item-group">浮点型：I</span>
                </template>
                <div class="abap-api-item-2">
                    <div>显示</div>
                    <div>
                        <el-switch v-model="form.f.show"/>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>变量名</div>
                    <div>
                        <el-input v-model="form.f.paramName"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>默认值</div>
                    <div>
                        <el-input v-model="form.f.defaultValue" placeholder="默认 0"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>长度</div>
                    <div>
                        <el-input v-model="form.f.length" placeholder="默认 8"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>赋值</div>
                    <div>
                        <el-input v-model="form.f.value"></el-input>
                    </div>
                </div>
            </el-collapse-item>

            <el-collapse-item>
                <template slot="title">
                    <span class="abap-api-item-group">包类型：P</span>
                </template>
                <div class="abap-api-item-2">
                    <div>显示</div>
                    <div>
                        <el-switch v-model="form.p.show"/>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>变量名</div>
                    <div>
                        <el-input v-model="form.p.paramName"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>默认值</div>
                    <div>
                        <el-input v-model="form.p.defaultValue" placeholder="默认 0"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>长度</div>
                    <div>
                        <el-input v-model="form.p.length" placeholder="默认 8"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>小数位</div>
                    <div>
                        <el-input v-model="form.p.decimalLength" placeholder="默认 0"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>赋值</div>
                    <div>
                        <el-input v-model="form.p.value"></el-input>
                    </div>
                </div>
            </el-collapse-item>

            <el-collapse-item>
                <template slot="title">
                    <span class="abap-api-item-group">文本型：C</span>
                </template>
                <div class="abap-api-item-2">
                    <div>显示</div>
                    <div>
                        <el-switch v-model="form.c.show"/>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>变量名</div>
                    <div>
                        <el-input v-model="form.c.paramName"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>默认值</div>
                    <div>
                        <el-input v-model="form.c.defaultValue" placeholder="默认空字符串"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>长度</div>
                    <div>
                        <el-input v-model="form.c.length" placeholder="默认 1"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>赋值</div>
                    <div>
                        <el-input v-model="form.c.value"></el-input>
                    </div>
                </div>
            </el-collapse-item>

            <el-collapse-item>
                <template slot="title">
                    <span class="abap-api-item-group">数值型：N</span>
                </template>
                <div class="abap-api-item-2">
                    <div>显示</div>
                    <div>
                        <el-switch v-model="form.n.show"/>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>变量名</div>
                    <div>
                        <el-input v-model="form.n.paramName"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>默认值</div>
                    <div>
                        <el-input v-model="form.n.defaultValue" placeholder="默认 '0'"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>长度</div>
                    <div>
                        <el-input v-model="form.n.length" placeholder="默认 1"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>赋值</div>
                    <div>
                        <el-input v-model="form.n.value"></el-input>
                    </div>
                </div>
            </el-collapse-item>

            <el-collapse-item>
                <template slot="title">
                    <span class="abap-api-item-group">日期：D</span>
                </template>
                <div class="abap-api-item-2">
                    <div>显示</div>
                    <div>
                        <el-switch v-model="form.d.show"/>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>变量名</div>
                    <div>
                        <el-input v-model="form.d.paramName"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>默认值</div>
                    <div>
                        <el-input v-model="form.d.defaultValue" placeholder="默认 '00000000'"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>赋值</div>
                    <div>
                        <el-input v-model="form.d.value" placeholder="格式：YYYYMMDD"></el-input>
                    </div>
                </div>
            </el-collapse-item>

            <el-collapse-item>
                <template slot="title">
                    <span class="abap-api-item-group">时间：T</span>
                </template>
                <div class="abap-api-item-2">
                    <div>显示</div>
                    <div>
                        <el-switch v-model="form.t.show"/>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>变量名</div>
                    <div>
                        <el-input v-model="form.t.paramName"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>默认值</div>
                    <div>
                        <el-input v-model="form.t.defaultValue" placeholder="默认 '00000000'"></el-input>
                    </div>
                </div>
                <div class="abap-api-item-2">
                    <div>赋值</div>
                    <div>
                        <el-input v-model="form.t.value"  placeholder="格式：hhmmss"></el-input>
                    </div>
                </div>
            </el-collapse-item>

        </el-collapse>
    </div>
</template>

<script>
import AbapItemBase from './AbapItemBase'

export default {
    name: 'AbapCodeDataDefine',
    extends: AbapItemBase,
    data() {
        return {
            form: {
                i: {
                    show: false,
                    defaultValue: undefined,
                    paramName: "lv_i",
                    length: undefined,
                    value: undefined,
                },
                f: {
                    show: false,
                    defaultValue: undefined,
                    paramName: "lv_f",
                    length: undefined,
                    value: undefined,
                },
                p: {
                    show: false,
                    defaultValue: undefined,
                    paramName: "lv_p",
                    length: undefined,
                    decimalLength: undefined,
                    value: undefined,
                },
                c: {
                    show: false,
                    defaultValue: undefined,
                    paramName: "lv_c",
                    length: undefined,
                    value: undefined,
                },
                n: {
                    show: false,
                    defaultValue: undefined,
                    paramName: "lv_n",
                    length: undefined,
                    value: undefined,
                },
                d: {
                    show: false,
                    defaultValue: undefined,
                    paramName: "lv_d",
                    value: undefined,
                },
                t: {
                    show: false,
                    defaultValue: undefined,
                    paramName: "lv_t",
                    value: undefined,
                },
                baseType: [],
                customType: '',
                showDefine: true,
                showDefineValue: false,
                showParam: false,
                showSetData: false,
                showSysParam: false,
            }
        }
    },
    watch: {
        form: {
            handler: 'initCode',
            deep: true
        }
    },
    created() {
        this.initCode()
    },
    methods: {
        initCode() {
            console.log("重载...");
            let str = "";
            str += this.showI();
            str += this.showF();
            str += this.showP();
            str += this.showC();
            str += this.showN();
            str += this.showD();
            str += this.showT();
            this.abapCode  = str;
        },
        showI() {
            let str = "";
            let obj = this.form.i;
            if (!obj.show) {
                return "";
            }

            let defaultValue = obj.defaultValue;
            let value = obj.value == undefined ? '' : obj.value;
            let length = obj.length == undefined ? '' : `(${obj.length})`;
            let paramName = obj.paramName;

            if (defaultValue == undefined || defaultValue == null || defaultValue == '') {
                str += `DATA ${paramName}${length} TYPE I. "整数\n`;
            } else {
                str += `DATA ${paramName}${length} TYPE I VALUE ${defaultValue}. "整数\n`;
            }
            if (obj.value != undefined) {
                str += `${paramName} = ${value}.\n`;
            }
            return str;
        },
        showF() {
            let str = "";
            let obj = this.form.f;
            if (!obj.show) {
                return "";
            }

            let defaultValue = obj.defaultValue;
            let value = obj.value == undefined ? '' : obj.value;
            let length = obj.length == undefined ? '' : `(${obj.length})`;
            let paramName = obj.paramName;

            if (defaultValue == undefined || defaultValue == null || defaultValue == '') {
                str += `DATA ${paramName}${length} TYPE F. "浮点数\n`;
            } else {
                str += `DATA ${paramName}${length} TYPE F VALUE '${defaultValue}'. "浮点数\n`;
            }
            if (obj.value != undefined) {
                str += `${paramName} = '${value}'.\n`;
            }
            return str;
        },
        showP() {
            let str = "";
            let obj = this.form.p;
            if (!obj.show) {
                return "";
            }

            let defaultValue = obj.defaultValue;
            let value = obj.value == undefined ? '' : obj.value;
            let length = obj.length == undefined ? '' : `(${obj.length})`;
            let decimalLength = obj.decimalLength == undefined ? '' : ` DECIMALS ${obj.decimalLength}`;
            let paramName = obj.paramName;

            if (defaultValue == undefined || defaultValue == null || defaultValue == '') {
                str += `DATA ${paramName}${length} TYPE P. "包类型(定点数)\n`;
            } else {
                str += `DATA ${paramName}${length} TYPE P${decimalLength} VALUE '${defaultValue}'. "包类型(定点数)\n`;
            }
            if (obj.value != undefined) {
                str += `${paramName} = '${value}'.\n`;
            }
            return str;
        },
        showC() {
            let str = "";
            let obj = this.form.c;
            if (!obj.show) {
                return "";
            }

            let defaultValue = obj.defaultValue;
            let value = obj.value == undefined ? '' : obj.value;
            let length = obj.length == undefined ? '' : `(${obj.length})`;
            let paramName = obj.paramName;

            if (defaultValue == undefined || defaultValue == null || defaultValue == '') {
                str += `DATA ${paramName}${length} TYPE C. "文本\n`;
            } else {
                str += `DATA ${paramName}${length} TYPE C VALUE '${defaultValue}'. "文本\n`;
            }
            if (obj.value != undefined) {
                str += `${paramName} = '${value}'.\n`;
            }
            return str;
        },
        showN() {
            let str = "";
            let obj = this.form.n;
            if (!obj.show) {
                return "";
            }

            let defaultValue = obj.defaultValue;
            let value = obj.value == undefined ? '' : obj.value;
            let length = obj.length == undefined ? '' : `(${obj.length})`;
            let paramName = obj.paramName;

            if (defaultValue == undefined || defaultValue == null || defaultValue == '') {
                str += `DATA ${paramName}${length} TYPE N. "数值\n`;
            } else {
                str += `DATA ${paramName}${length} TYPE N VALUE '${defaultValue}'. "数值\n`;
            }
            if (obj.value != undefined) {
                str += `${paramName} = '${value}'.\n`;
            }
            return str;
        },
        showD() {
            let str = "";
            let obj = this.form.d;
            if (!obj.show) {
                return "";
            }

            let defaultValue = obj.defaultValue;
            let value = obj.value == undefined ? '' : obj.value;
            let paramName = obj.paramName;

            if (defaultValue == undefined || defaultValue == null || defaultValue == '') {
                str += `DATA ${paramName} TYPE D. "日期\n`;
            } else {
                str += `DATA ${paramName} TYPE D VALUE '${defaultValue}'. "日期\n`;
            }
            if (obj.value != undefined) {
                str += `${paramName} = '${value}'.\n`;
            }
            return str;
        },
        showT() {
            let str = "";
            let obj = this.form.t;
            if (!obj.show) {
                return "";
            }

            let defaultValue = obj.defaultValue;
            let value = obj.value == undefined ? '' : obj.value;
            let paramName = obj.paramName;

            if (defaultValue == undefined || defaultValue == null || defaultValue == '') {
                str += `DATA ${paramName} TYPE T. "时间\n`;
            } else {
                str += `DATA ${paramName} TYPE T VALUE '${defaultValue}'. "时间\n`;
            }
            if (obj.value != undefined) {
                str += `${paramName} = '${value}'.\n`;
            }
            return str;
        }
    }
}
</script>

<style scoped>
</style>
