add-confirm.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*******************************************************************************
  2. * Copyright(c) 2022 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:增值定制
  5. * 编辑履历:
  6. * 作者 日期 版本 修改内容
  7. * 周兴 2024-5-15 1.00 新建
  8. *******************************************************************************/
  9. const Constants = require('@/utils/Constants.js');
  10. const mixins = require('@/mixins/index.js');
  11. const config = require('@/config/config.js');
  12. const app = getApp()
  13. Page({
  14. mixins: [mixins],
  15. /**
  16. * 页面的初始数据
  17. */
  18. data: {
  19. regions: [],
  20. functionItems: [],
  21. funIds: [],
  22. imageUrl: config.image_url + '/static/img/',
  23. userEndDate: null,
  24. userEndDateFlg: false,
  25. userEndDateString: '',
  26. factAmt: 0,
  27. routeObjName: 'company',
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad(options) {
  33. console.log("app.globalData.company.funPackage",app.globalData.company.funPackage);
  34. // 用户到期日期
  35. if (app.globalData.company.userEndDate) {
  36. this.setData({
  37. userEndDate: app.globalData.company.userEndDate
  38. })
  39. }
  40. },
  41. /**
  42. * 生命周期函数--加载数据
  43. */
  44. loadInit() {
  45. let regions = this.data.regions
  46. regions.push(this.data.item)
  47. this.setData({
  48. regions: regions,
  49. })
  50. //获取服务器的最新时间
  51. this.getCurrentDate()
  52. },
  53. /**
  54. * @desc : 服务器的日期
  55. * @author : 姜永辉
  56. * @date : 2024/4/1
  57. */
  58. getCurrentDate() {
  59. let _this = this
  60. let service = app.globalData['commonService']
  61. _this.excute(service, service.getCurrentDate, {}).then(res => {
  62. if (res.data.code == Constants.SUCESS_CODE) {
  63. //服务器的时间
  64. let nowDate = res.data.data.currentDate
  65. let endDate = new Date(nowDate).addMonths(12).addDays(-1).toDateStr()
  66. // 用户到期日期
  67. if (_this.data.userEndDate == null || !_this.data.userEndDate) {
  68. this.setData({
  69. userEndDate: endDate,
  70. userEndDateFlg: true,
  71. userEndDateString: _this.data.item.wxPrice + '元/年(' + _this.data.item.activityItemDescribe + ')',
  72. factAmt: _this.data.item.wxPrice,
  73. extendDays: 365,
  74. nowDate,
  75. })
  76. } else {
  77. // 和 服务器的时间一致
  78. if (_this.data.userEndDate == endDate) {
  79. this.setData({
  80. userEndDateFlg: true,
  81. userEndDateString: _this.data.item.wxPrice + '元/年(' + _this.data.item.activityItemDescribe + ')',
  82. factAmt: _this.data.item.wxPrice,
  83. extendDays: 365,
  84. nowDate,
  85. })
  86. } else {
  87. let extendDays = Math.ceil(new Date(_this.data.userEndDate).dayDiff(new Date(nowDate)) + 1);
  88. let price = (Math.round((_this.data.item.wxPrice / 365 + Number.EPSILON) * 100) / 100).toFixed(2)
  89. console.log(price);
  90. let factAmt = (Number(price) * extendDays).toFixed(2)
  91. this.setData({
  92. userEndDateFlg: false,
  93. userEndDateString: price + '元/天(' + _this.data.item.activityItemDescribe + ')* ' + extendDays + '天=' + factAmt + '元',
  94. factAmt: factAmt,
  95. extendDays,
  96. nowDate,
  97. })
  98. }
  99. }
  100. }
  101. });
  102. },
  103. /**
  104. * @desc : 设置保存参数
  105. * @author : 周兴
  106. * @date : 2024/4/1
  107. */
  108. setParams(params) {
  109. let funPackage = app.globalData.company.funPackage? [...app.globalData.company.funPackage] : []
  110. params.endDate = app.globalData.company.endDate
  111. params.userEndDate = this.data.userEndDate
  112. params.gradeCode = app.globalData.company.gradeCode
  113. params.cpId = app.globalData.company.cpId
  114. params.tradeNo = this.generateRandomNo();
  115. params.wxUserId = app.globalData.user.userId
  116. params.tradeAmount = Number(this.data.factAmt)
  117. params.buyBeginDate = this.data.nowDate;
  118. params.buyEndDate = this.data.userEndDate
  119. params.extendDays = 0;
  120. params.wxMaxNum = app.globalData.company.wxMaxNum
  121. params.webMaxNum = app.globalData.company.webMaxNum
  122. params.activityId = this.data.item.activityId
  123. params.activityItemId = this.data.item.itemId
  124. params.remarks = this.data.userEndDateString
  125. params.reNew = app.globalData.company.reNew
  126. params.activityIds = [this.data.item.activityId]
  127. params.activityItemIds = [this.data.item.itemId]
  128. funPackage.push({
  129. funUuids: this.data.item.funUuids,
  130. activityId: this.data.item.activityId,
  131. })
  132. params.funPackage = funPackage
  133. if (app.globalData.company.vip) {
  134. params.vip = true;
  135. }
  136. params.buyLong = this.data.extendDays + '天'
  137. console.log(params);
  138. return params;
  139. },
  140. /**
  141. * @desc : 保存数据
  142. * @author : 周兴
  143. * @date : 2024/5/17
  144. */
  145. saveData(params) {
  146. return this.excute(this.data.service, this.data.service.saveFunc, this.data.params).then(res => {
  147. if (res.data.code == Constants.SUCESS_CODE) {
  148. // 成功后跳转支付
  149. this.toPay(res.data.data);
  150. }
  151. })
  152. },
  153. })