Administrator
2021-08-11 92d0cf73df170131eba84490d875bc954eb7a708
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<template>
    <div>
        <div class="security-apply">
            <div class = "security-title">
                <span>2021 保安证考试报名</span>
            </div>
            <div>
                <button class="security-btn" @click="applySubmit">报 名</button>
                <button class="security-btn" @click="cancelApply">取 消 报 名</button>
            </div>
            <div class = "apply-status">
                 <span>{{status}}</span>
            </div>
        </div>
    </div>
</template>
 
<script>
import { mapState } from 'vuex';
import {
  addApply,
  cancelApply,
  getSecurityApplyInfo
} from "@/api/examapi/applyexam";
 
export default {
  data() {
    return {
        status:null,
        id:null,
        form:{}
    };
  },
  computed: {
      ...mapState({
            userInfo: state => state.user.userInfo
        }),
  },
  mounted() {
    //查询保安人员报名信息
    this.getSecurityApplyInfo(null);
  },
  methods:{
    getSecurityApplyInfo(id){
        getSecurityApplyInfo(id,this.userInfo.user_id).then((res) => {
          this.form = res.data;
          if(res.data.id!=-1){
              this.id = res.data.id;
          }
          if(res.data.isApply==-1 || res.data.isApply==2){
            this.status = "尚未报名";
          }
          if(res.data.isApply==1){
            this.status = "已报名";
          }
        });
    },
    applySubmit(){
      addApply({
        userId: this.userInfo.user_id
      }).then(
        (res) => {
          if (res.data.data == 201) {
            this.$message({
              type: "warning",
              message: "已报名,不能重复报名",
            });
          } else if (res.data.data == 202) {
            this.$message({
              type: "warning",
              message: "报名失败",
            });
          } else {
            this.$message({
              type: "success",
              message: "报名成功",
            });
            this.getSecurityApplyInfo(null);
          }
        },
        (error) => {
          window.console.log(error);
        }
      );
    },
    cancelApply(){
      cancelApply({
        id:this.id,
        userId: this.userInfo.user_id
      }).then(
        (res) => {
          if (res.data.data == 201) {
            this.$message({
              type: "warning",
              message: "尚未报名",
            });
          } else {
            this.$message({
              type: "success",
              message: "取消报名成功",
            });
            this.getSecurityApplyInfo(null);
          }
        },
        (error) => {
          window.console.log(error);
        }
      );
    }
  }
};
</script>
 
<style lang="scss">
    .security-apply{
        width: 100%;
        height: 100%;
        margin-top: 250px;
 
        .security-title{
            width: 30%;
            font-size: 28px;
            margin-left: 35%;
            text-align: center;
            color: cadetblue;
        }
 
        .security-btn{
            width: 10%;
            margin-left: 45%;
            text-align: center;
            margin-top: 20px;
        }
 
        .apply-status{
            width: 10%;
            margin-left: 45%;
            text-align: center;
            margin-top: 20px;
        }
    }
 
    
</style>