<style>
@import "../../../assets/css/newTravelManager.css";
</style>
<template>
<div class="flexOne quoTation">
  <div class="query-box">
    <ul>
      <li>
                          <span>
                              <em>所属线路</em>
                              <el-select v-model="queryData.LineId" class='w200' filterable
                                          :placeholder="$t('pub.pleaseSel')" @change="getLineTeamList()">
                                  <el-option :label="$t('pub.unlimitedSel')" :value='noLimit'></el-option>
                                  <el-option
                                    v-for="item in LineList"
                                    :label='item.LineName'
                                    :value='item.LineID'
                                    :key='item.LineID'>
                                  </el-option>
                              </el-select>
                          </span>
      </li>
      <li>
                          <span>  
                              <em>所属系列</em>
                              <el-select v-model="queryData.LineteamId" class='w200' filterable
                                          :placeholder="$t('pub.pleaseSel')">
                                  <el-option :label="$t('pub.unlimitedSel')" :value='noLimit'></el-option>
                                  <el-option
                                    v-for="item in LineTeamList"
                                    :label='item.LtName'
                                    :value='item.LtID'
                                    :key='item.LtID'>
                                  </el-option>
                              </el-select>
                          </span>
      </li>
      <li>
                          <span>
                              <em>提交人</em>
                              <el-select v-model="queryData.CreateBy" filterable :placeholder="$t('pub.pleaseSel')">
                                  <el-option :label="$t('pub.unlimitedSel')" :value='noLimit'></el-option>
                                  <el-option v-for="item in EmployeeList"
                                              :label='item.EmName'
                                              :value='item.EmployeeId'
                                              :key='item.EmployeeId'>
                                  </el-option>
                              </el-select>
                          </span>
      </li>
      <li>
        <button class="hollowFixedBtn" @click="getList(),resetPageIndex()">查询</button>
      </li>
    </ul>
  </div>
  <el-tabs v-model="activeName" @tab-click="handleClick(activeName)">
    <el-tab-pane v-for="item in $tripUtils.TravelStateList" :label="item.label" :name="item.Id"
                  :key="item.subCode"></el-tab-pane>
  </el-tabs>
  <div class="commonContent" v-loading="loading">
    <ul class="_content">
        <li v-for="item in dataList" :key="item.subCode" :data-id='item.ID'>
            <div class="_left">
              <div>
                <p class="quoListName" @click="getJourney(item.ID,item.Title)">
                    <el-tooltip popper-class="max-w250" effect="dark" :content="item.Title" placement="top-start">
                      <span>{{item.Title}}</span>
                    </el-tooltip>
                </p>
                <p class="Quo_Content"><i v-if="item.ProductRecommend" class="iconfont icon-richeng"></i>
                    <span>{{item.ProductRecommend}}</span>
                </p>
              </div>
            </div>
            <div class="_cent">
                <div class="stayDays">{{item.DayNum}}天{{item.NightNum}}晚</div>
                  <div class="">
                    销售定价  
                    <el-popover
                      popper-class="salsSetPrice"
                      trigger="click">
                      <div class="priceContentDiv" v-if="item.QuotationPrice!=null">
                        <div>
                          <div>成人</div>
                          <div class="priceList">
                            <div>
                              <span class="pLeftPrice">同业会员:¥{{item.QuotationPrice.B2BMemberPrice}}</span>
                              <span class="pRightPrice">同业:¥{{item.QuotationPrice.B2BPrice}}</span>
                            </div>
                            <div class="priceDivCon">
                              <span class="pLeftPrice">直客会员:¥{{item.QuotationPrice.B2CMemberPrice}}</span>
                              <span class="pRightPrice">直客:¥{{item.QuotationPrice.B2CPrice}}</span>
                            </div>
                          </div>
                          <div>小孩</div>
                          <div class="priceList">
                            <div>
                              <span class="pLeftPrice">占床:¥{{item.QuotationPrice.ChildNeedPrice}}</span>
                              <span class="pRightPrice">不占床:¥{{item.QuotationPrice.ChildNoNeedPrice}}</span>
                            </div>
                            <div class="priceDivCon">
                              <span class="pLeftPrice">婴儿:¥{{item.QuotationPrice.BabyPrice}}</span>
                              <span class="pRightPrice">附加费:¥{{item.QuotationPrice.BabyChargePrice}}</span>
                            </div>
                          </div>
                          <div>老人</div>
                          <div class="priceList">
                            <div>
                              <span class="pLeftPrice">附加费:¥{{item.QuotationPrice.OldManChargePrice}}</span>
                            </div>
                          </div>
                          <div>杂费</div>
                          <div class="priceList">
                            <div>
                              <span class="pLeftPrice">签证:¥{{item.QuotationPrice.VisaPrice}}</span>
                              <span class="pRightPrice">单房差:¥{{item.QuotationPrice.SingleRoomPrice}}</span>
                            </div>
                            <div class="priceDivCon">
                              <span class="pLeftPrice">杂费:¥{{item.QuotationPrice.OtherPrice}}</span>
                            </div>
                          </div>
                          <div>单项报价</div>
                          <div class="priceList">
                            <div>
                              <span class="pLeftPrice">单地接:¥{{item.QuotationPrice.SingleDMCPrice}}</span>
                            </div>
                          </div>
                          <div>优惠</div>
                          <div class="priceList">
                            <div>
                              <span class="pLeftPrice">同行返佣:¥{{item.QuotationPrice.RebatePrice}}</span>
                              <span class="pRightPrice">早鸟优惠:¥{{item.QuotationPrice.DiscountPrice}}</span>
                            </div>
                          </div>
                        </div>
                      </div>
                      <span slot="reference" class="diPrice" >{{item.SalesPrice}}<span class="qi">起</span></span>
                    </el-popover> 
                    <span class="AudiDanTeamDate">有效期:{{item.QuotationLimitStartStr}} 至&nbsp;{{item.QuotationLimitEndStr}}</span>
                </div>
            </div>
            <div class="_rightAudit">
                <div class="AuditUserInfo clearfix aa">
                  <div class="AuditDanHeader">
                    <img v-if="item.CreateUserPhoto" :src="item.CreateUserPhoto" alt="">
                    <img v-else src="../../../assets/img/default_head_img.jpg" alt="">
                  </div>
                  <div class="AuditUserInfoDetail">
                    <div>{{item.CreateUserName}}</div>
                    <div class="AuditChangeDate">{{item.CreateDate}}</div>
                  </div>
              </div>
              <div class="AuditStatus">
                  <div v-if="item.TravelState==2">
                    <div>待审核</div>
                  </div>
                  <div v-if="item.TravelState==3">
                    <div class="Auditapproved">已通过</div>
                    <el-popover
                      popper-class="salsSetPrice"
                      trigger="click">
                      <div class="priceContentDiv">
                        <div>
                          <span>审批结果</span>
                          <span class="AuditDate">{{item.hours}}</span>
                        </div>
                        <div>{{item.AuditContent}}</div>
                      </div>
                      <div slot="reference" class="AuditLookDetail">查看说明</div>
                    </el-popover>
                  </div>
                  <div v-if="item.TravelState==4">
                    <div class="Auditrejected">已驳回</div>
                    <el-popover
                      popper-class="salsSetPrice"
                      trigger="click">
                      <div class="priceContentDiv">
                        <div>
                          <span>审批结果</span>
                          <span class="AuditDate">{{item.hours}}</span>
                        </div>
                        <div>{{item.AuditContent}}</div>
                      </div>
                      <div slot="reference" class="AuditLookDetail">查看说明</div>
                    </el-popover>
                  </div>
              </div>
              <div class="AD_Operation">
                  <span class="openGroup opbd">
                      <el-tooltip class="item" effect="dark" content="查看" placement="top-start"
                                  popper-class="max-w250">
                          <span @click="goUrl('QuotationDetails',item.ID,1)">查</span>
                      </el-tooltip>
                  </span>
                  <span class="openGroup opbd" v-if="item.TravelState==2">
                      <el-tooltip class="item" effect="dark" content="审核" placement="top-start"
                                  popper-class="max-w250">
                          <span @click="goUrl('QuotationDetails',item.ID,2)">审</span>
                      </el-tooltip>
                  </span>
                  <span class="openGroup opbd">
                    <el-tooltip class="item" effect="dark" content="日志" placement="top-start"
                                popper-class="max-w250">
                        <el-popover
                          popper-class="salsSetPrice"
                          trigger="click">
                            <div class="priceContentDiv">
                            <div class="AuditLog">报价单日志</div>
                            <div class="logContact">
                                <div v-for="(childItem,logIndex) in AuditLogList" :key="childItem.subCode">
                                        <div class="clearfix">
                                            <div class="Auditcircle"></div>
                                            <div class="operateName">{{childItem.UserName}}</div>
                                            <div class="operateDate">{{childItem.hour}}</div>
                                        </div>
                                        <div>{{childItem.LogContent}}<span class="spread"
                                                                            v-if="childItem.LogType==2"
                                                                            @click="expectInfo(logIndex)">{{childItem.expectName}}</span></div>
                                        <div v-if="childItem.isShow">{{childItem.LogRemark}}</div>
                                    </div>
                            </div>
                            </div>
                            <span slot="reference" class="AuditLogSpan" @click="getAudiDanLog(item.ID)">志</span>
                        </el-popover>  
                    </el-tooltip>
                  </span>
              </div>
            </div>
        </li>
    </ul>
    <div class="noData" v-show="noData">
      {{$t('system.content_noData')}}
    </div>
  </div>
  <el-pagination background @current-change="handleCurrentChange" :current-page.sync="currentPage"
                  layout="total,prev, pager, next, jumper" :page-size="queryData.pageSize" :total="total">
  </el-pagination>
  <el-dialog custom-class='ComTeamPlan_info_box' :title="tripTitle" :visible.sync="outerVisible" center>
    <commonTeamInfo ref="comDialog"></commonTeamInfo>
  </el-dialog>
  <div class="shenheBtm" v-if="isShowDan">
    <el-form label-width="100px" :model="AuditInfo" :rules="rules" ref="AuditInfo">
      <el-col :span="3">
        <div style="margin:58px 0 0 50px;">
          <el-radio v-model="AuditInfo.TravelState" label="3">通过</el-radio>
          <el-radio v-model="AuditInfo.TravelState" label="4">驳回</el-radio>
        </div>
      </el-col>
      <el-col :span="10" style="margin-top:30px;">
        <el-form-item label="审批说明" prop="AuditContent">
          <el-input type="textarea" class="w600" v-model="AuditInfo.AuditContent"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="3" style="margin-top:60px;">
        <button class="hollowFixedBtn" @click="isShowDan=false">取消</button>
        <button class="normalBtn" @click="submitForm('AuditInfo')">保存</button>
      </el-col>
    </el-form>
  </div>
</div>
</template>
<script>
 import commonTeamInfo from "../../commonPage/commonTeamInfo.vue";
export default {
  data() {
    return {
      queryData: {
        LineId: 0,
        LineteamId: 0,
        CreateBy: 0,
        PageIndex: "1",
        PageSize: "5",
        TravelState: 2
      },
      AuditInfo: {
        ID: "",
        TravelState: "",
        AuditContent: ""
      },
      rules: {
        AuditContent: [
          { required: true, message: "请填写审核说明", trigger: "blur" }
        ]
      },
      loading: true,
      //默认选中
      activeName: "2",
      //员工列表
      EmployeeList: [],
      //日志
      AuditLogList: "",
      //显示隐藏审核
      isShowDan: false,
      //线路列表
      LineList: "",
      noLimit: 0,
      //系列列表
      //是否有数据
      noData: false,
      LineTeamList: "",
      dataList: "",
      total: 0,
      currentPage: 1,
      SalesPriceList: [],
      CostList: [],
      outerVisible: false,
      tripTitle: ""
    };
  },
  components: {
    commonTeamInfo: commonTeamInfo
  },
  methods: {
    handleCurrentChange(val) {
      this.queryData.pageIndex = val;
      this.getList();
    },
    resetPageIndex() {
      this.queryData.pageIndex = 1;
      this.currentPage = 1;
    },
    //选项卡切换
    handleClick(activeName) {
      this.queryData.TravelState = activeName;
      this.getList();
    },
    //获取操作日志
    getAudiDanLog(ID) {
      let msg = {
        configId: ID
      };
      this.apipost("travel_get_GetTravelConfigLog", msg, res => {
        if (res.data.resultCode == 1) {
          var endDate = new Date();
          endDate.setMonth(endDate.getMonth() + 1);
          var tempData = res.data.data;
          tempData.forEach(x => {
            if (x.LogType == 2) {
              x.isShow = false;
              x.expectName = "展开";
            }
            x.hour = this.$commonUtils.formatMsgTime(x.LogTimeStr);
          });
          this.AuditLogList = tempData;
        }
      });
    },
    expectInfo(logIndex) {
      var flag = this.AuditLogList[logIndex].isShow;
      this.AuditLogList[logIndex].isShow = !flag;
      if (this.AuditLogList[logIndex].isShow) {
        this.AuditLogList[logIndex].expectName = "关闭";
      } else {
        this.AuditLogList[logIndex].expectName = "展开";
      }
    },
    //获取线路列表
    getLineList() {
      this.apipost("line_post_GetList", {}, res => {
        if (res.data.resultCode == 1) {
          this.LineList = res.data.data;
        }
      });
    },
    //获取系列列表
    getLineTeamList(lineId) {
      this.queryData.LineteamId = 0;
      let msg = {
        lineID: this.queryData.LineId,
        isTOOP: 1
      };
      this.apipost("team_post_GetList", msg, res => {
        if (res.data.resultCode == 1) {
          this.LineTeamList = res.data.data;
        }
      });
    },
    //初始化表格数据
    getList() {
      this.loading = true;
      this.apipost(
        "travel_get_GetTravelOfferAuditPageList",
        this.queryData,
        res => {
          this.loading = false;
          if (res.data.resultCode == 1) {
            this.total = res.data.data.count;
            this.noData = !this.total > 0;
            var tempData = res.data.data.pageData;
            tempData.forEach(x => {
              x.hours = this.$commonUtils.formatMsgTime(x.AuditDate);
            });
            this.dataList = tempData;
          }
        }
      );
    },
    //点击销售定价获取数据
    getSalsPrice(ID) {
      let msg = {
        ID: ID
      };
      this.SalesPriceList = [];
      this.apipost("travel_get_GetTravelQuotationPrice", msg, res => {
        if (res.data.resultCode == 1) {
          this.SalesPriceList.push(res.data.data[0]);
        }
      });
    },
    //点击地接成本获取数据
    getCostPrice(ID) {
      let msg = {
        ID: ID
      };
      this.CostList = [];
      this.apipost("travel_get_GetTravelOfferPrice", msg, res => {
        if (res.data.resultCode == 1) {
          if (res.data.data[0] != undefined || res.data.data[0] != null) {
            let cost = res.data.data[0];
            let dayNum = 0;
            cost.LocalOfferPriceList.forEach(x => {
              if (x.DayNum > dayNum) {
                dayNum = x.DayNum;
              }
            });
            let offerPriceList = [];
            for (let i = 1; i <= dayNum; i++) {
              let dayOfferPriceList = [];
              let totalPrice = 0;
              cost.LocalOfferPriceList.forEach(x => {
                if (x.DayNum == i) {
                  dayOfferPriceList.push(x);
                  totalPrice += x.OfferPrice;
                }
              });
              let offerPrice = { day: i, dayOfferPriceList, totalPrice };
              offerPriceList.push(offerPrice);
            }
            cost["offerPriceList"] = offerPriceList;
            this.CostList.push(cost);
          }
        }
      });
    },
    //根据当前员工所在部门获取该部门及子部门员工信息
    getEmployeeList() {
      this.apipost(
        "admin_get_GetEmployeeByUserDepartmentId",
        {},
        res => {
          if (res.data.resultCode == 1) {
            this.EmployeeList = res.data.data;
          }
        },
        err => {}
      );
    },
    getJourney(id, title) {
      //根据ID 获取行程内容
      var that = this;
      this.tripTitle = title;
      this.$nextTick(() => {
        that.$refs.comDialog.GetTrip(id);
      });
      that.outerVisible = true;
    },
    goUrl(path, configId, qType) {
      if (configId > 0) {
        this.$router.push({
          name: path,
          query: { configId: configId, Qtype: qType }
        });
      } else {
        this.$router.push({ name: path });
      }
    },
    submitForm() {
      //提交创建、修改表单
      this.$refs["AuditInfo"].validate(valid => {
        if (valid) {
          this.saveAudit();
        } else {
          return false;
        }
      });
    },
    auditDanList(ID) {
      this.isShowDan = true;
      this.AuditInfo.ID = ID;
    },
    //提交审核
    saveAudit() {
      this.apipost(
        "travel_get_AuditTravelConfig",
        this.AuditInfo,
        res => {
          if (res.data.resultCode == 1) {
            this.Success("审核成功");
            this.isShowDan = false;
            this.getList();
          }
        },
        err => {}
      );
    },
    //格式化日期去掉年
    formatStartDate(value) {
      if (value == null || value == undefined) {
        return "";
      } else {
        let dataArr = value.split("-");
        return dataArr[1] + "-" + dataArr[2];
      }
    }
  },
  mounted() {
    this.getLineList();
    this.getEmployeeList();
    this.getList();
  }
};
</script>