<template>
    <div class="flex-container">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <!-- 搜索区域 -->
            <a-form layout="inline">
                <a-row :gutter="24">
                    <a-col :md="3" :sm="6">
                        <a-form-item label="县分">
                            <a-select v-model="queryParam.subName" @change="getSchoolNames">
                                <a-select-option key="">--全部--</a-select-option>
                                <a-select-option v-for="d in subNames" :key="d.value" :value="d.value">{{d.text}}
                                </a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :md="5" :sm="10">
                        <a-form-item label="学校">
                            <a-select v-model="queryParam.schoolName">
                                <a-select-option key="">--全部--</a-select-option>
                                <a-select-option v-for="d in schoolNames" :key="d.value" :value="d.value">{{d.text}}
                                </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.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>
                    <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-divider type="vertical"/>
                          <a-button @click="add()" type="primary">添加</a-button>
                          <a-divider type="vertical"/>
                          <a-button @click="imp">批量导入</a-button>
                          <a-divider type="vertical"/>
                          <a-button v-show="!callback" @click="excelOut">导出</a-button>
                          <a-button v-show="callback">
                            导出中
                            <a-spin style="margin-left: 5px" size="small"/>
                          </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="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>
                <a-divider type="vertical"/>
                <a-popconfirm title="确定要删除此学院？" @confirm="deleteSchool(record)">
                    <a>删除</a>
                </a-popconfirm>
            </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-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: 8, 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: 8, offset: 1}" label="单宽学校名称">
                    <a-select placeholder="请选择" v-decorator="[ 'bandproductId']">
                        <a-select-option key="">请选择</a-select-option>
                        <a-select-option v-for="data in products" :key="data.productId">
                            {{ data.ProductUniversity}}
                        </a-select-option>
                    </a-select>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 8, offset: 1}" label="网点id(合伙人id)">
                    <a-input placeholder="网点id(合伙人id)" v-decorator="[ 'netId']"></a-input>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 8, offset: 1}" label="揽装工号（宽带）">
                    <a-input placeholder="揽装工号（宽带）" v-decorator="[ 'lzgh' ]"></a-input>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 8, offset: 1}" label="揽装人（宽带）">
                    <a-input placeholder="揽装人（宽带）" v-decorator="[ 'lzUser' ]"></a-input>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 8, offset: 1}" label="网点编码">
                    <a-input placeholder="网点编码" v-decorator="[ 'networkCode' ]"></a-input>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 8, offset: 1}" label="网点名称">
                    <a-input placeholder="网点名称" v-decorator="[ 'networkName' ]"></a-input>
                </a-form-item>
                <!--                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 8, 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: 8, 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: 8, 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: 8, 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 label="按钮配置" :labelCol="{span: 6}" :wrapperCol="{span: 8, offset: 1}">
                    <template>
                        <a-tree-select
                                show-search
                                v-model="buttons"
                                style="width: 100%"
                                :tree-data="treeData"
                                placeholder="请选择按钮配置"
                                allow-clear
                                tree-checkable
                                :show-checked-strategy="SHOW_PARENT"
                                multiple
                                :treeCheckStrictly=treeCheckStrictly
                                tree-default-expand-all
                                @change="onTreeChange"
                        >

                        </a-tree-select>
                    </template>
                </a-form-item>

                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 8, offset: 1}" label="随身厅终端编码">
                    <a-input placeholder="随身厅终端编码" v-decorator="[ 'appId' ]"></a-input>
                </a-form-item>

                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 8, offset: 1}" label="随身厅终端密匙">
                    <a-input placeholder="随身厅终端密匙" v-decorator="[ 'appKey' ]"></a-input>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 8, offset: 1}" label="客服二维码">
                    <a-upload
                            ref="upload"
                            :action=uploadUrl
                            listType="picture-card"
                            :fileList="fileList"
                            :headers="header"
                            @preview="handlePreview"
                            @change="handleChange"
                            :data="fileid"
                            accept=".jpg"
                    >
                        <div>
                            <a-icon type="plus"/>
                            <div class="ant-upload-text"><span v-if="fileList2.length==0">上传二维码</span> <span
                                    v-if="fileList2.length>0">更换二维码</span></div>
                        </div>
                    </a-upload>
                    <a-modal :visible="previewVisible" :footer="null" @cancel="handleCancel">
                        <img alt="example" style="width: 100%" :src="previewImage"/>
                    </a-modal>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 8, offset: 1}" label="老用户升级套餐二维码">
                    <a-upload
                            ref="upload"
                            :action=uploadUrl2
                            listType="picture-card"
                            :fileList="fileList2"
                            :headers="header"
                            @preview="handlePreview"
                            @change="handleChange2"
                            :data="fileid"
                            accept=".jpg"
                    >
                        <div>
                            <a-icon type="plus"/>
                            <div class="ant-upload-text"><span v-if="fileList.length==0">上传二维码</span> <span
                                    v-if="fileList.length>0">更换二维码</span></div>
                        </div>
                    </a-upload>
                    <a-modal :visible="previewVisible" :footer="null" @cancel="handleCancel">
                        <img alt="example" style="width: 100%" :src="previewImage"/>
                    </a-modal>
                </a-form-item>
                <a-form-item :labelCol="{span: 6}" :wrapperCol="{span: 15, offset: 1}" label="套餐选择">
                    <a-checkbox-group v-model="chosePages" @change="chosePagesfunction">
                        <a-row>
                            <a-col :span="8" v-for=" (p,index) in package" v-if="index < more">
                                <a-checkbox :value="p.value">{{p.label}}</a-checkbox>
                            </a-col>
                        </a-row>
                        <a-button @click="showMore" v-show="isShowMore">更多</a-button>
                        <a-button @click="hideMore" v-show="!isShowMore">收起</a-button>
                    </a-checkbox-group>
                </a-form-item>
            </a-form>
        </a-modal>
        <a-modal
                title="批量导入"
                :visible="impXXModal"
                @ok="impOk"
                @cancel="impCancel"
                html-type="submit"
                width="400px"
        >
            <a-row :gutter="24">
                <a-col :md="24" :sm="12">
                    <p style="text-align:center">{{ importTile }}</p>
                </a-col>
            </a-row>
            <import-btn :url="importUrl" :responseFun="doPush">
                <a-tooltip placement="topLeft" title="导入文件" arrowPointAtCenter>
                    <a-row :gutter="24">
                        <a-col :md="24" :sm="12">
                            <p>
                                选择文件：
                                <a-button type="primary">选择文件</a-button>
                            </p>
                        </a-col>
                    </a-row>
                </a-tooltip>
            </import-btn>
            <a-row :gutter="24">
                <a-col :md="24" :sm="12">
                    <p v-show="yrymXXmoBan">
                        模板下载：
                        <a-button type="primary" @click="downloadXXMoBan">学校导出模板</a-button>
                    </p>
                </a-col>
            </a-row>
            <a-row :gutter="24" :v-show="yrymXXmoBan">
                <a-col :md="24" :sm="12">
                    <p>说明：</p>
                    <p>1.批量导入请严格按照模版进行导入;</p>
                </a-col>
            </a-row>
        </a-modal>
    </div>
</template>

<script>
    import Vue from 'vue'
    import {ACCESS_TOKEN} from "@/store/mutation-types"
    import STable from '@/components/table';
    import {
        excelMBOut,
        reportDownload,
        findByList,
        choosepages,
        modify,
        insert,
        hidestatus,
        deleteSchoolById,
    } from "../../../api/school-center/schoolManagermentAPI"
    import {cloneObject, exportFile} from '@/utils/util';
    import moment from "moment";
    import {TreeSelect} from 'ant-design-vue';

    const SHOW_PARENT = TreeSelect.SHOW_ALL;
    import {getSchoolNames, initSubstName} from "../../../api/school-center/userManager/newUserAPI";
    import ImportBtn from "../../../components/sysmanage/ImportBtn";

    export default {
        name: "schoolmanagement",
        components: {
            moment,
            STable,
            TreeSelect,
            ImportBtn
        },
        data: function () {
            return {
                yrymXXmoBan: false,
                impXXModal: false,
                importUrl: "",
                importTile: "",
                treeCheckStrictly: true,
                isShowMore: true,
                SHOW_PARENT,
                emptyText: {emptyText: '暂无数据'},
                callback: false,
                previewVisible: false,
                previewImage: '',
                fileList: [],
                fileList2: [],
                header: {
                    "Authorization": Vue.ls.get(ACCESS_TOKEN)
                },
                fileid: {},
                brackgroundurl: "manager/ciop/school/schoolManagement/qrcodeUpload",
                brackgroundurl2: "manager/ciop/school/schoolManagement/qrcodeUpload2",
                // form
                Formtable: this.$form.createForm(this, {name: 'Formtable'}),
                titleName: "",
                customimg: "",
                buttons: [],
                modifyForm: {
                    id: "",
                    networkCode: '',
                    networkName: '',
                    subName: "",
                    schoolName: "",
                    netId: "",
                    lzgh: "",
                    lzUser: "",
                    bandproductId: '',
                    isShowband: "",
                    netPhone: "",
                    isShowrh: "",
                    isRecv: "",
                    chosePages: "",
                    datePeriod: new Array(),
                    greaterFifty: "",
                    greaterHundred: "",
                    startDateStr: "",
                    endDateStr: "",
                    startDate: "",
                    endDate: "",
                    appKey: "",
                    appId: ""
                },
                treeData: [
                    {
                        title: '首页按钮',
                        value: 'indexButton',
                        key: 'indexButton',
                        disabled: true,
                        children: [
                            {
                                title: '手机卡办理',
                                value: 'sjkbl',
                                key: 'sjkbl',
                            }, {
                                title: '套餐升级',
                                value: 'tcsj',
                                key: 'tcsj',
                                children: [{
                                    title: '手机卡套餐升级',
                                    value: 'status',
                                    key: 'status',
                                }, {
                                    title: '毕业生宽带优惠',
                                    value: 'bysrh',
                                    key: 'bysrh',
                                }, {
                                    title: '5G升级会员包',
                                    value: 'sjktcsj',
                                    key: 'sjktcsj',
                                }]
                            }, {
                                title: '校园网办理',
                                value: 'isShowband',
                                key: 'isShowband',
                                children: [
                                    {
                                        title: '普通校园网',
                                        value: 'kdsl',
                                        key: 'kdsl',
                                        disabled: true,
                                    },
                                    {
                                        title: '高速校园网',
                                        value: 'isShowrh',
                                        key: 'isShowrh',
                                        disabled: true,
                                    },
                                    {
                                        title: '是否甩单',
                                        value: 'jiltKd',
                                        key: 'jiltKd',
                                        disabled: true,
                                    },
                                ]
                            }, {
                                title: '校园网提速',
                                value: 'kdyBtn',
                                key: 'kdyBtn',
                                children: [
                                    {
                                        title: '是否甩单',
                                        value: 'jiltKdy',
                                        key: 'jiltKdy',
                                        disabled: true,
                                    }
                                ]
                            }, {
                                title: '优惠购机',
                                value: 'isShowyhgj',
                                key: 'isShowyhgj',
                            },
                            {
                                title: '毕业生宽带',
                                value: 'bysyhBTN',
                                key: 'bysyhBTN',
                                children: [
                                    {
                                        title: '新用户办理',
                                        value: 'sjkbl',
                                        key: 'sjkbl',
                                    },
                                    {
                                        title: '老用户办理',
                                        value: 'lyhyh',
                                        key: 'lyhyh',
                                    }
                                ]
                            }
                        ],
                    },
                    {
                        title: '流程按钮',
                        value: 'processButton',
                        key: 'processButton',
                        disabled: true,
                        children: [
                            {
                                title: '0息购机',
                                value: 'netPhone',
                                key: 'netPhone',
                            },
                            {
                                title: '线上线下',
                                value: 'udBtn',
                                key: 'udBtn',
                            },
                            {
                                title: '是否已收到电信卡',
                                value: 'isRecv',
                                key: 'isRecv',
                            },
                        ],
                    },
                ],
                subNames: [],
                schoolNames: [],
                subNameList: [],
                packageName: [],
                more: 6,
                package: [],
                chosePages: [],
                products: [],
                //输入框列表
                queryParam: {
                    networkName: '',
                    status: '',
                    subName: '',
                    schoolName: '',
                },
                modifyvisible: false,
                columns: [
                    {dataIndex: 'subName', width: 100, title: '县分', align: "center"},
                    {dataIndex: 'schoolName', width: 200, title: '学校名称', align: "center"},
                    {
                        dataIndex: 'status',
                        width: 200,
                        title: '是否显示老客户升级页面',
                        scopedSlots: {customRender: 'statusDefault'},
                        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 findByList(Object.assign(params, obj)).then(res => {
                        console.log(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
                            }
                            if (this.subNameList.length == 0) {
                                res.data.records[0].subNameList.forEach((key) => {
                                    this.subNameList.push(key.subNameList)
                                })
                                res.data.records[0].packageName.forEach((key) => {
                                    let id = "" + key.id
                                    let d = {
                                        label: key.packageName,
                                        value: id
                                    }
                                    this.packageName.push(d)
                                })
                                res.data.records[0].products.forEach((key) => {
                                    let productId = "" + key.productId
                                    let d = {
                                        productId: productId,
                                        ProductUniversity: key.ProductUniversity
                                    }
                                    this.products.push(d)
                                })
                            }
                        }
                        return data
                    })
                }
            }
        },
        watch: {},
        methods: {
            showMore() {
                this.isShowMore = false;
                this.more = (this.packageName.length + 1);
            },
            hideMore() {
                this.isShowMore = true;
                this.more = 6;
            },
            onTreeChange(value) {
                const values = [];
                value.forEach(v => {
                    values.push(v.value);
                })
                this.modifyForm.buttons = values
            },
            changeStartDate(dates, dateString) {
                this.modifyForm.datePeriod = dates;
                this.modifyForm.startDate = dateString[0];
                this.modifyForm.endDate = dateString[1];
            },
            getuuid() {
                return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
                    var r = Math.random() * 16 | 0,
                        v = c == 'x' ? r : (r & 0x3 | 0x8);
                    return v.toString(16);
                });
            },
            baseuploadUrl() {
                const env = process.env.NODE_ENV; //获取当前环境
                let apis = "/";
                if (env === 'development') {     //测试环境默认添加前缀
                    apis = '/api/';
                }
                return apis
            },
            uploadUrl() {
                return this.baseuploadUrl() + this.brackgroundurl
            },
            uploadUrl2() {
                return this.baseuploadUrl() + this.brackgroundurl2
            }
            ,
            //背景图
            handleCancel() {
                this.previewVisible = false;
            },
            handlePreview(file) {
                this.previewImage = file.url || file.thumbUrl;
                this.previewVisible = true;
            },
            handleChange(obj) {
                if (this.fileList.length == 2) {
                    this.fileList.splice(0, 1)
                } else {
                    this.fileList = obj.fileList;
                }
            },
            handleChange2(obj) {
                if (this.fileList2.length == 2) {
                    this.fileList2.splice(0, 1)
                } else {
                    this.fileList2 = obj.fileList;
                }
            },
            delet(deletdata) {
                let status = 0;
                if (deletdata.status == 0) {
                    status = 1
                }
                let parent = {
                    id: deletdata.id,
                    status: status
                }
                hidestatus(parent).then(res => {
                    if (res.state == "success") {
                        this.$message.success(res.data ? res.data : '修改成功！', 5);
                        this.search();
                        return null
                    }
                    this.$message.error(res.data ? res.data : '修改失败！', 5);
                })
            },
            deleteSchool(deleteDate) {
                let parent = {
                    id: deleteDate.id,
                }
                deleteSchoolById(parent).then(res => {
                    if (res.state == "success") {
                        this.$message.success(res.data ? res.data : '修改成功！', 5);
                        this.search();
                        return null
                    }
                    this.$message.error(res.data ? res.data : res.msg, 5);
                })
            },
            chosePagesfunction(data) {
                this.chosePages = data
            },
            search() {
                this.$refs.table.refresh({search: true})
            },
            // 执行上传
            doPush(res) {
                if (!res || !res.response) {
                    this.$message.error("上传文件出错！", 10);
                    return false;
                }
                const response = res.response;
                if (response.state !== "success") {
                    this.$message.error(response.msg ? response.msg : "上传文件出错！", 10);
                    return false;
                }
                this.$message.success("上传成功！" + response.data, 5);
                this.impXXModal = false;
            },

            add() {
                this.titleName = "添加"
                this.isShowMore = true;
                this.more = 6;
                this.chosePages = [];
                this.modifyForm.datePeriod = [];
                this.modifyForm.startDate = "";
                this.modifyForm.endDate = "";
                this.modifyForm.buttons = [];
                this.modifyForm.appKey = "";
                this.modifyForm.appId = "";
                setTimeout(() => {
                    this.Formtable.setFieldsValue({
                        networkCode: '',
                        networkName: '',
                        greaterFifty: "",
                        greaterHundred: "",
                    })
                }, 0)
                this.buttons = [];
                this.modifyvisible = true;
                const temp = [];
                this.packageName.forEach(pName => {
                    temp.push(pName);
                })
                this.package = temp;
            },
            modifyfunction(data) {
                // 清空编辑选中内容
                this.isShowMore = true;
                this.fileList = [];
                this.fileList2 = [];
                this.more = 6;
                // 初始化按钮配置显示值
                this.buttons = [];
                // 初始化按钮配置选中值
                this.modifyForm.buttons = [];
                //初始化
                this.titleName = "编辑学校"
                let choosepagespare = {
                    id: data.id
                }
                this.fileid = {
                    id: data.id
                }
                let url = "";
                let url2 = "";
                if (data.serviceQrcode) {
                    url = this.baseuploadUrl() + "app/ciop" + data.serviceQrcode.replace("enclosure", "");
                } else {
                    url = this.baseuploadUrl() + "app/";
                }
                if (data.packageQrcode) {
                    url2 = this.baseuploadUrl() + "app/ciop" + data.packageQrcode.replace("enclosure", "");
                } else {
                    url2 = this.baseuploadUrl() + "app/";
                }

                if (data.serviceQrcode) {
                    //下载图片浏览
                    this.fileList.push({
                        uid: this.getuuid(),
                        name: '找不到图片',
                        status: 'done',
                        url: url,
                    })
                }
                if (data.packageQrcode) {
                    //下载图片浏览
                    this.fileList2.push({
                        uid: this.getuuid(),
                        name: '找不到图片',
                        status: 'done',
                        url: url2,
                    })
                }
                this.modifyForm.id = data.id
                this.chosePages = [];
                const head = [];
                const temp = [];
                this.packageName.forEach(pName => {
                    temp.push(pName);
                })
                this.package = [];
                //查询中间表
                choosepages(choosepagespare).then(res => {
                    if (res.state == 'success') {
                        let d = res.data.choosepages
                        for (let i = 0; i < d.length; i++) {
                            this.chosePages.push(d[i])
                            for (let j = 0; j < temp.length; ++j) {
                                if (this.chosePages.indexOf(temp[j].value) != -1) {
                                    head.push(temp[j]);
                                    temp.splice(j, 1);
                                    break;
                                }
                            }
                        }
                        if (head.length == 0) {
                            this.package = this.packageName;
                        } else {
                            for (let i = 0; i < temp.length; ++i) {
                                head.push(temp[i]);
                            }
                            this.package = head;
                        }
                    }
                })

                if (data.startDate == undefined || data.endDate == undefined) {
                    this.modifyForm.datePeriod = [];
                    this.modifyForm.startDate = "";
                    this.modifyForm.endDate = "";
                } else {
                    this.modifyForm.datePeriod = [moment(new Date(data.startDate)), moment(new Date(data.endDate))];
                    this.modifyForm.startDate = moment(new Date(data.startDate)).format("YYYY-MM-DD");
                    this.modifyForm.endDate = moment(new Date(data.endDate)).format("YYYY-MM-DD");
                }
                const buttons = [];
                if (data.isShowrh == 1) {
                    buttons.push({label: "高速校园网", value: "isShowrh"});
                }
                if (data.isRecv == 1) {
                    buttons.push({label: "是否已收到电信卡", value: "isRecv"});
                }
                if (data.isShowband == 1) {
                    buttons.push({label: "校园网办理", value: "isShowband"});
                }
                if (data.netPhone == 1) {
                    buttons.push({label: "0息购机", value: "netPhone"});
                }
                if (data.sjkbl == 1) {
                    buttons.push({label: "手机卡办理", value: "sjkbl"});
                }
                if (data.lyhyh == 1) {
                    buttons.push({label: "老用户优惠", value: "lyhyh"});
                }
                if (data.tcsj == 1) {
                    buttons.push({label: "套餐升级", value: "tcsj"});
                }
                if (data.status == 1) {
                    buttons.push({label: "手机卡套餐升级", value: "status"});
                }
                if (data.bysrh == 1) {
                    buttons.push({label: "毕业生宽带优惠", value: "bysrh"});
                }
                if (data.sjktcsj == 1) {
                    buttons.push({label: "5G加装包", value: "sjktcsj"});
                }
                if (data.kdsl == 1) {
                    buttons.push({label: "普通校园网", value: "kdsl"});
                }
                if (data.jiltKd == 1) {
                    buttons.push({label: "是否甩单", value: "jiltKd"});
                }
                if (data.kdyBtn == 1) {
                    buttons.push({label: "校园网提速", value: "kdyBtn"});
                }
                if (data.jiltKdy == 1) {
                    buttons.push({label: "是否甩单", value: "jiltKdy"});
                }
                if (data.isShowyhgj == 1) {
                    buttons.push({label: "优惠购机", value: "isShowyhgj"});
                }
                if (data.udBtn == 1) {
                    buttons.push({label: "线上线下", value: "udBtn"});
                }
                this.buttons = buttons;

                // 初始化选中值
                this.onTreeChange(this.buttons);

                setTimeout(() => {
                    this.Formtable.setFieldsValue({
                        subName: data.subName,
                        schoolName: data.schoolName,
                        bandproductId: data.bandproductId,
                        netId: data.netId,
                        lzgh: data.lzgh,
                        lzUser: data.lzUser,
                        networkName: data.networkName,
                        networkCode: data.networkCode,
                        greaterFifty: data.greaterFifty,
                        greaterHundred: data.greaterHundred,
                        appKey: data.appKey,
                        appId: data.appId,
                    })
                }, 50)
                this.customimg = "./img/custom" + data.serviceQrcode
                this.modifyvisible = true;
            },
            //提交表单
            createfunctionOk() {
                this.Formtable.validateFields(['networkCode', 'networkName', 'schoolName', 'bandproductId', "subName", "lzgh", "lzUser", 'netId', "isShowband", 'isShowrh', "netPhone", 'isRecv', 'greaterFifty', 'greaterHundred', 'appId', 'appKey'], {force: true}, (err, values) => {
                    if (!err) {
                        this.modifyForm.networkCode = values.networkCode
                        this.modifyForm.networkName = values.networkName == undefined ? "" : values.networkName
                        this.modifyForm.subName = values.subName
                        this.modifyForm.schoolName = values.schoolName
                        this.modifyForm.netId = values.netId
                        this.modifyForm.lzgh = values.lzgh
                        this.modifyForm.lzUser = values.lzUser
                        this.modifyForm.bandproductId = values.bandproductId == undefined ? "" : values.bandproductId
                        this.modifyForm.chosePages = ""
                        this.modifyForm.startDateStr = this.modifyForm.startDate;
                        this.modifyForm.endDateStr = this.modifyForm.endDate;

                        this.modifyForm.appId = values.appId;
                        this.modifyForm.appKey = values.appKey;

                        // 日期类型不传入后端
                        Vue.delete(this.modifyForm, 'startDate');
                        Vue.delete(this.modifyForm, 'endDate');
                        this.modifyForm.greaterFifty = values.greaterFifty == undefined ? "" : values.greaterFifty
                        this.modifyForm.greaterHundred = values.greaterHundred == undefined ? "" : values.greaterHundred
                        this.modifyForm.isShowrh = (this.modifyForm.buttons.indexOf("isShowrh") > -1) ? 1 : 0;
                        this.modifyForm.isShowband = (this.modifyForm.buttons.indexOf("isShowband") > -1) ? 1 : 0;
                        this.modifyForm.netPhone = (this.modifyForm.buttons.indexOf("netPhone") > -1) ? 1 : 0;
                        this.modifyForm.isRecv = (this.modifyForm.buttons.indexOf("isRecv") > -1) ? 1 : 0;

                        this.modifyForm.sjkbl = (this.modifyForm.buttons.indexOf("sjkbl") > -1) ? 1 : 0;
                        this.modifyForm.lyhyh = (this.modifyForm.buttons.indexOf("lyhyh") > -1) ? 1 : 0;
                        this.modifyForm.tcsj = (this.modifyForm.buttons.indexOf("tcsj") > -1) ? 1 : 0;
                        this.modifyForm.sjktcsj = (this.modifyForm.buttons.indexOf("sjktcsj") > -1) ? 1 : 0;
                        this.modifyForm.bysrh = (this.modifyForm.buttons.indexOf("bysrh") > -1) ? 1 : 0;

                        this.modifyForm.kdsl = (this.modifyForm.buttons.indexOf("kdsl") > -1) ? 1 : 0;
                        this.modifyForm.jiltKd = (this.modifyForm.buttons.indexOf("jiltKd") > -1) ? 1 : 0;
                        this.modifyForm.kdyBtn = (this.modifyForm.buttons.indexOf("kdyBtn") > -1) ? 1 : 0;
                        this.modifyForm.jiltKdy = (this.modifyForm.buttons.indexOf("jiltKdy") > -1) ? 1 : 0;
                        this.modifyForm.status = (this.modifyForm.buttons.indexOf("status") > -1) ? 1 : 0;

                        this.modifyForm.isShowyhgj = (this.modifyForm.buttons.indexOf("isShowyhgj") > -1) ? 1 : 0;
                        this.modifyForm.udBtn = (this.modifyForm.buttons.indexOf("udBtn") > -1) ? 1 : 0;

                        this.chosePages.forEach(value => {
                            if (value != undefined && this.modifyForm.chosePages.indexOf(value) == -1) {
                                this.modifyForm.chosePages = value + "," + this.modifyForm.chosePages
                            }
                        })
                        //插入数据
                        if (this.modifyForm.id == "") {
                            for (let key in this.modifyForm) {
                                if (this.modifyForm[key] == undefined) {
                                    this.modifyForm[key] = ""
                                }
                            }
                            insert(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);
                            })
                            return null;
                        }
                        //修改数据
                        modify(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({
                    subName: "",
                    schoolName: "",
                    netId: "",
                    lzgh: "",
                    lzUser: "",
                    bandproductId: "",
                    isShowband: "",
                    netPhone: "",
                    isShowrh: "",
                    isRecv: "",
                    greaterFifty: '',
                    greaterHundred: ''
                })
                this.fileList = []
                this.fileList2 = []
                this.modifyForm.id = ""
                this.modifyForm.chosePages = ""
                this.modifyForm.datePeriod = [];
                this.chosePages = [];
                this.modifyvisible = false;
            },
            getSchoolNames() {
                this.schoolNames = []
                this.queryParam.schoolName = ''
                getSchoolNames({"substName": this.queryParam.subName}).then((res) => {
                    if (res.state == "success") {
                        const result = res.data
                        result.forEach((r) => {
                            if (r.schoolName === 'null')
                                return;
                            this.schoolNames.push({
                                value: r.schoolName,
                                text: r.schoolName
                            })
                        })
                    }
                })
            },
            initSubstName() {
                initSubstName().then((res) => {
                    if (res.state == "success") {
                        const result = res.data
                        result.forEach((r) => {
                            if (r.subName === 'null')
                                return;
                            this.subNames.push({
                                value: r.subName,
                                text: r.subName
                            })
                        })
                    }
                })
            },
            excelOut() {
                this.callback = true;
                let today = new Date();
                today.setTime(today.getTime());
                let s2 = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate();
                exportFile(
                    reportDownload(this.queryParam),
                    "校园信息列表" + s2 + ".xlsx",
                    this.downloadstatu
                );
            },
            downloadXXMoBan: function () {
                exportFile(excelMBOut(), "学校列表模板.xlsx");
            },
            downloadstatu() {
                this.callback = false;
            },
            impOk() {
            },
            impCancel() {
                this.impXXModal = false;
                this.clearmodel();
            },
            imp() {
                this.handleSubmit1();
            },
            clearmodel() {
                this.importTile = "";
                this.yrymXXmoBan = false;

                this.importUrl = "";
            },
            handleSubmit1() {
                this.importTile = "学校导入";
                this.yrymXXmoBan = true;
                this.importUrl = "manager/ciop/school/schoolManagement/importDate";
                this.impXXModal = true;
            },
        },
        mounted() {
            this.initSubstName();
            this.getSchoolNames();
        },
    }
</script>

<style scoped>

</style>
