CloseReasonManagement.vue 5.02 KB
<template>
  <div class="close-reason-management">
    <div class="toolbar">
      <p class="description">管理商机关闭时可选择的原因</p>
      <el-button @click="isAddDialogOpen = true" type="primary" size="small">
        <i class="el-icon-plus"></i>
        添加原因
      </el-button>
    </div>

    <div class="reason-table">
      <el-table :data="reasons" style="width: 100%">
        <el-table-column prop="reason" label="关闭原因" width="300"></el-table-column>
        <el-table-column prop="category" label="分类" width="200">
          <template slot-scope="scope">
            <el-tag size="mini">{{ scope.row.category }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150">
          <template slot-scope="scope">
            <el-button 
              type="text" 
              size="small" 
              @click="editReason(scope.row)"
            >
              编辑
            </el-button>
            <el-button 
              type="text" 
              size="small" 
              @click="deleteReason(scope.row.id)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 添加/编辑原因对话框 -->
    <el-dialog
      :title="editingReason ? '编辑关闭原因' : '添加关闭原因'"
      :visible.sync="isAddDialogOpen"
      width="500px"
    >
      <el-form :model="reasonForm" :rules="reasonRules" ref="reasonForm" label-width="100px">
        <el-form-item label="关闭原因" prop="reason">
          <el-input 
            v-model="reasonForm.reason" 
            placeholder="请输入关闭原因"
          ></el-input>
        </el-form-item>
        
        <el-form-item label="分类" prop="category">
          <el-input 
            v-model="reasonForm.category" 
            placeholder="请输入分类"
          ></el-input>
        </el-form-item>
      </el-form>
      
      <div slot="footer" class="dialog-footer">
        <el-button @click="isAddDialogOpen = false">取消</el-button>
        <el-button type="primary" @click="submitReasonForm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 模拟关闭原因数据
const mockCloseReasons = [
  { id: '1', reason: '客户价格不接受', category: '价格因素' },
  { id: '2', reason: '客户暂无需求', category: '需求因素' },
  { id: '3', reason: '竞品已安装', category: '竞争因素' },
  { id: '4', reason: '客户联系不上', category: '联系因素' },
  { id: '5', reason: '技术不支持', category: '技术因素' },
  { id: '6', reason: '其他原因', category: '其他' }
]

export default {
  name: 'CloseReasonManagement',
  data() {
    return {
      reasons: mockCloseReasons,
      isAddDialogOpen: false,
      editingReason: null,
      reasonForm: {
        reason: '',
        category: ''
      },
      reasonRules: {
        reason: [
          { required: true, message: '请输入关闭原因', trigger: 'blur' }
        ],
        category: [
          { required: true, message: '请输入分类', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    editReason(reason) {
      this.editingReason = reason
      this.reasonForm = { ...reason }
      this.isAddDialogOpen = true
    },
    deleteReason(id) {
      this.$confirm('确定要删除该原因吗?此操作不可撤销。', '确认删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.reasons = this.reasons.filter(r => r.id !== id)
        this.$message.success('关闭原因删除成功')
      }).catch(() => {
        // 用户取消删除
      })
    },
    submitReasonForm() {
      this.$refs.reasonForm.validate((valid) => {
        if (valid) {
          if (this.editingReason) {
            // 更新原因信息
            const index = this.reasons.findIndex(r => r.id === this.editingReason.id)
            if (index !== -1) {
              this.$set(this.reasons, index, { ...this.editingReason, ...this.reasonForm })
              this.$message.success('关闭原因更新成功')
            }
          } else {
            // 添加新原因
            const newReason = {
              ...this.reasonForm,
              id: `REASON${Date.now()}`
            }
            this.reasons.push(newReason)
            this.$message.success('关闭原因添加成功')
          }
          
          // 重置表单和状态
          this.resetReasonForm()
          this.isAddDialogOpen = false
          this.editingReason = null
        }
      })
    },
    resetReasonForm() {
      this.reasonForm = {
        reason: '',
        category: ''
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.close-reason-management {
  .toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    
    .description {
      color: #909399;
      margin: 0;
    }
  }
  
  .reason-table {
    margin-bottom: 20px;
  }
}
</style>