<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2018-10-10 14:44:45
 * @LastEditors: 无尘
 * @LastEditTime: 2020-09-22 11:11:55
 -->
<template>
  <div class="reviewed-wrap common-set-wrap">
    <div class="right-content">
      <div class="right-box">
        <div class="reviewed-body-head">
          <el-input class="w-250" maxlength="50" placeholder="请输入提交人姓名或门店名称" prefix-icon="el-icon-search" v-model="searchValue" clearable @clear="clearSearch" @keyup.native="value => searchEnterFun(value, searchInput)"></el-input>
          <el-select class="w-130 m-l-10" v-model="filterValue" placeholder="全部状态" @change="getTableList">
            <el-option v-for="item in filterOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
          <el-select class="w-168 m-l-10" placeholder="全部品牌">
            <el-option label="全部品牌" value=""></el-option>
          </el-select>
          <span class="p-l-10 font-12 color-909399">展示管理员审核记录及门店成员自助增删导购及用户关联记录</span>
        </div>
        <div class="reviewed-body-content">
          <el-table ref="multipleTable" v-loading="loading" :data="tableData" tooltip-effect="dark" style="width: 100%">
            <el-table-column label="审核事项">
              <template slot-scope="scope">
                <span v-if="scope.row.auditType == 1">门店信息变更</span>
                <span v-if="scope.row.auditType == 2">导购绑定</span>
                <span v-if="scope.row.auditType == 3">导购新增</span>
                <span v-if="scope.row.auditType == 4">导购删除</span>
                <!--<span v-if="scope.row.auditType == 5">导购解绑</span>-->
              </template>
            </el-table-column>
            <!-- <el-table-column label="品牌">
              <template slot-scope="scope">
                {{ scope.row.brandName || '--' }}
              </template>
            </el-table-column> -->
            <el-table-column label="提交人" show-overflow-tooltip>
              <template slot-scope="scope">
                <div class="flex">
                  <el-popover placement="top-start" width="300" trigger="hover" @show="showSingleInfo(scope.row.commitStaffId)">
                    <div class="apply-info-detail">
                      <div class="flex">
                        <div class="apply-info-img flex-align-center flex-pack-center bg-82C5FF ">
                          <i v-if="!userData.headImg" class="iconfont-hb3 icon-yewuduanmorentouxian"></i>
                          <img v-else :src="userData.headImg" alt="img" />
                        </div>
                        <div class="flex flex-column apply-info-right flex-space-between">
                          <div class="apply-info-name">
                            {{ userData.staffName || '--' }} ( {{ userData.position || '--' }})
                            <!-- <i :class="[userData.sex == 2 ? 'icon-xingbienv color-FF585C' : 'icon-xingbienan color-508CEE', 'iconfont-hb3']"></i> -->
                          </div>
                          <div class="apply-info-phone">
                            <span class="w-80">手机号：</span><span class="w-130">{{ userData.nationCode == '86' ? userData.phoneNumber : '+' + userData.nationCode + '-' + userData.phoneNumber }}</span>
                          </div>
                          <div class="apply-info-store">
                            <span class="w-80">所属部门：</span><span class="w-130">{{ userData.departmentName || '--' }}</span>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div slot="reference">
                      <div class="flex flex-align-center flex-pack-center bg-82C5FF table-head-pic cursor-pointer">
                        <i v-if="!scope.row.commitStaffImg" class="iconfont-hb3 icon-yewuduanmorentouxian"></i>
                        <img v-else :src="scope.row.commitStaffImg" alt="img" />
                      </div>
                    </div>
                  </el-popover>
                  <div class="flex flex-column apply-info" style="overflow: hidden;text-overflow: ellipsis;white-space:nowrap;">
                    <span>{{ scope.row.commitStaffName }}</span>
                    <span class="font-13" style="overflow: hidden;text-overflow: ellipsis;white-space:nowrap;">{{ scope.row.commitStoreName }}</span>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="详情" show-overflow-tooltip>
              <template slot-scope="scope">
                <span v-if="scope.row.changeField != 6">{{ scope.row.detail }}</span>
                <div class="line-hidden-2" v-if="scope.row.changeField == 6">
                  <!-- <span> {{ scope.row.auditType == 0? '门店信息变更': scope.row.auditType == 0? '新增成员': '成员离职'}}</span> -->
                  <span>{{ scope.row.detail }}</span>
                  <el-button type="text" @click="showStoreChange(scope.row)">查看详情</el-button>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="提交时间" show-overflow-tooltip>
              <template slot-scope="scope">
                <div class="line-h-18">{{ scope.row.createTime | timeStampToYmd }}</div>
                <div class="line-h-18">{{ scope.row.createTime | timeStampToHms }}</div>
              </template>
            </el-table-column>
            <!-- <el-table-column label="审核时间" show-overflow-tooltip>
              <template slot-scope="scope">
                <div class="line-h-18">{{ scope.row.updateTime | timeStampToYmd }}</div>
                <div class="line-h-18">{{ scope.row.updateTime | timeStampToHms }}</div>
              </template>
            </el-table-column> -->
            <el-table-column label="审核人" show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.auditName || '--' }}
              </template>
            </el-table-column>
            <el-table-column label="状态">
              <template slot-scope="scope">
                <span :class="['span-dot', scope.row.auditStatus == 1 || scope.row.auditStatus == 4 ? 'bg-52c41a' : 'bg-f5222d']"></span><span v-if="scope.row.auditStatus == 1">已同意</span><span v-if="scope.row.auditStatus == 4">无需审核</span>
                <!-- <el-popover class="inline-block" placement="top" width="150" trigger="hover">
                  <div class="tooltip-text">{{ scope.row.auditReason }}</div>
                  <div slot="reference">
                    <span class="" v-if="scope.row.auditStatus == 2" @click="toggleReason(scope.row)" style="cursor: pointer;padding-bottom: 2px; border-bottom: 1px dashed #2F54EB;">已拒绝</span>
                  </div>
                </el-popover> -->
                <el-tooltip v-if="scope.row.auditStatus == 2 || scope.row.auditStatus == 5" class="item" effect="dark" :content="scope.row.auditReason" placement="top-start">
                  <span style="cursor: pointer;padding-bottom: 2px; border-bottom: 1px dashed #2F54EB;">{{ scope.row.auditStatus == 5 ? '审核失败' : '已拒绝' }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
          <div class="block common-wrap__page text-right" v-if="tableData.length != 0">
            <dm-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[20, 40, 60, 80]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </dm-pagination>
          </div>
        </div>
      </div>
    </div>
    <!-- 门店变更 -->
    <storeChange v-model="showStoreDialog" :storeChangeData="storeChangeData"> </storeChange>
  </div>
</template>
<script>
import storeChange from '@/components/review/store-change.vue';
import errMsg from '@/common/js/error';
import { getRequest, postRequest } from '@/api/api';
import { _debounce } from '@/common/js/public';
export default {
  name: 'reviewed',
  data() {
    return {
      wxEnterpriseId: sessionStorage.getItem('userInfos') ? JSON.parse(sessionStorage.getItem('userInfos')).wxEnterpriseId : '',
      filterValue: '',
      filterOptions: [
        // {
        //   label: '待审核',
        //   value: '0'
        // },
        {
          label: '全部状态',
          value: ''
        },
        {
          label: '已同意',
          value: '1'
        },
        {
          label: '已拒绝',
          value: '2'
        },
        {
          label: '无需审核',
          value: '4'
        },
        {
          label: '审核失败',
          value: '5'
        }
      ],
      searchValue: '', // 搜索
      loading: false,
      tableData: [
        // {
        //   enterpriseAuditingId: 1,
        //   auditType: 0, // 审核类型（0：门店信息变更，1：新增成员，2：成员离职）
        //   detail: '',
        //   relationId: 112,
        //   applyId: '12223233',
        //   applyName: '测试',
        //   headPic: '',
        //   storeName: '测试',
        //   refuseReason: '111111',
        //   auditStatus: 2, //审核状态 （0:待审核 ,1: 已同意,2:已拒绝）
        //   beforeContent: '',
        //   afterContent: '',
        //   createTime: '2018-12-09 14:34:56'
        // }
      ],
      multipleSelection: [],
      // 分页参数
      currentPage: 1,
      pageSize: 20,
      total: 0,
      // store
      showStoreDialog: false,
      storeChangeData: {},
      // user
      userData: {
        staffName: '',
        phoneNumber: '',
        nationCode: '',
        postion: '',
        departmentName: '',
        headImg: ''
      }
    };
  },
  computed: {},
  methods: {
    /**
     * 搜索标签清空
     */
    clearSearch() {
      const that = this;
      that.currentPage = 1;
      that.getTableList();
    },

    /**
     * 搜索标签
     */
    searchEnterFun: _debounce(function(e) {
      const that = this;
      let searchVal = String(e.target.value).trim();
      if (!searchVal) {
        return false;
      }
      that.currentPage = 1;
      that.getTableList();
    }, 200),

    toggleReason(item) {
      const that = this;
      item.visible = true;
      that.tableData.forEach(function(ele, index) {
        if (ele.enterpriseAuditingId != item.enterpriseAuditingId) {
          ele.visible = false;
        }
      });
    },

    /**
     * 表格---多选
     *  @param {Array} val
     */
    handleSelectionChange(val) {
      const that = this;
      that.multipleSelection = val;
    },

    /**
     * 分页---页码变化
     *  @param {Number} val
     */
    handleSizeChange(val) {
      const that = this;
      that.currentPage = 1;
      that.pageSize = val;
      that.getTableList();
    },

    /**
     * 分页---当前页变化
     *  @param {Number} val
     */
    handleCurrentChange(val) {
      const that = this;
      that.currentPage = val;
      // let fullPath = that.$route.fullPath;
      that.getTableList();
    },

    /**
     * 获取头像处显示信息
     */
    /* eslint-disable */
      showSingleInfo(memberId) {
        const that = this;
        const para = {
          staffId: memberId
        };
        postRequest('/haoban-manage3-web/get-staff-info', para)
          .then(res => {
            let resData = res.data;
            if (resData.errorCode == 1) {
              that.userData = resData.result;
              return;
            }
            errMsg.errorMsg(resData);
          })
          .catch(function(error) {
            that.$message.error({
              duration: 1000,
              message: error.message
            });
          });
      },

      /**
       * 显示门店变更
       */
      showStoreChange(item) {
        const that = this;
        that.storeChangeData = {
          beforeContent: [],
          afterContent: []
        };
        that.showStoreDialog = true;
        that.storeChangeData = {
          beforeContent: item.oldValue != '' ? item.oldValue.split(',') : [],
          afterContent: item.newValue != '' ? item.newValue.split(',') : []
        };
      },
      /**
       * 获取列表数据
       */
      getTableList(val) {
        const that = this;
        if (val) {
          that.currentPage = 1;
        }
        that.loading = true;
        let para = {
          wxEnterpriseId: that.wxEnterpriseId,
          auditStatus: that.filterValue,
          // auditStatus: '1',
          auditFlag: '1',
          search: that.searchValue || '', // 搜索字段
          pageNum: that.currentPage, // 当前页
          pageSize: that.pageSize, // 一页显示个数
        };
        getRequest('/haoban-manage3-web/audit/find-page', para)
          .then(res => {
            let resData = res.data;
            that.loading = false;
            if (resData.errorCode == 1) {
              that.tableData = resData.result.result || [];
              that.total = resData.result.totalCount;
              return;
            }
            errMsg.errorMsg(resData);
          })
          .catch(function(error) {
            that.loading = false;
            that.$message.error({
              duration: 1000,
              message: error.message
            });
          });
      }
    },
    mounted() {
      const that = this;
      that.getTableList();
    },
    components: {
      storeChange
    }
  };
</script>
<style lang="scss" scoped>
  /* flex */

  .flex {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
  }

  .flex-1 {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
  }

  .flex-column {
    -webkit-flex-direction: column;
    -moz-flex-direction: column;
    -ms-flex-direction: column;
    -o-flex-direction: column;
    flex-direction: column;
  }

  .flex-row {
    -webkit-flex-direction: row;
    -moz-flex-direction: row;
    -ms-flex-direction: row;
    -o-flex-direction: row;
    flex-direction: row;
  }

  .flex-align-center {
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .flex-pack-center {
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
  }

  .flex-start {
    -webkit-justify-content: flex-start;
    -moz-justify-content: flex-start;
    -ms-justify-content: flex-start;
    -o-justify-content: flex-start;
    justify-content: flex-start;
  }

  .flex-wrap {
    -webkit-flex-wrap: wrap;
    -moz-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
    -o-flex-wrap: wrap;
    flex-wrap: wrap;
  }

  .flex-space-between {
    -webkit-justify-content: space-between;
    -moz-justify-content: space-between;
    -ms-justify-content: space-between;
    -o-justify-content: space-between;
    justify-content: space-between;
  }

  .span-dot {
    display: inline-block;
    vertical-align: middle;
    width: 6px;
    height: 6px;
    margin-right: 6px;
    border-radius: 3px;
    &.bg-52c41a {
      background: #52c41a;
    }
    &.bg-f5222d {
      background: #f5222d;
    }
  }

  .inline-block {
    display: inline-block;
  }

  .bg-82C5FF {
    background: #82c5ff;
  }

  .color-508CEE {
    color: #508cee;
  }

  .color-FF585C {
    color: #ff585c;
  }

  .font-13 {
    font-size: 13px;
  }

  .font-14 {
    font-size: 14px;
  }

  .line-h-18 {
    line-height: 18px;
  }

  .line-hidden-2 {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    height: 46px;
    overflow: hidden;
    white-space: pre-wrap;
    span {
      display: -webkit-box;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      -webkit-box-orient: vertical;
      box-orient: vertical;
      max-height: 46px;
      overflow: hidden;
    }
  }

  .w-80 {
    width: 80px;
  }

  .w-130 {
    display: inline-block;
    width: 130px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .w-168 {
    display: inline-block;
    width: 168px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .w-250 {
    width: 250px;
  }

  .m-l-10 {
    margin-left: 10px;
  }

  .text-center {
    text-align: center;
  }

  .text-right {
    text-align: right;
  }

  .common-wrap__page {
    margin-top: 24px;
  }

  .tooltip-text {
    width: 100%;
    white-space: pre-wrap;
    word-break: break-all;
  }

  .right-content {
    padding: 20px;
    .right-box {
      .w-280 {
        width: 280px;
      }
      .w-514 {
        width: 514px;
      }
      .m-l-20 {
        margin-left: 20px;
      }
      .m-t-45 {
        margin-top: 45px;
      }
      .v-align-b {
        vertical-align: bottom;
      }
      .text-center {
        text-align: center;
      }
      .reviewed-body-head {
        margin-bottom: 22px;
      }
      .table-head-pic {
        width: 35px;
        height: 35px;
        border-radius: 4px;
        i {
          font-size: 20px;
          color: #e5f3ff;
        }
        img {
          width: 35px;
          height: 35px;
          border-radius: 3px;
        }
      }
      .apply-info {
        margin-left: 15px;
        line-height: 18px;
        span {
          font-size: 14px;
          color: #606266;
          &.font-13 {
            font-size: 13px;
          }
        }
      }
    }
  }

  .apply-info-detail {
    /*padding: 18px;*/
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    .apply-info-img {
      width: 64px;
      height: 64px;
      border-radius: 12px;
      text-align: center;
      i {
        font-size: 106px;
        color: #e5f3ff;
      }
      img {
        width: 64px;
        height: 64px;
        border-radius: 12px;
      }
    }
    .apply-info-name {
      font-size: 16px;
      color: #606266;
    }
    .apply-info-right {
      width: 229px;
      padding-left: 16px;
      font-size: 13px;
      color: #606266;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
      .w-80 {
        display: inline-block;
        vertical-align: top;
        color: #606266;
      }
      .w-130 {
        color: #606266;
      }
    }
  }

  .el-icon-question {
    font-size: 14px;
    color: #c0c4cc;
    cursor: pointer;
  }
</style>
