orderBy.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  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: 1,
  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. if(app.globalData.toViewIndex!=0){
  332. this.setData({
  333. toView: 'A' + (app.globalData.toViewIndex-1),
  334. selectProductList: app.globalData.toViewIndex-1
  335. })
  336. }else{
  337. this.setData({
  338. toView: 'A' + 0,
  339. selectProductList: 0
  340. })
  341. }
  342. console.log(res)
  343. }
  344. )
  345. },
  346. /**
  347. * 获取升级产品列表
  348. * /api/store/info
  349. */
  350. productV2(id) {
  351. get(
  352. 'v2/api/product/product', {
  353. id: id,
  354. store_id: this.data.storeId
  355. },
  356. (res) => {
  357. this.setData({
  358. selectProductData: res.data
  359. })
  360. console.log(res)
  361. }
  362. )
  363. },
  364. /**
  365. * 生命周期函数--监听页面加载
  366. */
  367. onLoad: function (options) {
  368. console.log(options, 'options');
  369. this.setData({
  370. navBarHeight: app.globalData.navBarData.navBarHeight
  371. })
  372. // this.getHomeData()
  373. let data = JSON.parse(JSON.stringify(this.initData))
  374. data.storeData = getApp().globalData.storeData
  375. data.storeId = data.storeData.id || wx.getStorageSync('store_id')
  376. // 存在传入的分类类型
  377. if (options.hasOwnProperty('cat_type')) {
  378. data.currentKeys = this.buildKeys(data.currentList, 'type')
  379. let _current = data.currentKeys['key_' + options.cat_type]
  380. if (_current != undefined) {
  381. data.current = _current
  382. data.currentType = options.cat_type
  383. }
  384. }
  385. // 存在传入的店铺ID
  386. if (options.hasOwnProperty('store_id')) {
  387. data.storeId = options.store_id
  388. // 更新店铺信息
  389. getStoreInfo(data.storeId)
  390. .then((res) => {
  391. data.storeData = res
  392. this.setData({
  393. storeData: res
  394. })
  395. })
  396. .catch(() => {})
  397. }
  398. this.setData(data, () => {
  399. this.getProductCategory(options)
  400. })
  401. this.productList()
  402. this.needAddGood()
  403. // 进入页面判断是否是直接跳转到美妆产品的是的话调用修改类型
  404. if (app.globalData.showGoods) {
  405. this.gotoGoods()
  406. }
  407. },
  408. // 监听页面隐藏
  409. onHide() {
  410. // 将全局的项目分类下标重置
  411. app.globalData.toViewIndex = 0
  412. },
  413. noneEnoughPeople() {
  414. },
  415. /**
  416. * 生命周期函数--监听页面初次渲染完成
  417. */
  418. onReady: function () {},
  419. /**
  420. * 生命周期函数--监听页面显示
  421. */
  422. onShow: function () {
  423. // this.orderDiscount()
  424. let version1 = wx.getStorageSync('version1')
  425. if (!version1 || version1 != 1) {
  426. this.setData({
  427. // inFirstIn: true
  428. })
  429. wx.setStorageSync('version1', 1)
  430. }
  431. // 当切换了店铺时,重新请求一次数据
  432. let storeData = getApp().globalData.storeData
  433. let storeId = storeData.id || wx.getStorageSync('store_id')
  434. if (storeId != this.data.storeId && this.data.storeId) {
  435. let data = JSON.parse(JSON.stringify(this.initData))
  436. this.setData(data, () => {
  437. this.setData({
  438. storeId: storeId,
  439. storeData: storeData
  440. }, () => {
  441. this.getProductCategory()
  442. this.getStoreInfo(storeId)
  443. this.productList()
  444. })
  445. })
  446. } else {
  447. this.getStoreInfo(storeId)
  448. }
  449. let that = this
  450. let curres = wx.getStorageSync('curre')
  451. // console.log('haves1')
  452. if (curres && curres == 1) {
  453. // console.log('haves')
  454. let item = that.data.currentList[0]
  455. this.setData({
  456. current: item.id,
  457. currentItemIndex: 0,
  458. currentType: item.type
  459. },
  460. () => {
  461. // this.getProduct(item.type, item.child[0].id)
  462. let _dataset = {
  463. currentTarget: {
  464. dataset: {
  465. item: item.child[0],
  466. index: 0
  467. }
  468. }
  469. }
  470. this.onTabsItem(_dataset)
  471. }
  472. )
  473. wx.setStorageSync('curre', 0)
  474. }
  475. setTimeout(() => {
  476. if (this.data.current == 3) {
  477. this.needAddGood()
  478. } else {
  479. this.needAddCar()
  480. }
  481. }, 500)
  482. if(app.globalData.toViewIndex!=0){
  483. this.setData({
  484. toView: 'A' + (app.globalData.toViewIndex-1),
  485. selectProductList: app.globalData.toViewIndex-1
  486. })
  487. }else{
  488. this.setData({
  489. toView: 'A' + 0,
  490. selectProductList: 0
  491. })
  492. }
  493. },
  494. //精选项目
  495. needAddCar() {
  496. let toSelectProduct = wx.getStorageSync('toSelectProduct')
  497. if (toSelectProduct && JSON.parse(toSelectProduct) == []) {
  498. wx.setStorageSync('toSelectProduct', JSON.stringify([]))
  499. return
  500. }
  501. let cardAddData = []
  502. if (toSelectProduct) {
  503. cardAddData = JSON.parse(toSelectProduct)
  504. }
  505. wx.setStorageSync('toSelectProduct', JSON.stringify([]))
  506. let selectProductCarData = this.data.selectProductCar
  507. for (let i = 0; i < selectProductCarData.length; i++) {
  508. if (selectProductCarData[i].id == cardAddData[i].id || cardAddData.id) {
  509. return
  510. }
  511. }
  512. console.log(selectProductCarData, 'cardAddData', cardAddData);
  513. selectProductCarData = selectProductCarData.concat(cardAddData)
  514. this.setData({ //对上一个页面data中的参数进行赋值(上一个页面的数据是在当前页面进行赋值的),就变相实现了向上一个页面传值
  515. selectProductCar: selectProductCarData
  516. })
  517. this.showCarMoney()
  518. },
  519. //美妆产品
  520. needAddGood() {
  521. let params = {
  522. store_id: this.data.storeId,
  523. page: this.data.page,
  524. limit: this.data.limit
  525. }
  526. get('v2/api/car/list', params, (res) => {
  527. if (res.code == 200) {
  528. let selectProductCarData = []
  529. selectProductCarData = selectProductCarData.concat(res.data.list)
  530. // 购物车产品总数量
  531. let sum = 0
  532. selectProductCarData.map(item => {
  533. sum += item.num
  534. })
  535. selectProductCarData.sum = sum
  536. // 设置美妆产品购物车总数量
  537. this.setData({
  538. sum: sum
  539. })
  540. this.setData({
  541. selectMakeupList: selectProductCarData,
  542. showMoneyGood: res.data.total_money == null ? "0.00" : res.data.total_money
  543. })
  544. if (this.data.selectMakeupList < res.data.count) {
  545. this.setData({
  546. page: this.data.page + 1
  547. })
  548. this.needAddGood()
  549. }
  550. if (res.data.list.length == 0) {
  551. this.setData({
  552. onMakeup: false
  553. })
  554. }
  555. }
  556. })
  557. },
  558. /**
  559. * 页面上拉触底事件的处理函数
  560. */
  561. onReachBottom: function () {
  562. this.getProduct(this.data.currentType, this.data.currentItemCatId, 1)
  563. },
  564. /**
  565. * 用户点击右上角分享
  566. */
  567. onShareAppMessage: function () {},
  568. /**
  569. * 转化对象
  570. */
  571. buildKeys: function (params, key) {
  572. let keys = {}
  573. for (let i = 0; i < params.length; i++) {
  574. let item = params[i]
  575. keys['key_' + item[key]] = i
  576. }
  577. return keys
  578. },
  579. /**
  580. * 切换tabs
  581. */
  582. onTabsChange(e) {
  583. if (this.data.inFirstIn) {
  584. return;
  585. }
  586. let item = e.currentTarget.dataset.item
  587. this.setData({
  588. current: item.id,
  589. currentItemIndex: 0,
  590. currentType: item.type
  591. },
  592. () => {
  593. // this.getProduct(item.type, item.child[0].id)
  594. let _dataset = {
  595. currentTarget: {
  596. dataset: {
  597. item: item.child[0],
  598. index: 0
  599. }
  600. }
  601. }
  602. this.onTabsItem(_dataset)
  603. if (this.data.current == 3) {
  604. this.needAddGood()
  605. return
  606. }
  607. this.showCarMoney()
  608. }
  609. )
  610. },
  611. /**
  612. * 切换子tabs
  613. */
  614. onTabsItem(e) {
  615. console.log(e, 'e')
  616. if (this.data.inFirstIn) {
  617. return;
  618. }
  619. // this.setData({
  620. // inFirstIn:true
  621. // })
  622. let that = this
  623. let item = e.currentTarget.dataset.item
  624. let currentItemIndex = e.currentTarget.dataset.index
  625. if (!item) {
  626. return
  627. }
  628. this.setData({
  629. currentItemIndex: currentItemIndex,
  630. currentItemCatId: item.id
  631. },
  632. () => {
  633. console.log(this.data.current, 'this.data.current')
  634. // if(this.data.current === 4){
  635. // // 查询次卡列表
  636. // this.getSecondaryCardList(that.data.currentType, item.id)
  637. // } else {
  638. // that.getProduct(that.data.currentType, item.id)
  639. // }
  640. that.getProduct(that.data.currentType, item.id)
  641. }
  642. )
  643. },
  644. knowSubmit: function () {
  645. this.setData({
  646. inFirstIn: false
  647. })
  648. },
  649. /**
  650. * 获取产品分类
  651. */
  652. getProductCategory(options = {}) {
  653. let {
  654. currentList,
  655. current,
  656. currentType,
  657. currentItemIndex,
  658. currentItemCatId
  659. } = this.data
  660. get('api/product/category', {}, (res) => {
  661. console.log(res, 'res')
  662. let {
  663. project,
  664. product,
  665. cardgoods,
  666. other
  667. } = res.data
  668. currentList[0].child = project
  669. currentList[1].child = product
  670. currentList[2].child = cardgoods
  671. currentList[3].child = other
  672. currentList[4].child = cardgoods
  673. // 存在传入的分类ID
  674. if (options.hasOwnProperty('cat_id')) {
  675. let catKyes = this.buildKeys(currentList[current].child, 'id')
  676. let _currentItemIndex = catKyes['key_' + options.cat_id]
  677. if (_currentItemIndex != undefined) {
  678. currentItemIndex = _currentItemIndex
  679. currentItemCatId = options.cat_id
  680. }
  681. } else {
  682. // 判断是否是跳转到下单页面直接显示美妆产品
  683. if (app.globalData.showGoods) {
  684. current = (other.length > 0 && '3') ||
  685. (project.length > 0 && '0') ||
  686. (product.length > 0 && '1') ||
  687. (cardgoods.length > 0 && '2')
  688. } else {
  689. current = (project.length > 0 && '0') ||
  690. (product.length > 0 && '1') ||
  691. (cardgoods.length > 0 && '2') ||
  692. (other.length > 0 && '3')
  693. }
  694. switch (current) {
  695. // 默认值
  696. case 0:
  697. currentItemCatId = project[0].id
  698. break
  699. case 1:
  700. currentItemCatId = product[0].id
  701. break
  702. case 2:
  703. currentItemCatId = cardgoods[0].id
  704. break
  705. case 3:
  706. currentItemCatId = other[0].id
  707. break
  708. }
  709. }
  710. this.setData({
  711. currentList,
  712. current,
  713. currentItemIndex,
  714. currentItemCatId
  715. },
  716. () => {
  717. if (project.length > 0) {
  718. this.getProduct(currentType, currentItemCatId)
  719. }
  720. }
  721. )
  722. })
  723. },
  724. /**
  725. * 项目/产品列表
  726. * type: 数据类型,1项目,2项目耗材,3美妆产品,默认1
  727. */
  728. getProduct(ptype, pcat_id, turn = 0) {
  729. let that = this
  730. let key = `pkey_${ptype}_${pcat_id}`
  731. let {
  732. productData,
  733. productDataLoading,
  734. storeId
  735. } = that.data
  736. let pcatData = productData[key] || {
  737. total: 0,
  738. list: [],
  739. page: 1,
  740. has_more: 1,
  741. type: ptype,
  742. cat_id: pcat_id
  743. }
  744. if (productDataLoading || !pcatData.has_more) return
  745. // 是否为翻页
  746. if (!turn && pcatData.total > 0) return
  747. this.setData({
  748. productDataLoading: true
  749. })
  750. let page = pcatData.page
  751. get(
  752. this.data.current !== 4 ? 'api/product' : 'v2/api/card/list', this.data.current !== 4 ? {
  753. store_id: storeId,
  754. type: ptype,
  755. category_id: pcat_id,
  756. page: page
  757. } : {
  758. store_id: storeId,
  759. category_id: pcat_id,
  760. page: page,
  761. limit: 5
  762. },
  763. (res) => {
  764. that.setData({
  765. productDataLoading: false
  766. })
  767. let plist = pcatData.list.concat(res.data.list)
  768. page++
  769. pcatData = Object.assign(pcatData, {
  770. total: res.data.total,
  771. page: page,
  772. list: plist,
  773. has_more: plist.length < res.data.total && res.data.list.length > 0
  774. })
  775. productData[key] = pcatData
  776. this.setData({
  777. productData: productData
  778. })
  779. },
  780. (err) => {
  781. that.setData({
  782. productDataLoading: false
  783. })
  784. }
  785. )
  786. },
  787. // 获取需要加购多少商品的价格
  788. getExchangePrice() {
  789. post('v2/api/car/plus_project', {
  790. store_id: this.data.storeId || wx.getStorageSync('store_id'),
  791. goods_id: '',
  792. type: 1
  793. }, (res) => {
  794. if (res.code == 200) {
  795. this.setData({
  796. exchangeInfo: res.data
  797. })
  798. }
  799. })
  800. },
  801. onOpenMakeup() {
  802. // 获取需要加购多少商品的价格
  803. this.getExchangePrice()
  804. this.setData({
  805. onMakeup: true
  806. })
  807. },
  808. onCloseMakeup() {
  809. this.setData({
  810. onMakeup: false
  811. })
  812. },
  813. // 删除购物车
  814. inDeleteCarGood(e) {
  815. let index = e.currentTarget.dataset.index
  816. get('v2/api/car/del', {
  817. car_id: this.data.selectMakeupList[index].id
  818. }, res => {
  819. if (res.code == 200) {
  820. this.needAddGood()
  821. // 获取需要加购多少商品的价格
  822. this.getExchangePrice()
  823. }
  824. })
  825. },
  826. //购物车结算
  827. toSubmitGood: function () {
  828. if (this.data.selectMakeupList.length == 0) {
  829. return
  830. }
  831. // let _projectData = this.data.selectMakeupList
  832. // 筛选出购物车中所有商品的id
  833. let {
  834. goods_ids
  835. } = this.data
  836. goods_ids = []
  837. this.data.selectMakeupList.map(item => {
  838. goods_ids.push(item.goods_id)
  839. })
  840. wx.navigateTo({
  841. url: `/pages/goodsOrderConfirm/goodsOrderConfirm?source=goods&storeId=${this.data.storeId}&goods_ids=${goods_ids}&type=1`,
  842. })
  843. },
  844. onChangeNum(e) {
  845. let params = {
  846. car_id: this.data.selectMakeupList[e].id,
  847. num: this.data.selectMakeupList[e].num
  848. }
  849. get('/v2/api/car/add_number', params, res => {
  850. if (res.code == 200) {
  851. this.needAddGood()
  852. // 获取加购多少商品价格
  853. this.getExchangePrice()
  854. }
  855. })
  856. },
  857. onReduce(e) {
  858. let index = e.currentTarget.dataset.index
  859. let num = this.data.selectMakeupList[index].num
  860. num = num - 1
  861. if (num < 0) {
  862. num = 0
  863. }
  864. let dataNum = `selectMakeupList[${index}].num`
  865. this.setData({
  866. [dataNum]: num
  867. })
  868. this.onChangeNum(index)
  869. },
  870. onLationAdd(e) {
  871. let index = e.currentTarget.dataset.index
  872. let num = this.data.selectMakeupList[index].num
  873. num = num + 1
  874. let dataNum = `selectMakeupList[${index}].num`
  875. this.setData({
  876. [dataNum]: num
  877. })
  878. this.onChangeNum(index)
  879. },
  880. // 点击美妆产品购物袋图标显示弹出购物车框
  881. showProduce(e) {
  882. console.log(e);
  883. this.setData({
  884. showProducePup: true,
  885. sourceId: e.target.dataset.proitem.id,
  886. proItem: e.target.dataset.proitem
  887. })
  888. this.setData({
  889. isIcon: this.data.showProducePup
  890. })
  891. },
  892. // 点击美妆产品购物袋加入购物车
  893. submit_add(type) {
  894. let params = {
  895. goods_id: this.data.sourceId,
  896. store_id: this.data.storeId
  897. }
  898. post('v2/api/car/add', params, (res) => {
  899. if (res.code == 200) {
  900. if (type == 'shopping') {
  901. wx.navigateTo({
  902. url: `/pages/goodsOrderConfirm/goodsOrderConfirm?storeId=${this.data.storeId}`,
  903. })
  904. } else {
  905. wx.showToast({
  906. title: '成功加入购物车!',
  907. icon: 'none'
  908. })
  909. this.needAddGood()
  910. setTimeout(() => {
  911. // wx.switchTab({
  912. // url: '/pages/orderBy/orderBy?cat_type=3',
  913. // })
  914. this.setData({
  915. showProducePup: false,
  916. isIcon: false
  917. })
  918. }, 1000)
  919. }
  920. }
  921. })
  922. },
  923. // 点击商品或者按钮直接跳转到下单页面的美妆产品页面(进入页面将类型改为美妆产品)
  924. gotoGoods() {
  925. this.setData({
  926. current: 3,
  927. currentType: 3,
  928. })
  929. },
  930. // 监听tab切换(判断进入页面是是否是上次跳转进来的美妆产品如果是直接刷新(current==3判断类型))
  931. onTabItemTap() {
  932. //具体操作
  933. if (this.data.current == 3) {
  934. wx.reLaunch({
  935. url: '/pages/orderBy/orderBy',
  936. })
  937. }
  938. }
  939. })