<template>
  <div class="demo-tabs-style right_con">
    <div v-if="adminGuild_type==='list'">
      <p class="title_summny" style="left:200px">说明：添加公会团长账号的功能，统计平台玩家游戏内的消费金额</p>
      <Tabs type="card" v-model="adminGuild_type">
        <TabPane label="公会列表" name="list">
          <div class="search">
            <Input placeholder="公会团长账号" class="wid_120" v-model="search.manager_name" @on-enter="getGuildList()"/>
            <Input placeholder="公会名称" class="wid_120" v-model="search.name" @on-enter="getGuildList()"/>
            <Input placeholder="姓名" class="wid_120" v-model="search.realname" @on-enter="getGuildList()"/>
            <Button type="primary" @click="getGuildList()">搜索</Button>
            <Button class="clear_btn" @click="removeSearch">清空</Button>
          </div>
          <Table :columns="adminGuildData" :data="adminGuildList" class="clear" border></Table>
          <div class="page">
            <Page :total="count" :current="pindex" :page-size="10" size="small" show-total show-elevator @on-change="getGuildList"/>
          </div>
        </TabPane>
        <TabPane label="添加公会" name="add"></TabPane>
        
      </Tabs>
      
      <studio-list :show.sync="platformBindListShow" :value="platformBindListId" @studio-delete="handlerUpdateEmit"></studio-list>
      <studio-update :name="platformBindShowTitle" :show.sync="platformBindShow" :value="platformBindId" @studio-bind="handlerUpdateEmit"></studio-update>
    </div>
    <div v-else>
      <editAdminGuild :adminGuild_type='adminGuild_type' @reuturn_last='reuturn_last' :guildId='gid' :gname='gname' :gnum='gnum' :pindex='pindex'></editAdminGuild>
    </div>
    <guildSale :isGuildSale.sync="isGuildSale" :gname='gname' :gnum='gnum' :gid='gid'></guildSale>
  </div>
</template>
<script>
import guildSale from "@@/user/guild_sale_detail";
import editAdminGuild from "@@/user/edit_adminGuild";
import studioList from "@@/user/studio_list";
import studioUpdate from "@@/user/studio_update";
import {removeSearch} from '@/assets/js/common'
export default {
  name: "admin_guild",
  components: { guildSale, editAdminGuild, studioList, studioUpdate },
  data() {
    return {
      pindex:1,
      count:0,
      is_bankInfo: false,
      gid:null,
      gname:'',
      gnum:null,
      is_edit_bankInfo: false,
      isGuildSale: false,
      adminGuild_type: "list",
      search:{
        manager_name:'',
        name:'',
        realname:''
      },
      platformBindListShow: false,
      platformBindListId: 0,
      isPlatformBindList: false,
      platformBindShow: false,
      platformBindId: 0,
      isPlatformBind:false,
      platformBindShowTitle: '',
      sumWater:null,
      sumPeople:null,
      adminGuildSumData:[
        {
          title:'text',
          width:60,
          render:(h,params)=>{
            return h('span','汇总')
          }
        },
        {
          title:'text',
          render:(h,params)=>{
            return h('span','--')
          }
        },
        {
          title:'text',
          render:(h,params)=>{
            return h('span',this.sumWater/100)
          }
        },
        {
          title:'text',
          render:(h,params)=>{
            return h('span','--')
          }
        },
        {
          title:'text',
          render:(h,params)=>{
            return h('span','--')
          }
        },
        {
          title:'text',
          render:(h,params)=>{
            return h('span','--')
          }
        },
        {
          title:'text',
          render:(h,params)=>{
            return h('span',this.sumPeople)
          }
        },
        {
          title:'text',
          render:(h,params)=>{
            return h('span','--')
          }
        },
        {
          title:'text',
          width:180,
          render:(h,params)=>{
            return h('span','--')
          }
        },
        {
          title:'text',
          width:70,
          render:(h,params)=>{
            return h('span','--')
          }
        },
        {
          title:'text',
          render:(h,params)=>{
            return h('span','--')
          }
        },
      ],
      adminGuildSumList:[
        {}
      ],
      adminGuildData: [
        {
          title: "公会名称",
          key: "name",
          render:(h,params) => {
            return h('span', {
              style:{
                'font-weight': params.row.name === '汇总'? 'bold':'normal'
              }
            }, params.row.name)
          }
        },
        {
          title: "绑定平台",
          key: 'platform_ids',
          render:(h,params)=>{
            if(!!params.row.platform_ids){
              if (params.row.platform_ids === '--') {
                return h('span','--')
              } else {
                return h('span',{
                  style: {
                    color: 'rgb(0, 156, 255)',
                    cursor: "pointer",
                  },
                  on: {
                    click: () => {
                      if (!this.isPlatformBindList) {
                        this.$Message.info('无操作权限')
                        return false
                      }
                      this.platformBindListShow = true
                      this.platformBindListId = params.row.id
                    }
                  }
                },(params.row.platform_ids.split(',').length))
              }
            }else{
              return h('span',{
                style:{color:'rgb(255, 121, 0)',cursor: "pointer"},
                on: {
                  click: () => {
                    if (!this.isPlatformBind) {
                      this.$Message.info('无操作权限')
                      return false
                    }
                    this.platformBindShow = true
                    this.platformBindId = params.row.id
                    this.platformBindShowTitle = params.row.name
                  }
                }
              },'未绑定')
            }
          }
        },
        {
          title: "总流水",
          key: 'recharge_amount',
          render:(h,params)=>{
            return h('span',{style:{
              'font-weight': params.row.name === '汇总'? 'bold':'normal'
            }},(Number(params.row.recharge_amount))/100)
          }
          
        },
        {
          title: "下级推广",
          key: 'channel_num',
          render:(h,params)=>{
            if (params.row.name === '汇总') {
              return h('span', {style:{
                'font-weight': 'bold'
              }},params.row.channel_num)
            } else if(Number(params.row.channel_num)===0){
              return h('span','0')
            }else{
              return h('span',{
                style: {
                  cursor: "pointer",
                  color: "rgba(0, 156, 255, 1)",
                  textDecoration: "underline"
                },
                on: {
                  click: () => {
                    this.gid=params.row.id
                    this.gname=params.row.name
                    this.gnum=params.row.channel_num
                    this.isGuildSale = true;
                  }
                }
              },params.row.channel_num)
            }
          },
        },
        {
          title: "公会参数",
          key: "param",
          render:(h, params) => {
            if (params.row.param === '--') {
              return h('span', '--')
            } else {
              return h('span', {
  
              }, '查看')
            }
          }
        },
        {
          title: "负责人",
          key: "manager_name",
        },
        {
          title: "联系方式",
          key: "mobile",
          
        },
        {
          title: "商务专员",
          key: "commissioner_name",         
        },
        {
          title: "创建时间",
          key: "create_time",
          width: 180
        },
        {
          title: "创建者",
          key: "creator"
        },
        {
          title: "状态",
          key: 'status',
          width:70,
          render: (h, params) => {
            if (params.row.status === '--') {
              return h('span', '--')
            } else if (params.row.status === 0) {
              return h("span",
                { 
                  style: { 
                    color: "rgba(255, 121, 0, 1)" 
                  }
                },"已锁定");
            } else {
              return h("span",
                { 
                  style: { 
                    color: "rgba(0, 156, 255, 1)" 
                  }
                },"正常");
            }
          }
        },
        {
          title: "操作",
          key: 'status',
          render: (h, params) => {
            const change_btn = h("span",
              {
                class: "operate-btn",
                style: {
                  color: "rgba(0, 156, 255, 1)"
                },
                on: {
                  click: () => {
                    this.adminGuild_type = "edit";
                    this.gid=params.row.id
                  }
                }
              },"编辑");
            const unlock_btn = h("div",
              {
                class: "operate-btn",
                style: {
                  color: "rgba(0, 156, 255, 1)"
                },
                on: {
                  click: () => {
                    this.openAdminInfo(params.row.id, params.index);
                  }
                }
              },"解锁");
            const lock_btn = h("div",
              {
                class: "operate-btn",
                style: {
                  color: "rgba(0, 156, 255, 1)"
                },
                on: {
                  click: () => {
                    this.closeAdminInfo(params.row.id, params.index);
                  }
                }
              },"锁定");
            if (params.row.status === '--') {
              return h('span', '--')
            } else if (params.row.status===0) {
              return [change_btn, unlock_btn];
            } else {
              return [change_btn, lock_btn];
            }
          }
        }
      ],
      adminGuildList: []
    };
  },
  watch: {},
  methods: {
    getAuth() {
      this.$api.getAuthRole({id:this.role_id}).then(data=>{
        if(data.code===200){
          let checkList=data.data.auth_ids.split(',')
          if(checkList.indexOf('275')>=0){
            this.isPlatformBindList=true
          }
          if(checkList.indexOf('274')>=0){
            this.isPlatformBind=true
          }
        }
      })
    },
    // 获取列表数据
    getGuildList(page=1) {
      this.sumWater=0
      this.sumPeople=0
      this.$store.commit('changeloading',true)
      this.pindex=page
      this.$api.getGuildList({limit:10,page:this.pindex,...this.search}).then(data => {
        if (data.code === 200) {
          this.adminGuildList=data.data
          this.count=data.count
          data.data.forEach((item,index) => {
            this.sumWater+=item.recharge_amount
            this.sumPeople+=item.channel_num
          });
          this.adminGuildList.push({
            name: '汇总',
            platform_ids: '--',
            recharge_amount: this.sumWater,
            manager_name: '--',
            mobile: '--',
            commissioner_name: '--',
            creator: '--',
            status: '--',
            param: '--',
            create_time: '--',
            channel_num: this.sumPeople
          })
          this.$store.commit('changeloading',false)
        } else {          
          this.$Message.error(data.msg);
          this.$store.commit('changeloading',false)
        }
      });
    },
    // 清空搜索条件
    removeSearch(){
      this.search={...removeSearch({...this.search})}
    },
    // 返回列表页
    reuturn_last(pindex){
      this.adminGuild_type='list'
      this.getGuildList(pindex)
    },
    // 锁定
    closeAdminInfo(id,index){
      this.$api.disableGuildInfo({id:id}).then(data =>{
        if(data.code===200){
          this.$Message.info(data.msg)
          this.adminGuildList[index].status=0
        }else{
          this.$Message.info(data.msg)
        }
      })
    },
    // 解锁
    openAdminInfo(id,index){
      this.$api.enableGuild({id:id}).then(data=> {
        if(data.code===200){
          this.$Message.info(data.msg)
          this.adminGuildList[index].status=1
        }else{
          this.$Message.info(data.msg)
        }
      })
    },
    handlerUpdateEmit () {
      this.getGuildList()
    }
  },
  created() {
    this.getAuth()
    this.getGuildList()
  }
};
</script>
<style>
.add-adminguild-form {
  margin-top: 20px;
}
.guild_text{
  position: relative;
}
.sumtable.ivu-table-wrapper{
  border-top: 0px!important
}
.sumtable .ivu-table td{
  background-color: rgba(245, 248, 253, 1);
}
</style>



