<style>
  .CM_look {
    padding: 4px !important;
    position: relative;
    top: 1px;
  }
  .opUl li {
      display: inline-block;
      margin: 10px 15px 10px 0;
  }
</style>
<template>
  <div class="flexOne domesticCommission">
    <div >
      <ul class="opUl">
        <li>
          <em>{{$t('objFill.v101.administrative.xuanzheqis')}}</em>
          <el-date-picker
      v-model="Periods"
      type="month"
      value-format="yyyy-MM"
      :placeholder="$t('objFill.v101.administrative.xuanzheqis')">
    </el-date-picker>
          <input v-if="IsAuth==1" type="button" class="normalBtn" @click="CreateAirticketCommission()" :value="$t('objFill.v101.administrative.shenchengtcbb')" :disabled="isDisable"  />
        </li>
        <li >
                  <el-button size="mini" type="danger" style="border-radius:14px" 
                      @click="exportExcel">{{$t('objFill.v101.administrative.daochuygztc')}}</el-button>
              </li>
      </ul>
    </div>
    <table class="singeRowTable" border="0" cellspacing="0" cellpadding="0" v-loading="loading">
      <tr>
        <th>{{$t('tips.qishu')}}</th>
        <th>{{$t('objFill.v101.administrative.ticehngzje')}}</th>
        <th>{{$t('admin.admin_czPerson')}}</th>
        <th>{{$t('sm.Date')}}</th>
        <th>{{$t('system.table_operation')}}</th>
      </tr>
      <tr v-for="(item,index) in dataList" :key="index">
        <td>{{item.Periods}}</td>
        <td>{{item.SumPrice}}</td>
        <td>{{item.CreateByName}}</td>
        <td>{{item.CreateTimeStr}}</td>
        <td>
          <el-tooltip class="item" effect="dark" :content="$t('fnc.chakan')" placement="top">
            <el-button type="primary" class="CM_look" @click="goUrl('ViittoCommissionDetail',item.ID)"
              icon="iconfont icon-chakan" circle></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" :content="$t('objFill.preparedocument')" placement="top">
            <el-button type="primary" class="CM_look" @click="goUrlZD" icon="iconfont icon-caidan-fill" circle></el-button>
          </el-tooltip>
        </td>
      </tr>
    </table>
    <!-- 分页 -->
    <el-pagination background @current-change="handleCurrentChange" :current-page.sync="currentPage"
      layout="total,prev, pager, next, jumper" :page-size='msg.PageSize' :total='total'>
    </el-pagination>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        msg: {
          PageIndex: 1,
          PageSize: 20
        },
        loading: false,
        //数据源
        dataList: [],
        total: 0,
        currentPage: 1,
        isDisable:false,
        IsAuth:0,//生成票务提成权限
        Periods:'',
      }
    },
    mounted() {
      let userInfo = this.getLocalStorage();
      this.GetAuth();
      this.getList();
    },
    methods: {
      exportExcel: function () {
        if(this.Periods&&this.Periods!=''&&this.Periods!=null&&this.Periods!=undefined){
          let msg = {
            RB_Group_Id: this.getLocalStorage().RB_Group_id,
            Periods: this.Periods,
      }
      let text = this.$t('tips.di')+this.Periods+this.$t('objFill.v101.administrative.yuangongztc')+".xls"
      this.GetLocalFile(
        "Commission_get_GetPeriodsIdAllUser",
        msg,
        text
      );
        }else{
          this.Error(this.$t('objFill.v101.administrative.qingxuanzqis'));
        }
 
    },
      goUrlZD(){
        let orderObj = {
          OrderID: 0,
          OrderSource: 8,
          Obj: {},
          SourceID: 0,
          CostType:194,
          SelectState:true,
        }
        let id=[29,31];
        this.$router.push({
            name: 'ChoiceAddFinancialDocuments',
            query: {
              Type: 2,
              templateID: JSON.stringify(id),
              'blank': 'y',
              'orderObj': JSON.stringify(orderObj)
            }
          })
      },
      handleCurrentChange(val) {
        this.msg.PageIndex = val;
        this.getList();
      },
      goUrl(path, id) {
        this.$router.push({
          path: path,
          query: {
            ID: id,
            blank: 'y',
            tab: '微途业绩详情'
          }
        });
      },
      //获取数据
      getList() {
        this.loading = true;
        this.apipost(
          "ViittoCommission_get_GetViittoCommissionPageListService",
          this.msg,
          res => {
            this.loading = false;
            if (res.data.resultCode == 1) {
              this.dataList = res.data.data.pageData;
              this.total = res.data.data.count;
            } else {
              this.Error(res.data.message);
            }
          },
          null
        );
      },
       GetAuth() {
        this.apipost('ViittoCommission_get_CreateViittoCommissionAuthService', {}, res => {
          if (res.data.resultCode == 1) {
            this.IsAuth = res.data.data;
          } else {
            this.$message.error(res.data.message);
          }
        }, err => {})
      },
      //生成票务提成报表
      CreateAirticketCommission() {
        this.loading=true;
        this.isDisable=true;
        this.apipost(
          "ViittoCommission_post_CreateViittoCommissionService", {},
          res => {
            this.loading=false;
            this.isDisable=false;
            if (res.data.resultCode == 1) {
              this.getList();
              this.Success(this.$t('objFill.v101.administrative.baobiaosccg'))
            } else {
              this.Error(res.data.message);
            }
          },
          null
        );
      }
    }
  }
</script>