<template>
    <div class="signature">
        <div class="signature_cheak">
            <div @click="checkBtn()">查询</div>
        </div>
        <div class="signature_tab">
            <div :class="tabNum===1?'signature_tab_ok':''" @click="tabChange(1)">未设置</div>
            <div :class="tabNum===2?'signature_tab_ok':''" @click="tabChange(2)">已设置</div>
        </div>
        <div class="signature_tabBox">
            <!-- 未设置面板 -->
            <div v-show="tabNum===1">
                <div class="signature_header">
                    <div>
                        <em>出团公司</em>
                        <el-select class="signature_header_input1" v-model='msg_1.RB_Branch_Id' clearable filterable>
                            <el-option key="-1" :label="$t('pub.unlimitedSel')" value="-1"></el-option>
                            <el-option v-for='(item,index) in companyList'
                                :key="index"
                                :label="item.BName"
                                :value="item.Id">
                            </el-option>
                        </el-select>
                    </div>
                    <div>
                        <em>团队编号</em><el-input class="signature_header_input1" v-model='msg_1.TCNUM' placeholder="请输入"></el-input>
                    </div>
                    <div>
                        <em>团队状态</em>
                        <el-select class="signature_header_input1" v-model='msg_1.TCState' clearable filterable>
                            <el-option v-for='(item,index) in teamSaleStateList'
                                :key="index"
                                :label="item.Name"
                                :value="item.Id">
                            </el-option>
                        </el-select>
                    </div>
                    <div>
                        <em>送签日期</em>
                        <el-date-picker class="signature_header_input2" v-model='msg_1.SendVisaStartDate' @change="dataDui('visa')" type="date" value-format="yyyy-MM-dd" :placeholder="$t('admin.admin_choDate')" clearable></el-date-picker>
                        <i>-</i>
                        <el-date-picker class="signature_header_input2" v-model='msg_1.SendVisaEndDate' @change="dataDui('visa')" type="date" value-format="yyyy-MM-dd" :placeholder="$t('admin.admin_choDate')" clearable></el-date-picker>
                    </div>
                    <div>
                        <em>发团日期</em>
                        <el-date-picker class="signature_header_input2" v-model='msg_1.StartDate' @change="dataDui('group')" type="date" value-format="yyyy-MM-dd" :placeholder="$t('admin.admin_choDate')" clearable></el-date-picker>
                        <i>-</i>
                        <el-date-picker class="signature_header_input2" v-model='msg_1.EndDate' @change="dataDui('group')" type="date" value-format="yyyy-MM-dd" :placeholder="$t('admin.admin_choDate')" clearable></el-date-picker>
                    </div>
                </div>
                <div class="signature_tableBox">
                  <table class="signature_table"  border="0" cellspacing="0" cellpadding="0" v-loading='tableLoading'>
                    <thead>
                      <tr>
                        <th width="13%">团号</th>
                        <th width="12.5%">发团日期</th>
                        <th width="12.5%">送签日期</th>
                        <th width="12%">状态</th>
                        <th width="12.5%">已报名人数/总人数</th>
                        <th width="12.5%">OP</th>
                        <th width="12.5%">操作人</th>
                        <th width="12.5%">操作</th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr v-for="(option,index) in list_1" :key="index">
                        <td>{{option.TCNUM}}</td>
                        <td>{{option.StartDate}}</td>
                        <td>{{option.SendVisaTime}}</td>
                        <td>{{option.TCStateStr}}</td>
                        <td>{{option.FinishedNumber}}/{{option.TotalNumber}}</td>
                        <td>{{option.OPName}}</td>
                        <td>{{option.SendVisaCreateBy}}</td>
                        <td class="signature_table_btn">
                          <el-button-group>
                            <el-tooltip effect="dark" content="修改" placement="top-start">
                              <el-button type="primary" style='background:#409EFF; border-color:#409EFF' icon="iconfont icon-img_bianji_small" @click="openEdit(index)"></el-button>
                            </el-tooltip>
			                    </el-button-group>
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </div>
                <el-pagination background @current-change="handleCurrentChange" 
                  :current-page.sync="msg_1.pageIndex"
                  layout="total,prev, pager, next, jumper"
                  :page-size="msg_1.pageSize"
                  :total="msg_1.total">
                </el-pagination>
            </div>
            <!-- 已设置面板 -->
            <div v-show="tabNum===2">
                <div class="signature_header">
                    <div>
                        <em>出团公司</em>
                        <el-select class="signature_header_input1" v-model='msg_2.RB_Branch_Id' clearable filterable>
                            <el-option key="-1" :label="$t('pub.unlimitedSel')" value="-1"></el-option>
                            <el-option v-for='(item,index) in companyList'
                                :key="index"
                                :label="item.BName"
                                :value="item.Id">
                            </el-option>
                        </el-select>
                    </div>
                    <div>
                        <em>团队编号</em><el-input class="signature_header_input1" v-model='msg_2.TCNUM' placeholder="请输入"></el-input>
                    </div>
                    <div>
                        <em>团队状态</em>
                        <el-select class="signature_header_input1" v-model='msg_2.TCState' clearable filterable>
                            <el-option v-for='(item,index) in teamSaleStateList'
                                :key="index"
                                :label="item.Name"
                                :value="item.Id">
                            </el-option>
                        </el-select>
                    </div>
                    <div>
                        <em>送签日期</em>
                        <el-date-picker class="signature_header_input2" v-model='msg_2.SendVisaStartDate' @change="dataDui('visa')" type="date" value-format="yyyy-MM-dd" :placeholder="$t('admin.admin_choDate')" clearable></el-date-picker>
                        <i>-</i>
                        <el-date-picker class="signature_header_input2" v-model='msg_2.SendVisaEndDate' @change="dataDui('visa')" type="date" value-format="yyyy-MM-dd" :placeholder="$t('admin.admin_choDate')" clearable></el-date-picker>
                    </div>
                    <div>
                        <em>发团日期</em>
                        <el-date-picker class="signature_header_input2" v-model='msg_2.StartDate' @change="dataDui('group')" type="date" value-format="yyyy-MM-dd" :placeholder="$t('admin.admin_choDate')" clearable></el-date-picker>
                        <i>-</i>
                        <el-date-picker class="signature_header_input2" v-model='msg_2.EndDate' @change="dataDui('group')" type="date" value-format="yyyy-MM-dd" :placeholder="$t('admin.admin_choDate')" clearable></el-date-picker>
                    </div>
                </div>
                <div class="signature_tableBox">
                  <table class="signature_table"  border="0" cellspacing="0" cellpadding="0" v-loading='tableLoading'>
                    <thead>
                      <tr>
                        <th width="13%">团号</th>
                        <th width="12.5%">发团日期</th>
                        <th width="12.5%">送签日期</th>
                        <th width="12%">状态</th>
                        <th width="12.5%">已报名人数/总人数</th>
                        <th width="12.5%">OP</th>
                        <th width="12.5%">操作人</th>
                        <th width="12.5%">操作</th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr v-for="(option,index) in list_2" :key="index">
                        <td>{{option.TCNUM}}</td>
                        <td>{{option.StartDate}}</td>
                        <td>{{option.SendVisaTime}}</td>
                        <td>{{option.TCStateStr}}</td>
                        <td>{{option.FinishedNumber}}/{{option.TotalNumber}}</td>
                        <td>{{option.OPName}}</td>
                        <td>{{option.SendVisaCreateBy}}</td>
                        <td class="signature_table_btn">
                          <el-button-group>
                            <el-tooltip effect="dark" content="修改" placement="top-start">
                              <el-button type="primary" style='background:#409EFF; border-color:#409EFF' icon="iconfont icon-img_bianji_small" @click="openEdit(index)"></el-button>
                            </el-tooltip>
			                    </el-button-group>
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </div>
                <el-pagination background @current-change="handleCurrentChange" 
                  :current-page.sync="msg_2.pageIndex"
                  layout="total,prev, pager, next, jumper"
                  :page-size="msg_2.pageSize"
                  :total="msg_2.total">
                </el-pagination>
            </div>
        </div>
        <!-- 修改窗口 -->
        <div class="signature_edit" v-show="editShow">
            <div class="signature_edit_tit">
              <span>修改送签日期</span>
              <div>
                  <button class="hollowFixedBtn" type="button" @click="closeEdit">{{$t('pub.cancelBtn')}}</button>
                  <button class="normalBtn" type="button" @click="editOk">{{$t('pub.saveBtn')}}</button>	            	
              </div>
            </div>
            <div class="signature_edit_form">
              <div>
                <em>送签日期</em>
                <el-date-picker class="signature_header_input2" v-model='msg_edit.SendVisaTime' @change="editInput" type="date" value-format="yyyy-MM-dd" :placeholder="$t('admin.admin_choDate')" clearable></el-date-picker>
              </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
  data() {
    return {
      tabNum: 1,
      editShow: false,
      getCompanyMsg: {
        RB_Group_Id: "",
        Status: 0,
        is_show: 0
      },
      companyList: [],
      teamSaleStateList: [],
      tableLoading: false,
      list_1: [],
      list_2: [],
      msg_1: {
        pageIndex: 1,
        pageSize: 10,
        RB_Branch_Id: "-1",
        TCState: 3,
        TCNUM: "",
        StartDate: "",
        EndDate: "",
        SendVisaStartDate: "",
        SendVisaEndDate: "",
        IsSetSendVisa: 2,
        total: 0
      },
      msg_2: {
        pageIndex: 1,
        pageSize: 10,
        RB_Branch_Id: "-1",
        TCState: 3,
        TCNUM: "",
        StartDate: "",
        EndDate: "",
        SendVisaStartDate: "",
        SendVisaEndDate: "",
        IsSetSendVisa: 1,
        total: 0
      },
      msg_edit: {
        TCID: 0,
        StartDate: "",
        SendVisaTime: ""
      }
    };
  },
  methods: {
    // tab切换
    tabChange: function(key) {
      if (key !== this.tabNum) {
        this.tabNum = key;
      }
    },
    // 结束日期不能大于开始日期
    dataDui(type) {
      let msg = this.tabNum === 1 ? this["msg_1"] : this["msg_2"];
      if (type === "visa") {
        if (msg.SendVisaStartDate > msg.SendVisaEndDate && msg.SendVisaEndDate !== "") {
          this.$message.error("结束日期不能大于开始日期");
          msg.SendVisaEndDate = "";
        }
      } else if (type === "group") {
        if (msg.StartDate > msg.EndDate && msg.EndDate !== "") {
          this.$message.error("结束日期不能大于开始日期");
          msg.EndDate = "";
        }
      }
    },
    // 送签日期不能大于开团日期
    editInput: function (val) {
      if (val > this.msg_edit.StartDate) {
        this.$message.error("送签日期不能大于发团日期");
        this.msg_edit.SendVisaTime = ''
      }
    },
    //获取销售状态列表
    getTeamSaleStateList: function() {
      this.apipost(
        "travel_get_GetTeamSaleStateList",
        {},
        res => {
          this.teamSaleStateList = res.data.data;
        },
        err => {}
      );
    },
    // 获取公司
    getCompany: function() {
      this.apipost(
        "admin_get_BranchGetList",
        this.getCompanyMsg,
        res => {
          if (res.data.resultCode == 1) {
            this.companyList = res.data.data;
          } else {
            this.$message.error("获取公司列表失败");
          }
        },
        err => {}
      );
    },
    // 获取列表数据
    getList: function(more) {
      this.tableLoading = true;
      let msg = this.tabNum === 1 ? this["msg_1"] : this["msg_2"];
      if (more) {
        msg = this["msg_2"];
      }
      this.apipost(
        "dmc_get_GetTravelSendVisaPageList",
        msg,
        res => {
          if (res.data.resultCode == 1) {
            msg.total = res.data.data.count;
            if (this.tabNum === 1 && !more) {
              this.list_1 = res.data.data.pageData;
            } else if (this.tabNum === 2 || more) {
              this.list_2 = res.data.data.pageData;
            }
          } else {
            this.$message.error("获取列表数据失败");
          }
          this.tableLoading = false;
        },
        err => {}
      )
    },
    // 分页切换
    handleCurrentChange: function(val) {
      let msg = this.tabNum === 1 ? this["msg_1"] : this["msg_2"];
      msg.pageIndex = val;
      this.getList();
    },
    // 查询按钮
    checkBtn: function () {
      let msg = this.tabNum === 1 ? this["msg_1"] : this["msg_2"];
      msg.pageIndex = 1
      this.getList();
    },
    // 打开修改窗口
    openEdit: function (key) {
      let list = this.tabNum === 1 ? this["list_1"] : this["list_2"];
      this.msg_edit.TCID = list[key].TCID
      this.msg_edit.StartDate = list[key].StartDate
      this.msg_edit.SendVisaTime = list[key].SendVisaTime
      this.editShow = true
    },
    // 关闭修改窗口
    closeEdit: function () {
      this.editShow = false
    },
    // 提交修改
    editOk: function () {
      if (this.msg_edit.SendVisaTime !== '') {
        this.apipost(
          "dmc_post_SetTravelSendVisaTime",
          this.msg_edit,
          res => {
            if (res.data.resultCode == 1) {
              this.editShow = false
              this.$message.success("修改成功");
              this.getList();
            } else {
              this.$message.error("修改失败");
            }
            
          },
          err => {}
        )
      } else {
        this.$message.error('送签日期不能为空')
      }
    }
  },
  mounted: function() {
    let userInfo = this.getLocalStorage();
    this.getCompanyMsg.RB_Group_Id = userInfo.RB_Group_id;
    this.getTeamSaleStateList();
    this.getCompany();
    this.getList();
    this.getList(2);
  }
};
</script>

<style>
.signature {
  font-size: 0px;
}
.signature_cheak {
  position: fixed;
  z-index: 10;
  top: 36px;
  right: 20px;
  margin: 20px 0 0px 0;
}
.signature_cheak > div:nth-child(1) {
  display: inline-block;
  width: 60px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  font-size: 14px;
  color: #e95252;
  border: 1px solid #e95252;
  border-radius: 15px;
  background-color: #FFFFFF;
  cursor: pointer;
}
.signature_tab {
  width: 100%;
  height: 40px;
}
.signature_tab > div {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-weight: bold;
  font-size: 14px;
  color: #000000;
  vertical-align: top;
  cursor: pointer;
}
.signature_tab > .signature_tab_ok {
  color: #409eff;
}
.signature_tab_ok::after {
  content: "";
  position: absolute;
  bottom: 0px;
  left: 20px;
  width: 20px;
  height: 3px;
  background-color: #409eff;
}

.signature_header {
  margin: 10px 0 20px 0;
}
.signature_header > div {
  margin: 10px 20px 0 0;
  display: inline-block;
  white-space: nowrap;
}
.signature_header > div > em {
  margin: 0 10px 0 0;
  font-size: 12px;
  color: #666666;
}
.signature_header > div > i {
  margin: 0 5px;
  color: #dde0e6;
  font-size: 14px;
}
.signature_header .signature_header_input1 {
  width: 160px;
}
.signature_header .signature_header_input2 {
  width: 150px;
}

.signature_table {
  width: 100%;
  font-size: 14px;
  color: #333;
}
.signature_table tr {
  background: #fff;
  text-align: left;
  border-bottom: 2px solid #333;
}
.signature_table tr th {
  background: #e6e6e6;
  height: 30px;
  font-size: 12px;
  text-align: left;
  text-indent: 25px;
}
.signature_table tr td {
  height: 50px;
  padding-left: 25px;
  border-bottom: 1px solid #f5f5f5;
  font-size: 14px;
  color: #333;
}

.signature_table_btn button {
  width: 28px;
  height: 28px;
  border-radius: 4px;
}
.signature_table_btn .el-button--primary {
  padding: 5px;
  margin: 0;
  font-size: 14px !important;
}

.signature_edit{
  overflow: auto;
  display: block;
  position: absolute;
  z-index: 50;
  bottom: 0;
  left: 0;
  border-top: 3px solid #38425d;
  background-color: #f9f9f9;
  padding: 10px;
  width: 100%;
  min-width: 1146px;
}

.signature_edit::-webkit-scrollbar {
  width: 4px;
  height: 8px;
}
.signature_edit::-webkit-scrollbar-thumb {
  border-radius: 4px;
  -webkit-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.2);
  background: #c9c9c9;
}
.signature_edit::-webkit-scrollbar-track {
  -webkit-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  background: #ededed;
}
.signature_edit_tit>span{
  padding-left: 10px;
  border-left: 3px solid #e95252;
  font-size: 16px;
  font-family: "PingFangSc-Fine";
  color: #000000;
}
.signature_edit_tit>div{
  float: right;
}
.signature_edit_form{
  margin: 20px 0 30px 0;
  padding: 0 0 0 13px;
}
.signature_edit_form > div > em {
  margin: 0 10px 0 0;
  font-size: 12px;
  color: #666666;
}
.signature_edit_form > div > .signature_header_input2 {
  width: 160px;
}
</style>