<template>
    <lj-win-common title="新建公告">
        <template slot="body">
            <lj-dictionary :data="mainObject" :columns="columns" :editing="true"
                           @action-row-click="handleActionRowClick" style="margin-bottom: 0;"/>
        </template>
        <template slot="footer">
            <mu-button large class="lj-background-color-primary" @click="handleSave" style="width:100%;color: white;">
                <i class="iconfont icon-tongyi  lj-card-summary-icon"></i>
                确定
            </mu-button>
        </template>
    </lj-win-common>
</template>

<script>
    import LjWinCommon from "components/lj-win-common";
    import LjDictionary from "components/lj-dictionary";

    export default {
        name: "workplan-edit",
        components: { LjDictionary, LjWinCommon},
        data() {
            return {
                mainObject: {},
                fileList: [],
                inputFile: []
            }
        },
        created() {
            let user = $lj.getStorage("userInfo");
            var beginDate = new Date();
            var endDate = new Date();
            endDate.setDate(endDate.getDate() + 7);
            
            this.mainObject = {
                sdate:beginDate.getFullYear() + "-" + (beginDate.getMonth() + 1) + "-" + beginDate.getDate() + " " + beginDate.getHours() + ":" + beginDate.getMinutes(),
                edate:endDate.getFullYear() + "-" + (endDate.getMonth() + 1) + "-" + endDate.getDate() + " " + endDate.getHours() + ":" + endDate.getMinutes(),
            };
        },
        methods: {
            handleActionRowClick(eventData) {
                
            },
            handleSave() {
                if (!this.mainObject.sdate) {
                    alert("请先填写开始有效期");
                    return;
                }
                if (!this.mainObject.edate) {
                    alert("请先填写结束有效期");
                    return;
                }
                if (!this.mainObject.dscrp) {
                    alert("请先填写公告内容");
                    return;
                }
                let requestBody = {
                    token: $lj.getStorage("token"),
                    post: Object.assign({}, this.mainObject),
                    type: 0
                };
                $lj.postLJRequest("SaveL1APPSysPost", requestBody, function (ret) {
                    if (ret) {
                        $lj.toast('新建成功!');
                        $lj.sendEvent("gonggao_edit");
                        $lj.closeWin();
                    }
                });
            }
        },
        computed: {
            columns() {
                let result = [
                    {
                        label: "分部",
                        property: "scid",
                        type: "Select",
                        selectOptions: {
                            optionsApi: "GetL1Scdef",
                            valueMap: ["scid", "scname"],
                        }
                    },
                    {
                        label: "部门",
                        property: "deptid",
                        type: "Select",
                        selectOptions: {
                            optionsApi: "GetL1Department",
                            valueMap: ["departmentid", "departmentname"],
                            extraOptions: [{departmentid: -1, departmentname: "全公司", areaname: "全公司", sonflag: 0, parentid: 0}]
                        },
                    },
                ];
                result.push({label: "公告内容", property: "dscrp", inputLine: 5});
                result.push({
                    label: "有效期",
                    property: "sdate",
                    type: "DateTime",
                    inlineDesc: "开始",
                    format: "YYYY-MM-DD HH:mm"
                });
                result.push({
                    label: "",
                    property: "edate",
                    type: "DateTime",
                    inlineDesc: "结束",
                    format: "YYYY-MM-DD HH:mm"
                });
                return result;
            },
        },
    }
</script>

<style scoped>

</style>