123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- // nova-tourism/pages/collect/collect-detail/index.js
- let Parse = getApp().Parse;
- const company = getApp().globalData.company
- const uid = Parse.User.current()?.id
- let sev = require('../../../service/request')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- statusBarHeight: 0,
- screenHeight: 0,
- customHeight: 0,
- bottomNavHeight: 0,
- contentHeight: 0,
- imageUrls: ['https://img95.699pic.com/photo/60072/5330.jpg_wh860.jpg',
- 'https://c-ssl.dtstatic.com/uploads/blog/201409/27/20140927230814_4QfVC.thumb.1000_0.jpeg',
- 'https://ts1.cn.mm.bing.net/th/id/R-C.37f4077f8eaca918401b84b4ee23af7c?rik=7HYWC88a9q4sZw&riu=http%3a%2f%2fpic.616pic.com%2fphotoone%2f00%2f06%2f03%2f618e27ad7ce8e1124.jpg&ehk=jkc6iZWAg%2bAEjAk6%2br0VAAy1lfffqslT6n%2fMWl293Yc%3d&risl=&pid=ImgRaw&r=0'
- ],
- gid: null, //商品id
- good: null, //商品详情
- spec: null, //商品规格
- checkSpec: null, //选中的规格
- totalPrice: 0, //订单总价
- specBox: false, //规格弹框
- address: null, //收货地址
- tradeNo: null, //订单编号
- order: null, //当前订单-parse
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- const systemInfo = wx.getSystemInfoSync();
- const statusBarHeight = systemInfo.statusBarHeight || 0;
- const screenHeight = systemInfo.screenHeight || 0;
- const custom = wx.getMenuButtonBoundingClientRect();
- const customHeight = custom.height + 10 + 2 || 0;
- const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
- const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
- this.setData({
- statusBarHeight,
- screenHeight,
- customHeight,
- bottomNavHeight,
- contentHeight
- });
- this.setData({
- gid: options?.gid
- })
- this.refersh()
- },
- async refersh() {
- this.getGood()
- },
- /**获取商品 */
- async getGood() {
- let {
- gid
- } = this.data
- let query = new Parse.Query('ShopGoods')
- let d = await query.get(gid)
- let good = d?.toJSON()
- console.log(good)
- let spec = good?.specMap?.specList.map(item => {
- let price = good.specMap[item][0].price
- let subName = price || good.price
- let obj = {
- name: item,
- subname: `售价¥${subName}`,
- color: 'gray',
- price: subName
- }
- return obj
- })
- let checkSpec = {}
- if (spec?.length) {
- checkSpec = spec[0]
- spec[0].color = 'red'
- }
- let totalPrice = checkSpec.price || good.price
- this.setData({
- good,
- spec,
- checkSpec,
- totalPrice
- })
- },
- /** 打开规格弹框*/
- openSpec() {
- let {spec} = this.data
- console.log(spec,'‘hhh')
- if(spec?.length<=0)return
- this.setData({
- specBox: true
- })
- },
- /**关闭规格弹框 */
- closeSpec() {
- this.setData({
- specBox: false
- })
- },
- /**选择规格 */
- getCheckSpec(e) {
- let {
- spec,
- checkSpec,
- totalPrice
- } = this.data
- checkSpec = e.detail
- spec = spec.map(item => {
- item.color = 'gray'
- if (item.name == checkSpec.name) {
- item.color = 'red'
- totalPrice = item.price
- }
- return item
- })
- this.setData({
- spec,
- checkSpec,
- totalPrice
- })
- },
- /** 跳转*/
- tourl(e) {
- const url = e.currentTarget.dataset.url
- wx.navigateTo({
- url: `${url}` // 目标页面的路径
- });
- },
- /** 判断是否可创建订单*/
- judgeOrder() {
- let {
- address
- } = this.data
- if (!address?.objectId) {
- wx.showToast({
- title: '请确认收货地址',
- icon: 'none',
- });
- return false
- }
- return true
- },
- /**创建订单 */
- async submitOrder() {
- let isPass = this.judgeOrder()
- if (!isPass) return
- let {
- good,
- totalPrice,
- checkSpec,
- address,
- order,
- tradeNo
- } = this.data
- let o = order
- if (!order?.id) {
- let now = new Date()
- tradeNo = "C" +
- String(now.getFullYear()) +
- (now.getMonth() + 1) +
- now.getDate() +
- now.getHours() +
- now.getMinutes() +
- now.getSeconds() +
- Math.random().toString().slice(-6);
- let Order = Parse.Object.extend("Order");
- o = new Order()
- o.set("company", {
- __type: 'Pointer',
- className: 'Company',
- objectId: company
- })
- o.set("user", {
- __type: 'Pointer',
- className: '_User',
- objectId: uid
- })
- o.set("orderNum", tradeNo);
- o.set('status', '100') //待支付
- o.set('type', 'scenery')
- o.set("targetObject", [{
- "__type": "Pointer",
- "className": "ShopGoods",
- "objectId": good?.objectId
- }])
- }
- o.set("totalPrice", totalPrice || 0);
- o.set("address", {
- __type: 'Pointer',
- className: 'ShopAddress',
- objectId: address?.objectId
- });
- o.set("info", {
- name: address?.name,
- mobile: address?.mobile,
- address: address?.full_region + address?.address
- });
- let specMap = {}
- specMap[good?.objectId] = {
- count: 1,
- price: good.price,
- spec: checkSpec.name
- }
- o.set("specMap", specMap);
- try {
- // order = await o.save()
- this.setData({
- tradeNo,
- order:o,
- showPay: true,
- })
- // wx.showToast({
- // title: '已创建订单',
- // icon: 'none'
- // })
- } catch (error) {
- wx.showToast({
- title: '出错了请检查后重试',
- icon: 'error'
- })
- }
- },
- /**支付回调 */
- async acceptResult(e) {
- let {
- order
- } = this.data
- let {
- params
- } = e.detail
- if (params == 'ok') {
- wx.showLoading({
- title: '加载中',
- })
- order.set('status', '200')
- order.set('payType', 'wx')
- order.set('isPay', true)
- try {
- await order.save()
- setTimeout(() => {
- wx.hideLoading()
- wx.redirectTo({
- url: '/nova-tourism/pages/my/my-order/index?active=0',
- })
- }, 1000);
- } catch (error) {
- wx.showToast({
- title: '保存订单出错,请联系客服核对订单',
- icon: 'none'
- })
- }
- } else {
- wx.showToast({
- title: '支付失败',
- icon: 'none'
- })
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- async onShow() {
- let address = await sev.getAddress()
- console.log(address)
- this.setData({
- address
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|