<template>
  <div>     <!-- height="calc(100% - 40px)"-->
            <div v-if="itemName" style="padding-bottom:10px;text-align:center;color: #606266;">{{itemName}}</div>

 
            <el-table class="com-table" ref="multipleTable" :data="tableData"
                        tooltip-effect="dark" size="small" border style="width: 100%" v-loading="loading"
                        :span-method="rowSpanForInputFile">
      

            <!--
            <el-table-column  type="index"  label="" align="center" width="50px"/>
            -->
            <el-table-column  prop="idx" label="序号" align="center" width="50px"/>

            <el-table-column label="业务属性" align="center">
              <el-table-column  prop="busiType"    label="业务类型" align="center"/>
              <el-table-column  prop="productName" label="产品名称" align="center"/>
              <el-table-column  prop="parterName"  label="企业名称" align="center"/>
            </el-table-column>
            <!--专家评审-->
            <template v-if="step=='4'">
                <el-table-column label="产品打分评审" align="center">
                      <el-table-column label="内容资源" align="center">
                        <el-table-column label="内容品质(15%)" align="center">
                              <template slot-scope="scope">
                                <el-input v-model="scope.row.s1"  size="small" max="20" @blur="setScore(scope.row.s1,'s1',scope.row)" class="expt_input"/>
                              </template>
                        </el-table-column>
                        <el-table-column label="内容授权(5%)" align="center">
                              <template slot-scope="scope">
                                <el-select v-model="scope.row.s2" @change="(value)=>{setScore(value,'s2',scope.row)}" placeholder="请选择" size="small">
                                  <el-option
                                    v-for="item in options"
                                    :key="item.value" 
                                    :label="item.label"  
                                    :value="item.value">
                                  </el-option>
                                </el-select>
                              </template>
                        </el-table-column>
                        <el-table-column label="用户认知(20%)" align="center">
                              <template slot-scope="scope">
                                <el-input v-model="scope.row.s3"  size="small" @blur="setScore(scope.row.s3,'s3',scope.row)" class="expt_input"/>
                              </template>
                        </el-table-column>
                      </el-table-column>
                        
                        <el-table-column label="创新性(20%)" align="center">
                            <template slot-scope="scope">
                              <el-input v-model="scope.row.s4"  size="small" @blur="setScore(scope.row.s4,'s4',scope.row)" class="expt_input"/>
                            </template> 
                        </el-table-column>
                        <el-table-column label="用户体验(20%)" align="center">
                            <template slot-scope="scope">
                              <el-input v-model="scope.row.s5"  size="small" @blur="setScore(scope.row.s5,'s5',scope.row)" class="expt_input"/>
                            </template> 
                        </el-table-column>
                        <el-table-column label="资费(10%)" align="center">
                              <template slot-scope="scope">
                                <el-select v-model="scope.row.s6" @change="(value)=>{setScore(value,'s6',scope.row)}" placeholder="请选择" size="small">
                                  <el-option
                                    v-for="item in options1"
                                    :key="item.value" 
                                    :label="item.label"  
                                    :value="item.value">
                                  </el-option>
                                </el-select>
                              </template>
                        </el-table-column>
                        <el-table-column label="信息安全(10%)" align="center">
                            <template slot-scope="scope">
                              <el-input v-model="scope.row.s7"  size="small" @blur="setScore(scope.row.s7,'s7',scope.row)" class="expt_input"/>
                            </template>
                        </el-table-column>
                </el-table-column>

                <el-table-column label="合计(100%)" align="center">
                          <template slot-scope="scope">
                            <el-input v-model="scope.row.s8"  :disabled="true" size="small" class="expt_input"/>
                          </template> 
                </el-table-column>
                
                <el-table-column label="备注" align="center" width="120px">
                          <template slot-scope="scope">
                            <el-input v-model="scope.row.note"  @blur="setScore(scope.row.note,'note',scope.row)" size="small" class="expt_input_note"/>
                          </template> 
                </el-table-column>
            </template> 
            <!--评审汇总,室主任初审,部门领导复审,会议结果录入-->
            <template v-if="step=='5' || step=='6' || step=='7'">
                <el-table-column label="产品打分评审" align="center">
                      <el-table-column label="内容资源" align="center">
                        <el-table-column label="内容品质(15%)" prop="s1" align="center"></el-table-column>
                        <el-table-column label="内容授权(5%)"  prop="s2" align="center"></el-table-column>
                        <el-table-column label="用户认知(20%)" prop="s3" align="center"></el-table-column>
                      </el-table-column>
                        
                        <el-table-column label="创新性(20%)" prop="s4" align="center"></el-table-column>
                        <el-table-column label="用户体验(20%)" prop="s5" align="center"></el-table-column>
                        <el-table-column label="资费(10%)" prop="s6" align="center"></el-table-column>
                        <el-table-column label="信息安全(10%)" prop="s7" align="center"></el-table-column>
                </el-table-column>

                <el-table-column label="合计(100%)" prop="s8" align="center">
                </el-table-column>

                
                <el-table-column label="评审专家" prop="expertLoginName" align="center">
                </el-table-column>

                <el-table-column label="备注" prop="note" align="center" >
                </el-table-column>

                                
                <el-table-column label="总平均分" prop="avgAllScore" align="center">
                </el-table-column>
            </template> 
                
            <!--会议结果录入-->
            <template v-if="step=='8'">
                <el-table-column label="合计(100%)"  prop="s8" align="center"/>
                <el-table-column label="会议记录"  align="center" >
                  <template slot-scope="scope">
                      <div>
                          
                          <el-upload
                            ref="inputFileUpload"
                            class="avatar-uploader"
                            action="string"
                            :show-file-list="true"
                            :on-success="handleAvatarSuccess"
                            :before-upload="beforeAvatarUpload"
                            :file-list="inputFielList"
                            >
                            <i class="el-icon-plus avatar-uploader-icon"></i>
                          </el-upload>
                      </div>
                  </template>
                </el-table-column>
            </template>

            <template v-if="step=='9' || step=='10' || step=='11' || step=='12' || step=='13'  || step=='14'  || step=='15'">
                <el-table-column label="合计(100%)"  prop="s8" align="center"/>
                <el-table-column label="会议记录"  align="center">
                    <template slot-scope="scope">
                      <down :files="scope.row.inputFile"></down>   
                  </template>
                </el-table-column>
                <template v-if="step=='13'">
                  <el-table-column label="附件"  align="center"  prop="">
                      <template slot-scope="scope">
                          <div>
                              <myUpload ref="publish" type="publish" :itemId="dataId" :idx="scope.row.idx" :fList="scope.row.publishFile"   @handleResult="handlePublishUpload"></myUpload>
                          </div>
                      </template>
                   </el-table-column>
                   
                   <el-table-column label="2月内上线"  align="center"  prop="">
                        <template slot-scope="scope">
                          <el-select v-model="scope.row.publishInRule" @change="(value)=>{setPublishInRule(value,'publishInRule',scope.row)}" placeholder="请选择" size="small">
                            <el-option
                              v-for="item in options2"
                              :key="item.value" 
                              :label="item.label"  
                              :value="item.value">
                            </el-option>
                          </el-select>
                        </template>>
                   </el-table-column>

                   <el-table-column label="是否已上线"  align="center"  prop="">
                        <template slot-scope="scope">
                          <el-select v-model="scope.row.isPublish" @change="(value)=>{setPublish(value,'isPublish',scope.row)}" placeholder="请选择" size="small">
                            <el-option
                              v-for="item in options2"
                              :key="item.value" 
                              :label="item.label"  
                              :value="item.value">
                            </el-option>
                          </el-select>
                        </template>
                   </el-table-column>
                </template>


                 <template v-if="step=='14'">
                   <!--
                   <el-table-column label="附件"  align="center"  prop="">
                        <template slot-scope="scope">
                          <div v-html="filesToUrl(scope.row.publishFile)" />
                        </template>
                   </el-table-column>
                   -->
                   
                   <el-table-column label="2月内上线"  align="center"  prop="">
                        <template slot-scope="scope">
                          {{parserYesNo(scope.row.publishInRule)}}
                        </template>>
                   </el-table-column>

                   <el-table-column label="是否已上线"  align="center"  prop="">
                        <template slot-scope="scope">
                          {{parserYesNo(scope.row.isPublish)}}
                        </template>
                   </el-table-column>
                 </template>

                <!--publish2-->
                <template v-if="step=='15'">
                  <el-table-column label="附件"  align="center"  prop="">
                        <template slot-scope="scope">
                        <div>
                            <myUpload ref="publish" type="publish" :itemId="dataId" :idx=scope.row.idx  @handleResult="handlePublishUpload"></myUpload>
                        </div>
                        </template>
                  </el-table-column>
                  
                  <el-table-column label="2月内上线"  align="center"  prop="">
                      <template slot-scope="scope">
                        {{parserYesNo(scope.row.publishInRule)}}
                      </template>>
                  </el-table-column>

                  <el-table-column label="是否已上线"  align="center"  prop="">
                      <template slot-scope="scope">
                          <el-select v-model="scope.row.isPublish" @change="(value)=>{setPublish(value,'isPublish',scope.row)}" placeholder="请选择" size="small">
                            <el-option
                              v-for="item in options2"
                              :key="item.value" 
                              :label="item.label"  
                              :value="item.value">
                            </el-option>
                          </el-select>
                      </template>
                  </el-table-column>
                </template>
            </template>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                      <el-button type="text" size="small" @click="viewItem(scope.row.itemId,scope.row.idx)">查看</el-button>
                    </template>
                </el-table-column>
          </el-table>
                
                

          <div style="margin-top:20px;" v-if="extFiles.length>0" >
            <div class="el-label"><i class="el-icon-paperclip"></i>附件列表</div>
            <div class="el-line"></div>
            <el-table class="com-table" :show-header="false" ref="multipleTable"  :data="extFiles"
              tooltip-effect="dark" size="small" border style="width: 100%" v-loading="loading">
                <el-table-column align="left" prop="l" width="180px"></el-table-column>
                <el-table-column align="left" prop="n"></el-table-column>
                <el-table-column align="center" prop="u" width="140px"></el-table-column>
                <el-table-column align="left" width="300px">
                      <template slot-scope="scope">
                          <down :files="scope.row.f"></down>   
                       </template>
                </el-table-column>
            </el-table>
          </div>

            <div style="margin-top:20px;" v-if="dataId!==''">
              <div class="el-label"><i class="el-icon-collection-tag"></i>审批轨迹</div>
              <div class="el-line"></div>
              <audit :itemId="dataId"></audit>
            </div>




            <idxDialog :dialogVisible="dialogVisible" :itemId="dataId" :idx="curIdx" @closeWin="closeWin"></idxDialog>
  </div>
</template>

<script>
import {strToHerf} from "@/utils/tv.js"
import myUpload from "@/components/uploadNew.vue";
import audit from "./audit.vue";
import idxDialog from "./idxDialog.vue";
import down from "@/components/uploadNewDown.vue";

export default {
  components:{myUpload,audit,idxDialog,down},
  props: {
    woNo:   { required: false,type: String},
    itemId: { required: false,type: String},
    step:{ required: true, type: String},
    expertLogin:{required: false, type: String}
  },

  data(){
    return{
      tableData:[],
      loading:false,
      itemName:'',
      dataId:'',
      options:[{value:'1',label:'1'},{value:'3',label:'3'},{value:'5',label:'5'}],
      options1:[{value:'0',label:'0'},{value:'5',label:'5'},{value:'10',label:'10'}],
      options2:[{value:'1',label:'是'},{value:'0',label:'否'}],
      inputFielList:[],
      publishFielList:[],
      fileList:[],
      extFiles:[],
      dialogVisible:false,
      curIdx:''
    }
  },

  methods:{
    closeWin(){
      this.dialogVisible = false;
    },
    parserYesNo(v){
      if(v==='0'){return "否"}
      else if(v==='1'){return "是"}
    },
    handlePublishUpload(v){
      //this.fileList = v.files
      let info = {}
      info.itemId = this.dataId
      info.idx = v.body.idx
      info.publishFile = JSON.stringify(v.files)
      //POST请求
      this.$http({
      url: "/market/tvImport/editExpert",
      method: "post",
      headers: {"Content-Type": "application/json"},
      data:info
      }).then((res) => {
        if(res.data.result!==0){
          this.$message({ showClose: true, message: '操作异常',type: 'error'});
        }
      });
    },
    viewItem(itemId,idx){
      this.curIdx = idx;
      this.dialogVisible = true;
    },
    filesToUrl(files){
      return strToHerf(files)
    },
    setScore(v,k,row){
      if(null==v || v==='' || v ==='null'){
        v = 0
        if(k=='s1'){row.s1 = 0}
        if(k=='s2'){row.s2 = 0}
        if(k=='s3'){row.s3 = 0}
        if(k=='s4'){row.s4 = 0}
        if(k=='s5'){row.s5 = 0}
        if(k=='s6'){row.s6 = 0}
        if(k=='s7'){row.s7 = 0}
      }else{
        
        if(k=='s1'){ if(v>15){this.$message({ message: '内容品质分数不能超过15分',type: 'warning' }); row.s1=15;  v=15;}}
        if(k=='s3'){ if(v>20){this.$message({ message: '用户认知分数不能超过20分',type: 'warning' }); row.s3=20;  v=20;}}
        if(k=='s4'){ if(v>20){this.$message({ message: '创新性分数不能超过20分',type: 'warning' }); row.s4=20;    v=20;}}
        if(k=='s5'){ if(v>20){this.$message({ message: '用户体验分数不能超过20分',type: 'warning' }); row.s5=20;  v=20;}}
        if(k=='s7'){ if(v>10){this.$message({ message: '用户体验分数不能超过10分',type: 'warning' }); row.s7=10;  v=10;}}
        
      }
      this.resultScore(row)
      this.setValue(v,k,row)
    },

    setValue(v,k,row){
        let url = "/market/tvImport/expert/set/score";
        if(k==="isPublish"){
          url = "/market/tvImport/expert/set/publish";
        }else if(k==='publishInRule'){
          url = "/market/tvImport/expert/set/publishInRule";
        }
        this.$http({
        url: url,
        method: "post",
        headers: {"Content-Type": "application/json"},
        data: {"itemId":row.itemId,"idx":row.idx,"v":v,"k":k}
      }).then((res) => {
        if(res.data.result!=0){
          this.$message({ showClose: true, message: res.data.desc,type: 'error'});
        }
      });
    }
    ,
    resultScore(row){
        row.s8 = this.pValue(row.s1) +this.pValue(row.s2) + this.pValue(row.s3) + 
                 this.pValue(row.s4) +this.pValue(row.s5) + this.pValue(row.s6) + this.pValue(row.s7)
    }
    ,
    pValue(v){
      let result = 0
      if(null==v || v==='' || v ==='null'){
        return result
      }else{
        result = parseInt(v)
      }
      return result;
    }
    ,
    setPublish(v,k,row){
        this.setValue(v,k,row)
    },
    setPublishInRule(v,k,row){
        this.setValue(v,k,row)
    },
    loadData(){
      let params = {}
      params.itemId = this.itemId
      params.woNo = this.woNo
      params.expertLogin = this.expertLogin

      if(this.step==='2'){this.isPass=""}
      let url = "/market/tvImport/queryExpert";

      //url
      if(this.step==='8' || this.step === '9'   || this.step === '10' 
                         || this.step === '11'  || this.step === '12' 
                         || this.step === '13'  || this.step === '14'  || this.step === '15'){
        params.isPass='1'
        url = "/market/tvImport/queryImport";
        params.s8="85"
      }



      let orderBy = "";
      if(this.step==='5' || this.step==='6' || this.step==='7'){
        orderBy = "a.item_id,a.idx";
        params.s8="85"
        params.orderBy = orderBy
      }

      if(this.step==='14' || this.step==='15'){
          params.publishInRule = "0"//未按时发布
      }

      this.$http({
        url: url,
        method: "post",
        headers: {"Content-Type": "application/json"},
        data: params
      }).then((res) => {
         if(res.data.result==0){
            this.tableData = res.data.body 
            if(null!=this.tableData && this.tableData.length>0){
              let iData = this.tableData[0]
              this.itemName = iData.itemName;
              this.dataId = iData.itemId;
              this.callBack(this.dataId)

              if(url=="/market/tvImport/queryImport"){
                /*
                if(iData.inputFile!=undefined){
                  let extFile = {"f":iData.inputFile,'n':iData.inputNote,'l':"会议结果录入",'u':''}
                  this.extFiles.push(extFile)
                }*/
                
                if(iData.marketFile!=undefined){
                   let extFile = {"f":iData.marketFile,'n':iData.marketNote,'l':'市场决策委员会审核','u':''}
                   this.extFiles.push(extFile)
                }
                if(iData.sendFile!=undefined){
                  //
                  let units = JSON.parse(iData.receiveUnit);
                  let unit = "";
                  for(var i = 0 ;i <units.length;i++){
                    unit = unit + units[i]+" ,";
                  }
                  unit = unit.substring(0,unit.length -1)
                  unit = "收函单位 : "+unit;

                  let extFile = {"f":iData.sendFile,'n':iData.sendNote,'l':'专业公司发函','u':unit}
                  this.extFiles.push(extFile)
                }
                if(iData.provinceFile!=undefined){
                  let extFile = {"f":iData.provinceFile,'n':iData.provinceNote,'l':'省内引入','u':''}
                  this.extFiles.push(extFile)
                }
              }
            }

         }else{
           this.$message({ showClose: true, message: '系统异常',type: 'error'});
         }
      });
    },
    callBack(dataId){
        this.$emit("callBack",dataId);
    },
    beforeAvatarUpload(file){
      let query = new FormData();
      let type  = ""
      query.append("file", file);
      query.append("itemId", this.dataId);
      //
      if(this.step==='8'){
        type = "inputFile";
      }
      if(this.step==='14'){
          type = "publishFile";
      }
      query.append("type", type);
      query.append("idx", "");

    //
      this.$http({
          url: "/market/tvImport/upload",
          method: "post",
          headers: {"Content-Type": "application/json",},
          data: query
      }).then((res) => {
          if(res.data.result===0){
              let file = {"name":res.data.body.realName,"url":res.data.body.path + "/" + res.data.body.fileName}
              if(this.step==='8'){
                this.inputFielList.push(file)
              }else if(this.step==='14'){
                this.publishFielList.push(file)
              }
          }else{
            this.$message({ message: res.data.desc,type: 'error'});
          }
      });
    },
    handleAvatarSuccess(){

    }
    ,
    getInputFileUploadList(){
      return this.inputFielList;
    }
    ,
    getPuhlishFileList(){
      console.log(this.$refs)
      //return this.publishFielList;
    },
    rowSpanForInputFile({ row, column, rowIndex, columnIndex }) {  
        //
        if(this.step=='5' || this.step=='6' || this.step=='7'){
              if (columnIndex === 14 || columnIndex === 15 || columnIndex === 0 || columnIndex===1 || columnIndex===2 || columnIndex===3) {
                if ((rowIndex % row.expertCount) ===0) {
                return {
                  rowspan: row.expertCount,
                  colspan: 1
                };
              }else {
                return {
                  rowspan: 0,
                  colspan: 0
                };
              }
            }
        }
        //
        else if(this.step=='8' || this.step=='9'  || this.step=='10' 
                          || this.step=='11' || this.step=='12' 
                          ){
          if (columnIndex === 6 || columnIndex == 5) {
            if (rowIndex === 0) {
            return {
              rowspan: this.tableData.length,
              colspan: 1
            };
          } else {
            return {
              rowspan: 0,
              colspan: 0
            };
          }
        }
      }else if(this.step=='14' || this.step=='13'){
        if (columnIndex == 5) {
                if (rowIndex === 0) {
                return {
                  rowspan: this.tableData.length,
                  colspan: 1
                };
            } else {
              return {
                rowspan: 0,
                colspan: 0
              };
            }
        }
      }
    },
  },
  mounted(){
    this.itemId = this.$route.query.itemId
    this.woNo = this.$route.query.woNo
    this.loadData()
  }
}
</script>

<style>
.expt_input{width:40px;text-align: center;padding:0px;}
.expt_input_note{width:80px;text-align: center;padding:0px;}
.el-input__inner{padding:0 0px;}
.el-label{
  color: #606266;
  border-bottom:1px dotted #bfc1c5;
  padding-bottom:5px;
}
.el-line{
  margin: 0px 0px 20px 0px;
}
</style>
