<style>
  .SupplierTable td {
    padding: 0 5px;
    text-align: center !important;
  }

  .SupplierTable .linkStr {
    color: blue;
    text-decoration: underline;
    cursor: pointer;
  }

</style>
<template>
  <div class="flexOne SupplierHandeFee">
    <div class="query-box">
      <ul class="user_time_picker">
        <li>
          <span>
            <em>月份</em>
            <el-date-picker v-model="msg.QMonthStr" type="month" value-format="yyyy-MM"
              :placeholder="$t('ground.xuanzenian')">
            </el-date-picker>
          </span>
        </li>
        <li>
          <span>
            <em>供应商</em>
            <el-select filterable v-model="msg.Supplier">
              <el-option :label="$t('system.ph_buxian')" :value="0"></el-option>
              <el-option v-for="(item,index) in SupplierList" :key="index" :label="item.Name" :value="item.ID">
              </el-option>
            </el-select>
          </span>
        </li>
        <li>
          <span>
            <em>团状态</em>
            <el-select v-model="msg.IsSetOut">
              <el-option label="正常发团" :value="0"></el-option>
              <el-option label="取消发团" :value="1"></el-option>
            </el-select>
          </span>
        </li>
        <li>
          <input type="button" class="hollowFixedBtn" value="查询" @click="getSearch()"> &nbsp;
          <input type="button" class="normalBtn" value="下载" @click="DownLoadFile()">
        </li>
      </ul>
    </div>
    <div class="clearfix"></div>
    <table class="singeRowTable SupplierTable" border="0" cellspacing="0" cellpadding="0" v-loading="loading">
      <tr>
        <th width="130">做账主体</th>
        <th width="180">团号</th>
        <th width="150">手配定团号</th>
        <th width="80">订单人数</th>
        <th width="100">单价(日元)</th>
        <th width="300">泊数/日期</th>
        <th width="120">小计(日元)</th>
        <th width="100">汇率</th>
        <th width="100">小计(人民币)</th>
        <th width="150">单号</th>
        <th width="80">生成单据</th>
      </tr>
      <tbody v-for="(item,index) in dataList" :key="index">
        <template v-for="(subItem,subIndex) in item.SubList">
          <tr :key="subIndex">
            <td>{{subItem.OutBranchName}}</td>
            <td><span class="linkStr" @click="gotoDmcTable(subItem)"> {{subItem.TCNUM}}({{subItem.TCID}})
              </span>
            </td>
            <td v-if="subIndex==0" :rowspan="item.SubList.length">
              <span class="linkStr" @click="gotoDmcTable(subItem)"> {{item.DMCNum}} </span>
            </td>
            <td>
              <span class="linkStr" @click="goUrlT(subItem)"> {{subItem.GuestNum}} </span>
            </td>
            <td>{{subItem.UnitPrice}}</td>
            <td style="text-align:left!important;">
              <span style="color:red;">{{subItem.DayCount}}泊</span>
              <br />
              {{subItem.UseTime}}
            </td>
            <td>{{subItem.SubtotalMoney}}</td>
            <td>
              <template v-if="subItem.Frids!=''">{{subItem.Rate}}</template>
            </td>
            <td>
              <template v-if="subItem.Frids!=''"> {{subItem.RMBMoney}}</template>
            </td>
            <td>
              <a v-if="subItem.Frids!=''" class="linkStr" @click="goFncUrl(subItem.Frids)">{{subItem.Frids}}</a>
            </td>
            <td v-if="subIndex==0" :rowspan="item.SubList.length">
              <el-tooltip class="item" effect="dark" content="生成单据" placement="top-start">
                <el-button type="success" icon="el-icon-check" circle @click="CreateSupplierBill(item)"></el-button>
              </el-tooltip>
            </td>
          </tr>
        </template>
      </tbody>
      <tfoot v-if="dataList.length>0">
        <tr>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td>
            <template v-if="totalJap>0">
              合计:{{totalJap}}
            </template>
          </td>
          <td></td>
          <td>
            <template v-if="rmbTotal>0">
              合计:{{rmbTotal}}
            </template>
          </td>
          <td></td>
          <td></td>
        </tr>
      </tfoot>
    </table>
    <div class="noDataNotice" v-if="dataList.length<1">
      <i class="iconfont icon-kong"></i>
      <p>{{$t("active.ld_noData")}}</p>
    </div>
    <el-pagination background @current-change="handleCurrentChange" v-if="dataList.length>0"
      :current-page.sync="currentPage" layout="total,prev, pager, next, jumper" :page-size="msg.PageSize"
      :total="total"></el-pagination>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        userInfo: {}, //用户信息
        //请求
        msg: {
          QMonthStr: "",
          Supplier: 0,
          PageIndex: 1,
          PageSize: 15,
          IsSetOut: 0, //0-正常发团,1-取消发团
        },
        loading: false,
        currentPage: 1,
        total: 0,
        dataList: [],
        //供应商
        SupplierList: [],
        totalJap: 0,
        rmbTotal: 0
      }
    },
    mounted() {
      this.userInfo = this.getLocalStorage();
      this.initSupplier();
    },
    filters: {},
    methods: {
      goUrlT(item) {
        this.$router.push({
          name: "RegistrationList",
          query: {
            "id": item.TCID,
            blank: 'y',
            tab: "报名清单"
          }
        })
      },
      goFncUrl(frid) {
        this.$router.push({
          name: "FinancialDocumentsDetail",
          query: {
            id: frid,
            blank: "y",
            tab: "单据详情"
          }
        });
      },
      gotoDmcTable(item) {
        this.$router.push({
          name: "dmcTotalTable",
          query: {
            TCNUM: item.TCNUM,
            blank: "y",
            tab: "详情"
          }
        });
      },
      //生成手配费单据
      CreateSupplierBill(item) {
        var that = this;
        this.Confirm("是否要生成财务单据?", function () {
          that.loading = true;
          that.apipost("dmcstatistics_get_CreateDmcSupplierHotelBillService", {
              TCID: item.TCIDS,
              Supplier: that.msg.Supplier,
              QMonthStr: that.msg.QMonthStr,
              IsSetOut: that.msg.IsSetOut,
            },
            res => {
              that.loading = false;
              if (res.data.resultCode == 1) {
                that.Success('生成单据成功!');
                that.getList();
              } else {
                that.Error(res.data.data);
              }
            }, null);
        });
      },
      //报价单下载
      DownLoadFile() {
        if (this.msg.QMonthStr == '' || this.msg.QMonthStr == null) {
          this.Error('请选择月份');
          return;
        }
        if (this.msg.Supplier == 0) {
          this.Error('请选择供应商');
          return;
        }
        var SupplierName = ''
        this.SupplierList.forEach(x => {
          if (this.msg.Supplier == x.ID) {
            SupplierName = x.Name
          }
        })
        var fileName = SupplierName + this.msg.QMonthStr + ".xls";
        this.loading = true;
        this.GetLocalFile("dmc_get_DowmLoadDmcSupplierHote", this.msg, fileName, res => {
          this.loading = false;
        });
      },
      //点击查询
      getSearch() {
        if (this.msg.QMonthStr == '' || this.msg.QMonthStr == null) {
          this.Error('请选择月份');
          return;
        }
        if (this.msg.Supplier == 0) {
          this.Error('请选择供应商');
          return;
        }
        this.msg.PageIndex = 1;
        this.getList();
      },
      //获取数据
      getList() {
        this.loading = true;
        this.apipost(
          'dmcstatistics_get_GetDmcSupplierHotelPageListService', this.msg,
          res => {
            this.loading = false;
            if (res.data.resultCode == 1) {
              this.dataList = res.data.data.pageData;
              this.total = res.data.data.count;
              this.totalJap = 0;
              this.rmbTotal = 0;
              this.dataList.forEach(x => {
                x.SubList.forEach(y => {
                  this.totalJap += y.SubtotalMoney;
                  this.rmbTotal += y.RMBMoney;
                })
              })
            } else {
              this.Error(res.data.message);
            }
          },
          err => {}
        )
      },
      handleCurrentChange(val) {
        this.msg.PageIndex = val;
        this.getList();
      },
      // 获取供应商
      initSupplier() {
        var qCountry = 0;
        if (this.userInfo.RB_Group_id == 2) {
          qCountry = 651;
        }
        if (this.userInfo.RB_Group_id == 91) {
          qCountry = 1252;
        }
        this.apipost("supplier_post_GetAllList", {
          Type: 1,
          Country: qCountry, //日本供应商
        }, res => {
          if (res.data.resultCode === 1) {
            this.SupplierList = res.data.data;
          }
        }, err => {});
      },
    }
  };

</script>