<template>
     <a-spin :spinning="spinning" tip="正在同步中...">
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="6" :sm="12">
            <a-form-item label="数据模块">
              
              <j-input placeholder="输入数据模块查询" ></j-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <a-form-item label="同步方式">
              <j-input placeholder="输入同步方式查询" ></j-input>
            </a-form-item>
          </a-col>


          

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>

            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
     <div class="table-operator" style="border-top: 5px">
      <a-button @click="pulldata()" type="primary" icon="plus" >拉取</a-button>
      <a-button @click="Udate()" type="primary" icon="plus" >U8</a-button>
      <a-button @click="synchronizationWeixin()" type="primary" icon="plus" >企业微信</a-button>
      <a-dropdown   :visible="show">
        <a-button @click="synchronizationPt()" type="primary" icon="plus" >平台</a-button>
        <a-menu slot="overlay">
          <a-menu-item >
          <a-month-picker placeholder="请选择日期"  v-model="date"/>
          </a-menu-item>
          
        </a-menu>
      </a-dropdown>
     
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        bordered
        size="middle"
        rowKey="id"
        :columns="columns"
        :dataSource="data"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type: 'radio'}"
        @change="handleTableChange">

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.avatar)" icon="user"/>
          </div>
        </template>

        <span slot="action" slot-scope="text, record">
        

          <!-- <a-dropdown>
            <a class="ant-dropdown-link">
              同步 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item >
                <a href="javascript:;" @click="handleDetail(record)">同步U8</a>
              </a-menu-item>

              <a-menu-item >
                <a href="javascript:;" @click="handleChangePassword(record.username)">同步中间平台</a>
              </a-menu-item>

              <a-menu-item >
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>同步企业微信</a>
                </a-popconfirm>
              </a-menu-item>

             
            </a-menu>
          </a-dropdown> -->
        </span>


      </a-table>
      
      
      
     
    </div>
    
    <!-- table区域-end -->

    

    <!-- 用户回收站 -->
    <user-recycle-bin-modal :visible.sync="recycleBinVisible" />

  </a-card>
  </a-spin>
</template>

<script>
  import UserModal from './modules/UserModal'
  import PasswordModal from './modules/PasswordModal'
  import {putAction,getFileAccessHttpUrl} from '@/api/manage';
  import {frozenBatch} from '@/api/api'
  import {pullData,synchronizationWeixin,tbquery,synchronizationPt,U8} from '@/api/api'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import JInput from '@/components/jeecg/JInput'
  import UserRecycleBinModal from './modules/UserRecycleBinModal'
  import JSuperQuery from '@/components/jeecg/JSuperQuery'

  export default {
    name: "UserList",
    mixins: [JeecgListMixin],
    components: {
      UserModal,
      PasswordModal,
      JInput,
      UserRecycleBinModal,
      
      JSuperQuery
    },
    data() {
      return {
        show:false,
        date:null,
        spinning:false,
        data:[],
        description: '这是数据同步管理页面',
        queryParam: {},
        recycleBinVisible: false,
        selectedRowKeys:[],
        columns: [
          {
            title: '编号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title: '数据模块',
            align: "center",
            dataIndex: 'name',
            width: 120,
            sorter: true
          },
          {
            title: '状态',
            align: "center",
            width: 100,
            dataIndex: 'state',
            customRender:function (t,r,index) {
            if(r.state==""||r.state==null){
              return "暂无";
            }
            if(r.state=="0"){
              return "成功";
            }
            if(r.state=="1"){
              return "失败";
            }
            }
          },
          {
            title: '同步方式',
            align: "center",
            width: 120,
            dataIndex: 'type',
          customRender:function (t,r,index) {
         
          if(r.type==""||r.type==null){
            return "暂无";
          }
          if(r.type=="0"){
            return "手动同步";
          }
          if(r.type=="1"){
            return "自动同步";
          }
          }
          },

          {
            title: '同步时间',
            align: "center",
            width: 120,
            dataIndex: 'date',
            sorter: true,
            customRender:function (t,r,index) {
                     
            if(r.date==""||r.date==null){
              return "暂无";
            }else{
              return r.date;
            }
           
            }
          },
          {
            title: '用时',
            align: "center",
            width: 100,
            dataIndex: 'time',
            customRender:function (t,r,index) {
                     
            if(r.time==""||r.time==null){
              return "暂无";
            }else{
              return r.time+"秒";
            }
                       
            }
          },
         
          {
            title: '操作',
            align: "center",
            width: 150,
          }

        ],
        
      }
    },
    /* watch:{
    	date:{
    		handler(newVal, objVal) {
          if(this.date!=null){
            this.show=false;
          }
      },
    	}
    }, */
   created() {
     this.querylist();
   },
    methods: {
      Udate(){
        if(this.selectedRowKeys.length<1){
          this.$message.warning('请选择需要同步的数据！');
          return false;
        }if(this.selectedRowKeys[0]!=1&&this.selectedRowKeys[0]!=3&&this.selectedRowKeys[0]!=5){
         this.$message.warning('该数据不能同步U8或拉取U8数据！');
         return false;
       }
       this.spinning=true;
       U8({dataType:this.selectedRowKeys[0]}).then(res=>{
         console.log(res);
         if(res.msg=="ok"){
           this.$message.success('同步成功!');
         }else{
           this.$message.warning(res.msg);
         }
          this.querylist();
          this.spinning=false;
        }) 
       
      },
      querylist:function(){
        tbquery({}).then(res=>{
          this.data=res;
        })
        
      },
      synchronizationPt:function(){
       if(this.selectedRowKeys.length<1){
         this.$message.warning('请选择需要同步的数据！');
         return false;
       }
       // if(this.selectedRowKeys[0]==1){
       //   this.$message.warning('该数据不能同步到平台！');
       //   return false;
       // }
       // this.show=true;
       // if(this.date==null){
       //   this.$message.warning('请选择需要同步的日期！');
       //   return false; 
       // }
       
         this.spinning=true;
       // var datetime=this.formats(this.date);
       synchronizationPt({dataType:this.selectedRowKeys[0]}).then(res=>{
         console.log(res);
         if(res.msg=="ok"){
           this.$message.success('同步成功!');
         }else{
           this.$message.warning(res.msg);
         }
          this.querylist();
          this.spinning=false;
        }) 
       
       
      },
      formats:function(e){
      	 var date = new Date(e);
      	  var seperator1 = "-";
      	  var year = date.getFullYear();
      	  var month = date.getMonth() + 1;
      	  if (month >= 1 && month <= 9) {
      	    month = "0" + month;
      	  }
      	 
      	  var currentdate = year + seperator1 + month;
      	  return currentdate;
      },
      onSelectChange(selectedRowKeys) {
           this.selectedRowKeys=selectedRowKeys;
          },
      synchronizationWeixin:function(){
        if(this.selectedRowKeys.length<1){
          this.$message.warning('请选择需要同步的数据！');
          return false;
        }
        if(this.selectedRowKeys[0]!=1){
          this.$message.warning('该数据不能同步到企业微信！');
          return false;
        }
       this.spinning=true;
        synchronizationWeixin({id:this.selectedRowKeys[0],type:0,typeGo:0}).then(res=>{
           if(res.msg=="ok"){
             this.$message.success('同步成功!');
           }else{
             this.$message.warning(res.msg);
           }
           this.querylist();
           this.spinning=false;
         }) 
      },
      pulldata:function(){
          this.spinning=true;
      pullData({}).then(res=>{
       if(res.msg=="ok"){
         this.$message.success('拉取数据成功!');
       }else{
         this.$message.warning(res.msg);
       }
         this.spinning=false;
        
       }) 
      },
      
     
    }

  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>