<template>
  <div class="firstStoreApply">
    <div class="head-title" >
      首店申请
      <div style="float:right;margin-top:-5px">
          <el-button type="primary" size="small" @click="batchadopt(1)">审核通过</el-button>
          <el-button type="primary" size="small" @click="batchadopt(2)">审核拒绝</el-button>
          <el-button style="" size="small" type="primary" @click="Export()">
              下载excel
          </el-button>
      </div>
     
    </div>
    <div class="content">
      <div>
        <div class="searchInput" style="width:250px">
          <el-input @keyup.enter.native="msg.pageIndex=1,getList()" @clear="msg.pageIndex=1,getList()"
            style="display:inline-block;width:225px;height:30px" placeholder="首店名称" v-model="msg.Name" size="small"
            clearable>
          </el-input>
          <span @click="msg.pageIndex=1,getList()" class="el-icon-search"
            style="color:#979dad;font-size:14px;position:relative;top:1px"></span>
        </div>
        <div class="searchInput" style="width:250px">
          <el-input @keyup.enter.native="msg.pageIndex=1,getList()" @clear="msg.pageIndex=1,getList()"
            style="display:inline-block;width:225px;height:30px" placeholder="联系人" v-model="msg.Contact" size="small"
            clearable>
          </el-input>
          <span @click="msg.pageIndex=1,getList()" class="el-icon-search"
            style="color:#979dad;font-size:14px;position:relative;top:1px"></span>
        </div>
        <div class="searchInput" style="width:250px">
          <el-input @keyup.enter.native="msg.pageIndex=1,getList()" @clear="msg.pageIndex=1,getList()"
            style="display:inline-block;width:225px;height:30px" placeholder="联系电话" v-model="msg.ContactMobile"
            size="small" clearable>
          </el-input>
          <span @click="msg.pageIndex=1,getList()" class="el-icon-search"
            style="color:#979dad;font-size:14px;position:relative;top:1px"></span>
        </div>
        <el-date-picker class="indataPicker" type="daterange" v-model="dateStr" range-separator="至"
          start-placeholder="开始日期" end-placeholder="结束日期" size="small" @change="getList" value-format="yyyy-MM-dd">
        </el-date-picker>
        <el-select class="w100" @change="getList()" style="margin-left: 10px;" v-model="msg.AuditState" size="small"
          placeholder="请选择">
          <el-option label="不限" :value="0"></el-option>
          <el-option label="未审核" :value="1"></el-option>
          <el-option label="审核通过" :value="2"></el-option>
          <el-option label="审核不通过" :value="3"></el-option>
        </el-select>
      </div>
      <el-table :data="tableData" v-loading="loading" border style="width: 100%;margin:20px 0" @selection-change="handleSelectionChange">
        <el-table-column
            type="selection"
            :selectable="checkSelectable"
            width="55"></el-table-column>
        <el-table-column prop="Name" width="200" label="首店名称">
        </el-table-column>
        <el-table-column prop="CoverImage" label="封面图" width="150">
          <template slot-scope="scope">
            <el-image title="点击查看大图" style="width:60px;" :src="scope.row.CoverImage"
            :preview-src-list="scope.row.ImageList"></el-image>
          </template>
        </el-table-column>
        <el-table-column prop="TypeName" width="100" label="类型">
        </el-table-column>
        <el-table-column prop="OpenTime" width="200" label="开业时间">
        </el-table-column>
        <el-table-column prop="Address" width="200" label="详细地址">
        </el-table-column>
        <el-table-column prop="AuditState" width="100" label="审核状态">
          <template slot-scope="scope">
            <span v-if="scope.row.AuditState==1" style="color:#1273bc;">未审核</span>
            <span v-if="scope.row.AuditState==2" style="color:green;">审核通过</span>
            <span v-if="scope.row.AuditState==3" style="color:#e95252;">审核不通过</span>
          </template>
        </el-table-column>
        <el-table-column prop="AuditDate" width="200" label="审核时间">
        </el-table-column>
        <el-table-column prop="Contact" label="联系人">
        </el-table-column>
        <el-table-column prop="ContactMobile" label="联系电话">
        </el-table-column>
        <el-table-column label="操作" width="130">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="详情" placement="top">
              <img @click="CommonJump('firstStoreDetail',{ID:scope.row.Id})"
                src="../../assets/img/userman/icon-show.png" alt="">
            </el-tooltip>
            <template v-if="scope.row.AuditState==1">
              <el-tooltip class="item" effect="dark" content="审核通过" placement="top">
                <img @click="AuditStore(scope.row.Id)" src="../../assets/img/userman/pass.png" alt="">
              </el-tooltip>
              <el-tooltip class="item" effect="dark" content="审核拒绝" placement="top">
                <img @click="AuditJujue(scope.row.Id)" src="../../assets/img/userman/nopass.png" alt="">
              </el-tooltip>
            </template>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination style="text-align:right" background @current-change="handleCurrentChange" :page-size="msg.pageSize"
        :current-page.sync="msg.pageIndex" layout="total,prev, pager, next" :total="total">
      </el-pagination>
    </div>

    <el-dialog title="审核拒绝" :visible.sync="resondialog" width="600px">
      <el-form label-width="80px">
        <el-form-item label="拒绝原因" class="is-required">
          <el-input type="textarea" :rows="6" v-model="auditMsg.AuditRemark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="resondialog = false">取 消</el-button>
        <el-button @click="sureJujue" size="small" type="primary">确 定</el-button>
      </span>
    </el-dialog>
     <el-dialog title="审核拒绝" :visible.sync="resondialog2" width="600px">
      <el-form label-width="80px">
        <el-form-item label="拒绝原因" class="is-required">
          <el-input type="textarea" :rows="6" v-model="batchmsg.AuditRemark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="resondialog2 = false">取 消</el-button>
        <el-button @click="BatchAuthenticationAudit(1)" size="small" type="primary">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        msg: {
          pageIndex: 1,
          pageSize: 15,
          Name: '', //首店名称
          Contact: '', //联系人
          StartTime: '', //开业开始时间
          EndTime: '', //开业结束时间
          ContactMobile: '', //联系电话
          AuditState: 0 //审核状态 1未审核 2审核通过 3审核不通过 
        },
        dateStr: [], //日期
        total: 0,
        tableData: [], //数据列表
        auditMsg: {
          AuthenticationId: '',
          AuditState: 2,
          AuditRemark: ''
        },
        batchmsg:{
          AuthenticationIds:'',
          AuditState:2,
          AuditRemark:'',
        },
        choiceList:[],
        resondialog: false,
        resondialog2: false,
      };
    },
    created() {
      this.getList();
    },
    methods: {
      getList() {
        this.loading = true;
        if (this.dateStr && this.dateStr.length > 0) {
          this.msg.StartTime = this.dateStr[0];
          this.msg.EndTime = this.dateStr[1];
        } else {
          this.msg.StartTime = '';
          this.msg.EndTime = '';
        }
        this.apipost("/api/Trade/GetAuthenticationPageList", this.msg, res => {
          this.loading = false;
          if (res.data.resultCode == 1) {
            this.total = res.data.data.count;
            let pageData = res.data.data.pageData;
            this.tableData = pageData;
          }
        })
      },
      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getList();
      },
      //审核通过
      AuditStore(Id) {
        let that = this;
        that.auditMsg.AuthenticationId = Id;
        that.auditMsg.AuditRemark = '';
        that.auditMsg.AuditState = 2;
        that.Confirm("确定审核通过?", function () {
          that.apipost(
            "/api/Trade/SetAuthenticationAudit", that.auditMsg,
            res => {
              if (res.data.resultCode == 1) {
                that.Success(res.data.message);
                that.getList();
              } else {
                that.Error(res.data.message);
              }
            },
          );
        });
      },
      AuditJujue(Id) {
        this.resondialog = true;
        this.auditMsg.AuthenticationId = Id;
        this.auditMsg.AuditState = 3;
        this.auditMsg.AuditRemark = '';
      },
      //审核拒绝
      sureJujue() {
        if(this.auditMsg.AuditRemark==''){
            this.Error('请输入拒绝原因');
            return;
        }
        this.apipost(
          "/api/Trade/SetAuthenticationAudit", this.auditMsg,
          res => {
            if (res.data.resultCode == 1) {
              this.Success(res.data.message);
              this.getList();
              this.resondialog = false;
            } else {
              this.Error(res.data.message);
            }
          },
        );
      },
      //导出excel
      Export() {
        let msg = this.msg;
        msg = JSON.parse(JSON.stringify(msg));
        msg.pageSize = 999;
        this.GetLocalFile(
          "/api/Trade/GetAuthenticationListToExcel",
          msg,
          "首店申请列表.xls"
        );
      },
       handleSelectionChange(e){
         this.choiceList =[]
         e.map(x=>{
            this.choiceList.push(x.Id)
         })
        
      },
      batchadopt(type){
        let that = this;

        if(that.choiceList.length==0){
          that.Error('请选择要审核的首店')
        }else{
          that.batchmsg.AuthenticationIds = that.choiceList.join(',');
        

          if(type==1){
              that.batchmsg.AuditState = 2;
              that.batchmsg.AuditRemark = '';
              that.Confirm("确定审核通过?", function () {
                that.BatchAuthenticationAudit()
             });
          }else if(type==2){
               that.resondialog2 = true;
                that.batchmsg.AuditState = 3;
                that.batchmsg.AuditRemark = '';
          }

          
        }
      },
      BatchAuthenticationAudit(type=0){
          if(type==1 && this.batchmsg.AuditRemark==''){
              this.Error('请输入拒绝原因');
              return;   
          }
          this.apipost(
          "/api/Trade/BatchAuthenticationAudit", this.batchmsg,
            res => {
              if (res.data.resultCode == 1) {
                this.Success(res.data.message);
                this.getList();
                this.resondialog2 = false;
              } else {
                this.Error(res.data.message);
              }
            },
        );
      },
      checkSelectable(row){//判断是否可以选择
          return row.AuditState==1
      },

    },
    mounted() {}
  };

</script>
<style>
  .firstStoreApply .content .searchInput {
    border: 1px solid #DCDFE6;
    border-radius: 4px;
  }

  .firstStoreApply .content .searchInput .el-input__inner {
    border: none;
    outline: none;
    height: 30px;
    line-height: 30px;
  }

  .firstStoreApply .content .searchInput {
    line-height: normal;
    display: inline-table;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    width: 250px;
    margin-right: 20px;
  }

  .firstStoreApply .content {
    background: #fff;
    margin-top: 10px;
    padding: 20px;
    box-sizing: border-box;
  }

</style>
