shoppingMall.js 25 KB

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