
<template>
  <div class="Feedback">
      <div class="query-box">
        <ul>
          <li>
            <span>
              <em>团号</em>
              <el-input v-model="msg.TCNUM"></el-input>
            </span>
          </li>
          <li>
            <span>
              <em>线路</em>
            </span>
            <el-select filterable v-model="obj.LineID" value-key="LineID"  @change="getLineTeamList">
              <el-option label="不限" :value='{LineName:"不限",LineID:0}'></el-option>
              <el-option v-for="item in LineList" :label='item.LineName' :value='item' :key='item.LineID'></el-option>
            </el-select>
          </li>
          <li>
            <span>
              <em>系列</em>
            </span>
            <el-select filterable v-model="obj.LineteamId" value-key="LtID" @change="getLineLtID">
              <el-option label="不限" :value='{LtName:"不限",LtID:0}'></el-option>
                <el-option v-for="item in LineTeamList" :label='item.LtName' :value='item' :key='item.LtID'>
                </el-option>
            </el-select>
          </li>
          <li>
            <span>
              <em>只看有评分</em>
            </span>
              <el-select filterable  class='multiple_input'  v-model='msg.isScore' :placeholder="$t('pub.pleaseSel')">
                  <el-option label="不限" :value="0"></el-option>
                  <el-option label="是" :value="1"></el-option>
                  <el-option label="否" :value="-1"></el-option>
              </el-select>
          </li>
          <li>
              <span>
              <em>发团时间</em>
            </span>
              <el-date-picker
                value-format="yyyy-MM-dd"
              :picker-options="pickerDisabled"
                  size="small"
                  v-model="dateList"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
                  </el-date-picker>
          </li>
          <li>
            <input
              type="button"
              class="hollowFixedBtn"
              value="查询"
              @click="resetPageIndex(),getList()"
            >
            <input type="button" @click="goUrl" class="normalBtn" value="旅客反馈分析"/>
          </li>
        </ul>
      </div>
    <table class="singeRowTable" border="0" cellspacing="0" cellpadding="0" v-loading="loading">
      <tr>
        <th>发团日期</th>
        <th>团号</th>
        <th>未填写人数</th>
        <th>整体评分</th>
        <th v-for="(item,i) in fields" :key="i">{{item}}</th>
        <th>操作</th>
      </tr>
      <tr v-for="(item,i) in dataList" :key="i">
        <td>{{item.start}}</td>
        <td>{{item.tCNUM}}</td>
        <td>{{item.number}}</td>
        <td>
          <span v-if="fields.length>0">
            <span v-if="item.sumScore/fields.length>3.5">{{(item.sumScore/fields.length).toFixed(1)}}</span>
            <span v-else style="color:red">{{(item.sumScore/fields.length).toFixed(1)}}</span>
            </span>
          <span v-else>
            <span v-if="item.sumScore>3.5">{{item.sumScore}}</span>
            <span v-else style="color:red">{{item.sumScore}}</span>
            
            </span>
          
        </td>
        <td  v-for="(c,childIndex) in fields" :key="childIndex">
          
          <span v-if="item[c]&&item[c]>3.5">{{item[c]?item[c]:0}}</span>
            <span v-else style="color:red">{{item[c]?item[c]:0}}</span>
          </td>
        
        <td>
          <span style="cursor:pointer" @click="chaKan(item)">明细</span>
        </td>
      </tr>
      <tr v-if="dataList.length==0">
        <td colspan="12" align="center">暂无数据</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 {
    name: 'Feedback',
    data (){
        return{
            obj:{},
            dataList:[],
            loading:false,
            msg:{
                pageSize:10,
                pageIndex:1,
                TCNUM: '',
                lineID:0,
                LineteamId:0,
                reStartDate:'',
                reEndDate:'',
                isScore:0,
                lineName:"不限",
                LineteamName:"不限",
            },
            total:0,
            currentPage:1,
            dateList:[],
            LineList:[],
            LineTeamList:[],
            fields:[],
            pickerDisabled:  {  //验证时间范围
            disabledDate:(time)=>{
              let _now = Date.now();
              return time.getTime() > _now ;
            }
          }
        }
    },
    created(){
      this.dateList[0]=moment().subtract(6, "month").format("YYYY-MM-DD");
      this.dateList[1]=moment().format("YYYY-MM-DD");
      this.getTitle();
    },
    mounted(){
       this.getLineList();
       this.getList();
    },
    methods:{
      chaKan(item){        
     	  this.$router.push({ name:'investigationList',query:{"TCID":item.tcid,blank: 'y'} })
      },
      goUrl(){
     	   this.$router.push({ name:'FeedbackChart',query:{"msg":JSON.stringify(this.msg),blank: 'y'} })
    	},
      getLineList() {
        this.apipost("line_post_GetAllList_V2", {LineDirection: 0}, res => {
          if (res.data.resultCode == 1) {
            this.LineList = res.data.data;
          }
        });
      },
      getLineLtID(val){
        this.msg.LineteamId=val.LtID;
        this.msg.LineteamName=val.LtName;
      },
      
      //获取系列列表
      getLineTeamList(val) { 
        let lineId=val.LineID;
        this.msg.lineID=val.LineID;
        this.msg.lineName=val.LineName;
        this.LineTeamList = []
        this.apipost("team_post_GetList", {
          lineID: lineId,
          isTOOP: 1
        }, res => {
          if (res.data.resultCode == 1) {
            this.LineTeamList = res.data.data;
          }
        });
      },
      getTitle() {
          this.apiJavaPost(
            "/api/erp/survey/getSurveyTitleList",
            {},
            res => {
              if (res.data.resultCode === 1) {
                res.data.data.forEach(item=>{
                  this.fields.push(item.title)

                })
              } else {
                this.Error(res.data.message);
              }
            },
            null
          );
      },

        getList(){
            if(this.dateList && this.dateList.length>0){
                this.msg.reStartDate=this.dateList[0];
                this.msg.reEndDate=this.dateList[1];
                //计算相差多少天 day可以是second minute
                let m1=moment(this.msg.reStartDate)
                let m2=moment(this.msg.reEndDate)
                let year = m2.diff(m1, 'year');
                if(year>0){
                  this.Error("最多查询一年的数据！")
                  return;
                }
              }else{
                this.msg.reStartDate="";
                this.msg.reEndDate="";  
              }
            
            
            this.loading=true;
            this.apiJavaPost("/api/erp/survey//getSurveyList", this.msg, res => {
                this.loading = false;
                if (res.data.resultCode === 1) {
                let arrays=[];
                res.data.data.pageData.forEach(x => {
                    let isHave=false
                  if(x.tCID!=0 || x.tCID || x.tCID!=''){

                    if(arrays.length>0){
                        arrays.forEach(y=>{
                            if(y.tcid==x.tCID){
                                y[x.title]=x.scoreNum
                                y.sumScore+=x.scoreNum
                                isHave=true
                                return false
                            }
                        })
                    }                   
                        if(!isHave){
                        let obj={
                              tcid:x.tCID,
                              start:"",
                              sumScore:x.scoreNum,
                              tCNUM:x.tCNUM,
                              number: x.number ? x.number : 0
                          }
                          if(x.startDate){
                            obj.start=x.startDate.split('T')[0]
                          }
                          
                          obj[x.title]=x.scoreNum
                          arrays.push(obj)
                      }
                    }
                    
                    
                });
                this.dataList=arrays;
                this.total=res.data.data.count;
                } else {
                  this.Error(res.data.message)
                }
            }, null);
        },



        handleCurrentChange(val) {
            this.msg.pageIndex = val;
            this.getList();
        },
        resetPageIndex() {
            this.msg.pageIndex = 1;
            this.currentPage = 1;
        },
    }	
}
		
</script>
<style scoped>
.Feedback ul>li{
    display: inline-block;
    font-size: 12px;
    color: #666;
    margin: 20px 30px 0px 0;
}
.Feedback .singeRowTable{
    margin-top: 20px;
}
</style>
