You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
4.6 KiB

2 years ago
  1. $(function () {
  2. 'use strict';
  3. var sLang = $('[http-equiv="content-language"]').attr('content') || 'zh-TW',
  4. sContactType = getUrlParam('T') || '',
  5. eForm = $("#form_contact"),
  6. /*
  7. * 目的 表單驗證初始化
  8. */
  9. fnSetForm_Rule = function () {
  10. eForm.validate({
  11. errorPlacement: function (error, element) {
  12. error.css({
  13. "border": "none",
  14. "color": "red"
  15. });
  16. var wrapper = $("<p></p>");
  17. error.appendTo(wrapper);
  18. $(element).parent().after(wrapper);
  19. },
  20. highlight: function (element, errorClass) {
  21. $(element).css({
  22. "border": "1px solid red"
  23. });
  24. },
  25. unhighlight: function (element, errorClass) {
  26. $(element).css({
  27. "border": ""
  28. });
  29. },
  30. rules: {
  31. },
  32. messages: {
  33. uname: {
  34. required: { 'zh-TW': '請輸入聯絡人姓名', 'zh': '请输入联络人姓名', 'en': 'Please enter contact name' }[sLang]
  35. },
  36. uemail: {
  37. email: { 'zh-TW': '電子信箱格式錯誤', 'zh': '电子信箱格式错误', 'en': 'Wrong email format' }[sLang],
  38. required: { 'zh-TW': '請輸入電子信箱', 'zh': '请输入电子信箱', 'en': 'Please enter your email address' }[sLang]
  39. },
  40. ucomp: {
  41. required: { 'zh-TW': '請輸入公司名稱', 'zh': '请输入公司名称', 'en': 'Please enter the company name' }[sLang]
  42. },
  43. utel: {
  44. required: { 'zh-TW': '請輸入聯絡電話', 'zh': '请输入联络电话', 'en': 'Please enter your contact number' }[sLang]
  45. },
  46. umailcontent: {
  47. required: { 'zh-TW': '請輸入內容', 'zh': '请输入内容', 'en': 'Please enter the content' }[sLang]
  48. },
  49. validcode: {
  50. required: { 'zh-TW': '請輸入驗證碼', 'zh': '请输入验证码', 'en': 'Please enter the verification code' }[sLang]
  51. }
  52. }
  53. });
  54. },
  55. /*
  56. * 目的 寄送郵件
  57. */
  58. fnSendMail = function () {
  59. if (!eForm.valid()) {
  60. return false;
  61. }
  62. var formdata = getFormSerialize(eForm);
  63. formdata.flag = 'cap1';
  64. return g_api.ConnectLite(Service.apiwebcom, 'SendMail', formdata, function (res) {
  65. if (res.RESULT) {
  66. if (res.DATA.rel) {
  67. showMsg({ 'zh-TW': '郵件已經寄出,我們將儘快為您處理', 'zh': '邮件已经寄出,我们将尽快为您处理', 'en': 'The mail has been sent out and we will deal with it for you as soon as possible' }[sLang], 'success'); // 郵件已經寄出,我們將儘快為您處理。
  68. setTimeout(function () {
  69. location.reload();
  70. }, 3000);
  71. }
  72. else {
  73. showMsg({ 'zh-TW': '郵件寄送失敗', 'zh': '邮件寄送失败', 'en': 'Please enter contact name' }[sLang], 'error'); // 郵件寄送失敗
  74. $('#change_validcode').click();
  75. }
  76. }
  77. else {
  78. showMsg(res.MSG, 'error'); // 驗證碼錯誤
  79. $('#change_validcode').click();
  80. }
  81. }, function () {
  82. showMsg({ 'zh-TW': '郵件寄送失敗', 'zh': '邮件寄送失败', 'en': 'Mail delivery failed' }[sLang], 'error'); // 郵件寄送失敗
  83. }, null, { 'zh-TW': '郵件寄送中...', 'zh': '邮件寄送中...', 'en': 'In the mail...' }[sLang]);
  84. },
  85. init = function () {
  86. if (sContactType) { $('#type').val(sContactType); }
  87. $('#change_validcode,.change_validcode').on('click', function () {
  88. var url = $('#imgvalidcode').data('url') || $('#imgvalidcode').attr('src');
  89. $('#imgvalidcode').attr('src', url + '&' + Math.random()).data('url', url);
  90. });
  91. fnSetForm_Rule();
  92. $("#sendmail").on("click", function () {
  93. fnSendMail();
  94. });
  95. };
  96. init();
  97. });