privilege-ops-panel.vue 3.88 KB
<template>
  <div class="privilege-ops-panel">
    <el-alert
      type="warning"
      show-icon
      :closable="false"
      title="越权操作说明"
      description="此处操作不受小程序跨月、开单作废开关等限制,但仍会校验是否存在消耗、退卡、补缴、储扣等关联数据。仅系统管理员可用,所有操作写入业务日志。"
      class="privilege-alert"
    />

    <el-card shadow="never" class="config-section">
      <div slot="header" class="config-section__header">
        <span>开单作废</span>
        <span class="config-section__tag config-section__tag--danger">越权</span>
      </div>
      <p class="config-section__tip">
        输入开单 ID 后执行作废。若该单已产生耗卡、退卡、有效补缴或储扣引用,系统将拒绝作废。
      </p>
      <el-form ref="formRef" :model="form" :rules="rules" label-width="96px" class="privilege-form">
        <el-form-item label="开单 ID" prop="id">
          <el-input
            v-model.trim="form.id"
            clearable
            placeholder="请输入开单记录 ID"
            maxlength="50"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="作废原因" prop="remarks">
          <el-input
            v-model.trim="form.remarks"
            type="textarea"
            :rows="3"
            maxlength="200"
            show-word-limit
            placeholder="请填写作废原因,便于审计追溯"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="danger" :loading="submitting" @click="handleSubmit">执行作废</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { privilegeCancelBilling } from '@/api/extend/privilegeOps'

export default {
  name: 'PrivilegeOpsPanel',
  data() {
    return {
      submitting: false,
      form: {
        id: '',
        remarks: ''
      },
      rules: {
        id: [{ required: true, message: '请输入开单 ID', trigger: 'blur' }],
        remarks: [{ required: true, message: '请填写作废原因', trigger: 'blur' }]
      }
    }
  },
  methods: {
    resetForm() {
      this.form = { id: '', remarks: '' }
      this.$nextTick(() => {
        this.$refs.formRef && this.$refs.formRef.clearValidate()
      })
    },
    handleSubmit() {
      this.$refs.formRef.validate(valid => {
        if (!valid) return
        this.$confirm(
          `确认越权作废开单 ${this.form.id} 吗?此操作不可撤销。`,
          '越权作废确认',
          { type: 'warning', confirmButtonText: '确认作废', cancelButtonText: '取消' }
        )
          .then(() => this.doCancel())
          .catch(() => {})
      })
    },
    async doCancel() {
      this.submitting = true
      try {
        const res = await privilegeCancelBilling({
          id: this.form.id,
          remarks: this.form.remarks
        })
        this.$message.success((res && res.msg) || '作废成功')
        this.resetForm()
      } catch (e) {
        const msg = (e && e.message) || (e && e.msg) || '作废失败'
        this.$message.error(msg)
      } finally {
        this.submitting = false
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.privilege-ops-panel {
  max-width: 720px;
}

.privilege-alert {
  margin-bottom: 16px;
}

.config-section {
  border: 1px solid #fde2e2;
}

.config-section__header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.config-section__tag {
  font-size: 12px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 4px;
  background: #f0f9eb;
  color: #67c23a;
}

.config-section__tag--danger {
  background: #fef0f0;
  color: #f56c6c;
}

.config-section__tip {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.6;
  color: #909399;
}

.privilege-form {
  max-width: 560px;
}
</style>