xieb
2025-03-06 8b23471d428d7d0a6444726cb5c1603a8b3d4010
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!--添加留言-->
<template>
  <div class="Addmessage">
    <van-cell-group inset>
      <van-field
        v-model="messagecom"
        class="van-hairline"
        rows="5"
        autosize
        type="textarea"
        placeholder="说点什么吧"
        show-word-limit
      />
    </van-cell-group>
    <div class="my-uploader">
      <van-uploader
        v-model="FileList"
        max-count="9"
        multiple
        :after-read="afterread"
        :before-delete="beforedelete"
      />
    </div>
    <div class="attention">
      <img src="images/attention.png" />
      <span>请勿涉及不文明及违规内容,违法必究!</span>
    </div>
    <div class="bottom">
      <div class="button">
        <van-button
          type="primary"
          @click="submit(2)"
          v-show="!this.shownim"
          :disabled="disabledsubmit"
        >匿名留言</van-button>
        <van-button type="primary" @click="submit(1)" :disabled="disabledsubmit">实名留言</van-button>
      </div>
    </div>
  </div>
</template>
              
<script>
import { leaveWords, endpoint } from "@/api/hfiveget/index.js";
export default {
  data() {
    return {
      messagecom: "",
      fileindex: null,
      disabledsubmit: false,
      FileList: [],
      submitlist: [],
      shownim: false
    };
  },
  mounted() {
    localStorage.setItem("Appraising", "message");
  },
  computed: {},
  created() {
    this.shownim = localStorage.getItem("tokensave") == "111";
  },
  methods: {
    // 上传图片后的操作
    afterread(event, indexto) {
      let temporary = [];
      if (event.length == undefined) {
        temporary.push(event);
      } else {
        temporary = event;
      }
      temporary.map((item, index) => {
        this.FileList[index].status = "uploading";
        this.FileList[index].message = "加载中";
      });
      temporary.forEach((element, index) => {
        const formdata = new FormData();
        formdata.append("file", element.file);
        endpoint(formdata).then(res => {
          if (res.data.code == 200) {
            this.FileList[index].status = "";
            this.FileList[index].message = "";
          }
          this.submitlist.push(res.data.data.link);
        });
      });
    },
    // 删除图片前的操作
    beforedelete(file, filelist) {
      this.submitlist.splice(filelist.index, 1);
      this.FileList.splice(filelist.index, 1);
    },
    // 添加留言:1;匿名添加:2
    submit(index) {
      let toData = {
        userName: "匿名用户",
        content: this.messagecom,
        imageUrls: this.submitlist.join(",")
      };
      if (localStorage.getItem("tokensave") != "111") {
        toData.userName = localStorage.getItem("nick_name");
        toData.userDept = localStorage.getItem("dept_name");
        toData.userPost = localStorage.getItem("post_name");
      }
      if (this.messagecom == "" && this.submitlist.length == 0) {
        this.$toast.fail("留言内容不能为空");
      } else {
        if (index == 2) {
          toData.userDept = "";
          toData.userPost = "";
          toData.userName = "匿名用户";
        }
        leaveWords(toData).then(res => {
          this.disabledsubmit = true;
          setTimeout(() => {
            this.$router.push("/");
          }, 1000);
          this.$toast.success("添加成功");
        });
      }
    }
  }
};
</script>
              
<style scoped lang="scss">
.Addmessage {
  height: 100vh;
  width: 100%;
  position: relative;
  padding: 20px;
  [class*="van-hairline"]::after {
    border: none;
    font-size: 40px;
  }
  .van-cell-group--inset {
    margin: 0px;
    .van-cell {
      padding: 0px;
      font-size: 20px;
    }
  }
  .attention {
    display: flex;
    align-items: center;
    margin: 10px 0px;
    img {
      width: 16px;
      height: 16px;
      margin-right: 4px;
    }
    span {
      font-size: 14px;
      color: #999999;
    }
  }
  .bottom {
    position: absolute;
    bottom: 50px;
    left: 0;
    width: 100%;
    .button {
      display: flex;
    }
    .van-button {
      // margin: 0px 10px;
      text-align: center;
      width: 40%;
      margin: 0px 10px;
      flex: 1;
      font-size: 18px;
      border-radius: 5px;
      background: linear-gradient(to right, #01bdfc, #017bfc);
    }
  }
}
</style>
<style >
</style>