shoppingCart.html 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  8. <meta name='apple-touch-fullscreen' content='yes'>
  9. <meta name="apple-mobile-web-app-capable" content="yes"/>
  10. <meta content="fullscreen=yes,preventMove=no" name="ML-Config">
  11. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  12. <meta name="renderer" content="webkit">
  13. <meta name="apple-mobile-web-app-capable" content="yes"/>
  14. <meta name="keywords" content="电子烟,关键字"/>
  15. <meta name="Description" content="网站描述"/>
  16. <title>购物车</title>
  17. <link rel="stylesheet" href="/assets/index/css/common.css?t=18">
  18. <link rel="stylesheet" href="/assets/index/css/shoppingCart.css?t=5">
  19. </head>
  20. <body>
  21. <!-- 头部导航栏 -->
  22. <header class="headerContainer" id="headerContainer">
  23. <!-- 顶部提示 -->
  24. <div class="warnContainer">
  25. <h4 class="warnText">WARNING: This product contains nicotine. Nicotine is an addictive chemical.</h4>
  26. </div>
  27. <!-- pc端头部 -->
  28. <div id="computerEndHeader">
  29. <a href="/index/index/index.html">
  30. <h1 class="computerLogo">
  31. <img src="/assets/index/asstes/icon/logo.png" alt="Free Shipping Vapes" title="Free Shipping Vapes">
  32. </h1>
  33. </a>
  34. <div class="headNavContainer">
  35. <nav class="headNavItem active">
  36. <h2 class="headNavTitle">NEW VAPES</h2>
  37. <p class="back"></p>
  38. </nav>
  39. <!-- <nav class="headNavItem">
  40. <h2 class="headNavTitle">DISPOSABLES</h2>
  41. <p class="back"></p>
  42. </nav>-->
  43. </div>
  44. <div class="headIconContainer">
  45. <!-- 购物车 -->
  46. <a href="/index/cart/shoppingCart.html">
  47. <div class="headIconItem shoppingCartIcon">
  48. <img src="/assets/index/asstes/icon/shoppingCart.png" alt="shoppingCart" tabindex="shoppingCart">
  49. </div>
  50. </a>
  51. <!-- 收藏 -->
  52. <!-- <div class="headIconItem collectIcon">-->
  53. <!-- <img src="/assets/index/asstes/icon/collect.png" alt="collect" tabindex="collect">-->
  54. <!-- </div>-->
  55. <!-- 个人中心 -->
  56. <a href="/index/user/order.html">
  57. <div class="headIconItem userIcon">
  58. <img src="/assets/index/asstes/icon/user.png" alt="user" tabindex="user">
  59. </div>
  60. </a>
  61. </div>
  62. </div>
  63. <!-- 移动端头部 -->
  64. <div id="mobileEndHeader">
  65. <div class="mobileEndHeaderConten">
  66. <a href="../index/index.html">
  67. <h1 class="mobileLogo">
  68. <img src="/assets/index/asstes/icon/logo.png" alt="Free Shipping Vapes" title="Free Shipping Vapes">
  69. </h1>
  70. </a>
  71. <div class="mobileUserIconList">
  72. <div class="mobileUserIcon userIcon">
  73. <img src="/assets/index/asstes/icon/user.png" alt="user" tabindex="user">
  74. </div>
  75. </div>
  76. <div class="mobileMenu">
  77. <p id="mobileMenuBot">
  78. <span id="mobileMenuLink"></span>
  79. </p>
  80. </div>
  81. </div>
  82. <!-- 移动端菜单 -->
  83. <section class="mobileMenuFixed">
  84. <div class="mobileMenuItem active">
  85. <a href="/index/index/index.html">
  86. <h2 class="menuItemTitle">NEW VAPES</h2>
  87. </a>
  88. </div>
  89. <!-- <div class="mobileMenuItem">
  90. <a href="#">
  91. <h2 class="menuItemTitle">DISPOSABLES</h2>
  92. </a>
  93. </div>-->
  94. <div class="mobileMenuItem">
  95. <a href="/index/cart/shoppingCart.html">
  96. <h2 class="menuItemTitle shoppingCartIcon">Shopping Cart</h2>
  97. </a>
  98. </div>
  99. <!-- <div class="mobileMenuItem">
  100. <h2 class="menuItemTitle collectIcon">Collect</h2>
  101. </div>-->
  102. <div class="mobileMenuItem">
  103. <a href="/index/user/personal.html">
  104. <h2 class="menuItemTitle userIcon">Personal</h2>
  105. </a></div>
  106. </section>
  107. </div>
  108. </header>
  109. <main id="main">
  110. <section class="pageContainer">
  111. <h1 class="pageTitle">Shopping Cart</h1>
  112. <div class="pageDataBox">
  113. <!-- 商品模块 -->
  114. <section class="productConatiner">
  115. <h3 class="productModelTitle">Product</h3>
  116. <div class="productList">
  117. {foreach $list as $cart}
  118. <div class="productItem" data-id="{$cart['id']}" goods-id="{$cart['goods']['goods_id']}"
  119. goods-sku-id="{$cart['goods']['skuInfo']['goods_sku_id']}"
  120. data-goods-num="{$cart['goods_num']}">
  121. <div class="productImgBox">
  122. <img class="lazy" src="/assets/index/asstes/icon/transparent.png"
  123. data-original="{$cart['goods']['goods_image']}" alt="提示信息seo"
  124. title="提示信息seo">
  125. </div>
  126. <div class="productInfo">
  127. <div class="lfBox">
  128. <h2 class="productTitle">{$cart['goods']['goods_name']}</h2>
  129. <p class="specs">specs</p>
  130. </div>
  131. <div class="nunberBox">
  132. <p class="numberReduce">-</p>
  133. <p class="numberInput">{$cart['goods_num']}</p>
  134. <p class="numberAdd">+</p>
  135. </div>
  136. <p class="productPrice">${$cart['goods']['goods_price_min']}</p>
  137. <div class="productDelete">
  138. <img src="/assets/index/asstes/icon/productDelete.png" alt="">
  139. </div>
  140. </div>
  141. </div>
  142. {/foreach}
  143. </div>
  144. </section>
  145. <!-- 结算模块 -->
  146. <section class="windContainer">
  147. <div class="windTBox">
  148. <p class="lt">CART TOTALS</p>
  149. <p class="cartTotals"></p>
  150. </div>
  151. <div class="linkItem">
  152. <div class="windInfoBox">
  153. <p class="key">Subtotal</p>
  154. <p class="val">${$cartMoney}</p>
  155. </div>
  156. </div>
  157. <div class="mbItem">
  158. <div class="windInfoBox">
  159. <p class="key">Free Shipping</p>
  160. <p class="val">$0.00</p>
  161. </div>
  162. <!-- <div class="windInfoBox">-->
  163. <!-- <p class="key">Free Shipping</p>-->
  164. <!-- </div>-->
  165. </div>
  166. <div class="mbItem" id="addressInfo">
  167. <div class="windInfoBox">
  168. <div class="key">
  169. <p class="keyItem" id="fullNameText">{$fullName}</p>
  170. <p class="keyItem" id="contactNumberText">{$phone}</p>
  171. <p class="keyItem" id="emailText">{$email}</p>
  172. <p class="keyItem" id="addressText">{$full}</p>
  173. </div>
  174. </div>
  175. <div class="windInfoBox">
  176. <p class="key" id="changeAddress">Change address</p>
  177. </div>
  178. </div>
  179. <!-- 填写地址模块 -->
  180. <div id="addressContainer">
  181. <!-- 名字 -->
  182. <div class="addressItem">
  183. <p class="addItmeTitle">First Name:</p>
  184. <input class="addInput" id="userName" type="text" placeholder="First Name">
  185. </div>
  186. <div class="addressItem">
  187. <p class="addItmeTitle">Last Name:</p>
  188. <input class="addInput" id="lastName" type="text" placeholder="Last Name">
  189. </div>
  190. <!-- 手机号码 -->
  191. <div class="addressItem">
  192. <p class="addItmeTitle">Contact Number:</p>
  193. <input class="addInput" id="phoneNumber" type="text" placeholder="Contact Number">
  194. </div>
  195. <!-- 地区 -->
  196. <div class="addressItem">
  197. <p class="addItmeTitle">State:</p>
  198. <select id="areaSelect">
  199. <option value="0" selected>--Choose A state--</option>
  200. {foreach $states50 as $state}
  201. <option value="{$state['id']}">{$state['name']}</option>
  202. {/foreach}
  203. </select>
  204. </div>
  205. <!-- 详情地址 -->
  206. <div class="addressItem">
  207. <p class="addItmeTitle">Address:</p>
  208. <input class="addInput" id="address" type="text" placeholder="Address">
  209. </div>
  210. <!-- 邮箱 -->
  211. <div class="addressItem">
  212. <p class="addItmeTitle">Mailbox:</p>
  213. <input type="text" id="mailbox" class="addInput" placeholder="Mailbox">
  214. </div>
  215. <!-- 邮政编码 -->
  216. <div class="addressItem">
  217. <p class="addItmeTitle">Zip Code:</p>
  218. <input class="addInput" id="postalCode" type="text" placeholder="Zip Code">
  219. </div>
  220. <div id="addressButModel">
  221. <div class="addressButtonBox">
  222. <div id="addCancel">Cancel</div>
  223. <div id="addSave">Save</div>
  224. </div>
  225. </div>
  226. </div>
  227. <!-- <div class="mbItem">
  228. <div class="windInfoBox freeshipping">
  229. <p class="key">Free shipping</p>
  230. </div>
  231. <div class="windInfoBox">
  232. <p class="key">$199.99</p>
  233. </div>
  234. </div>-->
  235. <div class="totalBox">
  236. <p class="totalT">Total</p>
  237. <p class="totalVal">${$cartMoney}</p>
  238. </div>
  239. <div class="mbItem">
  240. <div class="windInfoBox freeshipping">
  241. {if $payByPoints}
  242. <p class="key">You can redeem this order for free through points!</p>
  243. {/if}
  244. </div>
  245. <div class="windInfoBox">
  246. <p class="key">Your Points:{$points}</p>
  247. </div>
  248. </div>
  249. <div class="payPalButton">
  250. <span>PayPal</span>
  251. </div>
  252. <div class="orBox">
  253. <div class="link"></div>
  254. <p class="or">OR</p>
  255. <div class="link"></div>
  256. </div>
  257. <div class="checkoutButton">
  258. <span>Redemption using Points</span>
  259. </div>
  260. </section>
  261. </div>
  262. </section>
  263. </main>
  264. <!-- 底部 -->
  265. <footer class="footerContainer" id="footerContainer">
  266. <section class="sectionContainer">
  267. <div class="elementorContainer">
  268. <div class="footerConter">
  269. <div class="leftText">
  270. <p class="ltK">NEWALETTER</p>
  271. <p class="ltV">Sign up for the Free Shipping Vapes</p>
  272. </div>
  273. <div class="footerInuptBox">
  274. <img class="mailIcon" src="/assets/index/asstes/icon/mailIcon.png" alt="">
  275. <input class="footerInupt" type="text">
  276. <img class="arrowIcon" src="/assets/index/asstes/icon/arrowIcon.png" alt="">
  277. </div>
  278. <div class="footerIconContainer">
  279. <div class="footerIconList">
  280. <a href="#">
  281. <div class="footerIconItem">
  282. <img src="https://i1.branchcn.com/social_media/Wechat.png" alt="">
  283. </div>
  284. </a>
  285. <a href="#">
  286. <div class="footerIconItem">
  287. <img src="https://i1.branchcn.com/social_media/Wechat.png" alt="">
  288. </div>
  289. </a>
  290. <a href="#">
  291. <div class="footerIconItem">
  292. <img src="https://i1.branchcn.com/social_media/Wechat.png" alt="">
  293. </div>
  294. </a>
  295. </div>
  296. <div class="footerVlsaImg">
  297. <a href="#">
  298. <div class="footerVlsaItem">
  299. <img src="https://img2.baidu.com/it/u=1367821108,121397947&fm=253&fmt=auto&app=138&f=JPEG?w=1200&h=500"
  300. alt="">
  301. </div>
  302. </a>
  303. <a href="#">
  304. <div class="footerVlsaItem">
  305. <img src="https://img2.baidu.com/it/u=1367821108,121397947&fm=253&fmt=auto&app=138&f=JPEG?w=1200&h=500"
  306. alt="">
  307. </div>
  308. </a>
  309. <a href="#">
  310. <div class="footerVlsaItem">
  311. <img src="https://img2.baidu.com/it/u=1367821108,121397947&fm=253&fmt=auto&app=138&f=JPEG?w=1200&h=500"
  312. alt="">
  313. </div>
  314. </a>
  315. </div>
  316. </div>
  317. </div>
  318. </div>
  319. </section>
  320. </footer>
  321. <!-- 年龄提示层 -->
  322. <section class="maskContainer">
  323. <div class="ageReminderBox">
  324. <img class="ageReminderBack"
  325. src="https://img1.baidu.com/it/u=3449617615,1431463931&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1709485200&t=489bafcac7c5bebed91cf50c14356269"
  326. alt="">
  327. <div class="ageReminderInfo">
  328. <h3>ARE YOU OF LEAAL SMOKING AGE?</h3>
  329. <div class="ageReminderButBox">
  330. <div class="ageRBut ageReminderNo"><span>NO</span></div>
  331. <div class="ageRBut ageReminderYes"><span>Yes, I am 21+</span></div>
  332. </div>
  333. </div>
  334. </div>
  335. </section>
  336. <!-- 年龄提示层 -->
  337. <section class="maskContainer">
  338. <div class="ageReminderBox">
  339. <img class="ageReminderBack"
  340. src="https://img1.baidu.com/it/u=3449617615,1431463931&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1709485200&t=489bafcac7c5bebed91cf50c14356269"
  341. alt="">
  342. <div class="ageReminderInfo">
  343. <h3>ARE YOU OF LEAAL SMOKING AGE?</h3>
  344. <div class="ageReminderButBox">
  345. <div class="ageRBut ageReminderNo"><span>NO</span></div>
  346. <div class="ageRBut ageReminderYes"><span>Yes, I am 21+</span></div>
  347. </div>
  348. </div>
  349. </div>
  350. </section>
  351. <div id="loadingModel">
  352. <div class="loadingBox">
  353. <img src="/assets/index/asstes/icon/loading.gif" alt="Jumping to paypal.">
  354. </div>
  355. </div>
  356. <div id="toastContainer"></div>
  357. </body>
  358. <script src="/assets/index/js/jquery-1.12.0.js"></script>
  359. <script src="/assets/index/js/flexible.js"></script>
  360. <script src="/assets/index/js/public.js?t=11"></script>
  361. <script src="/assets/index/js/swiper.js?t=6"></script>
  362. <script src="/assets/index/js/jquery.lazyload.js"></script>
  363. <script>
  364. $(document).ready(function () {
  365. var addressId = {$addressId};
  366. var payByPoints = "{$payByPoints}";
  367. //console.log(payByPoints, payByPoints)
  368. //默认地址
  369. const defaultAddressInfo = {
  370. userName: "{$name}",
  371. lastName: "{$lastName}",
  372. phoneNumber: "{$phone}",
  373. areaSelect: "{$regionId}",
  374. address: "{$detail}",
  375. mailbox: "{$email}",
  376. postalCode: "{$zipCode}"
  377. }
  378. // 是否已填写过地址
  379. if (addressId) {
  380. var isAddress = true
  381. } else {
  382. var isAddress = false
  383. }
  384. //初始化地址模块标签显示隐藏
  385. function initAddressLabel() {
  386. //是否已填写过地址、显示默认地址,隐藏填写地址表单
  387. if (isAddress) {
  388. $("#addressInfo").show(0)
  389. $("#addressContainer").hide(0)
  390. } else {
  391. $("#addressInfo").hide(0)
  392. $("#addressContainer").show(0)
  393. $("#addressButModel").show(0)
  394. }
  395. }
  396. //初始化表单
  397. function initAddressForm() {
  398. const {userName, lastName, phoneNumber, areaSelect, address, mailbox, postalCode} = defaultAddressInfo || {}
  399. userName && $("#userName").val(userName)
  400. lastName && $("#lastName").val(lastName)
  401. phoneNumber && $("#phoneNumber").val(phoneNumber)
  402. areaSelect && $("#areaSelect").val(areaSelect)
  403. address && $("#address").val(address)
  404. mailbox && $("#mailbox").val(mailbox)
  405. postalCode && $("#postalCode").val(postalCode)
  406. }
  407. initAddressLabel()
  408. initAddressForm()
  409. //更改地址,需显示填写地址表单、取消保存按钮
  410. $("#changeAddress").on(tap, async function () {
  411. $("#addressContainer").show(0)
  412. $("#addressButModel").show(0)
  413. });
  414. //取消更改
  415. $("#addCancel").on(tap, async function () {
  416. $("#addressContainer").hide(0)
  417. });
  418. // 添加地址
  419. function addAddress() {
  420. const userNameEle = $("#userName")
  421. const lastNameEle = $("#lastName")
  422. const phoneNumberEle = $("#phoneNumber")
  423. const areaSelectEle = $("#areaSelect")
  424. const addressEle = $("#address")
  425. const mailboxEle = $("#mailbox")
  426. const postalCodeEle = $("#postalCode")
  427. // 名字
  428. const userName = userNameEle.val()
  429. const lastName = lastNameEle.val()
  430. // 手机号码
  431. const phoneNumber = phoneNumberEle.val()
  432. // 地区
  433. const areaSelect = areaSelectEle.val()
  434. // 详情地址
  435. const address = addressEle.val()
  436. // 邮箱
  437. const mailbox = mailboxEle.val()
  438. // 邮政编码
  439. const postalCode = postalCodeEle.val()
  440. if (!userName || userName === "") {
  441. userNameEle.focus()
  442. return
  443. }
  444. if (!phoneNumber || phoneNumber === "") {
  445. phoneNumberEle.focus()
  446. return
  447. }
  448. if (!areaSelect || areaSelect === "") {
  449. areaSelectEle.focus()
  450. return
  451. }
  452. if (!address || address === "") {
  453. addressEle.focus()
  454. return
  455. }
  456. const params = {
  457. form: {
  458. name: userName,
  459. last_name: lastName,
  460. phone: phoneNumber,
  461. email: mailbox,
  462. region: [{label: '', value: 1}, {label: '', value: 2}, {label: areaSelect, value: areaSelect}],
  463. //mailbox,
  464. detail: address,
  465. zip_code: postalCode
  466. }
  467. }
  468. return new Promise(function (resolve, reject) {
  469. $.ajax({
  470. url: "/index/address/add",
  471. method: 'POST',
  472. data: JSON.stringify(params),
  473. headers: {
  474. 'Content-Type': 'application/json',
  475. 'storeId': '10001',
  476. 'platform': 'H5',
  477. },
  478. dataType: 'json',
  479. success: function (response) {
  480. resolve(response);
  481. },
  482. error: function (xhr, status, error) {
  483. reject(error);
  484. }
  485. });
  486. });
  487. }
  488. //保存更改
  489. $("#addSave").on(tap, async function () {
  490. const {data, status} = await addAddress()
  491. if (status === 200 || status === "200") {
  492. showToast('Success')
  493. setTimeout(function () {
  494. $("#addressInfo").show(0)
  495. addressId = data.address_id
  496. $("#addressText").text(data.full)
  497. $("#fullNameText").text(data.name + " " + data.last_name)
  498. $("#contactNumberText").text(data.phone)
  499. $("#emailText").text(data.email)
  500. $("#addressContainer").hide(0)
  501. }, 2000)
  502. } else {
  503. showToast('Something wrong.Try again later.')
  504. }
  505. });
  506. function showToast(message) {
  507. var toastElement = $('#toastContainer');
  508. toastElement.text(message);
  509. toastElement.stop(true, true).fadeIn(200).delay(2000).fadeOut(200);
  510. }
  511. //支付方法
  512. const orderPayment = (params) => {
  513. return new Promise(function (resolve, reject) {
  514. $.ajax({
  515. url: "/index/checkout/submit?payType=30&mode=cart&address_id=" + addressId,
  516. method: "POST",
  517. data: JSON.stringify(params),
  518. headers: {
  519. "Content-Type": "application/json",
  520. "storeId": "10001",
  521. "platform": "H5",
  522. // "Access-Token": vapesToken
  523. },
  524. dataType: "json",
  525. success: function (response) {
  526. resolve(response);
  527. },
  528. error: function (xhr, status, error) {
  529. reject(error);
  530. }
  531. });
  532. });
  533. }
  534. const orderPaymentPoints = (params) => {
  535. return new Promise(function (resolve, reject) {
  536. $.ajax({
  537. url: "/index/checkout/submit?payType=50&mode=cart&address_id=" + addressId,
  538. method: "POST",
  539. data: JSON.stringify(params),
  540. headers: {
  541. "Content-Type": "application/json",
  542. "storeId": "10001",
  543. "platform": "H5",
  544. // "Access-Token": vapesToken
  545. },
  546. dataType: "json",
  547. success: function (response) {
  548. resolve(response);
  549. },
  550. error: function (xhr, status, error) {
  551. reject(error);
  552. }
  553. });
  554. });
  555. }
  556. /**
  557. * 商品操作方法
  558. * @param _this $(this)
  559. * @param type 类型:add || reduce || delete
  560. * @returns
  561. */
  562. function productOperate(_this, type) {
  563. //商品id
  564. const productId = _this.closest(".productItem").attr("data-id");
  565. const goodsId = _this.closest(".productItem").attr("goods-id");
  566. const goodsSkuId = _this.closest(".productItem").attr("goods-sku-id");
  567. let goodsNum = parseInt(_this.closest(".productItem").attr("data-goods-num"));
  568. //console.log(productId, goodsId, goodsSkuId)
  569. //商品增加
  570. if (type === "add" || type === "reduce") {
  571. if (type === "add") {
  572. goodsNum += 1
  573. } else {
  574. goodsNum -= 1
  575. }
  576. $.ajax({
  577. url: "/index/cart/update?goodsId=" + goodsId + "&goodsSkuId=" + goodsSkuId + "&goodsNum=" + goodsNum,
  578. method: "POST",
  579. headers: {
  580. "Content-Type": "application/json",
  581. "storeId": "10001",
  582. "platform": "H5",
  583. "Accept": "*/*"
  584. // "Access-Token": vapesToken
  585. },
  586. dataType: "json",
  587. success: function (obj) {
  588. if (obj.status === 200 || obj.status === '200') {
  589. showToast("Successful")
  590. window.location.href = '../cart/shoppingCart';
  591. } else if (obj.status === 401 || obj.status === '401') {
  592. window.location.replace('../passport/logIn.html')
  593. } else {
  594. showToast(obj.message)
  595. }
  596. //window.location.replace( '/index/cart/shoppingCart.html')
  597. },
  598. error: function (xhr, status, error) {
  599. showToast("Please enter the quantity of products")
  600. //reject(error);
  601. }
  602. });
  603. return
  604. }
  605. //商品减少
  606. //商品删除
  607. if (type === "delete") {
  608. var params = {"cartIds": [productId]}
  609. console.log("商品删除")
  610. $.ajax({
  611. url: "/index/cart/clear",
  612. method: "POST",
  613. headers: {
  614. "Content-Type": "application/json",
  615. "storeId": "10001",
  616. "platform": "H5",
  617. // "Access-Token": vapesToken
  618. },
  619. data: JSON.stringify(params),
  620. dataType: "json",
  621. success: function (obj) {
  622. if (obj.status === 200 || obj.status === '200') {
  623. //showToast("Successful")
  624. window.location.href = '../cart/shoppingCart';
  625. } else if (obj.status === 401 || obj.status === '401') {
  626. window.location.replace('../passport/logIn.html')
  627. } else {
  628. showToast(obj.message)
  629. }
  630. },
  631. error: function (xhr, status, error) {
  632. reject(error);
  633. }
  634. });
  635. }
  636. }
  637. //支付
  638. $(".payPalButton").on(tap, async function () {
  639. console.log("paypaing")
  640. $("#loadingModel").show(0)
  641. // 支付之前先判断是否有默认地址
  642. if (!addressId) {
  643. showToast('No address')
  644. return
  645. // 先添加地址
  646. // const res = await addAddress()
  647. // addressId = res
  648. }
  649. const params = {
  650. //"cartIds": "10002",
  651. "delivery": 10,
  652. "address_id": addressId
  653. }
  654. const res = await orderPayment(params)
  655. const {status, message, data} = res || {}
  656. if (status === 200 || status === "200") {
  657. window.open(data.payment.approval_link, "_blank");
  658. var interId = setInterval(function () {
  659. fetchOrder(data.orderId, interId);
  660. }, 3000)
  661. } else if (status === 401 || status === "401") {
  662. window.location.replace('../passport/logIn.html')
  663. } else {
  664. showToast(message)
  665. }
  666. });
  667. function fetchOrder(orderId, interId) {
  668. $.get('/index/order/detail?orderId=' + orderId, function (res) {
  669. console.log(res.data.order.pay_status);
  670. if (res.status == 200 && res.data.order.pay_status == 20) {
  671. clearInterval(interId);
  672. $("#loadingModel").hide(0);
  673. window.location.replace('/index/user/orderDetails.html?orderId=' + orderId)
  674. }
  675. })
  676. }
  677. //支付
  678. $(".checkoutButton").on(tap, async function () {
  679. if (payByPoints !== '1'){
  680. showToast('Insufficient points!')
  681. return;
  682. }
  683. console.log("points")
  684. const params = {
  685. "delivery": 10,
  686. "address_id": addressId
  687. }
  688. $("#loadingModel").show(0)
  689. const res = await orderPaymentPoints(params)
  690. const {status, message, data} = res || {}
  691. if (status === 200 || status === "200") {
  692. $("#loadingModel").hide(0)
  693. showToast(message)
  694. setTimeout(function () {
  695. window.location.replace('/index/user/order.html')
  696. }, 3000)
  697. } else if (status === 401 || status === "401") {
  698. showToast('Login first!')
  699. setTimeout(function () {
  700. window.location.replace('../passport/logIn.html')
  701. }, 3000)
  702. //window.location.replace('../passport/logIn.html')
  703. } else {
  704. showToast(message)
  705. }
  706. });
  707. //商品减少
  708. $(".numberReduce").on(tap, function () {
  709. productOperate($(this), "reduce")
  710. })
  711. //商品增加
  712. $(".numberAdd").on(tap, function () {
  713. productOperate($(this), "add")
  714. })
  715. //商品删除
  716. $(".productDelete").on(tap, function () {
  717. productOperate($(this), "delete")
  718. })
  719. //前往购物车
  720. $(".shoppingCartIcon").on(tap, function () {
  721. window.location.href = "./shoppingCart.html"
  722. });
  723. })
  724. </script>
  725. </html>