shoppingCart.html 30 KB

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