<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>用户管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/css/oksub.css}">
    <link rel="stylesheet" th:href="@{/lib/iview/styles/iview.css}">
</head>
<body>
<div id="app" class="ok-body" v-cloak>
    <!--模糊搜索区域-->
    <template>
        <div style="margin-bottom: 8px;margin-top: 8px;">
            <i-input placeholder="输入内容"  v-model="user.description"  style="width: 200px"></i-input>
            <i-button type="primary"  icon="ios-search" @click="load()">搜索</i-button>
            <i-button type="primary"  icon="ios-redo" @click="reload()" >重置</i-button>
        </div>
    </template>
    <template>
        <i-table size="small" :columns="tableTitle"  :data="tableData">
        </i-table>
        <br>
        <Page  style="float: right;" :current="user.pageNumber" :total="tableSize" :page-size="user.pageSize"  @on-change="changePage" @on-page-size-change="changePageSize" show-elevator show-sizer show-total></Page>
    </template>
</div>
<!--js逻辑-->
<script type="text/javascript" th:src="@{/lib/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/lib/vue/vue.min.js}" ></script>
<script type="text/javascript" th:src="@{/lib/iview/iview.min.js}"></script>
<script th:inline="none">
layui.use(["okUtils", "okLayer"], function () {
    var okUtils = layui.okUtils;
    var okLayer = layui.okLayer;
    var vm = new Vue({
        el: '#app',
        data: function(){
        var _this = this;
		return {
            tableTitle : [{
                title: '序号',
                minWidth : 100,
                render: function(h, params) {
                    return h('span', params.index + (_this.user.pageNumber- 1) * _this.user.pageSize + 1);
                }
            },{
                key : "nickName",
                title : "昵称",
                minWidth:150
            },{
                key : "openid",
                title : "openid",
                minWidth:250
            },
<!--            {-->
<!--                key : "country",-->
<!--                title : "国家",-->
<!--                minWidth:150-->
<!--            },{-->
<!--                key : "city",-->
<!--                title : "城市",-->
<!--                minWidth:150-->
<!--            },-->
            {
                key : "gender",
                title : "性别",
                minWidth:80,
                render : function(h, params) {
                    var gender = params.row.gender==1?"男":"女";
                    return h('div', gender);
                }
            },{
                key : "gmtCreate",
                title : "注册时间",
                minWidth:150,
            },{
                key : "subscribe",
                title : "订阅",
                minWidth:80,
            },{
                title : '操作',
                key : 'action',
                minWidth : 100,
                align : 'center',
                render : function(h, params) {
                    var functionList = [];
                    var remove = h('Button', {
                        props : {
                            type : 'primary',
                            size : 'small',
                            icon : 'md-trash'
                        },
                        style : {
                            marginRight : '8px'
                        },
                        on : {
                            click : function() {
                                vm.remove(params.row);
                            }
                        }
                    }, '删除');
                    functionList.push(remove);
                    return h('div', functionList);
                }
            } ],
            tableData : [],
            user  : {
                pageSize : 10,
                pageNumber : 1,
                description:'',
            },
            tableSize : 50,
          }
        },
        methods: {
            load : function() {
               var _this = this;
               okUtils.ajax("/sys/weChat/list", "post", this.user, false).done(function (response) {
                    _this.tableData = response.msg.pageData;
                    _this.tableSize = response.msg.totalCount;
                }).fail(function (error) {
                    console.log(error)
                });
            },
            reload : function(){
                this.user.pageNumber=1;
                this.user.pageSize=10;
                this.user.pornStatus=null;
                this.load();
            },
            changePage : function(pageNumber) {
                vm.user.pageNumber = pageNumber;
                vm.load();
            },
            changePageSize : function(pageSize) {
                vm.user.pageSize = pageSize;
                vm.load();
            },
            edit : function(user) {

            },
            remove : function(user) {
                okLayer.confirm("确定要删除吗？", function () {
                    okUtils.ajaxCloud({
                        url:"/sys/weChat/delete",
                        param : {id:user.id},
                        success : function(result) {
                            okLayer.msg.greenTick(result.msg, function () {
                                  vm.load();
                            })
                        }
                    });
                 })
            }
        },
        created: function() {
            this.load()
        }
    })
  });
</script>
</body>
</html>
