<template>
  <el-dialog v-if="show" title="报销审批" :visible.sync="show" width="800px">
    <el-descriptions :column="2" border>
      <el-descriptions-item v-for="(item, index) in showColumns" :key="index" :label="item.label">
        {{ info[item.prop] }}
      </el-descriptions-item>
    </el-descriptions>
    <el-form ref="form" class="mt20" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="是否通过" prop="auditStatus">
        <el-radio-group v-model="form.auditStatus">
          <el-radio :label="1">通过</el-radio>
          <el-radio :label="0">驳回</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="审批说明" prop="auditRemark">
        <el-input v-model="form.auditRemark" type="textarea" placeholder="请输入" />
      </el-form-item>
    </el-form>

    <span slot="footer">
      <el-button @click="show = false">取消</el-button>
      <el-button type="primary" @click="handleSure">确定</el-button>
    </span>
  </el-dialog>

</template>

<script>
export default {
  data() {
    return {
      show: false,
      showColumns: [],
      info: {},
      form: {
        auditStatus: 1,
        auditRemark: undefined
      },
      rules: {
        auditRemark: { required: true, message: '请输入', trigger: 'blur' }
      }
    };
  },
  methods: {
    init(data) {
      this.show = true;
      this.info = { ...data, type: '1' };
      const commonColumns = [
        { prop: 'applyUser', label: `申请人` },
        { prop: 'applyDate', label: `申请时间` },
        { prop: 'applyRemark', label: `申请备注` },
        { prop: 'expenseType', label: `报销款项` },
        { prop: 'expenseTotal', label: `报销金额` }
      ];
      const otherColumns = {
        1: [{ prop: 'spotName', label: `报名点` }],
        2: [{ prop: 'stuName', label: `成交学员` }]
      };
      this.showColumns = otherColumns[this.info.type].concat(commonColumns);
    },
    handleSure() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          // 提交审批结果
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped></style>
