relevance.vue 9.84 KB
<template>
  <div class="gl-page">
    <div class="page-title">
      <span>门店账户关联企微</span>
      <span class="min-title">关联之后不允许修改,请谨慎操作!</span>
    </div>
    <div class="page-wrapper">
      <div class="wrap-title">
        <span>选择你要绑定的商户/门店</span>
        <span class="wrap-min-title">(只有账户状态正常的门店和商户才允许关联,如未开通,请联系您的专属顾问)</span>
      </div>
      <div class="sel-wrap">
        <div class="sel-lable">商户/门店账户</div>
        <el-cascader ref="cascaderRef1" placeholder="请选择商户/门店" @change="getCurMerchant" :show-all-levels="false" v-model="shopName" :props="mypropParam1" :options="shopList" size="small" style="width: 320px" separator=" " filterable></el-cascader>
      </div>
      <div style="height: 32px"></div>
      <div class="wrap-title">
        <span>选择你要绑定的企微门店</span>
        <span class="wrap-min-title">(企业微信授权成功后,企业微信相关内容才会显示)</span>
      </div>
      <div class="sel-wrap">
        <div class="sel-lable">企业微信</div>
        <el-cascader ref="cascaderRef" @change="getCurDepartment" placeholder="请选择企微门店" :show-all-levels="false" v-model="selectedDepartment" :props="mypropsParam" :options="departmentList" size="small" style="width: 320px" separator=" " filterable></el-cascader>
      </div>
      <div class="btn-wrap">
        <el-button type="purple" size="small" icon="el-icon-link" @click="handlerGL">关联</el-button>
      </div>
    </div>
    <div class="tbale-wrapper">
      <div class="wrap-title">
        <span>绑定的商户/门店</span>
        <span class="wrap-min-title">(绑定成功后,门店账户管理列表-关联的企业微信会显示关联的内容)</span>
      </div>
      <div class="table_widget">
        <GLTable :hasPage="false" :tableParams="tableParams" :tableData="dataList" :headerStyle="{ background: '#F4F6FC', color: '#333333', fontSize: '14px', height: '54px' }">
          <template slot="auth-button" slot-scope="scope" :data="scope.scope">
            <span @click="deleteLine(scope.scope)" class="blue-text">删除</span>
          </template>
        </GLTable>
      </div>
    </div>
    <div style="height: 64px"></div>
    <div class="fixed-footer">
      <div :style="{ width: customWidth + 'px' }" class="btn-custom" @click="closeCurRouter">取消</div>
      <div style="width: 40px"></div>
      <div :style="{ width: customWidth + 'px' }" ref="btnWidth" class="btn-custom pruple" @click="handleMutiGL">确定关联({{ dataList.length }})</div>
    </div>
  </div>
</template>

<script>
import { getMerchantTree, getDepartment, toGL } from '../../api/modules/baseinfoApi'
export default {
  name: '',
  data() {
    return {
      departmentList: [],
      shopList: [],
      qwShop: '',
      tableParams: {
        tableColumns: [
          {
            label: '商户/门店账户',
            prop: 'merchantName'
          },
          {
            label: '企微门店',
            prop: 'departmentName'
          }
        ],
        tableOption: {}
      },
      mypropParam1: {
        value: 'id',
        label: 'label',
        children: 'children',
        disabled: 'entmicroName'
      },
      mypropsParam: {
        label: 'departmentName',
        value: 'id',
        children: 'children',
        checkStrictly: true,
        disabled: 'relevanceMerchant'
      },
      dataList: [],
      customWidth: 113,
      shopName: '',
      selectedDepartment: ''
    }
  },
  created() {
    this.getDepartmentList()
    this.getMerchantList()
  },
  mounted() {},
  methods: {
    // 设置底部按钮宽度
    setBtnWidth() {
      let _this = this
      this.$nextTick(function () {
        _this.customWidth = _this.$refs.btnWidth.clientWidth
      })
    },
    // 获取当前选择的商户
    getCurMerchant(val) {
      let id = val[val.length - 1]
      let labels = this.$refs.cascaderRef1.getCheckedNodes()[0].pathLabels
      let curLabel = labels[labels.length - 1]
      this.curTempMerchant = {
        merchantId: id,
        merchantName: curLabel
      }
    },
    // 获取当前选择的部门
    getCurDepartment(val) {
      let ids = val[val.length - 1]
      let labels = this.$refs.cascaderRef.getCheckedNodes()[0].pathLabels
      let curLabel = labels[labels.length - 1]
      this.tempDepart = {
        departmentId: ids,
        departmentName: curLabel
      }
      this.$refs.cascaderRef.dropDownVisible = false
    },
    getDepartmentList() {
      getDepartment({ id: 1 }).then(res => {
        this.departmentList = res
      })
    },
    getMerchantList() {
      getMerchantTree().then(res => {
        this.shopList = res
      })
    },
    // 关联当前选择的
    handlerGL() {
      if (!this.curTempMerchant) {
        this.$message({
          message: '请选择门店/商户',
          type: 'warning'
        })
        return
      }
      if (!this.tempDepart) {
        this.$message({
          message: '请选择企微门店',
          type: 'warning'
        })
        return
      }
      this.curGLData = {
        ...this.curTempMerchant,
        ...this.tempDepart
      }
      let flag = false
      this.dataList.forEach(item => {
        if (item.departmentId == this.curGLData.departmentId && item.merchantId == this.curGLData.merchantId) {
          flag = true
        }
      })
      if (flag) {
        this.$message({
          message: '该关联已在列表当中',
          type: 'warning'
        })
        return
      }
      this.dataList.push(this.curGLData)
      this.setBtnWidth()
    },
    closeCurRouter() {
      history.go(-1)
    },
    // 批量关联
    handleMutiGL() {
      if (!this.dataList.length) {
        this.$message({
          message: '请选择',
          type: 'warning'
        })
        return
      }
      let merchantIds = []
      let departmentIds = []
      let departNames = []
      let arrpara1 = []
      let arrpara2 = []
      let arrpara3 = []
      this.dataList.forEach(item => {
        merchantIds.push(item.merchantId)
        departmentIds.push(item.departmentId)
        departNames.push(item.departmentName)
      })
      merchantIds.forEach((item, index) => {
        let keyval = `list[${index}].merchantId`
        let val = item
        arrpara1.push({
          [keyval]: val
        })
      })
      departmentIds.forEach((item, index) => {
        let keyval = `list[${index}].departmentId`
        let val = item
        arrpara2.push({
          [keyval]: val
        })
      })
      departNames.forEach((item, index) => {
        let keyval = `list[${index}].departName`
        let val = item
        arrpara3.push({
          [keyval]: val
        })
      })
      let all = [...arrpara1,...arrpara2,...arrpara3]
      let para = Object.assign({},...all)
      toGL(para).then(res => {
        if (res) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
        }
      })
    },
    deleteLine(row) {
      let tempindex = 0
      this.dataList.forEach((item, index) => {
        if (item.departmentId == row.departmentId) {
          tempindex = index
        }
      })
      console.log(tempindex)
      this.$confirm('此操作将删除该项, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.dataList.splice(tempindex, 1)
          this.setBtnWidth()
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
  }
}
</script>
<style lang="scss" scoped>
.gl-page {
  box-sizing: border-box;
  padding: 20px 20px 20px 40px;
}
.page-title {
  font-size: 20px;
  font-weight: 500;
  color: #424242;
  .min-title {
    font-size: 12px;
    font-weight: 500;
    color: #5850ff;
    letter-spacing: 1px;
    margin-left: 10px;
  }
}
.page-wrapper {
  width: 100%;
  height: 320px;
  background: #ffffff;
  box-shadow: 0px 10px 20px 0px rgba(88, 80, 255, 0.1);
  box-sizing: border-box;
  padding: 32px 0 0 20px;
  margin-top: 20px;
  .sel-wrap {
    display: flex;
    align-items: center;
    margin-top: 12px;
    .sel-lable {
      width: 128px;
      box-sizing: border-box;
      padding-right: 10px;
      font-size: 14px;
      font-weight: 400;
      color: #333333;
      text-align: right;
    }
  }
  .btn-wrap {
    padding-left: 20px;
    padding-top: 40px;
  }
}
.tbale-wrapper {
  width: 100%;
  height: 590px;
  background: #ffffff;
  box-shadow: 0px 10px 20px 0px rgba(88, 80, 255, 0.1);
  box-sizing: border-box;
  padding: 20px;
  margin-top: 20px;
  .table_widget {
    margin-top: 16px;
    // height: 439px;
  }
  .blue-text {
    font-size: 14px;
    font-weight: 400;
    color: #5850ff;
    cursor: pointer;
  }
}
.fixed-footer {
  position: fixed;
  // left: 0;
  right: 0;
  bottom: 0;
  width: calc(100% - 177px);
  // background: #5850ff;
  height: 64px;
  z-index: 10;
  background: #ffffff;
  box-shadow: 0px -1px 1px 0px rgba(88, 80, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  .btn-custom {
    font-size: 14px;
    color: #fff;
    font-weight: 400;
    background: #999999;
    border-radius: 4px;
    cursor: pointer;
    text-align: center;
    padding: 8px 0;
  }
  .pruple {
    background: #5850ff;
  }
}
.wrap-title {
  font-size: 16px;
  font-weight: 500;
  color: #333333;
  .wrap-min-title {
    font-size: 12px;
    font-weight: 500;
    color: #999999;
    letter-spacing: 1px;
    margin-left: 10px;
  }
}
// table{
//   max-height: 430px!important;
// }
.el-button--purple {
  color: #fff;
  background-color: #5850ff;
  border-color: #5850ff;
  border-radius: 4px;
}
</style>