<!--
 * @Descripttion:
 * @version:
 * @Author: kBank
 * @Date: 2022-10-24 15:45:01
-->
<template>
  <div class="page">
    <topBar v-if="topList.length > 0"
            :topList="topList"
            :moren="moren"></topBar>
    <div class="main">
      <div class="form_all">
        <el-form ref="select"
                 :model="select"
                 label-width="auto">
          <el-row :gutter="10">
            <el-col :span="4">
            <el-form-item :label="'会员编号'">
              <el-input
                v-model="select.memberCode"
                clearable
              />
            </el-form-item>
          </el-col>
            <el-col :span="4">
              <el-form-item :label="'会员姓名'">
                <el-input clearable
                          v-model="select.memberName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'真实奖衔'">
                <el-select clearable
                           :placeholder="'请选择'"
                           v-model="select.pkAward">
                  <el-option v-for="item in awardsList"
                             :key="item.pkId"
                             :label="item.awardsName"
                             :value="item.pkId"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'隶属体系'">
                <el-select v-model="select.pkVertex"
                           clearable>
                  <el-option v-for="item in vertexList"
                             :key="item.value"
                             :label="item.vertexName"
                             :value="item.pkId" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'隶属团队'">
                <el-select v-model="select.pkTeam"
                           clearable>
                  <el-option v-for="item in memberteamList"
                             :key="item.value"
                             :label="item.teamName"
                             :value="item.pkId" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'法人姓名'">
                <el-input clearable
                          v-model="select.legalName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'营业执照名称'">
                <el-input clearable
                          v-model="select.licenseName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'统一社会信用代码'">
                <el-input clearable
                          v-model="select.creditCode"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="'省/市/区/县'"
                            prop="">
                <el-cascader style="width: 100%"
                             clearable
                             v-model="select.shoppingAddress"
                             :options="areaData"
                             :props="regionParams"
                             @change="handleChange1"></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="'详细地址'">
                <el-input clearable
                          v-model="select.licenseAddress"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'审核状态'">
                <el-select clearable
                           :placeholder="'请选择'"
                           v-model="select.approveStatus">
                  <el-option v-for="item in gradeRangList"
                             :key="item.value"
                             :label="item.label"
                             :value="item.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="'创建日期'">
                <el-date-picker v-model="creationTime"
                                @change="changeTime"
                                value-format="yyyy-MM-dd"
                                type="daterange"
                                :range-separator="'至'"
                                :start-placeholder="'开始日期'"
                                :end-placeholder="'结束日期'">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="'审核日期'">
                <el-date-picker v-model="creationTime1"
                                @change="changeTime1"
                                value-format="yyyy-MM-dd"
                                type="daterange"
                                :range-separator="'至'"
                                :start-placeholder="'开始日期'"
                                :end-placeholder="'结束日期'">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button type="primary"
                         @click="getDataList"> {{ '搜索' }}</el-button>
              <el-button type=""
                         @click="reset"> {{ '重置' }}</el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="maintop">
        <div class="mainbtn">
          <!-- <el-button size="small"
                     @click="openDig"
                     v-hasButtons="['MissionAdd']"
                     class="addBtn">{{'添加'}}</el-button> -->
          <el-button size="small"
                     @click="handleExport"
                     v-hasButtons="['businessExport']"
                     style="background-color: #ffad41"
                     class="thebtn1"> {{ '导出' }}</el-button>
        </div>
      </div>
      <div class="maintable">
        <el-table :data="tableData"
        v-loading="loading"
                  style="width: 100%"
                  :header-cell-style="{ background: '#EEEEEE' }"
                  :row-class-name="tableRowClassName"
                  @selection-change="handleSelectionChange">
          <el-table-column type="selection"
                           width="55"> </el-table-column>
          <el-table-column align="center"
                           prop="picture"
                           :label="'营业执照'">
            <template slot-scope="scope">
              <el-image style="width: 28px; height: 20px"
                        :src="scope.row.licenseImage"
                        :preview-src-list="[scope.row.licenseImage]">
              </el-image>
            </template>
          </el-table-column>
          <el-table-column align="center"
                           prop="memberCode"
                           :label="'会员编号'">
          </el-table-column>

          <el-table-column align="center"
                           prop="memberName"
                           :label="'会员姓名'">
          </el-table-column>
          <el-table-column align="center"
                           prop="phone"
                           :label="'联系方式'">
          </el-table-column>
          <el-table-column align="center"
                           prop="awardTransactionVal"
                           :label="'真实奖衔'">
          </el-table-column>
          <el-table-column align="center"
                           prop="vertexName"
                           :label="'隶属体系'">
          </el-table-column>
          <el-table-column align="center"
                           prop="teamName"
                           :label="'隶属团队'">
          </el-table-column>
          <el-table-column align="center"
                           prop="parentChief"
                           :label="'所属总监'">
          </el-table-column>
          <el-table-column align="center"
                           prop="parentChiefName"
                           :label="'所属总监' + '姓名'">
          </el-table-column>
          <el-table-column align="center"
                           prop="licenseName"
                           :label="'营业执照名称'">
          </el-table-column>
          <el-table-column align="center"
                           prop="creditCode"
                           :label="'统一社会信用代码'">
          </el-table-column>
          <el-table-column align="center"
                           prop="legalName"
                           :label="'法人姓名'">
          </el-table-column>
          <el-table-column align="center"
                           prop="province"
                           :label="'省'">
          </el-table-column>
          <el-table-column align="center"
                           prop="city"
                           :label="'市'">
          </el-table-column>
          <el-table-column align="center"
                           prop="county"
                           :label="'区/县'">
          </el-table-column>
          <el-table-column align="center"
                           prop="licenseAddress"
                           :label="'详细地址'">
          </el-table-column>
          <el-table-column align="center"
                           prop="approveStatusVal"
                           :label="'审核状态'">
            <template slot-scope="scope">
              <div v-if="scope.row.approveStatus == 4">
                <el-popover placement="right"
                            width="400"
                            trigger="hover">
                  <div v-html="scope.row.rejectMsg"></div>
                  <div style="color:#b42b2a;cursor: pointer;"
                       slot="reference">{{ scope.row.approveStatusVal }}</div>
                </el-popover>
              </div>
              <div v-else>{{ scope.row.approveStatusVal }}</div>
            </template>
          </el-table-column>
          <el-table-column align="center"
                           prop="creationTime"
                           :label="'创建日期'">
          </el-table-column>
          <el-table-column align="center"
                           prop="approveTime"
                           :label="'审核日期'">
          </el-table-column>

          <el-table-column align="center"
                           prop="time"
                           :label="'操作'"
                           fixed="right">
            <template slot-scope="scope">
              <div style="display:flex;justify-content: center;">
                <div v-show="scope.row.approveStatus == 2"
                     @click="toFixed(scope.row.pkId,0)"
                     v-hasButtons="['businessSh']"
                     style="color:#3181e5;font-size: 12px;margin-right:10px;cursor: pointer;"> {{'审核'}}</div>
                <div v-show="scope.row.approveStatus == 5"
                     @click="toFixed(scope.row.pkId,1)"
                     v-hasButtons="['businessSh']"
                     style="color:#FFAD41;font-size: 12px;margin-right:10px;cursor: pointer;"> {{'重置'}}</div>
                <div v-show="scope.row.approveStatus == 2"
                     @click="handleDelete(scope.row.pkId)"
                     v-hasButtons="['businessBh']"
                     style="color: #C8161D;font-size: 12px;cursor: pointer;"> {{'驳回'}}</div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <el-dialog title="驳回意见"
               :visible.sync="isShow"
               width="40%"
               center
               :close-on-click-modal="false"
               :before-close="handleClose1">
      <div>
        <editor ref="sptwEditor"
                v-model="relContent"
                :min-height="283"
                :upload-url="uploadImgUrl" />
      </div>
      <div class="button-s">
        <div class="submit"
             @click="handleClose1"> {{ '取消' }}</div>
        <div class="submit colors"
             @click="confirmSubmit"> {{ '确认' }}</div>
      </div>
    </el-dialog>
    <pagination v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getDataList" />
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import * as api from '@/api/business.js'
import * as site from '@/api/site.js'

import Editor from '@/components/Editor/index.vue'
import { getgradeRanglist, getAwardsListChiose } from '@/api/level'
import { getvertexValue, getmemberTeamList } from '@/api/member'
export default {
  name: 'Bzpz',
  components: {
    topBar,
    Editor,
  },
  data() {
    return {
      creationTime: [],
      creationTime1: [],
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      total: 0,
      loading:false,
      tableData: [],
      gradeRangList: [],
      awardsList: [],
      yesNoList: [],
      vertexList: [],
      memberteamList: [],
      moren: 'businessLicense',
      topList: [
        {
          name: '营业执照',
          path: 'businessLicense',
        },
      ],
      isShow: false,
      relContent: '',
      uploadImgUrl: process.env.VUE_APP_BASE_API + '/system/upload',
      storeCode: '',
      areaData: [],
      regionParams: {
        label: 'name',
        value: 'id',
        children: 'children',
        expandTrigger: 'hover',
      },
    }
  },
  mounted() {
    // 获取列表
    this.getDataList()
    this.getData()
    // this.getAwardsListChiose();
    // this.getEYesNoList()
  },
  methods: {
    handleClose1() {
      this.isShow = false
      this.relContent = ''
      this.storeCode = ''
    },
    //审核状态
    getData() {
      getAwardsListChiose().then((res) => {
        this.awardsList = res.rows
      })
      api.approvalStatus().then((res) => {
        this.gradeRangList = res.data
      })
      getvertexValue().then((res) => {
        this.vertexList = res.data
      })
      getmemberTeamList().then((res) => {
        this.memberteamList = res.rows
      })
      site.areaList().then((res) => {
        this.areaData = res.data
      })
    },
    reset() {
      this.select = {}
      this.creationTime = []
      this.creationTime1 = []
      this.getDataList()
    },
    changeTime(val) {
      this.select.startDate = val ? val[0] : ''
      this.select.endDate = val ? val[1] : ''
    },
    changeTime1(val) {
      this.select.startApproveTime = val ? val[0] : ''
      this.select.endApproveTime = val ? val[1] : ''
    },

    // 点击修改
    toFixed(id, index) {
      let approvalBusiness
      if (index == 0) {
        approvalBusiness = 133
      } else {
        approvalBusiness = 135
      }
      this.$router.push({
        path: 'businessZxqc',
        query: {
          pkId: id,
          approvalBusiness: approvalBusiness,
        },
      })
    },
    // 驳回申请
    confirmSubmit() {
      if (this.relContent.length == 0) {
        this.$message({
          message: '请输入驳回信息',
          type: 'warning',
        })
        return false
      }
      api
        .licenseReject({
          pkId: this.storeCode,
          rejectMsg: this.relContent,
        })
        .then((res) => {
          if (res.code == '200') {
            this.$message({
              message: res.msg,
              type: 'success',
            })
            this.isShow = false
            this.relContent = ''
            this.storeCode = ''
            this.getDataList()
          } else {
            this.$message({
              message: res.msg,
              type: 'error',
            })
          }
        })
    },
    handleChange1(val) {
      this.select.licenseProvince = val[0]
      this.select.licenseCity = val[1]
      this.select.licenseCounty = val[2] || ''
    },
    // 删除
    handleDelete(id) {
      this.storeCode = id
      this.isShow = true

      // this.$confirm('是否驳回该申请?', '提示', {
      //   confirmButtonText: '确定',
      //   cancelButtonText: '取消',
      //   type: 'warning',
      // }).then(() => {
      //   api
      //     .licenseReject({
      //       pkId: id,
      //     })
      //     .then((res) => {
      //       this.getDataList()
      //     })
      // })
    },
    openDig() {
      this.$router.push({
        path: 'transSet',
      })
    },
    getDataList() {
      this.loading = true
      api
        .licenseList(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.loading = false
          this.tableData = res.rows
          this.total = res.total
        })
    },
    handleSelectionChange(val) {},
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then((_) => {
        this.download(
          '/member/manager/business/license/export',
          Object.assign({}, this.queryParams, this.select),
          `${'营业执照'}${new Date().getTime()}.xlsx`
        )
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return 'warning-row'
      } else if (rowIndex % 2 == 0) {
        return 'success-row'
      }
      return ''
    },
  },
}
</script>
<style scoped lang="scss">
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-select {
  width: 100%;
}
.uploadIcon ::v-deep .el-upload--picture-card {
  display: none !important; /* 上传按钮隐藏 */
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    .form_all {
      padding: 0px 20px 0 0px;
      // margin-bottom: 20px;
      background: #fff;
      border-radius: 8px;
    }
    .maintop {
      display: flex;
      padding: 0px 0px;
      justify-content: space-between;
      align-items: center;

      background: #f8f8f8;
      .mainbtn {
        .thebtn1 {
          background: #3181e5;
          color: #ffffff;
        }
        .thebtn2 {
          background: #ffad41;
          color: #ffffff;
        }
      }
      .maintitle {
        font-size: 10px;
        font-family: MicrosoftYaHei;
        color: #999999;
      }
    }
  }
  .tem {
    display: flex;
    align-items: center;
    justify-content: center;
    img {
      width: 28px;
      height: 20px;
      margin-right: 3px;
    }
  }
  .isRed {
    color: #ed1d25;
  }
  .isGreen {
    color: #1ab62b;
  }
  .bgImg {
    width: 48px;
    height: 48px;
  }
}
.openClose {
  text-align: right;
  margin-right: 10px;
  color: #3181e5;
}
.dizhi {
  ::v-deep .el-cascader {
    width: 100%;
  }
}
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}
.button_s {
  padding: 3px 5px;
}
.button-s {
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  margin-top: 20px;
  .submit {
    width: 209px;
    height: 48px;
    background: #cccccc;
    border-radius: 5px 5px 5px 5px;
    line-height: 48px;
    text-align: center;
    color: #fff;
    font-size: 18px;
  }
  .colors {
    margin-left: 40px;
    background-color: #48b2fd;
  }
}
</style>
