<template>
    <div class="flex-container">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <!-- 搜索区域 -->
            <a-form layout="inline">
                <a-row :gutter="24">
                    <a-col :md="4" :sm="12">
                        <a-form-item  label="县分：">
                            <a-input  placeholder="县分" v-model="queryParam.subName"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :md="4" :sm="12">
                        <a-form-item  label="学校名称">
                            <a-input  placeholder="学校名称" v-model="queryParam.schoolName"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :md="6" :sm="12">
                        <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="0">隐藏中</a-select-option>
                                <a-select-option key="1">显示中</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :md="6" :sm="12">
                        <a-form-item :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}" label="新装融合 ">
                            <a-select placeholder="请选择" v-model="queryParam.netType">
                                <a-select-option key="">请选择</a-select-option>
                                <a-select-option key="0">是 </a-select-option>
                                <a-select-option key="1">否</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 :columns="columns" :data="rowdata" bordered ref="table" size="small" class="flex-filling">
            <!--拦截器-->
            <template slot="statusDefault" slot-scope="text">
                <span v-if="text=='1'">
                    显示中
                </span>
                <span v-else>
                    隐藏中
                </span>
            </template>
            <template slot="operation" slot-scope="text,record">
                <a @click="modifyfunction(record)">编辑</a>
                <span v-if="record.status=='1'">
                     <a-divider type="vertical"/>
                <a-popconfirm title="是否隐藏老客户？" @confirm="delet(record)">
                    <a>隐藏老客户</a>
                </a-popconfirm>
                </span>
                <span v-else>
                    <a-divider type="vertical"/>
                <a-popconfirm title="是否显示老客户？" @confirm="delet(record)">
                    <a>显示老客户</a>
                </a-popconfirm>
                </span>

            </template>

        </s-table>

        <!--编辑----弹框-->
        <a-modal title="编辑学校" :visible="modifyvisible"  @ok="createfunctionOk" @cancel="createfunctionCancel" html-type="submit" width="1024px">
            <a-form :form="Formtable">
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 9, offset: 1}" label="县分">
                    <a-select placeholder="请选择" v-decorator="[ 'subName', {rules: [{ required: true, message: '县分不能为空！' ,whitespace:true}]} ]">
                        <a-select-option key="">请选择</a-select-option>
                        <a-select-option v-for="data in subNameList" :key="data">
                            {{ data}}
                        </a-select-option>
                    </a-select>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 9, offset: 1}" label="学校名称">
                    <a-input placeholder="学校名称" v-decorator="[ 'schoolName', {rules: [{ required: true, message: '学校名称不能为空！' ,whitespace:true}]} ]"></a-input>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 9, offset: 1}" label="单宽学校名称">
                    <a-input placeholder="单宽学校名称" v-decorator="[ 'number', {rules: [{ required: true, message: '输入格式不正确！' ,whitespace:true,pattern:'^(([0-9]{8})|(1[0-9]{10}))$'}]} ]"></a-input>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 9, offset: 1}" label="网点id(合伙人id)">
                    <a-input placeholder="网点id(合伙人id)" v-decorator="[ 'netId', {rules: [{ required: true, message: '网点id不能为空！' ,whitespace:true}]} ]"></a-input>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 9, offset: 1}" label="揽装工号">
                    <a-input placeholder="揽装工号" v-decorator="[ 'lzgh', {rules: [{ required: true, message: '黄名单的备注不能为空！' ,whitespace:true}]} ]"></a-input>
                </a-form-item>

                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 9, offset: 1}" label="是否显示宽带办理">
                    <a-radio-group  v-decorator="['isShowband']">
                        <a-radio value="0">不显示</a-radio>
                        <a-radio value="1">显示</a-radio>
                    </a-radio-group>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 9, offset: 1}" label="是否显示0息购机">
                    <a-radio-group  v-decorator="['netPhone']">
                        <a-radio value="0">不显示</a-radio>
                        <a-radio value="1">显示</a-radio>
                    </a-radio-group>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 9, offset: 1}" label="是否显示融合办理">
                    <a-radio-group  v-decorator="['isShowrh']">
                        <a-radio value="0">不显示</a-radio>
                        <a-radio value="1">显示</a-radio>
                    </a-radio-group>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 9, offset: 1}" label="是否已收到电信卡">
                    <a-radio-group  v-decorator="['isRecv']">
                        <a-radio value="0">否</a-radio>
                        <a-radio value="1">是</a-radio>
                    </a-radio-group>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 9, offset: 1}" label="客户二维码">
                    <img :src="customimg" style="width: 150px">
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 12, offset: 1}" label="套餐选择">
                    <a-row>
                        <a-col :span="8"  v-for="data in packageName"><a-checkbox :value="data">{{data}}</a-checkbox></a-col>
                    </a-row>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 12, offset: 1}" label="二维码默认办理卡品">
                    <a-radio-group :options="taochangName" />
                </a-form-item>
            </a-form>
        </a-modal>
    </div>
</template>

<script>
    import STable from '@/components/table';
    import {findByList} from "@/api/school-center/schoolManagermentAPI"
    import {cloneObject} from '@/utils/util';
    export default {
        name: "schoolmanagement",
        components: {
            STable,
        },
        data: function () {
            return {
                // form
                Formtable: this.$form.createForm(this, {name: 'Formtable'}),
                customimg:"",
                modifyForm: {
                    subName: '',
                    status: '',
                    schoolName: '',
                    netType: '',
                    isShowband:"0"
                },
                subNameList: [],
                packageName:[],
                taochangName:[],
                checkboxdata:[],
                //输入框列表
                queryParam: {
                    subName: '',
                    status: '',
                    schoolName: '',
                    netType: '',
                },
                modifyvisible: false,
                columns: [
                    {dataIndex: 'subName', width: 200, title: '县分', align: "center"},
                    {dataIndex: 'schoolName', width: 200, title: '学校名称', align: "center"},
                    {
                        dataIndex: 'status',
                        width: 200,
                        title: '是否显示老客户升级页面 ',
                        scopedSlots: {customRender: 'statusDefault'},
                        align: "center"
                    },
                    {
                        dataIndex: 'operation',
                        width: 100,
                        title: '操作',
                        align: "center",
                        scopedSlots: {customRender: 'operation'},
                        fixed: "right"
                    }]
                ,
                rowdata: parameter => {
                    let params = {
                        pageNo: parameter.pageNo,
                        pageSize: parameter.pageSize
                    }
                    //表示
                    let obj = cloneObject(this.queryParam)
                    return findByList(Object.assign(params, obj)).then(res => {
                        let data = {}
                        if (res.state !== 'success') {
                            data = {
                                data: [],
                                pageSize: parameter.pageSize,
                                pageNo: 1,
                                totalCount: 0
                            }
                        } else {
                            data = {
                                data: res.data.records,
                                pageSize: parameter.pageSize,
                                pageNo: parameter.pageNo,
                                totalCount: res.data.total
                            }
                        }
                        return data
                    })
                },
                packagedata:""
            }
        },
        methods:{
            search() {
                this.$refs.table.refresh({search: true})
            },
            modifyfunction(data){
                data.subNameList.forEach((key)=>{
                    this.subNameList.push(key.subNameList)
                })
                data.packageName.forEach((key)=>{
                    this.packageName.push(key.packageName)
                    this.taochangName.push(key.name)
                })
                let showband="0"
                if (data.isShowband=="1"){
                    showband=data.isShowband
                }
                let isShowrh="0"
                if (data.isShowrh=="1"){
                    isShowrh=data.isShowrh
                }
                setTimeout(()=>{
                    this.Formtable.setFieldsValue({
                        subName:data.subName,
                        schoolName:data.schoolName,
                        netId:data.netId,
                        lzgh:data.lzgh,
                        isShowband:showband,
                        netPhone:new String(data.netPhone).toString(),
                        isShowrh:isShowrh,
                        isRecv:new String(data.isRecv).toString(),
                    })
                },0)
                this.customimg="./img/custom"+data.serviceQrcode
                this.modifyvisible=true;
            },
            createfunctionOk(){

            },
            createfunctionCancel(){
                this.modifyvisible=false;
                this.packageName=[]
                this.taochangName=[]
                this.subNameList=[]
            }
        },
        created(){
        }
    }
</script>

<style scoped>

</style>