addSale.vue 8.88 KB
<template>
  <div class="drawer-sale-panel">
    <el-form label-width="150px" :model="addForm">
      <div class="scrm-textRight sale-reload">
        <el-button size="small" slot="append" type="primary" @click="syncEntmicroIsOutsiderStaff" :loading="loading">同步有外部联系人权限的员工</el-button>
      </div>
      <el-form-item label="请选择员工">
        <div class="sale-select">
          <div class="el-input-tag input-tag-wrapper" @click="foucusTagInput">
            <el-tag effect="plain" type="info" v-for="(tag, idx) in innerTags" :key="idx" closable :disable-transitions="false" @close="remove(tag)">
              <i class="el-icon-user-solid"></i>
              {{ tag.staffName }}
            </el-tag>
            <el-input size="small" v-model.trim="newTag" placeholder="选择员工" @input="inputTag" style="outline: none; border: none"></el-input>
          </div>

          <div><el-button size="small" class="sale-select-btn" type="primary" @click="searchEmp">查询</el-button></div>
        </div>
        <div>
          <div class="select-sale-panel">
            <select-emp @selectTable="selectTable" ref="selectEmpTabel"></select-emp>
            <div class="popper__arrow"></div>
          </div>
        </div>
      </el-form-item>
      <el-form-item label="请选择跟进员工类型">
        <div class="emp-type">
          <div @click="handleType(index)" :class="{ checked: typeIndex == index }" class="emp-type-btn" v-for="(item, index) in empType" :key="index">
            {{ item.followName }}
            <i class="el-icon-error" @click="delEmpType(item, index)" v-if="!item.commonFlag"></i>
          </div>
        </div>
        <div class="sale-select">
          <el-input size="small" v-model="empTypeValue" placeholder="添加类型名称" maxlength="8" show-word-limit></el-input>
          <div><el-button size="small" class="sale-select-btn" type="primary" @click="addEmpType">新增</el-button></div>
        </div>
        <div class="sale-type-desc">跟进员工类型最多新增30个,已新增{{ empType.length - empTypeF.length }}个</div>
      </el-form-item>
      <el-form-item label="负责的业务类型" v-if="typeIndex != 2 && typeIndex != 4">
        <el-checkbox-group v-model="selectBusiness" @change="selectType">
          <el-checkbox :disabled="(typeIndex == 0 && item.id != 1) || (typeIndex == 1 && item.id == 1)" v-for="item in businessType" :key="item" :label="item.id">{{ item.businessName }}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item style="text-align: center">
        <el-button @click="onCancel" size="small">取消</el-button>
        <el-button type="primary" @click="onSubmit" size="small">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import selectEmp from './selectEmp'
export default {
  name: 'addSale',

  components: {
    selectEmp
  },

  data() {
    return {
      loading: false,
      editStatus: false,
      addForm: {},
      typeIndex: 0,
      empType: [],
      empTypeF: [],
      empTypeValue: '',
      newTag: '',
      innerTags: [],
      dialog_temp: {},
      businessType: [],
      selectBusiness: []
    }
  },
  watch: {
    typeIndex(val) {
      if (val == 0) {
        this.selectBusiness = [1]
      } else {
        this.selectBusiness = []
      }
    }
  },
  methods: {
    init() {
      this.newTag = ''
      this.innerTags = []
      this.empTypeValue = ''
      this.selectBusiness = []
      if (this.$refs.selectEmpTabel.listTree.length != 0) {
        this.$refs.selectEmpTabel.listEntmicroStaff()
        this.$refs.selectEmpTabel.clearSelection()
      }
    },
    // 获取业务类型
    getBusinessType() {
      var params = {}
      // flag 0-跟进专员调用 1-素材调用
      params.flag = 0
      this.$apis.emp.getListEntBusinessType(params).then(res => {
        this.businessType = res
        this.selectBusiness = [1]
      })
    },
    // 选取业务类型
    selectType(data) {
      console.log(data, 'businessType')
      this.selectBusiness = data
    },
    selectTable(val) {
      this.innerTags = val
    },
    listEntFollowerType() {
      const merchantId = this.$globalState.session.merchantId
      this.$apis.emp.listEntFollowerType({ merchantId }).then(res => {
        this.empType = res
        this.empTypeF = res.filter(item => item.commonFlag)
      })
    },
    handleType(index) {
      this.typeIndex = index
    },
    foucusTagInput() {
      if (this.readOnly || !this.$el.querySelector('.tag-input')) {
        return
      } else {
        this.$el.querySelector('.tag-input').focus()
      }
    },
    remove(row) {
      this.$refs.selectEmpTabel.clearSelect(row)
    },
    //查询
    searchEmp() {
      this.$refs.selectEmpTabel.listEntmicroStaff(this.newTag)
    },
    addEmpType() {
      if (!this.empTypeValue) {
        this.$message.error('请输入类型名称')
        return
      }
      if (this.empType.length == 33) {
        this.$message.error('跟进员工类型最多新增30个')
        return
      }
      let params = {
        followName: this.empTypeValue,
        merchantid: this.$globalState.session.merchantId
      }
      this.$apis.emp.saveFollowerType(params).then(res => {
        this.listEntFollowerType()
      })
      this.empTypeValue = ''
    },
    delEmpType(item, index) {
      this.$apis.emp.deleteFollowerType({ id: item.id }).then(res => {
        if (res) {
          this.listEntFollowerType()
          this.typeIndex = 0
        }
      })
    },
    syncEntmicroIsOutsiderStaff() {
      this.loading = true
      let params = {
        departmentId: 1,
        merchantId: this.$globalState.session.merchantId
      }
      this.$apis.emp.syncEntmicroIsOutsiderStaff(params).then(res => {
        if (res) {
          this.$refs.selectEmpTabel.listEntmicroStaff()
          this.$message({
            message: '同步成功',
            type: 'success'
          })
        }
        this.loading = false
      })
    },
    onSubmit() {
      if (this.innerTags.length == 0) {
        this.$message({
          message: '请选择员工',
          type: 'error'
        })
        return
      }
      let userIds = []
      this.innerTags.forEach(item => {
        userIds.push(item.userId)
      })
      this.$emit('handSelectdEmp', this.empType[this.typeIndex].id, userIds, this.selectBusiness)
    },
    onCancel() {
      if (this.innerTags.length != 0) {
        this.$confirm('当前有内容信息未保存,是否继续返回?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          customClass: 'gl-message-box',
          type: 'warning'
        }).then(() => {
          this.$emit('closeDrawer')
        })
      } else {
        this.$emit('closeDrawer')
      }
    }
  },

  mounted() {
    this.listEntFollowerType(), this.getBusinessType()
  }
}
</script>

<style scoped lang="scss">
.drawer-sale-panel {
  padding: 0px 20px;
  .sale-reload {
    margin-bottom: 10px;
  }
  .sale-select {
    display: flex;
    align-items: center;
  }
  .sale-select-btn {
    margin-left: 8px;
  }
  .sale-type-desc {
    font-size: 14px;
    font-weight: 400;
    color: #adadad;
    line-height: 17px;
    margin-top: 10px;
  }
}
.emp-type {
  margin-bottom: 10px;
  &-btn {
    cursor: pointer;
    display: inline-block;
    padding: 8px 10px;
    margin-bottom: 10px;
    margin-right: 10px;
    position: relative;
    background: #ffffff;
    border-radius: 4px;
    border: 1px solid #e8e8ea;
    line-height: 1;
    font-size: 14px;
    color: #7d7d7d;
    &.checked {
      border: 1px solid #5850ff;
      color: #5850ff;
    }
    i {
      position: absolute;
      right: -6px;
      top: -6px;
      font-size: 12px;
      color: #999999;
    }
  }
}
.input-tag-wrapper {
  position: relative;
  font-size: 14px;
  background-color: #fff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  box-sizing: border-box;
  color: #666;
  display: inline-block;
  outline: none;
  padding: 0 10px 0 5px;
  flex-wrap: wrap;
  line-height: 32px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 100%;
  display: flex;
  align-items: center;
  /deep/ input {
    /* input { */
    /* background-color: red!important;  调试用的样式 */
    outline: none !important;
    border: none !important;
  }
  /deep/ .el-input {
    min-width: 150px;
    width: auto;
    flex: 1;
  }
  i {
    color: #75acff;
    margin-right: 3px;
    font-size: 14px;
  }
}

.el-tag {
  margin-right: 4px;
  height: 26px;
  line-height: 24px;
}

.tag-input {
  background: transparent;
  border: none !important;
  font-size: 14px;
  height: 32px;
  outline: none;
  padding-left: 0;
  width: 100px;
}

.el-input-tag--mini .tag-input {
  height: 24px;
  line-height: 24px;
}

.el-input-tag--small .tag-input {
  height: 32px;
  line-height: 32px;
}

.el-input-tag--medium .tag-input {
  height: 32px;
  line-height: 32px;
}
</style>