checkout.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. $(function(){
  2. $('#oc-address').click(function(){
  3. var areaId=0;
  4. $.post(ajaxarea_url,{'areaId':areaId,'goods_id':goods_id},function(data){
  5. $('#areaprovince').html('<option value="0">选择省份</option>');
  6. $.each(data,function(no,items){
  7. $('#areaprovince').append('<option value="'+items.area_id+'">'+items.area_name+'</option>');
  8. });
  9. $('#m-addr-mask').show();
  10. });
  11. })
  12. $("#areaprovince").change(function(){
  13. var areaId = $(this).val();
  14. if(areaId == 0){
  15. $('#areacity').html('<option value="0">选择城市</option>');
  16. $('#areadistrict').html('<option value="0">选择地区</option>')
  17. } else {
  18. $.post(ajaxarea_url,{'areaId':areaId,'goods_id':goods_id},function(data){
  19. $('#areacity').html('<option value="0">选择城市</option>');
  20. $.each(data,function(no,items){
  21. $('#areacity').append('<option value="'+items.area_id+'">'+items.area_name+'</option>');
  22. });
  23. $('#areadistrict').html('<option value="0">选择地区</option>');
  24. });
  25. }
  26. })
  27. $("#areacity").change(function(){
  28. var areaId = $(this).val();
  29. if(areaId == 0){
  30. $('#areadistrict').html('<option value="0">选择地区</option>')
  31. } else {
  32. $.post(ajaxarea_url,{'areaId':areaId},function(data){
  33. $('#areadistrict').html('<option value="0">选择地区</option>');
  34. $.each(data,function(no,items){
  35. $('#areadistrict').append('<option value="'+items.area_id+'">'+items.area_name+'</option>');
  36. });
  37. });
  38. }
  39. })
  40. $('.oc-mall-coupon-info').on('click',function(){
  41. check_voucher_use(1);
  42. })
  43. $('.m-addr-save').on('click',function(){
  44. var name = $('#name').val();
  45. var m_addr_mobile = $('.m-addr-mobile').val();
  46. var areaprovince = $('#areaprovince').val();
  47. var areaprovince_html = $('#areaprovince').find("option:selected").text();
  48. var areacity = $('#areacity').val();
  49. var areacity_html = $('#areacity').find("option:selected").text();
  50. var areadistrict = $('#areadistrict').val();
  51. var areadistrict_html = $('#areadistrict').find("option:selected").text();
  52. var addr_address = $('#addr_address').val();
  53. if($.trim(name) == ''){
  54. showTip('请填写姓名');
  55. return false;
  56. }
  57. if($.trim(m_addr_mobile) == ''){
  58. showTip('请填写手机');
  59. return false;
  60. }
  61. if(!m_addr_mobile.match('^1[3|5|8|7][0-9]{9}$')){
  62. showTip('请输入正确的手机号码');
  63. return false;
  64. }
  65. if(areaprovince <= 0)
  66. {
  67. showTip('请选择省份');
  68. return false;
  69. }
  70. if(areacity <= 0)
  71. {
  72. showTip('请选择城市');
  73. return false;
  74. }
  75. if(areadistrict <= 0)
  76. {
  77. showTip('请选择地区');
  78. return false;
  79. }
  80. if($.trim(addr_address) == ''){
  81. showTip('请填写详细街道地址');
  82. return false;
  83. }
  84. var data_obj = {name:name,telephone:m_addr_mobile,is_default:1,province_id:areaprovince,city_id:areacity,country_id:areadistrict,address:addr_address};
  85. $.ajax({
  86. url:ajaxaddress_add_url,
  87. type:'post',
  88. data:data_obj,
  89. dataType:'json',
  90. success:function(json){
  91. if(json.code == 1) {
  92. var oc_address_html = '';
  93. oc_address_html+= '<div class="oc-address-info">';
  94. oc_address_html+= ' <div class="oc-address-receiver">';
  95. oc_address_html+= ' '+name+'&nbsp;&nbsp;&nbsp;'+m_addr_mobile;
  96. oc_address_html+= ' </div>';
  97. oc_address_html+= ' <div class="oc-address-detail">';
  98. oc_address_html+= ' '+areaprovince_html+'&nbsp;'+areacity_html+'&nbsp;'+areadistrict_html+'&nbsp;'+addr_address;
  99. oc_address_html+= ' </div>';
  100. oc_address_html+= '</div>';
  101. $('#m-addr-mask').hide();
  102. $('#oc-address').removeClass('oc-add-address');
  103. $('#oc-address').removeClass('indicator');
  104. $('#oc-address').html(oc_address_html);
  105. address_id = json.address_id;
  106. } else {
  107. showTip(json.error);
  108. return false;
  109. }
  110. }
  111. })
  112. })
  113. $('.m-addr-close').click(function(){
  114. $('#m-addr-mask').hide();
  115. })
  116. $('.check-lst li a').click(function(){
  117. $(this).parent().siblings().children('a').removeClass('checkboxed');
  118. $(this).addClass('checkboxed');
  119. var type = $(this).attr('type');
  120. if(type == 'express')
  121. {
  122. var s_fare = $(this).attr('fare');
  123. if(s_fare == undefined)
  124. {
  125. s_fare = 0;
  126. }
  127. $('#trans_free').val(s_fare);
  128. $('#fare_show').html('¥'+s_fare);
  129. express_id = $(this).attr('rel');
  130. } else if(type == 'pickup'){
  131. $('#trans_free').val(0);
  132. $('#fare_show').html('¥0');
  133. pick_up_id = $(this).attr('rel');
  134. }
  135. change_total_free();
  136. })
  137. $("#skuNum").keyup(function(){
  138. $(this).val($(this).val().replace(/[^0-9]/g,'1'));
  139. var num = parseInt($(this).val());
  140. if(num > max_quantity) {
  141. $(this).val(max_quantity);
  142. check_voucher_use(0);
  143. change_total_free();
  144. showTip('很抱歉,该商品当前至多能购买'+max_quantity+'份');
  145. }
  146. if(isNaN(num))
  147. {
  148. $(this).val(1);
  149. }
  150. check_voucher_use(0);
  151. change_total_free();
  152. if($(this).val() >1){
  153. $('.oc-goods-reduce').removeClass('oc-increase-disable');
  154. }
  155. }).bind("paste",function(){ //CTR+V事件处理 $(this).val($(this).val().replace(/[^0-9.]/g,''));
  156. }).css("ime-mode", "disabled"); //CSS设置输入法不可用
  157. $('.oc-goods-increase').click(function(){
  158. $('#skuNum').val($('#skuNum').val().replace(/[^0-9]/g,'1'));
  159. var num = parseInt($('#skuNum').val())+1;
  160. $('#skuNum').val(num);
  161. if($('#skuNum').val() >1){
  162. $('.oc-goods-reduce').removeClass('oc-increase-disable');
  163. }
  164. if(num > max_quantity) {
  165. $('#skuNum').val(max_quantity);
  166. check_voucher_use(0);
  167. change_total_free();
  168. showTip('很抱歉,该商品当前至多能购买'+max_quantity+'份');
  169. }else {
  170. $('#skuNum').val(num);
  171. check_voucher_use(0);
  172. change_total_free();
  173. }
  174. })
  175. $('.oc-goods-reduce').click(function(){
  176. $('#skuNum').val($('#skuNum').val().replace(/[^0-9]/g,'1'));
  177. var num = parseInt($('#skuNum').val());
  178. if(num > max_quantity) {
  179. $('#skuNum').val(max_quantity);
  180. check_voucher_use(0);
  181. change_total_free()
  182. showTip('很抱歉,该商品当前至多能购买'+max_quantity+'份');
  183. }
  184. num = parseInt($('#skuNum').val()) - 1;
  185. if(num == 0){
  186. $('#skuNum').val(1);
  187. check_voucher_use(0);
  188. change_total_free()
  189. $('.oc-goods-reduce').addClass('oc-increase-disable');
  190. }else {
  191. $('#skuNum').val(num);
  192. check_voucher_use(0);
  193. change_total_free()
  194. }
  195. })
  196. $('.oc-pay-btn').click(function(){
  197. if(!can_sub) {
  198. return false;
  199. } else {
  200. //can_sub = false;
  201. $(this).html('正在支付请稍后');
  202. }
  203. if(address_id == 0)
  204. {
  205. can_sub = true;
  206. $(this).html('立即支付');
  207. showTip('请添加收货地址');
  208. return false;
  209. }
  210. if(limit_haitao)
  211. {
  212. can_sub = true;
  213. $('.id-card-main-v2').show();
  214. return false;
  215. }
  216. var remark = $('#remark').val();
  217. var num = $('#skuNum').val();
  218. var transport_id = $('#transport_id').val();
  219. var payment_method = $('.oc-payment-selected').attr('payment-method');
  220. if(parseInt(num) == 0){
  221. $(this).html('立即支付');
  222. can_sub = true;
  223. showTip('请选择购买数量');
  224. return false;
  225. }
  226. $.ajax({
  227. url:cartdone_url,
  228. type:'post',
  229. data:{num:num,remark:remark,transport_id:transport_id,payment_method:payment_method,voucher_id:voucher_id,address_id:address_id,pick_up_id:pick_up_id,express_id:express_id,delivery:delivery},
  230. dataType:'json',
  231. success:function(res){
  232. if(res.code ==0){
  233. showTip(res.msg);
  234. can_sub = true;
  235. } else if(res.code == 1) {
  236. location.href = res.url;
  237. return false;
  238. }
  239. }
  240. })
  241. })
  242. })
  243. function check_voucher_use(is_show)
  244. {
  245. //store_id
  246. var goods_price = parseFloat($('#goods_price').attr('data-price'));
  247. var skuNum = parseInt($('#skuNum').val());
  248. var trans_free = parseFloat($('#trans_free').val());
  249. var total_free = ((goods_price*skuNum) + trans_free).toFixed(2);
  250. $.ajax({
  251. url:user_pay_voucher_url,
  252. type:'post',
  253. data:{store_id:store_id,total_free:total_free,voucher_id:voucher_id},
  254. dataType:'json',
  255. success:function(result){
  256. if(result.code == 1){
  257. $('.oc-coupons').html(result.html);
  258. if(is_show == 1)
  259. $('.oc-coupons').show();
  260. }else if(result.code == 2) {
  261. $('.oc-coupons').html(result.html);
  262. voucher_id = 0;
  263. voucher_money = 0;
  264. $('.oc-mall-coupon-desc').html(voucher_money+'元');
  265. change_total_free();
  266. if(is_show == 1)
  267. {
  268. $('.oc-coupons').show();
  269. }
  270. }else if(result.code == 0){
  271. //$('.oc-coupons').html('暂无可用的优惠券');
  272. var s_html = '';
  273. s_html += '<div class="oc-coupons-mian" style="bottom: 0px;">';
  274. s_html += ' <div class="oc-coupons-title-container">';
  275. s_html += ' <div class="oc-coupons-title">';
  276. s_html += ' <span class="oc-coupons-title-m">暂无可用的优惠券</span>';
  277. s_html += ' <div class="oc-coupons-close" onclick="close_couponmain()">';
  278. s_html += ' <div class="oc-coupons-close-icon"></div>';
  279. s_html += ' </div>';
  280. s_html += ' </div>';
  281. s_html += ' </div>';
  282. s_html += '</div>';
  283. $('.oc-coupons').html(s_html);
  284. if(is_show == 1)
  285. {
  286. $('.oc-coupons').show();
  287. }
  288. }
  289. }
  290. })
  291. }
  292. function close_couponmain()
  293. {
  294. $('.oc-coupons').hide();
  295. }
  296. function coupon_ck(obj)
  297. {
  298. $(obj).siblings().removeClass('oc-m-coupons-selected');
  299. $(obj).removeClass('oc-m-coupons-unselected');
  300. $(obj).addClass('oc-m-coupons-selected');
  301. voucher_id = $(obj).attr('data-voucher-id');
  302. voucher_money = parseFloat( $(obj).attr('data-voucher-credit'));
  303. change_total_free();
  304. if(voucher_money > 0)
  305. {
  306. $('.oc-mall-coupons').html('<span>'+$(obj).children('.oc-m-coupon-right').children('.oc-m-coupon-min').html()+'</span>');
  307. $('.oc-mall-coupon-desc').html('- '+voucher_money+'元');
  308. }
  309. else
  310. $('.oc-mall-coupon-desc').html(voucher_money+'元');
  311. $('.oc-coupons').hide();
  312. }
  313. function get_voucher(quan_id)
  314. {
  315. $.ajax({
  316. url:get_vouher_url,
  317. type:'post',
  318. data:{quan_id:quan_id},
  319. dataType:'json',
  320. success:function(result){
  321. showTip(result.msg);
  322. }
  323. })
  324. }
  325. function change_total_free()
  326. {
  327. var goods_price = parseFloat($('#goods_price').attr('data-price'));
  328. var skuNum = parseInt($('#skuNum').val());
  329. if($('#trans_free').val() == undefined){
  330. $('#trans_free').val(0)
  331. var trans_free = 0;
  332. } else{
  333. var trans_free = parseFloat($('#trans_free').val());
  334. }
  335. var total_free = ((goods_price*skuNum) + trans_free - voucher_money).toFixed(2);
  336. if(total_free<0)
  337. {
  338. total_free = 0;
  339. }
  340. if(is_free_tuan ==1)
  341. {
  342. $('#total_free').html( '¥0(免单券开团)');
  343. $('.oc-finial-amount').html('¥0(免单券开团)');
  344. } else{
  345. $('#total_free').html( '¥'+ total_free);
  346. $('.oc-finial-amount').html('¥'+ total_free);
  347. }
  348. }