/******************************************************************************* * Copyright(c) 2022 dongke All rights reserved. / Confidential * 类的信息: * 1.程序名称:增值定制 * 编辑履历: * 作者 日期 版本 修改内容 * 周兴 2024-5-15 1.00 新建 *******************************************************************************/ const Constants = require('@/utils/Constants.js'); const mixins = require('@/mixins/index.js'); const config = require('@/config/config.js'); const app = getApp() Page({ mixins: [mixins], /** * 页面的初始数据 */ data: { regions: [], functionItems: [], funIds: [], imageUrl: config.image_url + '/static/img/', userEndDate: null, userEndDateFlg: false, userEndDateString: '', factAmt: 0, routeObjName: 'company', }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log("app.globalData.company.funPackage",app.globalData.company.funPackage); // 用户到期日期 if (app.globalData.company.userEndDate) { this.setData({ userEndDate: app.globalData.company.userEndDate }) } }, /** * 生命周期函数--加载数据 */ loadInit() { let regions = this.data.regions regions.push(this.data.item) this.setData({ regions: regions, }) //获取服务器的最新时间 this.getCurrentDate() }, /** * @desc : 服务器的日期 * @author : 姜永辉 * @date : 2024/4/1 */ getCurrentDate() { let _this = this let service = app.globalData['commonService'] _this.excute(service, service.getCurrentDate, {}).then(res => { if (res.data.code == Constants.SUCESS_CODE) { //服务器的时间 let nowDate = res.data.data.currentDate let endDate = new Date(nowDate).addMonths(12).addDays(-1).toDateStr() // 用户到期日期 if (_this.data.userEndDate == null || !_this.data.userEndDate) { this.setData({ userEndDate: endDate, userEndDateFlg: true, userEndDateString: _this.data.item.wxPrice + '元/年(' + _this.data.item.activityItemDescribe + ')', factAmt: _this.data.item.wxPrice, extendDays: 365, nowDate, }) } else { // 和 服务器的时间一致 if (_this.data.userEndDate == endDate) { this.setData({ userEndDateFlg: true, userEndDateString: _this.data.item.wxPrice + '元/年(' + _this.data.item.activityItemDescribe + ')', factAmt: _this.data.item.wxPrice, extendDays: 365, nowDate, }) } else { let extendDays = Math.ceil(new Date(_this.data.userEndDate).dayDiff(new Date(nowDate)) + 1); let price = (Math.round((_this.data.item.wxPrice / 365 + Number.EPSILON) * 100) / 100).toFixed(2) console.log(price); let factAmt = (Number(price) * extendDays).toFixed(2) this.setData({ userEndDateFlg: false, userEndDateString: price + '元/天(' + _this.data.item.activityItemDescribe + ')* ' + extendDays + '天=' + factAmt + '元', factAmt: factAmt, extendDays, nowDate, }) } } } }); }, /** * @desc : 设置保存参数 * @author : 周兴 * @date : 2024/4/1 */ setParams(params) { let funPackage = app.globalData.company.funPackage? [...app.globalData.company.funPackage] : [] params.endDate = app.globalData.company.endDate params.userEndDate = this.data.userEndDate params.gradeCode = app.globalData.company.gradeCode params.cpId = app.globalData.company.cpId params.tradeNo = this.generateRandomNo(); params.wxUserId = app.globalData.user.userId params.tradeAmount = Number(this.data.factAmt) params.buyBeginDate = this.data.nowDate; params.buyEndDate = this.data.userEndDate params.extendDays = 0; params.wxMaxNum = app.globalData.company.wxMaxNum params.webMaxNum = app.globalData.company.webMaxNum params.activityId = this.data.item.activityId params.activityItemId = this.data.item.itemId params.remarks = this.data.userEndDateString params.reNew = app.globalData.company.reNew params.activityIds = [this.data.item.activityId] params.activityItemIds = [this.data.item.itemId] funPackage.push({ funUuids: this.data.item.funUuids, activityId: this.data.item.activityId, }) params.funPackage = funPackage if (app.globalData.company.vip) { params.vip = true; } params.buyLong = this.data.extendDays + '天' console.log(params); return params; }, /** * @desc : 保存数据 * @author : 周兴 * @date : 2024/5/17 */ saveData(params) { return this.excute(this.data.service, this.data.service.saveFunc, this.data.params).then(res => { if (res.data.code == Constants.SUCESS_CODE) { // 成功后跳转支付 this.toPay(res.data.data); } }) }, })