<style>
.happyMoney .tit {
  margin: 20px 0;
}
.happyMoney .tit .name {
  width: 284px;
  height: 28px;
  background: #e3e3e3;
  line-height: 28px;
  font-size: 14px;
  font-weight: bold;
  color: rgba(51, 51, 51, 1);
  text-align: center;
}
.happyMoney .content-box {
  background-color: white;
  padding: 30px 20px;
}
.happyMoney .content-box-tit {
  font-size: 14px;
}
.happyMoney .content-box-tit p {
  margin-bottom: 10px;
}
.happyMoney .content-box-tit p .blod {
  font-weight: 800;
}
.happyMoney .content-box-tit p .red {
  color: #e95252;
}
.happyMoney table tr td input {
  border: none;
}
.happyMoney ._addUpload_box {
  display: block;
  margin-top: 15px;
}
.happyMoney ._addUpload_box img {
  width: 100%;
}
.happyMoney ._addUpload_box > div {
  float: left;
  width: 138px;
  height: 92px;
  border: 1px dashed rgba(210, 210, 210, 1);
  border-radius: 2px;
  cursor: pointer;
  margin-bottom: 10px;
  padding: 5px;
  margin-right: 10px;
  position: relative;
}
.happyMoney ._addUpload_box > div:hover {
  background-color: #f5f5f5;
}
.happyMoney ._addFile_name {
  padding-left: 15px;
  max-width: 450px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.happyMoney ._addUpload_box .icon-guanbi1 {
  font-size: 12px;
  color: white;
  display: inline-block;
  margin-left: 15px;
  position: absolute;
  right: -6px;
  top: -9px;
  background-color: #f56c6c;
  border-radius: 50%;
  height: 20px;
  width: 20px;
  text-align: center;
  line-height: 20px;
}
.happyMoney ._addUpload_box .icon-guanbi1:hover {
  font-size: 12px;
  color: #c94052;
}
.happyMoney ._addUpload_box .icon-excel,
.happyMoney ._addUpload_box .icon-pdf {
  text-align: center;
  font-size: 38px;
  color: green;
  line-height: 75px;
}
.happyMoney ._show_img_box {
  position: fixed;
  background: rgba(0, 0, 0, 0.6);
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 999;
  text-align: center;
}
.happyMoney ._pic_upload .el-upload-dragger {
  font-size: 28px;
  color: #8c939d;
  width: 126px;
  height: 80px;
  line-height: 41px;
  text-align: center;
}
.happyMoney ._pic_upload .el-upload--text.el-upload .el-upload__text {
  font-size: 14px;
}
.happyMoney .avatar-uploader-icon {
  height: 30px;
}
.happyMoney .normalBtn{
  margin-top: 20px;
}
.happyMoney .normalBtn2{
  background-color: #a0a0a0;
}
.happyMoney .normalBtn2:hover{
  background-color: #a0a0a0;
  border-color: #a0a0a0;
}
</style>
<template>
  <div class="happyMoney" v-if="show">
    <div class="tit">
      <div class="name">{{dataList.model.AllianceName + dataList.model.EndYear}}年度大红包结算</div>
    </div>
    <el-row>
      <el-col :span="16">
        <div class="content-box">
          <div class="content-box-tit">
            <p>
              经系统统计本联盟在
              <span class="blod">{{dataList.model.StartYear + '-' + dataList.model.EndYear}}年</span>
              <span class="red">销售额为¥{{moneyFormat(dataList.model.TradeMoney)}}万</span>,
              <span>合计</span>
              <span class="red">人头数{{dataList.model.TotalGuestNum}}人</span>
            </p>
            <p>
              按大红包规则获得《
              <span class="blod">{{dataList.commissionRatioModel.MinPrice}}元-{{dataList.commissionRatioModel.Money}}元》返{{dataList.commissionRatioModel.Ratio}}}‰</span>，因而将
              <span class="red">返回给本联盟{{dataList.model.PredictPrice}}元</span>到幸福存折，以下为所有门店交易明细，请及时确认
            </p>
          </div>
          <table
            class="singeRowTable"
            border="0"
            cellspacing="0"
            cellpadding="0"
            v-loading="loading"
          >
            <tr>
              <th>名称</th>
              <th>交易金额</th>
              <th>交易人头</th>
              <th>预计返现</th>
              <th width="200">确认返现</th>
            </tr>
            <tr v-for="(item, index) in dataList.model.CustomerList">
              <td>{{item.CustomerName}}</td>
              <td>¥{{moneyFormat(item.TradeMoney)}}</td>
              <td>{{item.TotalGuestNum}}人</td>
              <td>¥{{moneyFormat(item.PredictPrice)}}</td>
              <td>
                <input type="number" v-model="item.ClosePrice" @change="maxMoney(index)" placeholder="请输入返现金额" />
              </td>
            </tr>
          </table>
          <div class="_addUpload_box clearfix">
            <template v-for="(file,fIndex) in saveMsg">
              <div v-if="file.Type==3">
                <div style="width:100%;height:100%;overflow: hidden;">
                  <img :src="file.Url?file.Url:file.Content" @click="showUpLoadFile(file)" />
                </div>
                <span class="iconfont icon-guanbi1" @click="deleteUploadFile(fIndex)"></span>
              </div>
              <div v-if="file.Type==1">
                <div
                  class="iconfont"
                  :class="file.Content.substring(file.Content.lastIndexOf('.')+1,file.Content.length).toUpperCase()=='PDF'? 'icon-pdf' : 'icon-excel'"
                  @click="showUpLoadFile(file)"
                ></div>
                <span class="iconfont icon-guanbi1" @click="deleteUploadFile(fIndex)"></span>
              </div>
              <div v-if="file.Type==2">
                <div class="iconfont icon-excel" @click="showUpLoadFile(file)"></div>
                <span class="iconfont icon-guanbi1" @click="deleteUploadFile(fIndex)"></span>
              </div>
            </template>
            <div class="_pic_upload">
              <el-upload
                drag
                :http-request="uploadFileBtn"
                :multiple="true"
                :show-file-list="false"
                action
              >
                <i class="el-icon-plus avatar-uploader-icon"></i>
                <div class="el-upload__text">{{$t('active.ld_djscwj')}}</div>
              </el-upload>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row> 
      <input type="button" class="normalBtn" :value="$t('fnc.tijiao')"  @click="subData" />
    </el-row>
    <div v-if="picIsShow" class="_show_img_box" @click="picIsShow=false,picObj=[]">
      <div
        style="position: absolute; width: 800px; height: 600px; left: 50%; top: 50%; margin-left: -400px; margin-top: -300px;"
      >
        <el-carousel :initial-index="initialIndex" height="600px" :interval="5000" trigger="click">
          <el-carousel-item
            style="height: 600px;overflow:auto;"
            v-for="(item,index) in picObj"
            :key="index"
          >
            <img :src="item" style />
          </el-carousel-item>
        </el-carousel>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loading: false, 
      saveMsg: [],
      picIsShow: false,
      show: false,
      dataList: {}, 
    };
  },
  mounted() {
    let id = this.$route.query.id
    this.getList(id);
  },
  methods: {
    maxMoney: function (index) {
      let allMoney = 0
      this.dataList.model.CustomerList.map(x=>{
        allMoney = x.ClosePrice ? parseFloat(x.ClosePrice) + allMoney : allMoney + 0
      })
      if (allMoney > this.dataList.model.PredictPrice) { 
        this.dataList.model.CustomerList[index].ClosePrice = 0;
        this.$message.error('返现金额有误，请仔细核对');
        return
      } 
    },
    subData: function () {
      let allMoney = 0
      this.dataList.model.CustomerList.map(x=>{
        allMoney = x.ClosePrice ? parseFloat(x.ClosePrice) + allMoney : allMoney + 0
      }) 
      if (allMoney > this.dataList.model.PredictPrice) {  
        this.$message.error('返现金额有误，请仔细核对');
        return
      } 
      this.dataList.model.FileList = this.saveMsg
      this.apipost(
        "app_customer_UpdateClearingAlliance",
        this.dataList,
        res => {
          if (res.data.resultCode === 1) {
            this.$router.push({
              name: 'LianMengManagement',
            });
          } else {
            this.$message.error(res.data.message);
          }
        },
        null
      );
    },
    getList: function(id) {
      this.show = false
      this.apipost(
        "app_customer_GetClearingAllianceList",
        { Id: id},
        res => {
          if (res.data.resultCode === 1) {
            this.show = true;
            this.dataList = res.data.data
          }
        },
        null
      );
    },
    showUpLoadFile(i) {
      // 预览上传文件
      if (i.Type == 3) {
        this.picObj.push(i.Url);
        this.imgList.push(i.Url);
        this.picIsShow = true;
      } else {
        if (
          i.Content.substring(
            i.Content.lastIndexOf(".") + 1,
            i.Content.length
          ).toUpperCase() == "PDF"
        ) {
          this.previewPDF(i.Url);
        } else {
          window.open(
            "https://view.officeapps.live.com/op/view.aspx?src=" + i.Url
          );
        }
      }
    },
    deleteUploadFile(i) {
      // 删除上传文件
      this.saveMsg.splice(i, 1);
    },
    uploadFileBtn(file) {
      //上传
      if (file.file.size > 1024 * 1024 * 10) {
        this.$message.warning(this.$t("tips.wjdxbncgsz"));
        return;
      }
      //  1 文档  2 数据 3 图片
      let typeArr = [
        { stringArr: "GIF|JPG|JPEG|PNG|BMP", type: 3 },
        { stringArr: "DOCX|DOC|XLSX|XLS|PPT|PPTX|PDF", type: 1 }
      ];
      let ft = file.file.name
        .substring(file.file.name.lastIndexOf(".") + 1, file.file.name.length)
        .toUpperCase();
      let fileTypeNumber = 2;
      let typeOk = false;
      typeArr.forEach(x => {
        if (x.stringArr.indexOf(ft) != "-1") {
          fileTypeNumber = x.type;
          typeOk = true;
        }
      });
      if (!typeOk) return this.$message.error(this.$t("tips.qscWEfile"));
      let newArr = [];
      newArr.push(file.file);
      let path = "/Upload/Temporary/";
      this.$message.info(this.$t("tips.shangchuanzhong"));
      this.UploadSelfFileT(
        path,
        newArr,
        x => {
          let fileSize =
            file.file.size < 1024
              ? file.file.size
              : (file.file.size / 1024).toFixed(0);
          this.saveMsg.push({
            Content: x.data.FilePath,
            ID: 0,
            Type: fileTypeNumber,
            Url: this.domainManager().ViittoFileUrl + x.data.FilePath
          });
        },
        1
      );
    }
  }
};
</script>
