<style>
.user_time_picker .el-date-editor--date > .el-input__inner {
  padding: 0 10px;
  font-size: 13px;
}
.user_time_picker .el-date-editor--date > span.el-input__prefix {
  display: none;
}
.user_time_picker .el-date-editor--date > span.el-input__suffix {
  top: -4px;
  right: 2px;
}
.zidingyiFz i {
  font-size: 14px !important;
}
</style>
<template>
  <div class="flexOne">
    <div class="query-box">
      <ul class="user_time_picker">
        <li>
          <span
            ><em>{{ $t("system.table_company") }}</em
            ><el-select class="w180"
              filterable
              v-model="msg.RB_Branch_Id"
              @change="linkageDepartment()"
            >
              <el-option :label="$t('pub.unlimitedSel')" :value="-1"></el-option>
              <el-option
                v-for="item in companyList"
                :label="item.BName"
                :value="item.Id"
                :key="item.Id"
              >
              </el-option>
            </el-select>
          </span>
        </li>
        <li>
          <span
            ><em>{{ $t("admin.admin_Department") }}</em
            ><el-select class="w180"
              filterable
              v-model="msg.DepartmentId"
              @change="linkagePost()"
            >
              <el-option :label="$t('pub.unlimitedSel')" value="0"></el-option>
              <el-option
                v-for="item in departMentList"
                :label="item.DepartmentName"
                :value="item.DepartmentID"
                :key="item.DepartmentID"
              >
              </el-option>
            </el-select>
          </span>
        </li>
        <li>
          <span
            ><em>发布人</em
            ><el-select class="w180" filterable v-model="msg.CreateBy">
              <el-option :label="$t('pub.unlimitedSel')" value="0"></el-option>
              <el-option v-for='item in employeeList'
                    :label='item.name'
                    :value='item.empId'
                    :key='item.empId'>
                </el-option>
            </el-select>
          </span>
        </li>
        <li>
          <span
            ><em>{{$t('salesModule.Time')}}</em>
            <el-date-picker
            v-model="dateList"
            type="daterange"
            :range-separator="$t('OrderList.zhi')"
            value-format="yyyy-MM-dd"
            :start-placeholder="$t('OrderList.star')"
            :end-placeholder="$t('OrderList.end')">
            </el-date-picker>
          </span>
        </li>

        <li>
          <input
            type="button"
            class="hollowFixedBtn"
            :value="$t('pub.searchBtn')"
            @click="resetPageIndex(), getList()"
          />

        </li>
      </ul>
    </div>
    <div class="clearfix"></div>

    <table class="singeRowTable" border="0" cellspacing="0" cellpadding="0" v-loading="loading">
      <tr>
        <th>员工编号</th>
        <th>公司</th>
        <th>部门</th>
        <th>{{$t('system.query_name')}}</th>
        <th>发布数量</th>
        <!-- <th>开始时间</th>
        <th>结束时间</th> -->
      </tr>
      <tr v-for="(item, index) in DataList" :key="index" >
        <td>{{ item.EmployeeId }}</td>
        <td>{{ item.BranchName }}</td>
        <td>{{ item.DepartmentName }}</td>
        <td>{{ item.EmName }}</td>
        <td>
            <span style="text-decoration: underline;" @click="goUrl(item)">{{ item.Number }}</span>
        </td>
        <!-- <td>{{ item.StartTime | YMD}}</td>
        <td>{{ item.EndTime | YMD}}</td> -->

      </tr>
      <tr v-show="DataList.length==0">
          <td colspan="10" align="center">{{$t('system.content_noData')}}</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>
import moment from 'moment'
export default {
  data() {
    return {
      loading: false,
      isleaveBtn: false,
      total: 0,
      pageSize: "",
      currentPage: 1,
      dateList:[],
      //请求
      msg: {
        pageIndex: 1,
        pageSize: 15,
        CreateBy:'',
        StartTime:'',
        EndTime:'',
        RB_Branch_Id:-1,
        DepartmentId:'',
      },


      getGroupMsg: {
        Status: "0",
        GroupName: "",
        Domain: "",
        Versions_Id: ""
      },
      getCompanyMsg: {
        RB_Group_Id: "0",
        Status: "0"
      },
      getDepartmentMsg: {
        RB_Group_Id: "0",
        RB_Branch_Id: "-1",
        Status: "0"
      },
      companyList:[],
      departMentList:[],
      employeeMsg: {
            RB_Group_id:'0',
            RB_Branch_id:'-1',
            departmentId:'0',
            IsLeave:'-1',
        },
        DataList:[],
        employeeList:[],

    };
  },
    mounted() {
        let userInfo = this.getLocalStorage();
        this.getCompanyMsg.RB_Group_Id = userInfo.RB_Group_id; //集团ID
        // this.dateList[0]=moment().format("YYYY-MM-DD");
        // this.dateList[1]=moment().format("YYYY-MM-DD");
        let date=moment().format("YYYY-MM-DD");
        this.dateList=[];
        this.dateList.push(date)
        this.dateList.push(date)
        this.getList();
        this.getCompany();
        this.getDerpartMent();
        this.getEmployee();
    },
    filters:{
        YMD(date){
            if(date!=''){
                return moment(date).format("YYYY-MM-DD");
            }else{
                return date;
            }

        }
    },

  methods: {
      goUrl(item) {
        let StartTime='';
        let EndTime='';
        if(item.StartTime!=''){
           StartTime= moment(item.StartTime).format("YYYY-MM-DD");
        }
        if(item.EndTime!=''){
           EndTime= moment(item.EndTime).format("YYYY-MM-DD");
        }
        this.$router.push({
            name: 'PublishvideoList',
            query: {
                CreateBy: item.EmployeeId,
                StartTime:StartTime,
                EndTime:EndTime,
                blank: "y",
                tab: "视频发布列表"
            }
      });
    },
    linkagePost() {
      //联动岗位
      this.msg.CreateBy='0';
      this.employeeMsg.RB_Branch_id = this.msg.RB_Branch_Id;
      this.employeeMsg.departmentId = this.msg.DepartmentId;
      this.getEmployee();
    },
    getEmployee() {
        this.apipost('app_get_company_employee', this.employeeMsg, res => {
            if(res.data.resultCode == 1) {
                this.employeeList = res.data.data;
            }
        }, err => {})
    },
    getCompany() {
      this.apipost(
        "admin_get_BranchGetList",
        this.getCompanyMsg,
        res => {
          if (res.data.resultCode == 1) {
              this.companyList = res.data.data;
          } else {
          }
        },
        err => {}
      );
    },
    getDerpartMent() {
      //获取部门
      this.apipost(
        "admin_get_DepartmentGetList",
        this.getDepartmentMsg,
        res => {
          if (res.data.resultCode == 1) {
              this.departMentList = res.data.data;
          } else {
          }
        },
        err => {}
      );
    },

    getList() {
      //获取数据
      this.loading = true;
      if(this.dateList && this.dateList.length>0){
          this.msg.StartTime=this.dateList[0];
          this.msg.EndTime=this.dateList[1];
      }else{
          this.msg.StartTime='';
          this.msg.EndTime='';
      }
        this.apipost(
          "Video_get_GetVideoStatisticsPublishPageList",
          this.msg,
          res => {
              this.loading = false;
            if (res.data.resultCode == 1) {

              this.DataList = res.data.data.pageData;
              this.total = res.data.data.count;
            } else {
            }
          },
          err => {}
        );
    },

    linkageDepartment() {
      //联动部门
      this.msg.DepartmentId = "0";
      this.msg.CreateBy='0';
      this.getDepartmentMsg.RB_Branch_Id = this.msg.RB_Branch_Id;
      this.getDerpartMent();
    },

    handleCurrentChange(val) {
      this.msg.pageIndex = val;
      this.getList();
    },
    resetPageIndex() {
      this.msg.pageIndex = 1;
      this.currentPage = 1;
    },


  }
};
</script>
