leaveMsg.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <template>
  2. <el-container class="chatBox">
  3. <el-header height='80px'>
  4. <el-row type="flex" justify='space-between' align='middle' style="height:100%;">
  5. <el-col class="tit nopd">
  6. <span @click="back()" class="back pointer"></span>
  7. <span>我要留言</span>
  8. </el-col>
  9. </el-row>
  10. </el-header>
  11. <div class="cationer">
  12. <el-main>
  13. <form action="">
  14. <div class="call">
  15. <label for="">
  16. <span>您的称呼</span>
  17. <span class="star"> *</span>
  18. </label>
  19. <el-input v-model="call" placeholder="请输入内容" style="paddiing:0 9px;"></el-input>
  20. </div>
  21. <div class="phone">
  22. <label for="">
  23. <span>您的手机号</span>
  24. </label>
  25. <el-input v-model="phone" placeholder="请输入手机号"
  26. style="paddiing:0 9px;"></el-input>
  27. </div>
  28. <div class="qq">
  29. <label for="">
  30. <span>您的QQ号</span>
  31. </label>
  32. <el-input v-model="QQ" type="number" placeholder="请输入QQ号" style="paddiing:0 9px;"></el-input>
  33. </div>
  34. <div class="wx">
  35. <label for="">
  36. <span>您的微信号</span>
  37. </label>
  38. <el-input v-model="WX" placeholder="请输入微信号" style="paddiing:0 9px;"></el-input>
  39. </div>
  40. <div class="eMail">
  41. <label for="">
  42. <span>您的邮箱地址</span>
  43. <span class="star"> </span>
  44. <span class="tips" v-if="emailError">(请输入正确的邮箱地址)</span>
  45. </label>
  46. <el-input v-model="eMail" @blur='sureinfor(10)' placeholder="请输入邮箱地址"
  47. style="paddiing:0 9px;"></el-input>
  48. </div>
  49. <div class="leaveMsg">
  50. <label for="">
  51. <span>您的留言信息</span>
  52. <span class="star"> *</span>
  53. </label>
  54. <el-input type="textarea" @blur="widthCheck($event.target, 100)" placeholder="比赛中遇到作弊怎么办?"
  55. v-model="leaveInfor"></el-input>
  56. </div>
  57. <!-- 上传图片 -->
  58. <div class="addPhoto">
  59. <label for="">
  60. <span>上传图片</span>
  61. </label>
  62. <!-- :on-preview="handlePictureCardPreview" :on-remove="handleRemove" -->
  63. <el-upload style="margin-top:14px;"
  64. action="/api/index/upload/uploadImg"
  65. :before-upload="beforeAvatarUpload"
  66. :on-change='uploadChange'
  67. :on-success='uploadSuccess'
  68. :on-error="uploadError"
  69. :on-remove="handleRemove"
  70. :auto-upload="false"
  71. list-type="picture-card"
  72. ref="upload"
  73. :limit="4"
  74. :on-exceed="handleExceed"
  75. >
  76. <i slot="default" class="el-icon-plus"></i>
  77. </el-upload>
  78. <el-dialog>
  79. <img width="100%" :src="dialogImageUrl" alt="">
  80. </el-dialog>
  81. </div>
  82. <!-- 按钮 -->
  83. <div class="btn">
  84. <el-button type="primary" @click='sub()'>提交留言</el-button>
  85. </div>
  86. </form>
  87. </el-main>
  88. </div>
  89. </el-container>
  90. </template>
  91. <script>
  92. import '../css/index.css'
  93. export default {
  94. name: 'leaveMsg',
  95. data() {
  96. return {
  97. call: '', //称呼
  98. error: false, //手机号错误提示
  99. leaveInfor: '', // 留言信息
  100. phone: '', //手机信息
  101. leaveMsg: '', // 留言信息
  102. eMail: '',
  103. dialogImageUrl: '',
  104. emailError: false,
  105. QQ: "",
  106. WX: '',
  107. uploadImg: [],//上传图片的数据集合
  108. imgUrl:'',
  109. }
  110. },
  111. methods: {
  112. // 返回传值到父组件
  113. back() {
  114. this.$emit('value', 100)
  115. },
  116. // 提交
  117. sub() {
  118. if (this.call == '') {
  119. this.$message.error('请填写称呼!');
  120. } else if (this.leaveInfor == '') {
  121. this.$message.error('请填写留言信息!');
  122. } else {
  123. // 手动上传
  124. this.$refs.upload.submit();
  125. let _this = this;
  126. let uid = localStorage.getItem('uid');
  127. setTimeout(function () {
  128. console.log(this.imgUrl,"上传的图片")
  129. let params = {
  130. 'name': _this.call,
  131. 'email': _this.eMail,
  132. 'content': _this.leaveInfor,
  133. 'phone': _this.phone,
  134. 'qq': _this.QQ,
  135. 'wechat': _this.WX,
  136. 'file': _this.imgUrl,
  137. 'account_id': uid,
  138. }
  139. _this.$axios.post('/api/index/User/LeavingMessage', params).then(res => {
  140. if (res.data.code == 1) {
  141. _this.$message.success('留言成功')
  142. _this.$emit('value', 10);
  143. }
  144. })
  145. }, 1500)
  146. }
  147. },
  148. widthCheck(str, len) {
  149. var temp = 0
  150. for (var i = 0; i < str.value.length; i++) {
  151. if (str.value.length < 4) {
  152. str.value = ''
  153. }
  154. }
  155. },
  156. // 失去焦点时验证
  157. sureinfor(type) {
  158. if (type == 1) {
  159. // if (!/^1[34578]\d{9}$/.test(this.phone)) {
  160. // this.error = true;
  161. // this.phone = '';
  162. // } else {
  163. // this.error = false;
  164. // }
  165. }
  166. else if (type == 10) {
  167. if (!/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(this.eMail)) {
  168. this.emailError = true;
  169. this.eMail = '';
  170. } else {
  171. this.emailError = false;
  172. }
  173. }
  174. },
  175. // 上传之前
  176. beforeAvatarUpload(file) {
  177. const isJPG = file.type == 'image/jpeg' || 'image/jpg' || 'image/png' || 'image/svg';
  178. const isLt1M = file.size / 1024 / 1024 < 2;
  179. if (!isJPG) {
  180. this.$message.error('上传只能是图片格式!');
  181. }
  182. if (!isLt1M) {
  183. this.$message.error('上传文件大小不能超过 2MB!');
  184. }
  185. return isJPG && isLt1M;
  186. },
  187. // 上传成功时的回调
  188. uploadSuccess(res, file) {
  189. this.imgUrl = this.imgUrl ? this.imgUrl + "," + res.data.src :res.data.src;
  190. console.log(this.imgUrl)
  191. },
  192. // 上传失败
  193. uploadError() {
  194. this.$message.error('上传失败,请重新上传')
  195. },
  196. handleExceed(files, fileList) {
  197. this.$message.error(`图片上传数量最多4张`);
  198. },
  199. //删除回掉
  200. handleRemove(file, fileList,) {
  201. this.uploadImg = fileList
  202. },
  203. // 每次改变图片状态返回的回调
  204. uploadChange(file, fileList) {
  205. console.log('每次改变图片状态返回的回调', fileList)
  206. },
  207. }
  208. }
  209. </script>
  210. <style scoped>
  211. .chatBox {
  212. width: 700px;
  213. }
  214. .el-header {
  215. background: linear-gradient(90deg, rgba(22, 84, 209, 1) 0%, rgba(9, 52, 173, 1) 100%);
  216. box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.2);
  217. }
  218. .tit {
  219. height: 100%;
  220. line-height: 80px;
  221. text-align: left;
  222. padding-left: 20px;
  223. }
  224. .tit span {
  225. font-size: 18px;
  226. }
  227. .el-col span {
  228. font-size: 18px;
  229. color: #FFFFFF;
  230. }
  231. .imgBox {
  232. text-align: right;
  233. }
  234. .imgBox img {
  235. margin-right: 20px;
  236. }
  237. .imgBox img:nth-last-child(1) {
  238. margin-right: 0
  239. }
  240. .el-main {
  241. background: #fff;
  242. width: 445px;
  243. padding: 0;
  244. }
  245. .el-aside {
  246. background: #F5F5F5;
  247. width: 255px;
  248. }
  249. .cationer, .artificial {
  250. display: flex;
  251. justify-content: space-between;
  252. /* align-items: center; */
  253. }
  254. .rt {
  255. width: 255px;
  256. box-sizing: inherit;
  257. }
  258. .artificial {
  259. /* width: 150px; */
  260. /* padding:0 20px; */
  261. margin-top: 23px;
  262. margin-bottom: 9px;
  263. vertical-align: middle;
  264. /* flex-direction: column;*/
  265. }
  266. .infor div {
  267. margin-bottom: 3px;
  268. }
  269. .infor div span, .autograph span {
  270. color: #999999;
  271. font-size: 14px;
  272. font-weight: 400;
  273. }
  274. .infor div span:nth-child(2), .autograph span:nth-child(2) {
  275. color: #666666;
  276. margin-left: 4px;
  277. }
  278. .headPortrait {
  279. width: 100px;
  280. height: 100px;
  281. }
  282. .autograph {
  283. margin-bottom: 11px;
  284. }
  285. .advent {
  286. border-top: 1px solid #DDDDDD;
  287. padding: 20px;
  288. }
  289. .advent img {
  290. width: 215px;
  291. height: 350px;
  292. }
  293. .pd {
  294. padding: 20px;
  295. }
  296. .pd20 {
  297. padding: 0 20px;
  298. }
  299. /* 留言框 */
  300. .el-main {
  301. padding: 20px 20px 23px 20px;
  302. position: relative;
  303. height: 600px;
  304. overflow: auto;
  305. }
  306. label {
  307. font-size: 14px;
  308. color: #666666;
  309. }
  310. .el-input {
  311. margin: 10px 0 20px;
  312. color: #333333;
  313. }
  314. .star {
  315. color: #F04992;
  316. vertical-align: middle;
  317. }
  318. .tips {
  319. font-size: 12px;
  320. color: #F04992;
  321. margin-left: 20px;
  322. }
  323. .addPhoto {
  324. margin: 20px 0 0;
  325. }
  326. .addPhoto label {
  327. margin-bottom: 14px;
  328. }
  329. .el-textarea {
  330. margin-top: 10px;
  331. }
  332. .btn {
  333. position: absolute;
  334. /* bottom: 23px; */
  335. right: 20px;
  336. }
  337. .el-button {
  338. width: 120px;
  339. height: 48px;
  340. background: linear-gradient(90deg, rgba(22, 84, 209, 1) 0%, rgba(9, 52, 173, 1) 100%);
  341. box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.2);
  342. border-radius: 10px;
  343. }
  344. .back {
  345. display: inline-block;
  346. width: 25px;
  347. height: 25px;
  348. background: url("./../assets/st-img/back.png") no-repeat;
  349. background-size: 100% 100%;
  350. vertical-align: middle;
  351. }
  352. .nopd {
  353. padding: 0;
  354. }
  355. /* 顶部三个图标 */
  356. .imgBox i {
  357. display: inline-block;
  358. width: 25px;
  359. height: 25px;
  360. margin-right: 20px;
  361. background: url("./../assets/st-img/pj.png") no-repeat;
  362. background-size: 100% 100%;
  363. vertical-align: middle;
  364. }
  365. i.scActy {
  366. background: #1654D1 url("./../assets/st-img/pjhover.png") no-repeat;
  367. width: 33px;
  368. height: 33px;
  369. background-position: 5px;
  370. }
  371. .imgBox .syActy {
  372. background: #1654D1 url("./../assets/st-img/jzsy.png") no-repeat;
  373. width: 33px;
  374. height: 33px;
  375. background-position: 5px;
  376. }
  377. .imgBox .sqActy {
  378. background: #1654D1 url("./../assets/st-img/sq2.png") no-repeat;
  379. width: 33px;
  380. height: 33px;
  381. transform: rotate(180deg);
  382. background-position: 5px;
  383. }
  384. .pointer {
  385. cursor: pointer;
  386. }
  387. </style>