<!--添加留言-->
|
<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>
|