123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- // pages/order/placeOrder/placeOrder.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- activeKey: 0,
- navList: [
- {
- tit: "活动"
- },
- {
- tit: "套餐"
- },
- {
- tit: "洗衣"
- },
- {
- tit: "洗鞋"
- },
- {
- tit: "其他"
- },
- {
- tit: "其他"
- },
- {
- tit: "其他"
- },
- {
- tit: "其他"
- },
- {
- tit: "其他"
- },
- ],
- height: '',
- show: false,
- detailsShow: false,
- carList: [
- ],
- carNum: 0,
- carPrice: '',
- shoppingList: [
- {
- num: 0,
- id: 0,
- price: 20
- },
- {
- num: 0,
- id: 1,
- price: 39
- }
- ]
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.getHeight()
- this.getCarAll()
- },
- shoppingMinus(e) {
- let items = e.currentTarget.dataset.item, list = this.data.shoppingList;
- list.map(item => {
- if (items.id == item.id) {
- item.num--
- console.log(item);
- this.changeCarList(item)
- }
- })
- this.setData({
- shoppingList: list
- })
- this.getCarAll()
- },
- shoppingPlus(e) {
- let items = e.currentTarget.dataset.item, list = this.data.shoppingList;
- list.map(item => {
- if (items.id == item.id) {
- item.num++
- this.changeCarList(item)
- }
- })
- this.setData({
- shoppingList: list
- })
- this.getCarAll()
- },
- changeCarList(item) {
- let carList = this.data.carList
- if (carList.length == 0) {
- carList.push(item)
- this.setData({
- carList
- })
- return
- }
- console.log(item);
- var type = false;
- carList.map((i, index) => {
- if (i.id === item.id) {
- i.num = item.num
- if (item.num == 0) {
- carList.splice(index, 1)
- }
- this.setData({
- carList
- })
- type = false
- } else {
- type = true
- }
- })
- if (type) {
- carList.push(item)
- }
- console.log(carList);
- this.setData({
- carList
- })
- },
- changeShoppingList(item) {
- console.log(item);
- let shoppingList = this.data.shoppingList;
- shoppingList.map(i => {
- if (item.id == i.id) {
- i.num = item.num
- }
- })
- this.setData({
- shoppingList
- })
- },
- getCarAll() {
- this.setData({
- carNum: 0,
- carPrice: 0
- })
- let carList = this.data.carList
- carList.map(item => {
- wx.nextTick(() => {
- this.setData({
- carNum: this.data.carNum + item.num,
- carPrice: this.data.carPrice + item.price * item.num
- })
- })
- })
- },
- getOrder() {
- wx.navigateTo({
- url: '/pages/order/confirmOreder/confirmOreder',
- })
- },
- carPlus(e) {
- let items = e.currentTarget.dataset.item, list = this.data.carList
- console.log(items);
- list.map((item, index) => {
- if (items.id == item.id) {
- item.num++
- this.changeShoppingList(item)
- }
- })
- this.setData({
- carList: list
- })
- this.getCarAll()
- },
- carMinus(e) {
- let items = e.currentTarget.dataset.item, list = this.data.carList
- list.map((item, index) => {
- if (items.id == item.id) {
- item.num--
- this.changeShoppingList(item)
- if (items.num - 1 <= 0) {
- list.splice(index, 1)
- }
- }
- })
- this.setData({
- carList: list
- })
- this.getCarAll()
- },
- clearCarAll() {
- this.setData({
- carList: []
- })
- let shoppingList = this.data.shoppingList
- shoppingList.map(item => {
- item.num = 0
- })
- this.setData({
- shoppingList
- })
- this.getCarAll()
- this.btnShow()
- this.getHeight()
- },
- closeNews() {
- console.log(this.data.height);
- this.setData({
- height: this.data.height + 40
- })
- },
- changeActive(e) {
- let { activekey } = e.currentTarget.dataset
- this.setData({
- activeKey: activekey
- })
- },
- addressDetail() {
- this.setData({
- detailsShow: !this.data.detailsShow
- })
- },
- getHeight() {
- var clientHeight;
- wx.getSystemInfo({
- success: (res) => {
- clientHeight = res.windowHeight;
- }
- });
- var query1 = wx.createSelectorQuery()
- var query2 = wx.createSelectorQuery()
- var query3 = wx.createSelectorQuery()
- query1.select('#footerBar').boundingClientRect()
- query2.select('#topBox').boundingClientRect()
- query3.select('#scrollBox').boundingClientRect()
- query2.exec(result => {
- query3.exec(r => {
- query1.exec(res => {
- if (res && res[0] != null) {
- this.setData({
- height: clientHeight - res[0].height - result[0].height - r[0].height - 40
- })
- } else {
- this.setData({
- height: clientHeight - result[0].height - r[0].height - 40
- })
- }
- console.log(clientHeight, result[0].height, r[0].height);
- })
- })
- })
- },
- btnShow() {
- this.setData({
- show: !this.data.show
- })
- },
- })
|