<template>
    <a-drawer
            :title="title"
            :width="800"
            placement="right"
            :closable="false"
            @close="close"
            :visible="visible"
    >

        <a-spin :spinning="confirmLoading">
            <a-form :form="form">

                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="账户ID">
                    <a-input placeholder="请输入账户ID" v-decorator="['accountId', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="广告活动ID">
                    <a-input placeholder="请输入广告活动ID" v-decorator="['campaignId', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="广告组ID">
                    <a-input placeholder="请输入广告组ID" v-decorator="['unitId', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="广告组名称">
                    <a-input placeholder="请输入广告组名称" v-decorator="['unitName', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="广告组状态">
                    <a-input-number v-decorator="[ 'status', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="审核拒绝理由">
                    <a-input placeholder="请输入审核拒绝理由" v-decorator="['reviewDetail', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="出价类型">
                    <a-input-number v-decorator="[ 'bidType', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="出价">
                    <a-input placeholder="请输入出价" v-decorator="['bid', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="OCPC出价">
                    <a-input placeholder="请输入OCPC出价" v-decorator="['cpaBid', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="OCPX行为类型   1： CPM， 2： CPC，">
                    <a-input-number v-decorator="[ 'ocpxActionType', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="单日预算">
                    <a-input placeholder="请输入单日预算" v-decorator="['dayBudget', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="投放方式  0：未知， 1：正常投">
                    <a-input-number v-decorator="[ 'speed', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="投放开始时间">
                    <a-input placeholder="请输入投放开始时间" v-decorator="['beginTime', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="投放结束时间">
                    <a-input placeholder="请输入投放结束时间" v-decorator="['endTime', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="投放时段">
                    <a-input placeholder="请输入投放时段" v-decorator="['schedule', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="创意展现方式  0：未知， 1：轮播，">
                    <a-input-number v-decorator="[ 'showModel', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="url类型 ">
                    <a-input-number v-decorator="[ 'urlType', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="落地页链接">
                    <a-input placeholder="请输入落地页链接" v-decorator="['url', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="APP ID">
                    <a-input placeholder="请输入APP ID" v-decorator="['appId', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="APP图标存储地址">
                    <a-input placeholder="请输入APP图标存储地址" v-decorator="['appIconUrl', {}]"/>
                </a-form-item>
                <a-form-item
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="应用信息">
                    <a-input placeholder="请输入应用信息" v-decorator="['diverseData', {}]"/>
                </a-form-item>

            </a-form>
        </a-spin>
        <a-button type="primary" @click="handleOk">确定</a-button>
        <a-button type="primary" @click="handleCancel">取消</a-button>
    </a-drawer>
</template>

<script>
    import {httpAction} from '@/api/manage'
    import pick from 'lodash.pick'
    import moment from "moment"

    export default {
        name: "KuaiShouGroupModal",
        data() {
            return {
                title: "操作",
                visible: false,
                model: {},
                labelCol: {
                    xs: {span: 24},
                    sm: {span: 5},
                },
                wrapperCol: {
                    xs: {span: 24},
                    sm: {span: 16},
                },

                confirmLoading: false,
                form: this.$form.createForm(this),
                validatorRules: {},
                url: {
                    add: "/kuaishou/kuaiShouGroup/add",
                    edit: "/kuaishou/kuaiShouGroup/edit",
                },
            }
        },
        created() {
        },
        methods: {
            add() {
                this.edit({});
            },
            edit(record) {
                this.form.resetFields();
                this.model = Object.assign({}, record);
                this.visible = true;
                this.$nextTick(() => {
                    this.form.setFieldsValue(pick(this.model, 'accountId', 'campaignId', 'unitId', 'unitName', 'status', 'reviewDetail', 'bidType', 'bid', 'cpaBid', 'ocpxActionType', 'dayBudget', 'speed', 'beginTime', 'endTime', 'schedule', 'showModel', 'urlType', 'url', 'appId', 'appIconUrl', 'diverseData'))
                    //时间格式化
                });

            },
            close() {
                this.$emit('close');
                this.visible = false;
            },
            handleOk() {
                const that = this;
                // 触发表单验证
                this.form.validateFields((err, values) => {
                    if (!err) {
                        that.confirmLoading = true;
                        let httpurl = '';
                        let method = '';
                        if (!this.model.id) {
                            httpurl += this.url.add;
                            method = 'post';
                        } else {
                            httpurl += this.url.edit;
                            method = 'put';
                        }
                        let formData = Object.assign(this.model, values);
                        //时间格式化

                        console.log(formData)
                        httpAction(httpurl, formData, method).then((res) => {
                            if (res.success) {
                                that.$message.success(res.message);
                                that.$emit('ok');
                            } else {
                                that.$message.warning(res.message);
                            }
                        }).finally(() => {
                            that.confirmLoading = false;
                            that.close();
                        })


                    }
                })
            },
            handleCancel() {
                this.close()
            },


        }
    }
</script>

<style lang="less" scoped>
    /** Button按钮间距 */
    .ant-btn {
        margin-left: 30px;
        margin-bottom: 30px;
        float: right;
    }
</style>