<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-03-20 14:36:37
 * @LastEditors: 无尘
 * @LastEditTime: 2020-08-19 17:13:01
 -->
<template>
  <div class="my-customer-wrap common-set-wrap authMerchant">
    <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">
            <div class="flex flex-space-between flex-align-center">
              <div class="overstore-tip">
                <div role="alert" class="el-alert el-alert--info flex flex-align-center">
                  <i class="el-alert__icon el-icon-warning font-13 color-2f54eb"></i>
                  <div class="el-alert__content">
                    <p class="el-alert__title color-303133 font-13">绑定门店：绑定门店拥有门店资源管理权限。能查看数据，绑定导购账号，管理门店等。</p>
                    <p class="el-alert__title color-303133 font-13">刷新门店：编辑或修改绑定门店范围，手动刷新获取最近门店列表。</p>
                  </div>
                </div>
              </div>
              <div>
                <span class="color-909399 font-13 m-r-19">最多授权 10 个商户</span>
                <el-button v-if="tableData.length < 10" type="primary" @click="AddAuthMerchant">新建授权</el-button>
              </div>
            </div>
            <div class="m-t-20">
              <el-table class="select-table" ref="multipleTable" v-loading="loading" :data="tableData" tooltip-effect="dark" :style="{ width: '100%', minHeight: tableH }">
                <el-table-column prop="" label="审核事项" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <div class="ul-li-cell flex">
                      <div class="cell-img">
                        <img :src="scope.row.enterpriseLogo" alt="img" />
                      </div>
                      <div class="cell-info">
                        <div class="cell-info-name flex font-14 color-303133">
                          <span class="gic-name color-606266">{{ scope.row.enterpriseName || '--' }}</span
                          ><span class="gic-version color-606266">{{ scope.row.version || '3.0' }}</span>
                        </div>
                        <div class="cell-info-name flex font-14 color-606266">
                          <span class="gic-name">{{ scope.row.brandName || '--' }}</span>
                        </div>
                      </div>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column prop="" label="提交人" show-overflow-tooltip>
                  <template slot-scope="scope"
                    ><span class="color-606266">{{ scope.row.staffName || '--' }}</span></template
                  >
                </el-table-column>
                <el-table-column prop="" label="完成时间" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <div class="line-18 color-606266">{{ scope.row.createTime | timeStampToYmd }}</div>
                    <div class="line-18 color-606266">{{ scope.row.createTime | timeStampToHms }}</div>
                  </template>
                </el-table-column>
                <el-table-column prop="" label="操作">
                  <template slot-scope="scope">
                    <el-button type="text" size="small" @click="AddAuthMerchant(scope.row)">编辑授权设置</el-button>
                    <el-button type="text" size="small" @click="toStoreList(scope.row)">绑定门店列表</el-button>
                    <el-button slot="reference" type="text" size="small" @click="refreshStoreBind(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="8"> </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 { getRequest } from '@/api/api';
import errMsg from '@/common/js/error';
// import { _debounce } from '@/common/js/public';
export default {
  name: 'authMerchant',
  data() {
    return {
      bgHeight: window.screen.availHeight - 104 + 'px',
      // 面包屑参数
      navpath: [
        {
          name: '首页',
          path: '/index'
        },
        {
          name: '通讯录',
          path: '/contactsList'
        },
        {
          name: '授权商户',
          path: ''
        }
      ],
      loading: true,
      // 分页参数
      currentPage: 1,
      pageSize: 20,
      total: 0,
      tableData: [],
      addShow: false,
      activeBrand: ''
    };
  },
  computed: {},
  methods: {
    /**
     * 新增企业
     */
    AddAuthMerchant(item) {
      if (item.enterpriseId) {
        this.changeRoute(`authMerchantForm?enterprise=${item.enterpriseId}`);
      } else {
        this.changeRoute(`authMerchantForm`);
      }
    },
    refreshData(res) {
      const that = this;
      that.addShow = false;
      if (res == 'close') {
        return false;
      }
      that.getTableList();
    },
    /**
     * 路由跳转
     *  @param {path} path
     */
    changeRoute(path) {
      this.$router.push(path);
    },
    toStoreList(item) {
      this.changeRoute(`merchantStoreList?enterprise=${item.enterpriseId}`);
    },

    /**
     * 分页---页码变化
     *  @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;
      that.getTableList();
    },
    /**
     * 获取列表数据
     */
    getTableList(val) {
      const that = this;
      that.loading = true;
      let para = {};
      getRequest('/haoban-manage3-web/wx-enterprise-list', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            that.loading = false;
            that.tableData = resData.result || [];
            return false;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.loading = false;
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    refreshStoreBind(item) {
      const that = this;
      that
        .$confirm(`确认要刷新吗?`, '', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          that.loading = true;
          let para = { enterpriseId: item.enterpriseId };
          getRequest('/haoban-manage3-web/flush-bind-store-list', para)
            .then(res => {
              that.loading = false;
              let resData = res.data;
              if (resData.errorCode == 1) {
                that.$message.success({
                  duration: 1000,
                  message: '刷新成功'
                });
                return false;
              }
              errMsg.errorMsg(resData);
            })
            .catch(function(error) {
              that.loading = false;
              that.$message.error({
                duration: 1000,
                message: error.message
              });
            });
        })
        .catch(() => {});
    }
  },
  watch: {
    activeBrand: function(newData, oldData) {
      const that = this;
      that.activeBrand = newData;
    },
    activeGroup: function(newData, oldData) {
      const that = this;
      that.activeGroup = newData;
    }
  },
  mounted() {
    const that = this;
    that.getTableList();
    document.documentElement.style.backgroundColor = '#f0f2f5';
  },
  destroyed() {
    document.documentElement.style.backgroundColor = '#fff';
  },
  components: {
    navCrumb
  }
};
</script>
<style type="text/scss" lang="scss" scoped>
.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;
  }
}
.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;
}
.el-alert--info {
  background: rgba(240, 245, 255, 1);
  border-radius: 2px;
  border: 1px solid rgba(133, 165, 255, 1);
  -webkit-box-align: flex-start;
  -webkit-align-items: flex-start;
  -ms-flex-align: flex-start;
  align-items: flex-start;
  .el-alert__icon {
    font-size: 12px;
    padding-top: 3px;
  }
}
.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;
        .overstore-body {
          background: #fff;
        }
        .daily-set-wrap {
          height: 100%;
          background: #fff;
        }
        .app-detail-wrap {
          height: 100%;
          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: 370px;
      height: 20px;
      line-height: 19px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .gic-name {
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      font-size: 14px;
      color: #303133;
      line-height: 18px;
    }
    .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>
