<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-03-20 14:36:37
 * @LastEditors: 无尘
 * @LastEditTime: 2020-11-30 11:35:25
 -->
<template>
  <div class="my-customer-wrap common-set-wrap">
    <nav-crumb :navpath="navpath"> </nav-crumb>
    <div class="right-content">
      <div class="right-box" style="min-height: calc(100vh - 104px);">
        <div class="apps-content flex" style="min-height: calc(100vh - 104px);">
          <div class="apps-content-right" v-loading="loading">
            <div class="flex flex-space-between">
              <div class="" style="width:643px;">
                <div role="alert" class="el-alert el-alert--info flex flex-align-start" style="width:643px;">
                  <i class="el-alert__icon el-icon-info font-12 color-2f54eb"></i>
                  <div class="el-alert__content">
                    <span class="el-alert__title color-606266 font-14">提示：授权的商户，需在同一个微信开放平台主体下；最多授权10个商户。  </span><el-button type="text" @click="openUrl">主体查询方法</el-button>
                  </div>
                </div>
              </div>
              <el-button type="primary" @click="changeRoute('/newAuthMerchant')">新建GIC商户授权</el-button>
            </div>
            <div class="m-t-20">
              <el-table class="select-table" ref="multipleTable" :data="tableData" tooltip-effect="dark" :style="{ width: '100%' }">
                <el-table-column prop="" label="商户列表" width="238" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <div class="ul-li-cell flex">
                      <div class="cell-img">
                        <img v-if="scope.row.enterpriseLogo" :src="scope.row.enterpriseLogo" alt="img" />
                        <img v-else src="../../assets/member.png" alt="img" />
                      </div>
                      <div class="cell-info">
                        <div class="cell-info-name flex font-14 color-303133">
                          <span class="gic-name">{{ scope.row.enterpriseName || '--' }}</span><span class="gic-version">{{ scope.row.version || '--' }}</span>
                        </div>
                        <div class="cell-info-name flex font-14 color-303133">
                          <span class="gic-name">{{ scope.row.companyName || '--' }}</span>
                        </div>
                      </div>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column prop="" label="绑定门店" show-overflow-tooltip>
                  <template slot="header" >
                    <el-tooltip class="item" effect="dark" placement="right">
                      <div slot="content">
                        绑定门店拥有门店资源管理权限。能查看数据，绑定导购账号，管理门店等
                      </div>
                      <span class="common-bottom-border">绑定门店</span>
                    </el-tooltip>
                  </template>
                  <template slot-scope="scope">
                    {{ scope.row.bindRange || '--' }}
                  </template>
                </el-table-column>
                <el-table-column prop="" label="共享门店" show-overflow-tooltip>
                  <template slot="header" >
                    <el-tooltip class="item" effect="dark" placement="right">
                      <div slot="content">
                        共享门店拥有门店资源查看权限。仅能授权查看数据，<br/>如会员数据，任务数据等，但无法操作及进行导购账号绑定
                      </div>
                      <span class="common-bottom-border">共享门店</span>
                    </el-tooltip>
                  </template>
                  <template slot-scope="scope">
                    {{ scope.row.shareRange || '--' }}
                  </template>
                </el-table-column>
                <el-table-column prop="" label="提交人" show-overflow-tooltip>
                  <template slot-scope="scope">{{ scope.row.referStaffName || '--' }}</template>
                </el-table-column>
                <el-table-column prop="" label="授权时间" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <div class="line-18">{{ scope.row.createTime | timeStampToYmd }}</div>
                    <div class="line-18">{{ scope.row.createTime | timeStampToHms }}</div>
                  </template>
                </el-table-column>
                <el-table-column prop="" label="更新时间" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <div class="line-18">{{ scope.row.updateTime | timeStampToYmd }}</div>
                    <div class="line-18">{{ scope.row.updateTime | timeStampToHms }}</div>
                  </template>
                </el-table-column>
                <el-table-column prop="" label="操作" width="203">
                  <template slot-scope="scope">
                    <el-button type="text" @click="toEdit(scope.$index, scope.row)">编辑授权设置</el-button>
                    <el-button type="text" @click="toAuditLog(scope.$index, scope.row)">审核日志</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <!-- <div class="block common-wrap__page text-right m-t-24" 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>
      </div>
    </div>
    <!-- <vue-gic-footer></vue-gic-footer> -->
  </div>
</template>
<script>
import navCrumb from '@/components/nav/nav.vue';
import fetch from '@/api/merchant-auth.js';
const { getAuthEnterprise } = fetch;
// import { _debounce } from '@/common/js/public';
export default {
  name: 'AuthMerchant',
  components: {
    navCrumb
  },
  data() {
    return {
      // 面包屑参数
      navpath: [
        /* {
          name: '首页',
          path: '/index'
        }, */
        {
          name: '通讯录',
          path: '/contactsList'
        },
        {
          name: '授权商户',
          path: ''
        }
      ],
      wxEnterpriseId: localStorage.getItem('haoBanUser') ? JSON.parse(localStorage.getItem('haoBanUser')).wxEnterpriseId : '',
      // 分页参数
      currentPage: 1,
      pageSize: 20,
      total: 0,
      tableData: [],
      loading: false
    };
  },
  mounted() {
    const that = this;
    that.getTableList();
    document.documentElement.style.backgroundColor = '#f0f2f5';
  },
  destroyed() {
    document.documentElement.style.backgroundColor = '#fff';
  },
  methods: {
    /**
     * @description: 编辑授权
     * @param {Number} index
     * @param {Object} row
     * @author: 无尘
     */
    toEdit(index, row) {
      const that = this;
      that.changeRoute(`/newAuthMerchant?enterpriseId=${row.enterpriseId}`);
    },
    /**
     * @description: 审核日志
     * @param {Number} index
     * @param {Object} row
     * @author: 无尘
     */
    toAuditLog(index, row) {
      const that = this;
      that.changeRoute(`/auditLog?enterpriseId=${row.enterpriseId}`);
    },
    /**
     * @description: url 跳转
     * @author: 无尘
     */
    openUrl() {
      window.open('https://developers.weixin.qq.com/community/develop/doc/00046610a9cbb0fd80f9a7dd354c09');
    },
    /**
     * @description: 路由跳转
     * @param {String} path
     * @author: 无尘
     */
    changeRoute(path) {
      this.$router.push(path);
    },
    /**
     * @description: 分页---页码变化
     * @param {Number} val
     * @author: 无尘
     */
    handleSizeChange(val) {
      const that = this;
      that.currentPage = 1;
      that.pageSize = val;
      that.getTableList();
    },
    /**
     * @description: 分页---当前页变化
     * @param {Number} val
     * @author: 无尘
     */
    handleCurrentChange(val) {
      const that = this;
      that.currentPage = val;
      that.getTableList();
    },
    /**
     * @description:获取列表数据
     * @author: 无尘
     */
    getTableList() {
      const that = this;
      that.loading = true;
      let para = {
        wxEnterpriseId: that.wxEnterpriseId
      };
      getAuthEnterprise(para)
        .then(res => {
          that.loading = false;
          that.tableData = res.result || [];
        })
        .catch(function(error) {
          that.loading = false;
        });
    }
  }
};
</script>
<style type="text/less" lang="less" scoped>
.span-dot {
  display: inline-block;
  vertical-align: middle;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 3px;
  &.bg-33af4a  {
    background: #33af4a ;
  }
  &.bg-f5222d {
    background: #f5222d;
  }
}
.bg-82C5FF {
  background: #82c5ff;
}
.color-508CEE {
  color: #508cee;
}
.color-FF585C {
  color: #ff585c;
}
.line-h-18 {
  line-height: 18px;
}
.tooltip-text {
  width: 100%;
  white-space: pre-wrap;
  word-break: break-all;
}
.w-293 {
  width: 293px;
}
.w-191 {
  width: 191px;
}
.common-bottom-border {
  cursor: pointer;
  padding-bottom: 2px;
  border-bottom: 1px dashed #2f54eb;
}
.my-customer-wrap {
  height: 100%;
}
.right-content {
  /*width: 100%;*/
  padding: 0 20px 20px 20px;
  min-height: calc(100% - 160px);
  .right-box {
    background: #fff;
    min-height: 500px;
    padding: 0px;
    .apps-content {
      .apps-content-right {
        width: 100%;
        padding: 20px;
        background: #fff;
        .common-set-wrap {
          height: 100%;
          background: #fff;
        }
      }
    }
  }
}

.ul-li-cell {
  .cell-img {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    height: 40px;
    border-radius: 2px;
    border: 1px solid rgba(228, 231, 237, 1);
    box-sizing: border-box;
    img {
      width: 100%;
    }
  }
  .cell-info {
    padding-left: 10px;
    box-sizing: border-box;
    .cell-info-name {
      max-width: 157px;
      height: 20px;
      line-height: 19px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .gic-name {
      font-size: 14px;
      color: #303133;
      line-height: 18px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .gic-version {
      display: inline-block;
      padding: 0 5px;
      height: 15px;
      line-height: 15px;
      margin-left: 5px;
      background: rgba(255, 241, 240, 1);
      border-radius: 2px;
      border: 1px solid rgba(255, 163, 158, 1);
      font-size: 10px;
      color: #f5222d;
    }
  }
}
</style>
