dabory-coupon.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. (function($) {
  2. $.fn.coupon = async function(options) {
  3. const opts = $.extend({}, $.fn.coupon.defaults, options)
  4. this.append(html.call(this, '', opts, ''))
  5. loadModule.call(this)
  6. };
  7. function html(couponList, opts, langJson) {
  8. return `<div class="dabory-coupon-popup coupon" style="top: ${opts['top']}px; left: ${opts['left']}px; width: ${opts['width']}px; display: none;">
  9. <button type="button" class="tab-close" data-widget="coupon">
  10. <img src="/dabory/common/image/close-button.svg" alt="close-butto">
  11. </button>
  12. <div class="dabory-coupon-box">
  13. <div class="dabory-coupon-row">
  14. <div class="dabory-coupon-col">
  15. <div class="dabory-coupon-form">
  16. <h3>Dabory Coupon</h3>
  17. <div class="form-div">
  18. <p>[사용방법]</p>
  19. <p>(1) 타 사이트의 품목상세 페이지 주소를 복사해서 붙여넣기</p>
  20. <p>(2) 타 사이트 품목상세 페이지에서 "다보리 쿠폰" 퀵런처가 보이면</p>
  21. <p class="in">해당 버튼을 클릭하기</p>
  22. </div>
  23. <div class="form-div">
  24. <label>상품상세페이지 인터넷 주소*</label>
  25. <input type="text" class="current-url-txt" placeholder="목표상품의 인터넷 주소를 복사/붙여넣기">
  26. </div>
  27. <div class="form-div">
  28. <label>쿠폰을 받을 이메일주소*</label>
  29. <input type="text" class="buyer-email-txt">
  30. </div>
  31. <div class="form-div">
  32. <label>할인 요청 %</label>
  33. <select class="init-dcrate-select">
  34. <option value="5">5%</option>
  35. <option value="10">10%</option>
  36. <option value="15">15%</option>
  37. <option value="20">20%</option>
  38. <option value="30">30%</option>
  39. <option value="40">40%</option>
  40. <option value="50">50%</option>
  41. <option value="60">60%</option>
  42. </select>
  43. </div>
  44. <div class="form-div">
  45. <label>할인 조건(이유)</label>
  46. <select class="sort-select">
  47. <option value="">해당 사항 없음</option>
  48. <option value="0">상품설명 블로그 작성(2000자 이상)</option>
  49. <option value="1">사용후기 작성(500자 이상)</option>
  50. <option value="2">대량구매(도매)</option>
  51. <option value="3">기타(직접입력)</option>
  52. </select>
  53. </div>
  54. <div class="form-div">
  55. <label>할인 조건 직접입력</label>
  56. <input type="text" class="sort-desc-txt" disabled>
  57. </div>
  58. <div class="form-div">
  59. <input type="checkbox" id="policy-txt" class="policy-txt">
  60. <label for="policy-txt">
  61. <a href="https://dabory-v1.daboryhost.com/policy-list" target="_blank">쿠폰 신청 이용 약관</a>
  62. </label>
  63. </div>
  64. <div class="form-div text-xs-center">
  65. <!-- 비밀키: 6Lc-nT8mAAAAAMfPpbrZtZWDd5kfmMDFHTE-LzjG-->
  66. <div id="captcha" class="g-recaptcha" data-sitekey="6Lc-nT8mAAAAAPFpx7YAB4LyOCjHel6_zrD0j1yy">
  67. </div>
  68. </div>
  69. <button type="button" class="send-btn" disabled>
  70. <span class="button__text">쿠폰 신청</span>
  71. </button>
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76. </div>`
  77. }
  78. function getLangText(langJson, key) {
  79. if (! langJson) { return key }
  80. return langJson[key]
  81. }
  82. function actCouponApi($btn) {
  83. const self = this
  84. $($btn).prop('disabled', true)
  85. $.fn.widget.spinnerLoading($(this).find('.send-btn'), true)
  86. $.fn.dataLinker.daboryApp('item-url-scrap', {
  87. "ItemUrl": $(this).find('.current-url-txt').val(),
  88. "InitDcrate": $(this).find('.init-dcrate-select').val(),
  89. "BuyerEmail": $(this).find('.buyer-email-txt').val(),
  90. "Sort": $(this).find('.sort-select').val(),
  91. "SortDesc": $(this).find('.sort-desc-txt').val(),
  92. }, function (response) {
  93. $.fn.widget.spinnerLoading($(self).find('.send-btn'), false)
  94. $($btn).prop('disabled', false)
  95. hidePopup.call(self)
  96. window.location.href = '/item-gallery/05'
  97. if (response.apiStatus) {
  98. if (response.apiStatus === 604) {
  99. return iziToast.error({ title: 'Error', message: '쿠폰지원예정-웹사이트(보류중)' });
  100. }
  101. return iziToast.error({ title: 'Error', message: 'API Error' });
  102. }
  103. return iziToast.success({ title: 'Success', message: 'Success' });
  104. })
  105. }
  106. function isRequiredInput() {
  107. if (! $(this).find('.current-url-txt').val()) {
  108. iziToast.error({ title: 'Error', message: '상품상세페이지 인터넷 주소를 입력하세요' });
  109. return false;
  110. }
  111. if (! $(this).find('.buyer-email-txt').val()) {
  112. iziToast.error({ title: 'Error', message: '쿠폰을 받을 이메일주소를 입력하세요' });
  113. return false;
  114. }
  115. if (! $(this).find('.policy-txt').prop('checked')) {
  116. return iziToast.error({ title: 'Error', message: '쿠폰 신청 이용 약관 에 동의하셔야 합니다' })
  117. }
  118. return true;
  119. }
  120. function hidePopup() {
  121. $(this).find('.dabory-coupon-popup').hide()
  122. $(this).closest('#dabory-widget-list').trigger('hide.widget', 'coupon')
  123. }
  124. function loadModule() {
  125. const self = this
  126. $(document).ready(function () {
  127. $(self).find('.dabory-coupon-popup').draggable()
  128. $(self).find('.sort-select').on('change', function() {
  129. $(self).find('.sort-desc-txt').val('')
  130. $(self).find('.sort-desc-txt').prop('disabled', $(this).val() !== '3')
  131. });
  132. $(self).find('.send-btn').on('click', function() {
  133. const v = grecaptcha.getResponse();
  134. if (v.length === 0) {
  135. return iziToast.error({ title: 'Error', message: "자동입력방지 기능 - '로봇이 아닙니다.'를 체크해주세요" });
  136. }
  137. if (isRequiredInput.call(self)) {
  138. actCouponApi.call(self, this)
  139. }
  140. });
  141. $(self).find('.current-url-txt').on('click', function() {
  142. $(this).val('')
  143. validateInputs.call(self)
  144. });
  145. $(document).on('show.widget', '.dabory-coupon-popup', function (event, widgetName) {
  146. const currentURL = window.location.protocol + "//" + window.location.host + window.location.pathname
  147. $(self).find('.current-url-txt').val(currentURL)
  148. });
  149. $(self).find('.current-url-txt').on('input', function () {
  150. validateInputs.call(self)
  151. });
  152. $(self).find('.buyer-email-txt').on('input', function () {
  153. validateInputs.call(self)
  154. });
  155. $(self).find('.policy-txt').on('change', function () {
  156. validateInputs.call(self)
  157. });
  158. });
  159. }
  160. function validateInputs() {
  161. // Get the input values
  162. const value1 = $(this).find('.current-url-txt').val()
  163. const value2 = $(this).find('.buyer-email-txt').val()
  164. // Perform your validation checks
  165. if (value1.length >= 1 && value2.length >= 1 && $(this).find('.policy-txt').prop('checked')) {
  166. // Enable the submit button
  167. $(this).find('.send-btn').prop('disabled', false)
  168. } else {
  169. // Disable the submit button
  170. $(this).find('.send-btn').prop('disabled', true)
  171. }
  172. }
  173. $.fn.coupon.defaults = {
  174. top: 0,
  175. left: 0,
  176. width: 500,
  177. langType: 'ko',
  178. basePath: '/dabory/widget/coupon',
  179. };
  180. }(jQuery));