<style>
  .CM_detail {
    color: #3980C8;
    cursor: pointer;
  }

  .CM_detail:hover {
    text-decoration: underline;
    color: #E95252;
  }

</style>

<template>
  <div class="flexOne">
    <div class="query-box">
      <ul>
        <li>
          <span>
            <em>{{$t('salesModule.keyWords')}}</em>
            <el-input placeholder="" v-model="queryMsg.IdCard"></el-input>
          </span>
        </li>
        <li>
          <input type="button" class="hollowFixedBtn" :value="$t('pub.searchBtn')" @click="getList(),resetPageIndex()" />&nbsp;
          <input type="button" class="normalBtn" :value="$t('pub.addBtn')" @click="showDialog(null)" />
        </li>
      </ul>
    </div>

    <div class="commonContent" v-loading="queryCommonData.loading">
      <table class="singeRowTable" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <th>{{$t('hotel.hotel_SerialNumber')}}</th>
          <th>身份证号码</th>
          <th>手机号码</th>
          <th>护照</th>
          <th>{{$t('pub.pubRemark')}}</th>
          <th>{{$t('active.cl_addPp')}}</th>
          <th>{{$t('system.table_operation')}}</th>
        </tr>
        <tr v-for="(item,index) in queryCommonData.dataList" :key="index+10000">
          <td>{{item.Id}}</td>
          <td>
            {{item.IdCard}}
          </td>
          <td>{{item.MobilePhone}}</td>
          <td>{{item.PassportNo}}</td>
          <td style="text-align:left;">{{item.Notes}}</td>
          <td>{{item.CreateByName}}</td>
          <td>
            <template v-if="CurrentUserInfo.EmployeeId==item.CreateBy||IsEditDlete">
              <span class="CM_detail" @click="showDialog(item)">修改</span>
              <span class="CM_detail" @click="delGuest(item)">删除</span>
            </template>
          </td>
        </tr>
      </table>
      <div class="noData" v-show="queryCommonData.noData">
        {{$t('system.content_noData')}}
      </div>
      <el-pagination background @current-change="handleCurrentChange" :current-page.sync="queryMsg.currentPage"
        layout="total,prev, pager, next, jumper" :page-size="queryMsg.pageSize" :total="queryMsg.total">
      </el-pagination>
    </div>
    <el-dialog custom-class='w500' :title="editTitle" :visible.sync="isShowGuestForm" center
      :before-close="closeDailog">
      <table class="layerTable" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="100" align="right">身份证号码：</td>
          <td>
            <el-input v-model='postMsg.IdCard' maxlength='100' placeholder="请填写身份证号码"></el-input>
          </td>
        </tr>
        <tr>
          <td width="100" align="right">手机号码：</td>
          <td>
            <el-input v-model='postMsg.MobilePhone' maxlength='100' placeholder="请填写手机号码"></el-input>
          </td>
        </tr>
        <tr>
          <td width="100" align="right">护照号：</td>
          <td>
            <el-input v-model='postMsg.PassportNo' maxlength='100' placeholder="请填写护照号"></el-input>
          </td>
        </tr>
        <tr>
          <td width="100" align="right">备注：</td>
          <td>
            <el-input v-model='postMsg.Notes' maxlength='200' placeholder="最多输入200个字"></el-input>
          </td>
        </tr>
      </table>
      <div slot="footer" class="dialog-footer">
        <button class="hollowFixedBtn" @click="closeDailog">取 消</button> &nbsp;
        <button class="normalBtn" type="primary" @click="saveGuest">确定</button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        queryCommonData: {
          //加载
          loading: false,
          //是否有数据
          noData: false,
          //数据列表
          dataList: [],
        },
        queryMsg: {
          IdCard: "",
          pageIndex: 1,
          pageSize: 10,
          //第几页
          currentPage: 1,
          //总数
          total: 0,
        },
        //新增修改旅客黑名单参数
        postMsg: {
          Id: 0,
          IdCard: "", //身份证号码
          MobilePhone: "", //手机号码
          PassportNo: "", //护照号
          Notes: "", //备注
        },
        isShowGuestForm: false, //是否显示新增修改弹窗
        editTitle: "新增旅客黑名单信息", //弹窗标题
        CurrentUserInfo: {}, //当前登录用户信息
        IsEditDlete: false, //是否有修改删除权限
      }
    },
    methods: {
      //添加修改投诉
      showDialog(item) {
        if (item) {
          this.editTitle = "修改旅客黑名单信息";
          this.postMsg.Id = item.Id;
          this.postMsg.IdCard = item.IdCard;
          this.postMsg.MobilePhone = item.MobilePhone;
          this.postMsg.PassportNo = item.PassportNo;
          this.postMsg.Notes = item.Notes;
        }
        this.isShowGuestForm = true;
      },
      //关闭弹窗
      closeDailog() {
        this.isShowGuestForm = false;
        this.postMsg.Id = 0;
        this.postMsg.IdCard = "";
        this.postMsg.MobilePhone = "";
        this.postMsg.PassportNo = "";
        this.postMsg.Notes = "";
      },
      //新增修改旅客黑名单
      saveGuest() {
        this.apipost('travel_post_SetTravelGuestBlack', this.postMsg, res => {
          if (res.data.resultCode == 1) {
            this.closeDailog();
            this.Success(res.data.message);
            this.getList();
          } else {
            this.Error(res.data.message)
          }
        }, err => {})
      },
      getList() {
        this.queryCommonData.loading = true;
        this.apipost('travel_post_GetGuestBlackPageList', this.queryMsg, res => {
          this.queryCommonData.loading = false;
          if (res.data.resultCode == 1) {
            this.queryMsg.total = res.data.data.count;
            this.queryCommonData.noData = !this.queryMsg.total > 0;
            this.queryCommonData.dataList = res.data.data.pageData;
          } else {
            this.Error(res.data.message)
          }
        }, err => {})
      },
      //翻页
      handleCurrentChange(val) {
        this.queryMsg.pageIndex = val
        this.getList()
      },
      //重新查询
      resetPageIndex() {
        this.queryMsg.pageIndex = 1;
        this.queryMsg.currentPage = 1;
      },
      //删除
      delGuest(item) {
        var that = this;
        var tipMsg = "是否删除【" + item.IdCard + "/" + item.MobilePhone + "/" + item.PassportNo + "】?";
        that.Confirm(tipMsg, function () {
          var msg = {
            Id: item.Id
          };
          that.apipost(
            "travel_post_DelTravelGuestBlack", msg, res => {
              if (res.data.resultCode == 1) {
                that.Success(res.data.message);
                that.getList();
              } else {
                that.Error(res.data.message);
              }
            },
            null
          );
        });
      },
      //是否有修改和删除旅客黑名单权限
      CheckAuth() {
        var actionCode = this.$AuthCode.F_EditDeleteGuest;
        this.CheckUserAuth(actionCode, res => {
          if (res.data.resultCode == 1 && res.data.data == 1) {
            this.IsEditDlete = true;
          }
        });
      },
    },
    created() {
      this.CurrentUserInfo = this.getLocalStorage();
      this.CheckAuth();
    },
    mounted() {
      this.getList();
    }
  }

</script>
