shoppingMall.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  1. // pages/orderBy/orderBy.js
  2. import {
  3. get,
  4. post
  5. } from '../../utils/http'
  6. import {
  7. PROJECT_TYPE
  8. } from '../../utils/global'
  9. import {
  10. getStoreInfo
  11. } from '../../utils/util'
  12. const app = getApp()
  13. Page({
  14. /**
  15. * 页面的初始数据
  16. */
  17. data: {},
  18. initData: {
  19. current: 0,
  20. currentType: 3,
  21. currentList: [{
  22. id: 0,
  23. title: '精选项目',
  24. type: PROJECT_TYPE.project,
  25. source: 'project',
  26. child: []
  27. },
  28. {
  29. id: 1,
  30. title: '项目耗材',
  31. type: PROJECT_TYPE.product,
  32. source: 'product',
  33. child: []
  34. },
  35. {
  36. id: 2,
  37. title: '项目卡券',
  38. type: PROJECT_TYPE.cardgoods,
  39. source: 'cardgoods',
  40. child: []
  41. },
  42. {
  43. id: 3,
  44. title: '美妆产品',
  45. type: PROJECT_TYPE.goods,
  46. source: 'goods',
  47. child: []
  48. },
  49. {
  50. id: 4,
  51. title: '次卡',
  52. type: PROJECT_TYPE.secondaryCard,
  53. source: 'secondaryCard',
  54. child: []
  55. }
  56. ],
  57. currentKeys: {},
  58. currentItemIndex: 0,
  59. currentItemCatId: 0,
  60. productData: {},
  61. productDataLoading: false,
  62. storeId: 0,
  63. storeData: {},
  64. inFirstIn: false,
  65. navBarData: app.globalData.navBarData,
  66. navBarBgClass: '',
  67. selectProductList: 0,
  68. productListV2: [],
  69. showProducePup: false,
  70. selectProductData: {},
  71. selectProductIndex: '',
  72. selectProductCar: [],
  73. onCloseCar: false,
  74. showMoney: 0.0,
  75. toView: '',
  76. orderDiscount: {},
  77. onMakeup: false,
  78. // 美妆产品购物车列表
  79. selectMakeupList: [],
  80. page: 1,
  81. limit: 20,
  82. showMoneyGood: 0,
  83. // 点击美妆产品购物袋图标标识
  84. isIcon: false,
  85. // 产品id
  86. sourceId: '',
  87. // 每个商品数据
  88. proItem: '',
  89. // 美妆产品总数量
  90. sum: 0,
  91. // 商品价格
  92. v2_price: '',
  93. goods_ids: [], //购物车中的产品id
  94. exchangeInfo: [], //需要加购多少商品的价格信息
  95. },
  96. /**
  97. * 首页数据
  98. */
  99. getHomeData() {
  100. get('api/home', {}, (res) => {
  101. this.setData({
  102. homeData: res.data
  103. }, )
  104. })
  105. },
  106. /**
  107. * 获取当前用户折扣
  108. * 折扣类型,0.无折扣,20.任意三个项目8折,50.新人五折活动,100.仪器免费使用权益
  109. */
  110. orderDiscount() {
  111. get('v2/api/order/discount', {}, (res) => {
  112. this.setData({
  113. orderDiscount: res.data
  114. }, )
  115. })
  116. },
  117. // 选择项目左边的操作
  118. selectProductList(e) {
  119. let selectProductList = e.currentTarget.dataset.index
  120. this.setData({
  121. selectProductList: selectProductList,
  122. toView: 'A' + selectProductList
  123. })
  124. },
  125. selectProduct(e) {
  126. let index = e.currentTarget.dataset.index
  127. this.setData({
  128. selectProductIndex: index
  129. })
  130. },
  131. rpxTopx(rpx) {
  132. let deviceWidth = wx.getSystemInfoSync().windowWidth; //获取设备屏幕宽度
  133. let px = (deviceWidth / 750) * Number(rpx)
  134. return Math.floor(px);
  135. },
  136. onDoHeight() {
  137. let productListV2 = this.data.productListV2
  138. let inHeight = 0
  139. let doHeight = []
  140. doHeight.push(0)
  141. for (let i = 0; i < productListV2.length; i++) {
  142. if (productListV2[i].products[0] && productListV2[i].products[0].type == 'one') {
  143. let needAdd = 0
  144. for (let j = 0; j < productListV2[i].products.length; j++) {
  145. needAdd = needAdd + 280 * productListV2[i].products[j].items.length + 140
  146. }
  147. inHeight = inHeight + this.rpxTopx(20 + 40 + 20 + needAdd)
  148. // console.log('xxxxxxxxxxx走了这里哈哈哈' + needAdd)
  149. } else {
  150. inHeight = inHeight + this.rpxTopx(20 + 40 + 20 + 280 * productListV2[i].products.length)
  151. }
  152. doHeight.push(inHeight)
  153. }
  154. this.setData({
  155. doHeight: doHeight
  156. })
  157. // console.log(doHeight)
  158. },
  159. scroll(e) {
  160. let that = this
  161. let doHeight = this.data.doHeight
  162. // console.log(e.detail.scrollTop)
  163. if (e.detail.scrollTop < doHeight[1] - 20) {
  164. that.setData({
  165. selectProductList: 0,
  166. })
  167. return
  168. }
  169. for (let i = 0; i < doHeight.length; i++) {
  170. if (e.detail.scrollTop > (doHeight[i] - 20) && e.detail.scrollTop < doHeight[i + 1]) {
  171. // console.log(e.detail.scrollTop)
  172. that.setData({
  173. selectProductList: i,
  174. })
  175. }
  176. }
  177. // if (e.detail.scrollTop > )
  178. },
  179. // 关闭产品包
  180. onClosePay() {
  181. this.setData({
  182. showProducePup: false
  183. })
  184. this.setData({
  185. isIcon: this.data.showProducePup
  186. })
  187. },
  188. buttomCar: function () {
  189. this.setData({
  190. onCloseCar: true
  191. })
  192. },
  193. // 删除购物车
  194. inDeleteCarOne(e) {
  195. let index = e.currentTarget.dataset.index
  196. let selectProductCars = this.data.selectProductCar
  197. selectProductCars.splice(index, 1)
  198. this.setData({
  199. selectProductCar: selectProductCars
  200. })
  201. this.showCarMoney()
  202. },
  203. toSubmit: function () {
  204. if (this.data.selectProductCar.length == 0) {
  205. return
  206. }
  207. wx.navigateTo({
  208. url: '../reserveCar/reserveCar?data=' + JSON.stringify(this.data.selectProductCar) + '&&money=' + this.data.showMoney + '&&type=project',
  209. })
  210. // this.setData({
  211. // selectProductCar:[]
  212. // })
  213. },
  214. onKeySubmit: function (e) {
  215. let keySubmit = e.currentTarget.dataset.item
  216. wx.navigateTo({
  217. url: '../reserveCar/reserveCar?data=' + JSON.stringify(keySubmit) + '&&money=' + keySubmit.price + '&&type=one',
  218. })
  219. },
  220. showCarMoney() {
  221. let that = this
  222. let money = 0
  223. let selectProductCars = this.data.current == 3 ? this.data.selectMakeupList : this.data.selectProductCar
  224. for (let i = 0; i < selectProductCars.length; i++) {
  225. // if (this.data.orderDiscount.discount != 0) {
  226. // let discountIn = that.data.orderDiscount.discount / 100
  227. // if (that.data.orderDiscount.discount == 20 && selectProductCars.length < 3) {
  228. // money = money + selectProductCars[i].price
  229. // } else {
  230. // money = money + selectProductCars[i].price - (selectProductCars[i].price * discountIn)
  231. // }
  232. // } else {
  233. money = money + selectProductCars[i].price
  234. // }
  235. console.log(money, 'moneymoney');
  236. if (selectProductCars[i].selectMaterial) {
  237. money = money + selectProductCars[i].selectMaterial.price * 1
  238. }
  239. }
  240. this.setData({
  241. showMoney: money.toFixed(2)
  242. })
  243. },
  244. onCloseCar: function () {
  245. this.setData({
  246. onCloseCar: false
  247. })
  248. },
  249. // 选择项目
  250. toSelectProduct(e) {
  251. let toSelectProduct = e.currentTarget.dataset.item
  252. for (let i = 0; i < this.data.selectProductCar.length; i++) {
  253. if (toSelectProduct.id == this.data.selectProductCar[i].id) {
  254. wx.showToast({
  255. title: '单项目只能选一次!',
  256. icon: "none"
  257. })
  258. return
  259. }
  260. }
  261. this.setData({
  262. toSelectProduct: toSelectProduct,
  263. selectProductIndex: '空',
  264. showProducePup: true
  265. })
  266. this.productV2(toSelectProduct.id)
  267. },
  268. submit_bottom: function () {
  269. let selectProductCars = this.data.selectProductCar
  270. let toSelectProducts = this.data.toSelectProduct
  271. if (this.data.selectProductIndex == '空') {
  272. toSelectProducts.selectMaterial = ''
  273. } else {
  274. toSelectProducts.selectMaterial = this.data.selectProductData.upgrade[this.data.selectProductIndex]
  275. }
  276. selectProductCars.push(toSelectProducts)
  277. this.setData({
  278. showProducePup: false,
  279. selectProductCar: selectProductCars
  280. })
  281. this.showCarMoney()
  282. },
  283. /**
  284. * 跳转店铺列表
  285. */
  286. goToStore() {
  287. if (this.data.inFirstIn) {
  288. return;
  289. }
  290. wx.navigateTo({
  291. url: '/pages/store/store?defaultStore=' +
  292. JSON.stringify(this.data.homeData.store)
  293. })
  294. },
  295. /**
  296. * 店铺信息
  297. * /api/store/info
  298. */
  299. getStoreInfo(store_id) {
  300. get(
  301. 'api/store/info', {
  302. store_id
  303. },
  304. (res) => {
  305. this.setData({
  306. ['homeData.store']: res.data
  307. },
  308. () => {
  309. wx.setStorageSync('store_id', String(store_id))
  310. app.globalData.storeData = res.data
  311. }
  312. )
  313. console.log(res)
  314. }
  315. )
  316. },
  317. /**
  318. * 获取项目产品数据
  319. * /api/store/info
  320. */
  321. productList() {
  322. get(
  323. 'v2/api/product/list', {
  324. store_id: this.data.storeId
  325. },
  326. (res) => {
  327. this.setData({
  328. productListV2: res.data
  329. })
  330. this.onDoHeight()
  331. this.setData({
  332. selectProductList: app.globalData.toViewIndex,
  333. toView: 'A' + app.globalData.toViewIndex,
  334. })
  335. console.log(res)
  336. }
  337. )
  338. },
  339. /**
  340. * 获取升级产品列表
  341. * /api/store/info
  342. */
  343. productV2(id) {
  344. get(
  345. 'v2/api/product/product', {
  346. id: id,
  347. store_id: this.data.storeId
  348. },
  349. (res) => {
  350. this.setData({
  351. selectProductData: res.data
  352. })
  353. console.log(res)
  354. }
  355. )
  356. },
  357. /**
  358. * 生命周期函数--监听页面加载
  359. */
  360. onLoad: function (options) {
  361. console.log(options, 'options');
  362. this.setData({
  363. navBarHeight: app.globalData.navBarData.navBarHeight
  364. })
  365. // this.getHomeData()
  366. let data = JSON.parse(JSON.stringify(this.initData))
  367. data.storeData = getApp().globalData.storeData
  368. data.storeId = data.storeData.id || wx.getStorageSync('store_id')
  369. // 存在传入的分类类型
  370. if (options.hasOwnProperty('cat_type')) {
  371. data.currentKeys = this.buildKeys(data.currentList, 'type')
  372. let _current = data.currentKeys['key_' + options.cat_type]
  373. if (_current != undefined) {
  374. data.current = _current
  375. data.currentType = options.cat_type
  376. }
  377. }
  378. // 存在传入的店铺ID
  379. if (options.hasOwnProperty('store_id')) {
  380. data.storeId = options.store_id
  381. // 更新店铺信息
  382. getStoreInfo(data.storeId)
  383. .then((res) => {
  384. data.storeData = res
  385. this.setData({
  386. storeData: res
  387. })
  388. })
  389. .catch(() => {})
  390. }
  391. this.setData(data, () => {
  392. this.getProductCategory(options)
  393. })
  394. this.productList()
  395. this.needAddGood()
  396. // 进入页面判断是否是直接跳转到美妆产品的是的话调用修改类型
  397. if (app.globalData.showGoods) {
  398. this.gotoGoods()
  399. }
  400. },
  401. // 监听页面隐藏
  402. onHide() {
  403. // 将全局跳转到下单页面是否直接显示美妆产品关闭
  404. app.globalData.showGoods = false
  405. },
  406. noneEnoughPeople() {
  407. },
  408. /**
  409. * 生命周期函数--监听页面初次渲染完成
  410. */
  411. onReady: function () {},
  412. /**
  413. * 生命周期函数--监听页面显示
  414. */
  415. onShow: function () {
  416. console.log('xasdadsa')
  417. // this.orderDiscount()
  418. let version1 = wx.getStorageSync('version1')
  419. if (!version1 || version1 != 1) {
  420. this.setData({
  421. // inFirstIn: true
  422. })
  423. wx.setStorageSync('version1', 1)
  424. }
  425. // 当切换了店铺时,重新请求一次数据
  426. let storeData = getApp().globalData.storeData
  427. let storeId = storeData.id || wx.getStorageSync('store_id')
  428. if (storeId != this.data.storeId && this.data.storeId) {
  429. let data = JSON.parse(JSON.stringify(this.initData))
  430. this.setData(data, () => {
  431. this.setData({
  432. storeId: storeId,
  433. storeData: storeData
  434. }, () => {
  435. this.getProductCategory()
  436. this.getStoreInfo(storeId)
  437. this.productList()
  438. })
  439. })
  440. } else {
  441. this.getStoreInfo(storeId)
  442. }
  443. let that = this
  444. let curres = wx.getStorageSync('curre')
  445. // console.log('haves1')
  446. if (curres && curres == 1) {
  447. // console.log('haves')
  448. let item = that.data.currentList[0]
  449. this.setData({
  450. current: item.id,
  451. currentItemIndex: 0,
  452. currentType: item.type
  453. },
  454. () => {
  455. // this.getProduct(item.type, item.child[0].id)
  456. let _dataset = {
  457. currentTarget: {
  458. dataset: {
  459. item: item.child[0],
  460. index: 0
  461. }
  462. }
  463. }
  464. this.onTabsItem(_dataset)
  465. }
  466. )
  467. wx.setStorageSync('curre', 0)
  468. }
  469. setTimeout(() => {
  470. if (this.data.current == 3) {
  471. this.needAddGood()
  472. } else {
  473. this.needAddCar()
  474. }
  475. }, 500)
  476. this.setData({
  477. toView: 'A' + app.globalData.toViewIndex,
  478. selectProductList: app.globalData.toViewIndex
  479. })
  480. },
  481. //精选项目
  482. needAddCar() {
  483. let toSelectProduct = wx.getStorageSync('toSelectProduct')
  484. if (toSelectProduct && JSON.parse(toSelectProduct) == []) {
  485. wx.setStorageSync('toSelectProduct', JSON.stringify([]))
  486. return
  487. }
  488. let cardAddData = []
  489. if (toSelectProduct) {
  490. cardAddData = JSON.parse(toSelectProduct)
  491. }
  492. wx.setStorageSync('toSelectProduct', JSON.stringify([]))
  493. let selectProductCarData = this.data.selectProductCar
  494. for (let i = 0; i < selectProductCarData.length; i++) {
  495. if (selectProductCarData[i].id == cardAddData[i].id || cardAddData.id) {
  496. return
  497. }
  498. }
  499. console.log(selectProductCarData, 'cardAddData', cardAddData);
  500. selectProductCarData = selectProductCarData.concat(cardAddData)
  501. this.setData({ //对上一个页面data中的参数进行赋值(上一个页面的数据是在当前页面进行赋值的),就变相实现了向上一个页面传值
  502. selectProductCar: selectProductCarData
  503. })
  504. this.showCarMoney()
  505. },
  506. //美妆产品
  507. needAddGood() {
  508. let params = {
  509. store_id: this.data.storeId,
  510. page: this.data.page,
  511. limit: this.data.limit
  512. }
  513. get('v2/api/car/list', params, (res) => {
  514. if (res.code == 200) {
  515. let selectProductCarData = []
  516. selectProductCarData = selectProductCarData.concat(res.data.list)
  517. // 购物车产品总数量
  518. let sum = 0
  519. selectProductCarData.map(item => {
  520. sum += item.num
  521. })
  522. selectProductCarData.sum = sum
  523. // 设置美妆产品购物车总数量
  524. this.setData({
  525. sum: sum
  526. })
  527. this.setData({
  528. selectMakeupList: selectProductCarData,
  529. showMoneyGood: res.data.total_money == null ? "0.00" : res.data.total_money
  530. })
  531. if (this.data.selectMakeupList < res.data.count) {
  532. this.setData({
  533. page: this.data.page + 1
  534. })
  535. this.needAddGood()
  536. }
  537. if (res.data.list.length == 0) {
  538. this.setData({
  539. onMakeup: false
  540. })
  541. }
  542. }
  543. })
  544. },
  545. /**
  546. * 页面上拉触底事件的处理函数
  547. */
  548. onReachBottom: function () {
  549. this.getProduct(this.data.currentType, this.data.currentItemCatId, 1)
  550. },
  551. /**
  552. * 用户点击右上角分享
  553. */
  554. onShareAppMessage: function () {},
  555. /**
  556. * 转化对象
  557. */
  558. buildKeys: function (params, key) {
  559. let keys = {}
  560. for (let i = 0; i < params.length; i++) {
  561. let item = params[i]
  562. keys['key_' + item[key]] = i
  563. }
  564. return keys
  565. },
  566. /**
  567. * 切换tabs
  568. */
  569. onTabsChange(e) {
  570. if (this.data.inFirstIn) {
  571. return;
  572. }
  573. let item = e.currentTarget.dataset.item
  574. this.setData({
  575. current: item.id,
  576. currentItemIndex: 0,
  577. currentType: item.type
  578. },
  579. () => {
  580. // this.getProduct(item.type, item.child[0].id)
  581. let _dataset = {
  582. currentTarget: {
  583. dataset: {
  584. item: item.child[0],
  585. index: 0
  586. }
  587. }
  588. }
  589. this.onTabsItem(_dataset)
  590. if (this.data.current == 3) {
  591. this.needAddGood()
  592. return
  593. }
  594. this.showCarMoney()
  595. }
  596. )
  597. },
  598. /**
  599. * 切换子tabs
  600. */
  601. onTabsItem(e) {
  602. console.log(e, 'e')
  603. if (this.data.inFirstIn) {
  604. return;
  605. }
  606. // this.setData({
  607. // inFirstIn:true
  608. // })
  609. let that = this
  610. let item = e.currentTarget.dataset.item
  611. let currentItemIndex = e.currentTarget.dataset.index
  612. if (!item) {
  613. return
  614. }
  615. this.setData({
  616. currentItemIndex: currentItemIndex,
  617. currentItemCatId: item.id
  618. },
  619. () => {
  620. console.log(this.data.current, 'this.data.current')
  621. // if(this.data.current === 4){
  622. // // 查询次卡列表
  623. // this.getSecondaryCardList(that.data.currentType, item.id)
  624. // } else {
  625. // that.getProduct(that.data.currentType, item.id)
  626. // }
  627. that.getProduct(that.data.currentType, item.id)
  628. }
  629. )
  630. },
  631. knowSubmit: function () {
  632. this.setData({
  633. inFirstIn: false
  634. })
  635. },
  636. /**
  637. * 获取产品分类
  638. */
  639. getProductCategory(options = {}) {
  640. let {
  641. currentList,
  642. current,
  643. currentType,
  644. currentItemIndex,
  645. currentItemCatId
  646. } = this.data
  647. get('api/product/category', {}, (res) => {
  648. console.log(res, 'res')
  649. let {
  650. project,
  651. product,
  652. cardgoods,
  653. other
  654. } = res.data
  655. currentList[0].child = project
  656. currentList[1].child = product
  657. currentList[2].child = cardgoods
  658. currentList[3].child = other
  659. currentList[4].child = cardgoods
  660. // 存在传入的分类ID
  661. if (options.hasOwnProperty('cat_id')) {
  662. let catKyes = this.buildKeys(currentList[current].child, 'id')
  663. let _currentItemIndex = catKyes['key_' + options.cat_id]
  664. if (_currentItemIndex != undefined) {
  665. currentItemIndex = _currentItemIndex
  666. currentItemCatId = options.cat_id
  667. }
  668. } else {
  669. current = (other.length > 0 && '3') ||
  670. (project.length > 0 && '0') ||
  671. (product.length > 0 && '1') ||
  672. (cardgoods.length > 0 && '2')
  673. switch (current) {
  674. // 默认值
  675. case 0:
  676. currentItemCatId = project[0].id
  677. break
  678. case 1:
  679. currentItemCatId = product[0].id
  680. break
  681. case 2:
  682. currentItemCatId = cardgoods[0].id
  683. break
  684. case 3:
  685. currentItemCatId = other[0].id
  686. break
  687. }
  688. }
  689. this.setData({
  690. currentList,
  691. current,
  692. currentItemIndex,
  693. currentItemCatId
  694. },
  695. () => {
  696. if (project.length > 0) {
  697. this.getProduct(currentType, currentItemCatId)
  698. }
  699. }
  700. )
  701. })
  702. },
  703. /**
  704. * 项目/产品列表
  705. * type: 数据类型,1项目,2项目耗材,3美妆产品,默认1
  706. */
  707. getProduct(ptype, pcat_id, turn = 0) {
  708. let that = this
  709. let key = `pkey_${ptype}_${pcat_id}`
  710. let {
  711. productData,
  712. productDataLoading,
  713. storeId
  714. } = that.data
  715. let pcatData = productData[key] || {
  716. total: 0,
  717. list: [],
  718. page: 1,
  719. has_more: 1,
  720. type: ptype,
  721. cat_id: pcat_id
  722. }
  723. if (productDataLoading || !pcatData.has_more) return
  724. // 是否为翻页
  725. if (!turn && pcatData.total > 0) return
  726. this.setData({
  727. productDataLoading: true
  728. })
  729. let page = pcatData.page
  730. get(
  731. this.data.current !== 4 ? 'api/product' : 'v2/api/card/list', this.data.current !== 4 ? {
  732. store_id: storeId,
  733. type: ptype,
  734. category_id: pcat_id,
  735. page: page
  736. } : {
  737. store_id: storeId,
  738. category_id: pcat_id,
  739. page: page,
  740. limit: 5
  741. },
  742. (res) => {
  743. that.setData({
  744. productDataLoading: false
  745. })
  746. let plist = pcatData.list.concat(res.data.list)
  747. page++
  748. pcatData = Object.assign(pcatData, {
  749. total: res.data.total,
  750. page: page,
  751. list: plist,
  752. has_more: plist.length < res.data.total && res.data.list.length > 0
  753. })
  754. productData[key] = pcatData
  755. this.setData({
  756. productData: productData
  757. })
  758. },
  759. (err) => {
  760. that.setData({
  761. productDataLoading: false
  762. })
  763. }
  764. )
  765. },
  766. // 获取需要加购多少商品的价格
  767. getExchangePrice() {
  768. post('v2/api/car/plus_project', {
  769. store_id: this.data.storeId || wx.getStorageSync('store_id'),
  770. goods_id: '',
  771. type: 1
  772. }, (res) => {
  773. if (res.code == 200) {
  774. this.setData({
  775. exchangeInfo: res.data
  776. })
  777. }
  778. })
  779. },
  780. onOpenMakeup() {
  781. // 获取需要加购多少商品的价格
  782. this.getExchangePrice()
  783. this.setData({
  784. onMakeup: true
  785. })
  786. },
  787. onCloseMakeup() {
  788. this.setData({
  789. onMakeup: false
  790. })
  791. },
  792. // 删除购物车
  793. inDeleteCarGood(e) {
  794. let index = e.currentTarget.dataset.index
  795. get('v2/api/car/del', {
  796. car_id: this.data.selectMakeupList[index].id
  797. }, res => {
  798. if (res.code == 200) {
  799. this.needAddGood()
  800. // 获取需要加购多少商品的价格
  801. this.getExchangePrice()
  802. }
  803. })
  804. },
  805. //购物车结算
  806. toSubmitGood: function () {
  807. if (this.data.selectMakeupList.length == 0) {
  808. return
  809. }
  810. // let _projectData = this.data.selectMakeupList
  811. // 筛选出购物车中所有商品的id
  812. let {
  813. goods_ids
  814. } = this.data
  815. goods_ids = []
  816. this.data.selectMakeupList.map(item => {
  817. goods_ids.push(item.goods_id)
  818. })
  819. wx.navigateTo({
  820. url: `/pages/goodsOrderConfirm/goodsOrderConfirm?source=goods&storeId=${this.data.storeId}&goods_ids=${goods_ids}&type=1`,
  821. })
  822. },
  823. onChangeNum(e) {
  824. let params = {
  825. car_id: this.data.selectMakeupList[e].id,
  826. num: this.data.selectMakeupList[e].num
  827. }
  828. get('/v2/api/car/add_number', params, res => {
  829. if (res.code == 200) {
  830. this.needAddGood()
  831. // 获取加购多少商品价格
  832. this.getExchangePrice()
  833. }
  834. })
  835. },
  836. onReduce(e) {
  837. let index = e.currentTarget.dataset.index
  838. let num = this.data.selectMakeupList[index].num
  839. num = num - 1
  840. if (num < 0) {
  841. num = 0
  842. }
  843. let dataNum = `selectMakeupList[${index}].num`
  844. this.setData({
  845. [dataNum]: num
  846. })
  847. this.onChangeNum(index)
  848. },
  849. onLationAdd(e) {
  850. let index = e.currentTarget.dataset.index
  851. let num = this.data.selectMakeupList[index].num
  852. num = num + 1
  853. let dataNum = `selectMakeupList[${index}].num`
  854. this.setData({
  855. [dataNum]: num
  856. })
  857. this.onChangeNum(index)
  858. },
  859. // 点击美妆产品购物袋图标显示弹出购物车框
  860. showProduce(e) {
  861. console.log(e);
  862. this.setData({
  863. showProducePup: true,
  864. sourceId: e.target.dataset.proitem.id,
  865. proItem: e.target.dataset.proitem
  866. })
  867. this.setData({
  868. isIcon: this.data.showProducePup
  869. })
  870. },
  871. // 点击美妆产品购物袋加入购物车
  872. submit_add(type) {
  873. let params = {
  874. goods_id: this.data.sourceId,
  875. store_id: this.data.storeId
  876. }
  877. post('v2/api/car/add', params, (res) => {
  878. if (res.code == 200) {
  879. if (type == 'shopping') {
  880. wx.navigateTo({
  881. url: `/pages/goodsOrderConfirm/goodsOrderConfirm?storeId=${this.data.storeId}`,
  882. })
  883. } else {
  884. wx.showToast({
  885. title: '成功加入购物车!',
  886. icon: 'none'
  887. })
  888. this.needAddGood()
  889. setTimeout(() => {
  890. // wx.switchTab({
  891. // url: '/pages/orderBy/orderBy?cat_type=3',
  892. // })
  893. this.setData({
  894. showProducePup: false,
  895. isIcon: false
  896. })
  897. }, 1000)
  898. }
  899. }
  900. })
  901. },
  902. // 点击商品或者按钮直接跳转到下单页面的美妆产品页面(进入页面将类型改为美妆产品)
  903. gotoGoods() {
  904. this.setData({
  905. current: 3,
  906. currentType: 3,
  907. })
  908. },
  909. })