<!--
 * @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">
    <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">
              <el-alert type="info" show-icon :closable="false" style="width: 300px" title="如需新增商户，请联系达摩运营人员"></el-alert>
              <!-- <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 min-width="200">
                  <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.wxEnterpriseType | wxEnterpriseTypeFilter }}</span></template
                  >
                </el-table-column>
                <el-table-column prop="" label="微信开放平台类型" show-overflow-tooltip>
                  <template slot-scope="scope"
                    ><span class="color-606266">{{ scope.row.memberOpenCardFlag ? '不同微信开放平台' : '同一微信开放平台' }}</span></template
                  >
                </el-table-column>
                <!-- <el-table-column prop="" label="导购编辑" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <el-switch v-model="scope.row.clerkEditFlag" :active-value="1" :inactive-value="0" :disabled="scope.row.wxEnterpriseType === 1" @change="clerkEditFlagChange(scope.row, scope.$index)"> </el-switch>
                  </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="操作" min-width="200">
                  <template slot-scope="scope">
                    <el-button type="text" v-if="$getButtonLimit($buttonCode.checkAuth)" :limit-code="$buttonCode.checkAuth" @click="AddAuthMerchant(scope.row)">查看授权设置</el-button>
                    <el-button v-if="$getButtonLimit($buttonCode.bindStoreList)" :limit-code="$buttonCode.bindStoreList" type="text" @click="toStoreList(scope.row)">绑定门店列表</el-button>
                    <el-button v-if="$getButtonLimit($buttonCode.refreshStore)" :limit-code="$buttonCode.refreshStore" type="text" @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>
  </div>
</template>
<script>
import { getRequest } from '@/api/api';
import errMsg from '@/common/js/error';
// import { _debounce } from '@/common/js/public';
export default {
  name: 'authMerchant',
  data() {
    return {
      loading: true,
      // 分页参数
      currentPage: 1,
      pageSize: 20,
      total: 0,
      tableData: [],
      addShow: false
    };
  },
  computed: {},
  filters: {
    wxEnterpriseTypeFilter(v) {
      return v == 0 ? '总部' : v == 1 ? '代理' : '';
    }
  },
  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 => {
          that.loading = false;
          let resData = res.data;
          if (resData.errorCode == 1) {
            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(() => {});
    },
    clerkEditFlagChange(item, index) {
      const that = this;
      that
        .$confirm(`是否确认修改导购编辑权限?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          that.loading = true;
          let para = { wxEnterprieseRelatedId: item.wxEnterpriseRelatedId, clerkEditFlag: that.tableData[index].clerkEditFlag ? 1 : 0 };
          getRequest('/haoban-manage3-web/set-clerk-edit', para)
            .then(res => {
              that.loading = false;
              let resData = res.data;
              if (resData.errorCode == 1) {
                that.$message.success({
                  duration: 1000,
                  message: '修改成功'
                });
                this.getTableList();
                return false;
              }
              this.getTableList();
              errMsg.errorMsg(resData);
            })
            .catch(function(error) {
              that.loading = false;
              that.$message.error({
                duration: 1000,
                message: error.message
              });
              this.getTableList();
            });
        })
        .catch(() => {
          that.tableData[index].clerkEditFlag = that.tableData[index].clerkEditFlag ? 0 : 1;
        });
    }
  },
  mounted() {
    const that = this;
    that.getTableList();
  }
};
</script>
<style type="text/scss" lang="scss" scoped>
.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>
