<style>
.saleRnkBefore .see_btn{
  color: #E95252;
  cursor: pointer;
}
.saleRnkBefore td,.saleRnkBefore th{
  padding-left: 20px;
  padding-right: 20px;
  text-align: left;
}
._saleRnk.el-dialog--center .el-dialog__body{
  padding: 0;
  max-height: 800px;
}


</style>
<template>
  <div class="saleRnkBefore">
    <div class="query-box">
      <ul>
        <li v-if="msg.Conditon==1">
          <span>
            <em>{{$t('sm.dateChoose')}}</em>
            <el-date-picker
              class="h34"
              @change="timeAdd(1)"
              v-model="productionDate"
              type="daterange"
              value-format="yyyy-MM-dd"
              :range-separator="$t('restaurant.res_To')"
            ></el-date-picker>
          </span>
        </li>
        <li>
          <input
            type="button"
            class="hollowFixedBtn"
            :value="$t('pub.searchBtn')"
            @click="resetPageIndex(),getList()"
          >
        </li>
      </ul>
    </div>
    <div class="commonContent" v-loading="loading">
      <table class="singeRowTable" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <th width="80">{{$t('active.ad_xuhao')}}</th>
          <th width>{{$t('tips.qishu')}}</th>
          <th width="150">{{$t('system.table_operation')}}</th>
        </tr>
        <tr v-for="(item, index) in dataList">
          <td>{{(msg.pageIndex-1)*msg.pageSize + index+1}}</td>
          <td>{{item.StartDateStr}}-{{item.EndDateStr}}</td>
          <td>
            <span class="see_btn" @click="getDetai(item)">{{$t('fnc.chakan')}}</span>
          </td>
        </tr>
      </table>
      <div>
        <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>
      <div class="noData" v-show="noData">{{$t('system.content_noData')}}</div>
    </div>
    <el-dialog custom-class='w800 PingFangSC _saleRnk' :title="$t('sm.saleRank')" :visible.sync="saleRnkShow" center :before-close="closeChangeMachie">
      <saleRnk @closeChangeMachie="closeChangeMachie" :detail="detail"/>
    </el-dialog>
  </div>
</template>

<script>
import saleRnk from "./saleRnk";
export default {
  components: {
    saleRnk
  },
  data() {
    return {
      saleRnkShow: false,
      loading: false,
      productionDate: [],
      dataList: [],
      detail: {},
      currentPage: 1,
      total: 0,
      noData: true,
      msg: {
        pageSize: 15,
        pageIndex: 1
      }
    };
  },
  mounted() {
    this.getList()
  },
  methods: {
    getDetai: function(obj) {
      let msg = {
        StartDate: obj.StartDate
      }
      this.apipost(
        "orderank_post_GetDetails",
        msg,
        res => {
          if (res.data.resultCode == 1) {
            this.saleRnkShow = true;
            this.detail = res.data.data
            let arr = localStorage.saleRnkInfo ? JSON.parse(localStorage.saleRnkInfo) : []
            let rep = false
            for(let i = 0; i < arr.length; i++){
              if (arr[i] === (this.detail.StartDateMonth+this.detail.StartDateDay)) {
                rep = true
                return
              }
            }
            if (!rep) {
              arr.push(this.detail.StartDateMonth+this.detail.StartDateDay)
            }
            localStorage.saleRnkInfo = JSON.stringify(arr)
          }
        },
        err => {}
      );
    },
    handleCurrentChange(val) { //翻页
      this.msg.pageIndex = val;
      this.getList();
    },
    closeChangeMachie(done) { //弹出框关闭 
      // done();
      this.saleRnkShow= false
    },
    getList() {
      //获取现有线路列表
      this.loading = true;
      this.apipost(
        "orderank_post_GetPageList",
        this.msg,
        res => {
          this.loading = false;
          if (res.data.resultCode == 1) {
            this.dataList = res.data.data.pageData;
            this.total = res.data.data.count;
            this.noData = !this.total > 0;
          } else {
            this.loading = false;
          }
        },
        err => {}
      );
    },
    resetPageIndex() {
      // 重置页码
      this.msg.pageIndex = 1;
      this.currentPage = 1;
    }
  }
};
</script>
