15179599649
2024-01-08 f29a96ac3cf82e0dc06e1b3874ab2abed2ebaeaa
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
<!--添加留言-->
<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">
      <van-button type="primary" @click="submit()">添加留言</van-button>
    </div>
  </div>
</template>
              
<script>
import { leaveWords, endpoint } from "@/api/hfiveget/index.js";
export default {
  data() {
    return {
      messagecom: "",
      fileindex: null,
      FileList: [],
      submitlist: []
    };
  },
  mounted() {
    localStorage.setItem("Appraising", "message");
  },
  computed: {},
  created() {},
  methods: {
    // 上传图片后的操作
    afterread(event, indexto) {
      console.log(event.length == undefined);
      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);
    },
    submit() {
      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 {
        leaveWords(toData).then(res => {
          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;
    width: 100%;
    .van-button {
      width: 90%;
      font-size: 18px;
      border-radius: 5px;
      background: linear-gradient(to right, #01bdfc, #017bfc);
    }
  }
}
</style>
<style >
</style>