123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- import {
- default as storeApi
- } from "../../api/store"
- import {
- default as commonApi
- } from "../../api/commonApi"
- import {
- default as requestApi
- } from "../../utils/request"
- import {
- default as productApi
- } from "../../api/product"
- const app = getApp();
- Page({
- data: {
- tabs: [{
- title: '足浴'
- },
- {
- title: '美甲'
- },
- {
- title: '附加服务'
- }
- ],
- activeTab: 0,
- tabHeight: 500,
- productList: [],
- isLocation: false,
- pageNo: [1, 1, 1],
- pageSum: [],
- activeIndex: 0,
- productHeight: 0
- },
- onLoad: async function (options) {
- console.log(options)
- const self = this
- const tokenData = await commonApi.getToken();
- console.log(tokenData)
- console.log(requestApi.HEAD.token)
- if (tokenData.token && !requestApi.HEAD.token) {
- console.log('设置token')
- wx.setStorageSync('token', tokenData.token)
- requestApi.HEAD.token = tokenData.token
- }
- if (!options.storeId) {
- wx.getSetting({
- success: (res) => {
- let authSetting = res.authSetting
- if (authSetting['scope.userLocation']) {
- console.log('已授权地理位置')
- // 已授权
- self.getLocation();
- } else {
- // 未授权
- console.log('未授权地理位置');
- wx.getLocation({
- type: 'wgs84',
- async success(res) {
- console.log(res)
- const latitude = res.latitude
- const longitude = res.longitude
- wx.setStorageSync('lon', longitude)
- wx.setStorageSync('lat', latitude)
- const rs = await storeApi.getNearStore(latitude, longitude)
- console.log(rs.info);
- if (!rs.info.distance) {
- wx.showModal({
- title: '提示',
- content: '该门店打样了哦',
- })
- }
- self.setData({
- locationFlag: true,
- storeInfo: rs.info
- })
- }
- })
- }
- }
- })
- } else {
- const rs = await storeApi.getStoreById(options.storeId)
- self.setData({
- storeInfo: rs.info
- })
- }
- //根据机型设置现有的tab-content盒子高度
- let windowHeight = parseInt(wx.getSystemInfoSync().windowHeight) * parseInt(750 / wx.getSystemInfoSync().windowWidth) - 185
- // await this.getProductList();
- self.setData({
- tabHeight: windowHeight
- })
- },
- onShow: async function (op) {
- console.log(op)
- const self = this
- if (self.data.isShow == 1) {
- return
- }
- const tokenData = await commonApi.getToken();
- if (tokenData.token && !requestApi.HEAD.token) {
- console.log('onshow设置了token')
- wx.setStorageSync('token', tokenData.token)
- requestApi.HEAD.token = tokenData.token
- }
- if (self.data.chooseStoreId) {
- const rs = await storeApi.getStoreById(self.data.chooseStoreId)
- self.setData({
- storeInfo: rs.info,
- chooseStoreId: 0
- })
- }
- await this.productTypeList()
- await this.getProductList();
- let tabs = this.data.tabs;
- let activeTab = this.data.activeTab;
- let defaultH = '100%'
- if (tabs[activeTab].list.length) {
- defaultH = tabs[activeTab].list.length * 170
- }
- let productHeight = defaultH
- self.setData({
- productHeight,
- isShow:1
- })
- },
- productTypeList: async function(){
- const self = this
- const rs = await productApi.getProductTypeList(1,10)
- self.setData({
- tabs: rs.list
- })
- },
- getProductList: async function (refresh = false) {
- const self = this
- let activeTab = self.data.activeTab;
- let tabs = self.data.tabs;
- let pageSum = self.data.pageSum;
- let pageNo = self.data.pageNo;
- let prolist = await productApi.getProductList(tabs[activeTab].id, pageNo[activeTab],10);
- pageSum[activeTab] = prolist.pageCount;
- let list = prolist.list;
- if (!tabs[activeTab].list) {
- tabs[activeTab].list = [];
- }
- if (pageNo[activeTab] == 1) {
- tabs[activeTab].list = list;
- } else {
- list.forEach((item) => {
- let oldList = tabs[activeTab].list;
- oldList.push(item);
- tabs[activeTab].list = oldList;
- })
- }
- self.setData({
- tabs,
- pageSum
- })
- },
- requestAll(url, data, header = {}, method) {
- const _self = this
- wx.showLoading()
- return new Promise((resolve, reject) => {
- wx.request({
- url: url,
- data: data,
- header: header,
- dataType: 'json',
- method: method,
- success: (res => {
- wx.hideLoading()
- if (res.data.code === 1) {
- //200: 服务端业务处理正常结束
- resolve(res.data)
- } else {
- if (res.data.code === 0) {
- wx.showToast({
- title: res.data.message,
- })
- }
- if (res.data.code === 901) {
- console.log(res.data)
- }
- //其它错误,提示用户错误信息
- if (this._errorHandler != null) {
- //如果有统一的异常处理,就先调用统一异常处理函数对异常进行处理
- this._errorHandler(res)
- }
- reject(res)
- }
- }),
- fail: (res => {
- if (this._errorHandler != null) {
- this._errorHandler(res)
- }
- wx.showToast({
- title: '网络异常请,稍后再试~',
- })
- reject(res)
- })
- })
- })
- },
- onTabClick(e) {
- const index = e.detail.index
- let tabs = this.data.tabs
- let defaultH = 600
- if (tabs[index].list && tabs[index].list.length) {
- defaultH = tabs[index].list.length * 170
- }
- let productHeight = defaultH
- console.log(productHeight)
- console.log(tabs[index].list)
- this.setData({
- activeTab: index,
- productHeight
- })
- },
- onChange(e) {
- const index = e.detail.index
- let pageNo = this.data.pageNo;
- this.setData({
- activeTab: index,
- // pageNo: [1, 1, 1, 1]
- }),
- this.getProductList()
- },
- handleClick(e) {
- },
- getLocation: async function () {
- console.log('getlocation')
- const self = this
- wx.getLocation({
- type: 'wgs84',
- async success(res) {
- console.log(res)
- const latitude = res.latitude
- const longitude = res.longitude
- wx.setStorageSync('lon', longitude)
- wx.setStorageSync('lat', latitude)
- const speed = res.speed
- const accuracy = res.accuracy
- const rs = await storeApi.getNearStore(latitude, longitude)
- console.log(rs.info);
- self.setData({
- locationFlag: true,
- storeInfo: rs.info
- })
- },
- fail(err) {
- console.log(err)
- }
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- let activeTab = this.data.activeTab;
- let pageNo = this.data.pageNo;
- let pageSum = this.data.pageSum;
- pageNo[activeTab]++;
- console.log('触底了')
- this.setData({
- pageNo
- })
- if (pageNo[activeTab] <= pageSum[activeTab]) {
- console.log(pageNo)
- this.getProductList()
- }
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- console.log(111)
- },
- showProduct: async function (e) {
- const self = this
- console.log(e.currentTarget.dataset.productid)
- var productId = e.currentTarget.dataset.productid;
- if (this.data.storeInfo) {
- var shopId = this.data.storeInfo.id;
- wx.navigateTo({
- url: '../product/product?shopId=' + shopId + '&productId=' + productId,
- })
- return
- }
- wx.getLocation({
- type: 'wgs84',
- async success(res) {
- console.log(res)
- const latitude = res.latitude
- const longitude = res.longitude
- const speed = res.speed
- const accuracy = res.accuracy
- const rs = await storeApi.getNearStore(latitude, longitude)
- console.log(rs.info);
- self.setData({
- locationFlag: true,
- storeInfo: rs.info
- })
- var shopId = self.data.storeInfo.id;
- wx.navigateTo({
- url: '../product/product?shopId=' + shopId + '&productId=' + productId,
- })
- }
- })
- },
- gotoAppointment: async function (e) {
- const self = this
- console.log(e.currentTarget.dataset.productid)
- let productId = e.currentTarget.dataset.productid;
- let shopId = this.data.storeInfo.id;
- let address = self.data.storeInfo.address;
- let shopName = self.data.storeInfo.storeName;
- const isAuth = await app.isAuth()
- if (!isAuth) {
- // wx.redirectTo({
- // url: '/pages/prompt/prompt?page=' + this.route + `&shopId=${shopId}&productId=${productId}&address=${address}&shopName=${shopName}`,
- // })
- // return
- }
- wx.navigateTo({
- url: '../appointment/appointment?' + 'shopId=' + shopId + '&productId=' + productId + '&address=' + address + "&shopName=" + shopName,
- })
- }
- })
|