leaveMsg.vue 9.6 KB

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