<template>
    <div class="flex-container">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <!-- 搜索区域 -->
            <a-form layout="inline">
                <a-row :gutter="24">
                    <a-col :md="4" :sm="8">
                        <a-form-item  label="活动标题：">
                            <a-input  placeholder="活动标题" v-model="queryParam.title"></a-input>
                        </a-form-item>
                    </a-col>

                    <a-col :md="3" :sm="6">
                        <a-form-item :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}" label="活动类型">
                            <a-select placeholder="请选择" v-model="queryParam.activityType">
                                <a-select-option key="">请选择</a-select-option>
                                <a-select-option key="个人活动">个人活动</a-select-option>
                                <a-select-option key="团队活动">团队活动</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :md="3" :sm="6">
                        <a-form-item :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}" label="活动小类">
                            <a-select placeholder="请选择" v-model="queryParam.subclass">
                                <a-select-option key="">请选择</a-select-option>
                                <a-select-option key="部长考核">部长考核</a-select-option>
                                <a-select-option key="前置营销">前置营销</a-select-option>
                                <a-select-option key="线上活动">线上活动</a-select-option>
                                <a-select-option key="线下活动">线下活动</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>

                    <a-col :md="4" :sm="8">
                        <a-form-item  label="参与者：">
                            <a-input  placeholder="活动标题" v-model="queryParam.creator"></a-input>
                        </a-form-item>
                    </a-col>

                    <a-col :md="4" :sm="8">
                        <a-form-item :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}" label="审核状态">
                            <a-select placeholder="请选择" v-model="queryParam.status">
                                <a-select-option key="">请选择</a-select-option>
                                <a-select-option key="1">未审核</a-select-option>
                                <a-select-option key="2">审核通过</a-select-option>
                                <a-select-option key="3">审核不通过</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>

                    <span class="table-page-search-submitButtons" style="float: left; overflow: hidden;">
                        <a-col :md="6" :sm="24">
                            <a-button @click="search()" type="primary">查询</a-button>
                        </a-col>
                    </span>
                </a-row>
            </a-form>
        </div>

        <!--列表-->
        <s-table  :locale="emptyText" :columns="columns" :data="rowdata" bordered ref="table" size="small" class="flex-filling">

            <template slot="operation" slot-scope="text,record">
                <a  @click="modifyfunction(record)">审核</a>

            </template>
        </s-table>

        <!--编辑----弹框-->
        <a-modal :title="titleName" :visible="modifyvisible"  @ok="createfunctionOk" @cancel="createfunctionCancel" html-type="submit" width="840px">
            <a-form :form="Formtable">

                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 8, offset: 1}" label="审核状态">
                    <a-radio-group  v-decorator="['status', {rules: [{ required: true, message: '审核状态不能为空！'}]} ]">
                        <a-radio value="2">通过</a-radio>
                        <a-radio value="3">不通过</a-radio>
                    </a-radio-group>
                </a-form-item>

                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 8, offset: 1}" label="所得积分">
                    <a-input placeholder="所得积分" v-decorator="[ 'integral', {rules: [{ required: true,type:'number', message: '所得积分不能为空！' ,whitespace:true,transform:(value)=> {return Number(value)} }]} ]"></a-input>
                </a-form-item>

                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 8, offset: 1}" label="审核备注">
                    <a-input placeholder="审核备注" v-decorator="[ 'remark', {rules: [{ required: false }]} ]"></a-input>
                </a-form-item>

            </a-form>
        </a-modal>
    </div>
</template>

<script>
    import STable from '@/components/table';
    import {getList,audit} from "../../../api/school-center/activityRecordAPI"
    import {cloneObject} from '@/utils/util';
    export default {
        name: "activityRecord",
        components: {
            STable,
        },
        data: function () {
            return {
                emptyText: {emptyText: '暂无数据'},
                previewVisible: false,
                previewImage: '',
                fileList: [
                ],

                fileid:{},
                // form
                Formtable: this.$form.createForm(this, {name: 'Formtable'}),
                titleName:"",
                modifyForm: {
                    id: '',
                    status: '',
                    integral: '',
                    remark: ''
                },
                subNameList: [],
                packageName:[],
                chosePages:[],
                products:[],
                //输入框列表
                queryParam: {
                    title: '',
                    activityType: '',
                    subclass: '',
                    status: '',
                    creator: '',
                },
                modifyvisible: false,
                columns: [
                    {dataIndex: 'title', width: 200, title: '活动标题', align: "center"},
                    {dataIndex: 'desc', width: 200, title: '活动详情', align: "center"},
                    {dataIndex: 'activityType', width: 200, title: '活动类型', align: "center"},
                    {dataIndex: 'subclass', width: 200, title: '活动小类', align: "center"},
                    {dataIndex: 'integral', width: 200, title: '活动积分', align: "center"},
                    {dataIndex: 'status', width: 200, title: '审核状态', align: "center"},
                    {dataIndex: 'remark', width: 200, title: '审核备注', align: "center"},
                    {dataIndex: 'recordIntegral', width: 200, title: '所得积分', align: "center"},
                    {dataIndex: 'creator', width: 200, title: '参与者', align: "center"},
                    {dataIndex: 'message', width: 200, title: '活动留言', align: "center"},
                    {dataIndex: 'createTime', width: 200, title: '参与时间', align: "center"},
                    {dataIndex: 'isRepeal', width: 200, title: '是否重复参与', align: "center"},
                    {
                        dataIndex: 'operation',
                        width: 200,
                        title: '操作',
                        align: "center",
                        scopedSlots: {customRender: 'operation'},
                        fixed: "right"
                    }]
                ,
                rowdata: parameter => {
                    let params = {
                        pageNo: parameter.pageNo,
                        pageSize: parameter.pageSize
                    }
                    //表示
                    let obj = cloneObject(this.queryParam)
                    return getList(Object.assign(params, obj)).then(res => {
                        let data = {}
                        if (res.state !== 'success') {
                            this.emptyText.emptyText = '查询失败！'
                            this.$message.error("查询失败！", 5);
                            data = {
                                data: [],
                                pageSize: parameter.pageSize,
                                pageNo: 1,
                                totalCount: 0
                            }
                        } else {
                            if (res.data.records.length==0){
                                return data
                            }
                            data = {
                                data: res.data.records,
                                pageSize: parameter.pageSize,
                                pageNo: parameter.pageNo,
                                totalCount: res.data.total
                            }
                        }
                        return data
                    })
                }
            }
        },
        methods:{
            chosePagesfunction(data){
                this.chosePages=data
            },
            search() {
                this.$refs.table.refresh({search: true})
            },
            modifyfunction(data){
                //初始化
                this.titleName="审核"
                alert(data.id);
                this.modifyForm.id = data.id
                this.modifyvisible=true;
            },
            //提交表单
            createfunctionOk(){
                this.Formtable.validateFields(['status', "integral","remark"], {force: true}, (err, values)=>{
                    if (!err){
                        this.modifyForm.status=values.status
                        this.modifyForm.remark=values.remark
                        this.modifyForm.integral=values.integral

                        //修改数据
                        audit(this.modifyForm).then(res=>{
                            if (res.state=="success") {
                                this.$message.success(res.data ? res.data : '审核成功！', 5);
                                this.search();
                                this.modifyvisible=false
                                return null;
                            }
                            this.$message.error(res.data ? res.data : '审核失败！', 5);
                        })
                    }
                })
            },
            createfunctionCancel(){
                this.Formtable.setFieldsValue({
                    status: '',
                    remark: '',
                    integral: ''
                })
                this.modifyForm.id=""
                this.modifyvisible=false;
            }
        }
    }
</script>

<style scoped>

</style>
