main.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. var vm_login = new Vue({
  2. el: '#vscope-login',
  3. data: {
  4. mobile: '',
  5. verify_coder: '',
  6. is_disabled: false,
  7. code_lefttime: 0,
  8. code_timeer: null
  9. },
  10. methods: {
  11. login: function(ajax_url){
  12. var self = this;
  13. if(! self.check()){
  14. return false;
  15. }
  16. // 登录
  17. var query = new Object();
  18. query.mobile = self.mobile;
  19. query.verify_coder = self.verify_coder;
  20. $.ajax({
  21. url:ajax_url,
  22. data:query,
  23. type:"POST",
  24. dataType:"json",
  25. success:function(result){
  26. if(result.status == 1){
  27. //返回分享页
  28. if(result.error){
  29. $.toast(result.error,1000);
  30. if(result.is_url){
  31. setTimeout(function(){
  32. location.href= result.url;
  33. },1000);
  34. }
  35. }else{
  36. if(result.is_url){
  37. location.href= result.url;
  38. }
  39. }
  40. }
  41. else{
  42. if(result.error){
  43. $.toast(result.error,1000);
  44. if(result.is_url){
  45. setTimeout(function(){
  46. location.href= result.url;
  47. },1000);
  48. }
  49. }
  50. else{
  51. $.toast("操作失败");
  52. }
  53. }
  54. }
  55. });
  56. },
  57. check: function(val, event){
  58. // 验证表单
  59. var self = this;
  60. if($.trim(self.mobile).length == 0)
  61. {
  62. $.toast("手机号码不能为空");
  63. return false;
  64. }
  65. if(!$.checkMobilePhone(self.mobile))
  66. {
  67. $.toast("手机号码格式错误");
  68. return false;
  69. }
  70. if(!$.maxLength(self.mobile,11,true))
  71. {
  72. $.toast("长度不能超过11位");
  73. return false;
  74. }
  75. else{
  76. return true;
  77. }
  78. },
  79. send_code: function(event){
  80. // 发送验证码
  81. var self = this;
  82. if(self.is_disabled){
  83. $.toast("发送速度太快了");
  84. return false;
  85. }
  86. else{
  87. var thiscountdown=$("#j-send-code");
  88. var query = new Object();
  89. query.mobile = self.mobile;
  90. $.ajax({
  91. url:APP_ROOT+"/mapi/index.php?ctl=login&act=send_mobile_verify&type=1",
  92. data:query,
  93. type:"POST",
  94. dataType:"json",
  95. success:function(result){
  96. if(result.status == 1){
  97. countdown = 60;
  98. // 验证码倒计时
  99. vm_login.code_lefttime = 60;
  100. self.code_lefttime_fuc("#j-send-code", self.code_lefttime);
  101. // $.showSuccess(result.info);
  102. return false;
  103. }
  104. else{
  105. $.toast(result.error);
  106. return false;
  107. }
  108. }
  109. });
  110. }
  111. },
  112. code_lefttime_fuc: function(verify_name,code_lefttime){
  113. // 验证码倒计时
  114. var self = this;
  115. clearTimeout(self.code_timeer);
  116. $(verify_name).html("重新发送 "+code_lefttime);
  117. code_lefttime--;
  118. if(code_lefttime >0){
  119. $(verify_name).attr("disabled","disabled");
  120. self.is_disabled=true;
  121. vm_login.code_timeer = setTimeout(function(){self.code_lefttime_fuc(verify_name,code_lefttime);},1000);
  122. }
  123. else{
  124. code_lefttime = 60;
  125. self.is_disabled=false;
  126. $(verify_name).removeAttr("disabled");
  127. $(verify_name).html("发送验证码");
  128. }
  129. }
  130. }
  131. });
  132. function infinite_scroll($page,ajax_url,cls,vm_paging,func) {
  133. if (loading || vm_paging.page>total_page){
  134. $(".content-inner").css({paddingBottom:"0"});
  135. return;
  136. }
  137. loading = true;
  138. handleAjax.handle(ajax_url,{page:vm_paging.page},"html").done(function(result){
  139. var tplElement = $('<div id="tmpHTML"></div>').html(result),
  140. htmlObject = tplElement.find(cls),
  141. html = $(htmlObject).html();
  142. $(html).find(".total_page").remove();
  143. vm_paging.page++;
  144. loading = false;
  145. $($page).find(cls).append(html);
  146. $.refreshScroller();
  147. if(func!=null){
  148. func();
  149. }
  150. // $('.lazyload').picLazyLoad();
  151. }).fail(function(err){
  152. $.toast(err);
  153. });
  154. }
  155. function pull_refresh($page,ajax_url,cls,vm_paging,callback){
  156. var loading = false;
  157. if (loading) return;
  158. loading =true;
  159. handleAjax.handle(ajax_url,'',"html").done(function(result){
  160. refreshing = false;
  161. var tplElement = $('<div id="tmpHTML"></div>').html(result),
  162. htmlObject = tplElement.find(cls),
  163. list_ele = $($page).find(cls),
  164. html = $(htmlObject).html();
  165. value = html.replace(/\s+/g,"");
  166. var result = $(result).find(".content").html(), total_page = htmlObject.find("input[name='total_page']").val();
  167. loading =false;
  168. vm_paging.page = 2;
  169. vm_paging.total_page = total_page;
  170. setTimeout(function() {
  171. list_ele.addClass('animated fadeInUp').html(value.length > 0 ? html : '<div style="text-align:center;color:#999;font-size:0.75rem;">暂无数据</div>');
  172. setTimeout(function(){
  173. list_ele.removeClass('fadeInUp');
  174. }, 1000);
  175. // 加载完毕需要重置
  176. $.pullToRefreshDone('.pull-to-refresh-content');
  177. $(".pull-to-refcontainerresh-layer").css({"visibility":"visible"});
  178. // 初始化分页数据
  179. page = 2;
  180. // 初始化懒加载图片
  181. // $('.lazyload').picLazyLoad();
  182. if(typeof(callback) == 'function'){
  183. callback.call(this);
  184. }
  185. }, 300);
  186. }).fail(function(err){
  187. $.toast(err);
  188. });
  189. }
  190. // 分销商品列表
  191. $(document).on("pageInit","#page-shop-distribution_goods_list", function(e, pageId, $page) {
  192. init_paramet();
  193. var vm_paging = new Vue({
  194. el: "#vscope-paging",
  195. data: {
  196. total_page: total_page,
  197. page: page,
  198. }
  199. });
  200. $(document).on('click', '.J-distribution', function(){
  201. var self = $(this);
  202. if(self.hasClass('is_distribution')) return;
  203. var goods_id = self.attr("data-id");
  204. handleAjax.handle(TMPL+"index.php?ctl=shop&act=add_distribution_goods",{goods_id:goods_id}).done(function(resp){
  205. self.addClass('is_distribution');
  206. $.toast(resp,1000);
  207. setTimeout(function(){
  208. self.html('已添加分销');
  209. },1000);
  210. }).fail(function(err){
  211. $.toast(err,1000);
  212. });
  213. });
  214. // 无限滚动
  215. $($page).on('infinite', function(e) {
  216. infinite_scroll($page,ajax_url,".shop-list",vm_paging);
  217. });
  218. //下拉刷新
  219. $($page).find(".pull-to-refresh-content").on('refresh', function(e) {
  220. pull_refresh($page,ajax_url,".shop-list",vm_paging);
  221. $("#search").val('');
  222. var all_options = document.getElementById("goods_cate").options;
  223. for (i=0; i<all_options.length; i++){
  224. if (all_options[i].id == 0) // 根据option标签的ID来进行判断 测试的代码这里是两个等号
  225. {
  226. all_options[i].selected = true;
  227. }
  228. }
  229. });
  230. // 初始化参数
  231. function init_paramet(){
  232. // var urlinfo = window.location.href; //获取url
  233. // paramet.content = decodeURI(urlinfo.split("&")[2].split("=")[1]);
  234. new_paramet = paramet.options ? '&options='+paramet.options : '',
  235. // new_paramet = paramet.content ? new_paramet+'&content='+paramet.content : new_paramet,
  236. // new_paramet = paramet.page ? new_paramet+'&page='+paramet.page : new_paramet,
  237. ajax_url = APP_ROOT+"/wap/index.php?ctl=shop&act=distribution_goods_list"+new_paramet;
  238. };
  239. $(function(){
  240. var option_url1 = TMPL + "index.php?ctl=shop&act=distribution_goods_list&options=1&cate_id=" + paramet.cate_id;
  241. var option_url2 = TMPL + "index.php?ctl=shop&act=distribution_goods_list&options=2&cate_id=" + paramet.cate_id;
  242. var option_url3 = TMPL + "index.php?ctl=shop&act=distribution_goods_list&options=3&cate_id=" + paramet.cate_id;
  243. $(".option1").attr("href",option_url1);
  244. $(".option2").attr("href",option_url2);
  245. $(".option3").attr("href",option_url3);
  246. });
  247. //分类筛选
  248. $(".select").change(function(){
  249. var self= $('option').not(function(){ return !this.selected });
  250. var id = self.attr("data-id");
  251. location.href = TMPL + "index.php?ctl=shop&act=distribution_goods_list&cate_id=" + id + "&options=" + paramet.options + "&page=" + data.page;
  252. });
  253. if(paramet.cate_id){
  254. if($("#search option").attr("data-id") == paramet.cate_id){
  255. $(this).attr("selected", true);
  256. }
  257. }
  258. //搜索关键字
  259. $(document).on('click', '.J-search', function(){
  260. var content = $("#search").val();
  261. console.log(data);
  262. location.href = TMPL + "index.php?ctl=shop&act=distribution_goods_list&content=" + content + "&options=" + paramet.options + "&page=" + data.page;
  263. });
  264. });
  265. $(document).on("pageInit","#page-shop-goods_details", function(e, pageId, $page) {
  266. $(document).on('click', '.J-anchor', function(){
  267. handleAjax.handle(TMPL+"index.php?ctl=shop&act=add_distribution_goods",{goods_id:goods_id}).done(function(resp){
  268. $.toast(resp,1000);
  269. setTimeout(function(){
  270. self.html('已添加分销');
  271. },1000);
  272. }).fail(function(err){
  273. $.toast(err,1000);
  274. });
  275. });
  276. });
  277. $(document).on("pageInit", "#page-shop-new_address", function(e, pageId, $page) {
  278. $("#city-picker").cityPicker({
  279. //value: ['四川', '内江', '东兴区']
  280. });
  281. $("#city-picker").click(function(){
  282. $("input:not(this)").blur();
  283. });
  284. function objBlur(obj, time){
  285. if(typeof obj != 'string') return false;
  286. var obj = document.getElementById(obj),
  287. time = time || 300,
  288. docTouchend = function(event){
  289. if(event.target!= obj){
  290. setTimeout(function(){
  291. obj.blur();
  292. document.removeEventListener('touchend', docTouchend,false);
  293. },time);
  294. }
  295. };
  296. if(obj){
  297. obj.addEventListener('focus', function(){
  298. //注释这部分是在一个页面多个这样的调用时禁止冒泡让他不要让ios默认输入框上下弹,最好写在对应页面里给对应元素写这里效率低,这种写法很差所以先注释掉下次优化再贴
  299. // var input = document.getElementsByTagName('input'),
  300. // ilength = input.length;
  301. // for(var i=0; i<ilength; i++){
  302. // input[i].addEventListener('touchend',function(e){e.stopPropagation()},false);
  303. // }
  304. // var textarea = document.getElementsByTagName('textarea'),
  305. // tlength = textarea.length;
  306. // for(var i=0; i<tlength; i++){
  307. // textarea[i].addEventListener('touchend',function(e){e.stopPropagation()},false);
  308. // }
  309. document.addEventListener('touchend', docTouchend,false);
  310. },false);
  311. }else{
  312. //找不到obj
  313. }
  314. };
  315. var isIPHONE = navigator.userAgent.toUpperCase().indexOf('IPHONE')!= -1;
  316. if(isIPHONE){
  317. var input = objBlur('input');
  318. input = null;
  319. }
  320. $('.item-input').find("input[name=consignee]").blur(function() {
  321. var consignee = $(this).val();
  322. data.consignee = consignee;
  323. });
  324. $('.item-input').find("input[name=consignee_mobile]").blur(function() {
  325. var consignee_mobile = $(this).val();
  326. data.consignee_mobile = consignee_mobile;
  327. });
  328. $('.item-input').find("input[name=consignee_address]").blur(function() {
  329. var consignee_address = $(this).val();
  330. data.consignee_address = consignee_address;
  331. });
  332. $(".J-save").click(function() {
  333. data.consignee_district = $("#city-picker").val();
  334. console.log(data.consignee_district);
  335. if ($.checkEmpty(data.consignee)) {
  336. $.toast("收货人不能为空");
  337. return false;
  338. }
  339. if ($.trim(data.consignee_mobile).length == 0) {
  340. $.toast("手机号码不能为空");
  341. return false;
  342. }
  343. if (!$.checkMobilePhone(data.consignee_mobile)) {
  344. $.toast("手机号码格式错误");
  345. return false;
  346. }
  347. if (!$.maxLength(data.consignee_mobile, 11, true)) {
  348. $.toast("手机号码长度不能超过11位");
  349. return false;
  350. }
  351. if ($.checkEmpty(data.consignee_address)) {
  352. $.toast("请输入收货地址");
  353. return false;
  354. }
  355. if ($.checkEmpty(data.consignee_district)) {
  356. $.toast("请输入收货地址");
  357. return false;
  358. }
  359. $.ajax({
  360. url: APP_ROOT + "/wap/index.php?ctl=shop&act=editaddress&post_type=json&itype=shop",
  361. type: "post",
  362. data: data,
  363. dataType: "json",
  364. beforeSend: function() {
  365. $.showIndicator();
  366. onload = function() {
  367. var a = document.querySelector("a");
  368. a.onclick = function() {
  369. if (this.disabled) {
  370. return false;
  371. }
  372. this.style.color = 'grey';
  373. this.disabed = true;
  374. };
  375. }
  376. },
  377. success: function(result) {
  378. if (result.status == 1) {
  379. $.toast("操作成功");
  380. history.back();
  381. } else {
  382. $.toast(result.error);
  383. }
  384. },
  385. error: function() {
  386. $.toast(err);
  387. },
  388. complete: function() {
  389. $.hideIndicator();
  390. }
  391. });
  392. });
  393. });
  394. $(document).on("pageInit", "#page-shop-order_settlement", function(e, pageId, $page) {
  395. for(var i=0;i<shop_info.length;i++){
  396. var obj_shop_info = shop_info[i], goods_obj = {};
  397. for(var j in obj_shop_info){
  398. if(j == "goods_id"){
  399. goods_obj.goods_id = shop_info[i][j];
  400. }
  401. if(j == "number"){
  402. goods_obj.number = shop_info[i][j];
  403. }
  404. if(j == "podcast_id"){
  405. goods_obj.podcast_id = shop_info[i][j];
  406. }
  407. if(j == "order_sn"){
  408. goods_obj.order_sn = shop_info[i][j];
  409. }
  410. }
  411. goods_arr.push(goods_obj);
  412. };
  413. var data_shop_arr = JSON.stringify(goods_arr);
  414. $(document).on('click', '.J-submit-order', function() {
  415. handleAjax.handle(APP_ROOT + "/wap/index.php?ctl=shop&act=goods_inventory", { shop_info: data_shop_arr }, '', 1).done(function(result) {
  416. if (result.status == 1) {
  417. location.href = TMPL + "index.php?ctl=pay&act=h5_pay&purchase_type=" + data.purchase_type + "&shop_info=" + data_shop_arr;
  418. } else {
  419. $.toast(result.error);
  420. return false;
  421. }
  422. }).fail(function(err) {
  423. $.toast(err);
  424. });
  425. });
  426. });
  427. $(document).on("pageInit", "#page-shop-order_settlement_user", function(e, pageId, $page) {
  428. $(document).on('click', '.J-address', function() {
  429. location.href = TMPL + "index.php?ctl=shop&act=new_address&address_id=" + data.address_id;
  430. });
  431. for(var i=0;i<shop_info.length;i++){
  432. var obj_shop_info = shop_info[i], goods_obj = {};
  433. for(var j in obj_shop_info){
  434. if(j == "goods_id"){
  435. goods_obj.goods_id = shop_info[i][j];
  436. }
  437. if(j == "number"){
  438. goods_obj.number = shop_info[i][j];
  439. }
  440. if(j == "podcast_id"){
  441. goods_obj.podcast_id = shop_info[i][j];
  442. }
  443. if(j == "order_sn"){
  444. goods_obj.order_sn = shop_info[i][j];
  445. }
  446. }
  447. goods_arr.push(goods_obj);
  448. };
  449. $(document).on('click','.confirm-ok', function () {
  450. var id = $(this).attr("data-id"), val = $(this).val();
  451. console.log(val);
  452. $.alert('<textarea class="footer-input" type="text" name="remarks" data-id="'+id+'" value="'+val+'" placeholder="选填:对本次交易的说明(建议填写已和卖家协商一致的内容)">'+val+'</textarea>', function() {
  453. var text = $(".modal").find("textarea"),text_id = text.attr("data-id");
  454. $(".liuyan-"+id).val(text.val());
  455. });
  456. });
  457. $(document).on('click', '.J-submit-order', function() {
  458. $(".goods-item").each(function(index, element){
  459. var self = $(this), i = index, input_remarks = self.find("input[name='remarks']");
  460. goods_arr[i].memo = input_remarks.val();
  461. });
  462. console.log(goods_arr);
  463. var data_shop_arr = JSON.stringify(goods_arr);
  464. if (data.address_id == '') {
  465. $.toast('地址不能为空', 1000);
  466. } else {
  467. handleAjax.handle(APP_ROOT + "/wap/index.php?ctl=shop&act=goods_inventory", { shop_info: data_shop_arr }, '', 1).done(function(result) {
  468. if (result.status == 1) {
  469. location.href = TMPL + "index.php?ctl=pay&act=h5_pay&address_id=" + data.address_id + "&purchase_type=" + data.purchase_type + "&shop_info="+data_shop_arr;
  470. } else {
  471. $.toast(result.error);
  472. return false;
  473. }
  474. }).fail(function(err) {
  475. $.toast(err);
  476. });
  477. }
  478. });
  479. });
  480. // 商品管理列表
  481. $(document).on("pageInit", "#page-shop-podcasr_goods_management", function(e, pageId, $page) {
  482. init_paramet();
  483. var vm_paging = new Vue({
  484. el: "#vscope-paging",
  485. data: {
  486. total_page: total_page,
  487. page: page,
  488. }
  489. });
  490. // 下架商品
  491. $(document).on('click', '.J-podcasr_shelves_goods', function() {
  492. var self = $(this);
  493. var goods_id = self.attr("data-id");
  494. handleAjax.handle(TMPL + "index.php?ctl=shop&act=podcasr_shelves_goods", { goods_id: goods_id }).done(function(resp) {
  495. $.toast(resp, 1000);
  496. setTimeout(function() {
  497. $("#goods-item-" + goods_id).remove();
  498. }, 1000);
  499. }).fail(function(err) {
  500. $.toast(err, 1000);
  501. });
  502. });
  503. // 删除下架商品
  504. $(document).on('click', '.J-podcasr_delete_goods', function() {
  505. var self = $(this);
  506. var goods_id = self.attr("data-id");
  507. handleAjax.handle(TMPL + "index.php?ctl=shop&act=podcasr_delete_goods", { goods_id: goods_id }).done(function(resp) {
  508. $.toast(resp, 1000);
  509. setTimeout(function() {
  510. $("#goods-item-" + goods_id).remove();
  511. }, 1000);
  512. }).fail(function(err) {
  513. $.toast(err, 1000);
  514. });
  515. });
  516. // 添加分销商品
  517. /* $(document).on('click', '#J-add_distribution_goods', function(){
  518. var self = $(this);
  519. var goods_id = self.attr("data-id");
  520. handleAjax.handle(TMPL+"index.php?ctl=shop&act=add_distribution_goods",{goods_id:goods_id}).done(function(resp){
  521. $.toast(resp,1000);
  522. setTimeout(function(){
  523. location.reload();
  524. },1000);
  525. }).fail(function(err){
  526. $.toast(err,1000);
  527. });
  528. });*/
  529. // 清空下架商品
  530. $(document).on('click', '#J-podcasr_empty_goods', function() {
  531. handleAjax.handle(TMPL + "index.php?ctl=shop&act=podcasr_empty_goods").done(function(resp) {
  532. $.toast(resp, 1000);
  533. setTimeout(function() {
  534. var html = '<div class="tc" style="color:#999;margin-top:50%;">' +
  535. ' <i class="icon iconfont" style="font-size:3rem;line-height:1;">&#xe63f;</i>' +
  536. ' <div>暂无分销商品,点击马上添加哦~</div>' +
  537. '</div>';
  538. $($page).find(".goods-list").html(html);
  539. }, 1000);
  540. }).fail(function(err) {
  541. $.toast(err, 1000);
  542. });
  543. });
  544. // 无限滚动
  545. $($page).on('infinite', function(e) {
  546. infinite_scroll($page,ajax_url,".goods-list",vm_paging);
  547. });
  548. //下拉刷新
  549. $($page).find(".pull-to-refresh-content").on('refresh', function(e) {
  550. pull_refresh($page,ajax_url,".goods-list",vm_paging);
  551. $("#search").val("");
  552. });
  553. // 初始化参数
  554. function init_paramet(){
  555. // var urlinfo = window.location.href; //获取url
  556. // paramet.content = decodeURI(urlinfo.split("&")[2].split("=")[1]);
  557. new_paramet = paramet.state ? '&state='+paramet.state : '',
  558. // new_paramet = paramet.content ? new_paramet+'&content='+paramet.content : new_paramet,
  559. // new_paramet = paramet.page ? new_paramet+'&page='+paramet.page : new_paramet,
  560. ajax_url = APP_ROOT+"/wap/index.php?ctl=shop&act=podcasr_goods_management"+new_paramet;
  561. };
  562. $(document).on('click', '.J-search', function(){
  563. var content = $("#search").val();
  564. location.href = encodeURI(TMPL + "index.php?ctl=shop&act=podcasr_goods_management&content=" + content + "&state=" + data.state + "&page=" + data.page);
  565. });
  566. });
  567. $(document).on("pageInit","#page-shop-shop_goods_details", function(e, pageId, $page) {
  568. var shop_arr = [];
  569. shop_arr.push({podcast_id:data.podcast_id,goods_id:data.goods_id,number:data.number});
  570. var data_shop_arr = JSON.stringify(shop_arr);
  571. $(document).on('click', '.J-anchor', function(){
  572. location.href = TMPL+"index.php?ctl=shop&act=order_settlement&shop_info="+data_shop_arr;
  573. });
  574. $(document).on('click', '.J-oneself', function(){
  575. location.href = TMPL+"index.php?ctl=shop&act=order_settlement_user&shop_info="+data_shop_arr;
  576. });
  577. });
  578. $(document).on("pageInit", "#page-shop-shop_goods_list", function(e, pageId, $page) {
  579. init_paramet();
  580. var vm_paging = new Vue({
  581. el: "#vscope-paging",
  582. data: {
  583. total_page: total_page,
  584. page: page,
  585. }
  586. });
  587. // 无限滚动
  588. $($page).on('infinite', function(e) {
  589. infinite_scroll($page, ajax_url, ".goods-list", vm_paging);
  590. });
  591. // 下拉刷新
  592. $($page).find(".pull-to-refresh-content").on('refresh', function(e) {
  593. pull_refresh($page, ajax_url, ".goods-list", vm_paging);
  594. $("#search").val('');
  595. });
  596. //增加购买数量
  597. $(".input-goods-num").val(0);
  598. $(document).on('click', '.add', function() {
  599. var self = $(this);
  600. var goods_id = self.attr("data-id");
  601. var num = parseInt($(this).siblings(".input-goods-num").val()) || 0;
  602. if(num < 99){
  603. num = num + 1;
  604. }
  605. // $(".input-goods-num").val(0);
  606. $(this).siblings(".input-goods-num").val(num);
  607. data.goods_id = goods_id;
  608. data.number = Number(num);
  609. });
  610. //减少购买数量
  611. $(document).on('click', '.lost', function() {
  612. var self = $(this);
  613. var goods_id = self.attr("data-id");
  614. var num = parseInt($(this).siblings(".input-goods-num").val()) || 0;
  615. if(num > 0){
  616. num = num - 1;
  617. }
  618. // $(".input-goods-num").val(0);
  619. $(this).siblings(".input-goods-num").val(num);
  620. data.goods_id = goods_id;
  621. data.number = Number(num);
  622. });
  623. $('.input-goods-num').blur(function() {
  624. var self = $(this);
  625. var goods_id = self.attr("data-id");
  626. data.goods_id = goods_id;
  627. data.number = Number($(this).val());
  628. });
  629. $('.input-goods-num').bind('input propertychange', function() {
  630. var self = $(this),
  631. self_num = self.val();
  632. // if (self_num) {
  633. // $(".input-goods-num").not(self).val(0);
  634. // }
  635. if (self_num>99) {
  636. $(this).val(99);
  637. }
  638. });
  639. //买给主播
  640. $(document).on('click', '.J-anchor', function() {
  641. var shop_arr = [];
  642. $(".goods-item").each(function(){
  643. var self = $(this), input_amount = self.find("input[name='amount']");
  644. if(input_amount.val()>0){
  645. shop_arr.push({podcast_id:data.podcast_id,goods_id: input_amount.attr("data-id"), number: input_amount.val()});
  646. }
  647. });
  648. var data_shop_arr = JSON.stringify(shop_arr);
  649. if (shop_arr.length) {
  650. location.href = TMPL + "index.php?ctl=shop&act=order_settlement&shop_info="+data_shop_arr;
  651. } else {
  652. $.toast("请先选择商品");
  653. return false;
  654. }
  655. });
  656. //买给自己
  657. $(document).on('click', '.J-oneself', function() {
  658. var shop_arr = [];
  659. $(".goods-item").each(function(){
  660. var self = $(this), input_amount = self.find("input[name='amount']");
  661. if(input_amount.val()>0){
  662. shop_arr.push({podcast_id:data.podcast_id,goods_id:input_amount.attr("data-id"),number:input_amount.val()});
  663. }
  664. });
  665. var data_shop_arr = JSON.stringify(shop_arr);
  666. if (shop_arr.length) {
  667. location.href = TMPL + "index.php?ctl=shop&act=order_settlement_user&shop_info="+data_shop_arr;
  668. } else {
  669. $.toast("请先选择商品");
  670. return false;
  671. }
  672. });
  673. $(document).on('click', '.J-details', function() {
  674. var self = $(this);
  675. var goods_id = self.attr("data-id");
  676. location.href = TMPL + "index.php?ctl=shop&act=shop_goods_details&podcast_id=" + data.podcast_id + "&goods_id=" + goods_id;
  677. });
  678. // 初始化参数
  679. function init_paramet() {
  680. // var urlinfo = window.location.href; //获取url
  681. // paramet.content = decodeURI(urlinfo.split("&")[2].split("=")[1]);
  682. new_paramet = paramet.podcast_id ? '&podcast_id=' + paramet.podcast_id : '',
  683. // new_paramet = paramet.content ? new_paramet+'&content='+paramet.content : new_paramet,
  684. // new_paramet = paramet.page ? new_paramet+'&page='+paramet.page : new_paramet,
  685. ajax_url = APP_ROOT + "/wap/index.php?ctl=shop&act=shop_goods_list" + new_paramet;
  686. }
  687. //搜索关键字
  688. $(document).on('click', '.J-search', function(){
  689. var content = $("#search").val();
  690. location.href = TMPL + "index.php?ctl=shop&act=shop_goods_list&content=" + content + "&podcast_id=" + data.podcast_id + "&page=" + data.page;
  691. });
  692. //加入购物车
  693. $(document).on('click', '.J-add_shopping_cart', function(){
  694. var self = $(this);
  695. var goods_id = self.attr('data-id'), number = self.parents(".card").find("input[name=amount]").val();
  696. if(number>0){
  697. handleAjax.handle(TMPL + "index.php?ctl=shop&act=join_shopping",{goods_id:goods_id, podcast_id:data.podcast_id, number:number}).done(function(resp){
  698. setTimeout(function(){
  699. $.toast('已添加购物车');
  700. },1000);
  701. }).fail(function(err){
  702. $.toast(err,1000);
  703. });
  704. }else{
  705. $.toast("请先选择商品");
  706. return false;
  707. }
  708. });
  709. });
  710. $(document).on("pageInit","#page-shop-shop_order", function(e, pageId, $page) {
  711. init_paramet();
  712. var vm_paging = new Vue({
  713. el: "#vscope-paging",
  714. data: {
  715. total_page: total_page,
  716. page: page,
  717. }
  718. });
  719. // 无限滚动
  720. $($page).on('infinite', function(e) {
  721. infinite_scroll($page,ajax_url,".goods-list",vm_paging);
  722. });
  723. // 下拉刷新
  724. $($page).find(".pull-to-refresh-content").on('refresh', function(e) {
  725. pull_refresh($page,ajax_url,".goods-list",vm_paging,function(){
  726. $(".left_time").each(function(){
  727. var leftTime = Math.abs(parseInt($(this).attr("data-leftTime")));
  728. left_time(leftTime,$(this));
  729. });
  730. });
  731. });
  732. $(document).on('click', '.J-pay', function(){
  733. var self = $(this);
  734. var order_id = self.attr("data-order_id");
  735. var order_sn = self.attr("data-order_sn");
  736. window.location.href = TMPL + "index.php?ctl=pay&act=h5_pay&order_sn="+order_sn+"&order_id="+order_id;
  737. // $.ajax({
  738. // url: APP_ROOT+"/mapi/index.php?ctl=pay&act=h5_pay",
  739. // data: {itype:"shop", order_id:order_id,order_sn:order_sn},
  740. // type: 'POST',
  741. // dataType: 'json',
  742. // success:function(data){
  743. // if(data.status == 1){
  744. // $.toast(data.error,1000);
  745. // setTimeout(function(){
  746. // window.location.reload();
  747. // },1000);
  748. // }
  749. // else{
  750. // $.toast(data.error,1000);
  751. // }
  752. // },
  753. // error:function(){
  754. // $.hideIndicator();
  755. // $.toast('请求失败,请检查网络',1000);
  756. // }
  757. // });
  758. });
  759. $(document).on('click', '.J-confirm', function(){
  760. var self = $(this);
  761. var to_podcast_id = self.attr("data-to_podcast_id");
  762. var order_sn = self.attr("data-order_sn");
  763. $.confirm("是否确认收货?",function(s){
  764. handleAjax.handle(TMPL+"index.php?ctl=pai_podcast&act=buyer_confirm_date",{to_podcast_id:to_podcast_id,order_sn:order_sn}).done(function(resp){
  765. $.toast('确认收货成功',1000);
  766. setTimeout(function(){
  767. window.location.reload();
  768. },1000);
  769. }).fail(function(err){
  770. $.toast(err,1000);
  771. });
  772. });
  773. });
  774. $(document).on('click', '.J-remind', function(){
  775. $.toast('已经提醒商家',1000);
  776. });
  777. $(document).on('click', '.J-detail', function(){
  778. var self = $(this);
  779. var order_id = self.attr("data-order_id");
  780. var order_sn = self.attr("data-order_sn");
  781. location.href = TMPL+"index.php?ctl=shop&act=virtual_shop_order_details&order_id="+order_id+"&order_sn="+order_sn;
  782. });
  783. // 初始化参数
  784. function init_paramet(){
  785. new_paramet = paramet.state ? '&state='+paramet.state : '',
  786. ajax_url = APP_ROOT+"/wap/index.php?ctl=shop&act=shop_order"+new_paramet;
  787. console.log(ajax_url);
  788. }
  789. });
  790. $(document).on("pageInit","#page-shop-shop_shopping_cart", function(e, pageId, $page) {
  791. all_js();
  792. init_paramet();
  793. var vm_paging = new Vue({
  794. el: "#vscope-paging",
  795. data: {
  796. total_page: total_page,
  797. page: page,
  798. }
  799. });
  800. // 无限滚动
  801. $($page).on('infinite', function(e) {
  802. infinite_scroll($page, ajax_url, ".goods-list", vm_paging);
  803. });
  804. // 下拉刷新
  805. $($page).find(".pull-to-refresh-content").on('refresh', function(e) {
  806. pull_refresh($page, ajax_url, ".goods-list", vm_paging, function(){
  807. all_js();
  808. });
  809. $(".J-money").html(0);
  810. $("input[name=shopping-cart-all]").prop('checked',false);
  811. });
  812. // 初始化参数
  813. function init_paramet() {
  814. // var urlinfo = window.location.href; //获取url
  815. // paramet.content = decodeURI(urlinfo.split("&")[2].split("=")[1]);
  816. new_paramet = paramet.page ? '&page=' + paramet.page : '',
  817. ajax_url = APP_ROOT + "/wap/index.php?ctl=shop&act=shop_shopping_cart&page=1";
  818. };
  819. function all_js() {
  820. var shopping_cart_top = $("input[name=shopping-cart-top]"),
  821. shopping_cart = $("input[name=shopping-cart]"),
  822. shopping_cart_all = $("input[name=shopping-cart-all]");
  823. shopping_cart_top.click(function(){
  824. var self = $(this);
  825. if(self.is(":checked")){
  826. // $(".input-check-"+id).prop('checked',true);
  827. self.parents(".card").find("input[name=shopping-cart]").prop('checked',true);
  828. }else{
  829. // $(".input-check-"+id).prop('checked',false);
  830. self.parents(".card").find("input[name=shopping-cart]").prop('checked',false);
  831. }
  832. var sum = 0;
  833. $("input[name=shopping-cart]:checked").each(function(){
  834. sum += parseFloat($(this).parent().find(".input-money").val()*$(this).parent().find(".goods-numb").attr("data-id"));
  835. });
  836. sum = sum.toFixed(2);
  837. $(".J-money").html(sum);
  838. var card_length = $(".card").length;
  839. var checked_top_length = $("input[name=shopping-cart-top]:checked").length;
  840. if (checked_top_length == card_length) {
  841. shopping_cart_all.prop('checked',true);
  842. }else{
  843. shopping_cart_all.prop('checked',false);
  844. }
  845. });
  846. shopping_cart.click(function(){
  847. if(shopping_cart.is(":checked")){
  848. }else{
  849. $(this).parents(".card").find("input[name=shopping-cart-top]").prop('checked',false);
  850. $(shopping_cart_all).prop('checked',false);
  851. }
  852. var card_content_length = $(this).parents(".card").find(".card-content").length;
  853. var checked_length = $(this).parents(".card").find("input[name=shopping-cart]:checked").length;
  854. if (checked_length == card_content_length) {
  855. $(this).parents(".card").find("input[name=shopping-cart-top]").prop('checked',true);
  856. }else{
  857. $(this).parents(".card").find("input[name=shopping-cart-top]").prop('checked',false);
  858. }
  859. var card_length = $(".card").length;
  860. var checked_top_length = $("input[name=shopping-cart-top]:checked").length;
  861. if (checked_top_length == card_length) {
  862. shopping_cart_all.prop('checked',true);
  863. }else{
  864. shopping_cart_all.prop('checked',false);
  865. }
  866. var sum = 0;
  867. $("input[name=shopping-cart]:checked").each(function(){
  868. sum += parseFloat($(this).parent().find(".input-money").val()*$(this).parent().find(".goods-numb").attr("data-id"));
  869. });
  870. sum = sum.toFixed(2);
  871. $(".J-money").html(sum);
  872. });
  873. //编辑
  874. $(".J-edit").click(function(){
  875. var self = $(this);
  876. var txt = self.html();
  877. var goods_id = self.attr("data-id"), podcast_id = self.attr("data-podcast_id"), number = self.parents(".card").find("input[name=amount]").val();
  878. if (txt =="编辑") {
  879. self.html('完成');
  880. }else if (txt =="完成") {
  881. self.html('编辑');
  882. handleAjax.handle(TMPL + "index.php?ctl=shop&act=update_shopping_goods", { goods_id: goods_id, podcast_id:podcast_id, number:number}).done(function(resp) {
  883. $.toast(resp,1000);
  884. setTimeout(function() {
  885. window.location.reload();
  886. });
  887. }).fail(function(err) {
  888. $.toast(err, 1000);
  889. });
  890. }
  891. self.parents(".card").find(".goods-text").toggleClass("active");
  892. self.parents(".card").find(".goods-edit").toggleClass("active");
  893. });
  894. //删除
  895. $(".J-delete").click(function(){
  896. var self = $(this);
  897. var parents_card = self.parents(".card");
  898. var goods_id = self.attr("data-id"), podcast_id = self.attr("data-podcast_id"), number = self.parents(".card").find("input[name=amount]").val();
  899. $.confirm('是否确定删除商品?',function () {
  900. handleAjax.handle(TMPL + "index.php?ctl=shop&act=delete_shopping_goods", { goods_id: goods_id, podcast_id:podcast_id, number:number}).done(function(resp) {
  901. setTimeout(function() {
  902. parents_card.remove();
  903. var sum = 0;
  904. $("input[name=shopping-cart]:checked").each(function(){
  905. sum += parseFloat($(this).parent().find(".input-money").val()*$(this).parent().find(".goods-numb").attr("data-id"));
  906. });
  907. sum = sum.toFixed(2);
  908. $(".J-money").html(sum);
  909. });
  910. }).fail(function(err) {
  911. $.toast(err, 1000);
  912. });
  913. });
  914. });
  915. shopping_cart_all.click(function(){
  916. if(shopping_cart_all.is(":checked")){
  917. $(".input-check").prop('checked',true);
  918. }else{
  919. $(".input-check").prop('checked',false);
  920. }
  921. var sum = 0;
  922. $("input[name=shopping-cart]:checked").each(function(){
  923. sum += parseFloat($(this).parent().find(".input-money").val()*$(this).parent().find(".goods-numb").attr("data-id"));
  924. });
  925. sum = sum.toFixed(2);
  926. $(".J-money").html(sum);
  927. });
  928. //增加购买数量
  929. $(".add").click(function() {
  930. var self = $(this);
  931. var goods_id = self.attr("data-id");
  932. var num = parseInt($(this).siblings(".input-goods-num").val()) || 0;
  933. if(num < 99){
  934. num = num + 1;
  935. }
  936. $(this).siblings(".input-goods-num").val(num);
  937. });
  938. //减少购买数量
  939. $(".lost").click(function() {
  940. var self = $(this);
  941. var goods_id = self.attr("data-id");
  942. var num = parseInt($(this).siblings(".input-goods-num").val()) || 0;
  943. if(num > 1){
  944. num = num - 1;
  945. }
  946. $(this).siblings(".input-goods-num").val(num);
  947. });
  948. $('.input-goods-num').blur(function() {
  949. var self = $(this);
  950. var goods_id = self.attr("data-id");
  951. });
  952. $('.input-goods-num').bind('input propertychange', function() {
  953. var self = $(this),
  954. self_num = self.val();
  955. // if (self_num) {
  956. // $(".input-goods-num").not(self).val(0);
  957. // }
  958. if (self_num>99) {
  959. $(this).val(99);
  960. }
  961. });
  962. //结算
  963. $(document).on('click', '.J-settlement', function(){
  964. var shop_arr = [];
  965. $("input[name=shopping-cart]:checked").each(function(){
  966. var self = $(this);
  967. var input_amount = self.parents(".card").find("input[name='input-number']");
  968. var input_money = self.parents(".card").find("input[name='input-money']");
  969. if(input_amount.val()>0){
  970. shop_arr.push({podcast_id:input_money.attr("data-podcast_id"),goods_id:input_money.attr("data-id"),number:input_amount.val()});
  971. }
  972. });
  973. var data_shop_arr = JSON.stringify(shop_arr);
  974. if (shop_arr.length) {
  975. location.href = TMPL + "index.php?ctl=shop&act=order_settlement_user&shop_info="+data_shop_arr;
  976. } else {
  977. $.toast("请先选择商品");
  978. return false;
  979. }
  980. });
  981. };
  982. });
  983. $(document).on("pageInit","#page-shop-virtual_shop_order_details", function(e, pageId, $page) {
  984. //付款
  985. $(document).on('click', '.J-pay', function(){
  986. window.location.href = TMPL + "index.php?ctl=pay&act=h5_pay&order_sn="+data.order_sn+"&order_id="+data.order_id;
  987. // $.ajax({
  988. // url: APP_ROOT+"/mapi/index.php?ctl=pay&act=h5_pay&itype=shop",
  989. // data: data,
  990. // type: 'POST',
  991. // dataType: 'json',
  992. // success:function(data){
  993. // if(data.status == 1){
  994. // $.toast(data.error,1000);
  995. // setTimeout(function(){
  996. // window.location.reload();
  997. // },1000);
  998. // }
  999. // else{
  1000. // $.toast(data.error,1000);
  1001. // }
  1002. // },
  1003. // error:function(){
  1004. // $.hideIndicator();
  1005. // $.toast('请求失败,请检查网络',1000);
  1006. // }
  1007. // });
  1008. });
  1009. $(document).on('click', '.J-remind', function(){
  1010. $.toast('已经提醒商家',1000);
  1011. });
  1012. $(document).on('click', '#J-return_virtual_pai', function(){
  1013. handleAjax.handle(TMPL+"index.php?ctl=pai_podcast&act=buyer_confirm_date",data).done(function(resp){
  1014. $.toast('确认收货成功',1000);
  1015. setTimeout(function(){
  1016. window.location.reload();
  1017. },1000);
  1018. }).fail(function(err){
  1019. $.toast(err,1000);
  1020. });
  1021. });
  1022. $(document).on('click', '.J-buyer_to_complaint', function(){
  1023. handleAjax.handle(TMPL+"index.php?ctl=pai_podcast&act=buyer_to_complaint",data).done(function(resp){
  1024. $.toast('已提交申请',1000);
  1025. setTimeout(function(){
  1026. window.location.reload();
  1027. },1000);
  1028. }).fail(function(err){
  1029. $.toast(err,1000);
  1030. });
  1031. });
  1032. });