leaveMsg.vue 11 KB

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