index.vue 4.77 KB
<template>
  <GLDialog :destroy-on-close="isdestroy" :close-on-click-modal="false" title="跟进人配置" mode="mid" :visible.sync="isFollowSync" :before-close="handleCancel">
    <GLTable :hasPage="false" :hasNum="true" :tableData="followListData" :tableParams="followTableParams">
      <div slot="followName" slot-scope="scope">
        <el-form v-if="scope.scope.followName == ''">
          <el-form-item style="margin-bottom: 0px">
            <el-select v-model="followName" filterable @change="handleSelect" :value-key="'uuid'" placeholder="请选择跟进人">
              <el-option v-for="(item, index) in selectList" :key="index" :label="item.staffName" :disabled="followDisabled(item)" :value="item"></el-option>
            </el-select>
          </el-form-item>
        </el-form>

        <span v-else>{{ scope.scope.followName }}</span>
      </div>
      <div class="table-btns" slot="table-btns" slot-scope="scope">
        <el-button type="text" size="small" @click="handleDelete(scope.scope, scope.index)">删除</el-button>
      </div>
    </GLTable>
    <div class="add-wrap" @click="addLine">
      <i class="el-icon-circle-plus-outline add-icon"></i>
      添加
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="handleCancel">取消</el-button>
      <el-button type="primary" size="small" @click="handleSave">确定</el-button>
    </span>
  </GLDialog>
</template>
<script>
export default {
  data() {
    return {
      isdestroy: true,
      followListData: [],
      followTableParams: {
        listName: 'list',
        tableOption: false,
        tableColumns: [
          {
            label: '跟进人',
            prop: 'followName',
            addHtml: 'followName'
          },
          {
            label: '操作',
            prop: '',
            width: 80,
            fixed: 'right',
            addHtml: 'table-btns'
          }
        ]
      },
      selectList: [],
      followAccountUuid: '',
      followName: ''
    }
  },
  props: {
    isFollowSync: {
      type: Boolean,
      default: false
    }
  },
  created() {
    this.getFollowPersonList()
  },
  mounted() {
    // 获取下拉框的跟进人数据
    this.getSelectFollowPersonList()
  },
  methods: {
    getFollowPersonList() {
      this.$apis.claims
        .getFollowPersonList({
          pageSize: 10000,
          pageNum: 1
        })
        .then(res => {
          this.followListData = res.list
        })
    },
    followDisabled(item) {
      let flag = false
      this.followListData.forEach(element => {
        if (element.followAccountUuid == item.uuid) {
          flag = true
        }
      })
      return flag
    },
    getSelectFollowPersonList() {
      this.$apis.claims.getFollowListApi({}).then(res => {
        this.selectList = res || []
      })
    },
    addLine() {
      if (this.followListData.length > 0 && this.followListData[this.followListData.length - 1].followAccountUuid == '') {
        return
      }
      this.followName = ''
      this.followAccountUuid = ''
      this.followListData.push({ followName: '', followAccountUuid: '' })
    },
    handleSelect(item) {
      this.$apis.claims.addFollowPerson({ followName: item.staffName, followAccountUuid: item.uuid }).then(res => {
        this.$message({
          type: 'success',
          message: '添加成功',
          customClass: 'msgHierarchy'
        })
        this.getFollowPersonList()
      })
    },
    handleSave() {
      if (this.followListData.length > 0 && this.followListData[this.followListData.length - 1].followAccountUuid == '') {
        this.$message({
          type: 'error',
          message: '请选择跟进人',
          customClass: 'msgHierarchy'
        })
        return
      }
      this.$emit('handleClose')
    },
    handleCancel() {
      this.$emit('handleClose')
    },
    //删除
    handleDelete(data, index) {
      if (data.id) {
        this.$confirm('确定要删除吗, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            if (data.id) {
              this.$apis.claims.delFollowPerson({ id: data.id }).then(res => {})
              this.followListData.splice(index, 1)
            }
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除',
              customClass: 'msgHierarchy'
            })
          })
      } else {
        this.followListData.splice(index, 1)
      }
    }
  }
}
</script>
<style scoped lang="scss">
.add-wrap {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: #2a58ad;
  margin-top: 10px;
  cursor: pointer;
  .add-icon {
    margin-right: 6px;
    font-size: 20px;
    color: #2a58ad;
  }
}
</style>