activity.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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 util = require('@/utils/util.js')
  11. const mixins = require('@/mixins/index.js');
  12. const app = getApp()
  13. Page({
  14. mixins: [mixins],
  15. /**
  16. * 页面的初始数据
  17. */
  18. data: {
  19. // 企业名称
  20. companyName: null,
  21. staffName: null,
  22. staffPhone: null,
  23. webMaxNum: null,
  24. wxMaxNum: null,
  25. cpEndDate: null,
  26. activityTable: null,
  27. readFlag: false,
  28. staffCount: {
  29. maxNum: 1,
  30. webMaxNum: 0,
  31. wxMaxNum: 0
  32. },
  33. curentAdItem: null,
  34. summaryInfo: {},
  35. routeObjName: 'company',
  36. pageFlag: false,
  37. // 当前用户授权数
  38. currentUserCount: null,
  39. //按钮
  40. buttonSaveList: [
  41. { code: 'save', title: mixins.$t('save'), width: '120rpx' }
  42. ],
  43. noticeInfo: Constants.noticeInfo
  44. },
  45. /**
  46. * @desc : 选择活动明细
  47. * @author : 周兴
  48. * @date : 2024/4/1
  49. */
  50. chooseAdItem(e) {
  51. let item = e.currentTarget.dataset.item;
  52. let summaryInfo = this.data.summaryInfo
  53. // 计算截止日期
  54. let months = item.validLong + item.extraLong
  55. let endDate = app.globalData.company.endDate
  56. endDate = new Date(endDate).addMonths(months)
  57. summaryInfo.endDate = endDate.toDateStr();
  58. this.setData({
  59. curentAdItem: item,
  60. summaryInfo: summaryInfo
  61. })
  62. // 计算金额
  63. this.countSummaryAmount(item);
  64. },
  65. /**
  66. * @desc : 勾选已阅读表示
  67. * @author : 周兴
  68. * @date : 2024/5/17
  69. */
  70. handleChangeCheckbox(e) {
  71. console.log('ee', e);
  72. this.setData({
  73. readFlag: e.detail
  74. })
  75. },
  76. /**
  77. * @desc : 计算金额
  78. * @author : 周兴
  79. * @date : 2024/4/1
  80. */
  81. countSummaryAmount() {
  82. let item = this.data.curentAdItem;
  83. let staffCount = this.data.staffCount;
  84. let summaryInfo = this.data.summaryInfo
  85. let amount = 0;
  86. // 先清空
  87. summaryInfo.amountInfo = '';
  88. // 共通用户
  89. if (staffCount.maxNum) {
  90. summaryInfo.amountInfo = item.stdPrice + '(打包价格)*' + staffCount.maxNum
  91. amount += item.stdPrice * staffCount.maxNum
  92. }
  93. // 手机端用户
  94. if (staffCount.wxMaxNum) {
  95. if (summaryInfo.amountInfo) {
  96. summaryInfo.amountInfo += ' + '
  97. }
  98. summaryInfo.amountInfo += item.wxPrice + '(手机端价格)*' + staffCount.wxMaxNum
  99. amount += item.wxPrice * staffCount.wxMaxNum
  100. }
  101. // 电脑端用户
  102. if (staffCount.webMaxNum) {
  103. if (summaryInfo.amountInfo) {
  104. summaryInfo.amountInfo += ' + '
  105. }
  106. summaryInfo.amountInfo += item.webPrice + '(电脑端价格)*' + staffCount.webMaxNum
  107. amount += item.webPrice * staffCount.webMaxNum
  108. }
  109. if (summaryInfo.amountInfo) {
  110. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  111. summaryInfo.amount = amount;
  112. }
  113. this.setData({
  114. summaryInfo: summaryInfo
  115. })
  116. // 统计两端用户数
  117. this.countStaffInfo();
  118. },
  119. /**
  120. * @desc : 统计电脑端和手机端的用户数
  121. * @author : 周兴
  122. * @date : 2024/4/1
  123. */
  124. countStaffInfo() {
  125. let summaryInfo = this.data.summaryInfo;
  126. let staffCount = this.data.staffCount;
  127. if (!staffCount) {
  128. return;
  129. }
  130. let webNum = staffCount.webMaxNum + staffCount.maxNum
  131. let wxNum = staffCount.wxMaxNum + staffCount.maxNum
  132. summaryInfo.staffInfo = '可配置手机端授权' + wxNum + '个;电脑端授权' + webNum + '个(包含当前用户)'
  133. summaryInfo.webMaxNum = webNum
  134. summaryInfo.wxMaxNum = wxNum
  135. summaryInfo.buyBeginDate = new Date(this.data.cpEndDate).addDays(1).toDateStr();
  136. summaryInfo.extendDays = new Date(summaryInfo.endDate).dayDiff(new Date(this.data.cpEndDate).addDays(1));
  137. // 计算一授权一天的单价
  138. let price = (summaryInfo.amount / (webNum + wxNum) / summaryInfo.extendDays).toFixed(2);
  139. summaryInfo.priceInfo = price
  140. this.setData({
  141. summaryInfo: summaryInfo
  142. })
  143. },
  144. /**
  145. * @desc : 修改用户数
  146. * @author : 周兴
  147. * @date : 2024/4/1
  148. */
  149. changeStaffCount(e) {
  150. let staffCount = this.data.staffCount
  151. let ds = e.currentTarget.dataset
  152. if (ds.type == 'wx') {
  153. staffCount.wxMaxNum = e.detail
  154. } else if (ds.type == 'web') {
  155. staffCount.webMaxNum = e.detail
  156. } else {
  157. staffCount.maxNum = e.detail
  158. }
  159. this.setData({
  160. staffCount: staffCount
  161. })
  162. // 计算金额
  163. this.countSummaryAmount();
  164. },
  165. /**
  166. * @desc : 保存
  167. * @author : 周兴
  168. * @date : 2024/4/1
  169. */
  170. handleSave() {
  171. let summaryInfo = this.data.summaryInfo;
  172. let currentUserCount = this.data.currentUserCount
  173. if (!currentUserCount) {
  174. return;
  175. }
  176. // 判断数量是否超出续约授权
  177. if (currentUserCount.wxNum > summaryInfo.wxMaxNum || currentUserCount.webNum > summaryInfo.webMaxNum) {
  178. let staffInfo = [{ wxMaxNum: this.data.wxMaxNum, webMaxNum: this.data.webMaxNum, title: '当前授权', wxTitle: '手机授权', webTitle: '电脑授权', code: 'current' }, { wxMaxNum: summaryInfo.wxMaxNum, webMaxNum: summaryInfo.webMaxNum, title: '续费授权', wxTitle: '手机授权', webTitle: '电脑授权', code: 'renew' }]
  179. this.save({ saveFlag: false, url: '/package-basic-data/pages/activity/detail/detail?staffInfo=' + JSON.stringify(staffInfo) });
  180. } else {
  181. this.save({});
  182. }
  183. },
  184. /**
  185. * @desc : 校验
  186. * @author : 周兴
  187. * @date : 2024/4/1
  188. */
  189. validData() {
  190. if (!this.data.readFlag) {
  191. util.showToast('请勾选阅读须知');
  192. return false;
  193. }
  194. let curentAdItem = this.data.curentAdItem;
  195. if (!curentAdItem) {
  196. util.showToast('请选择活动');
  197. return false
  198. }
  199. // 必须要选择一个授权
  200. let staffCount = this.data.staffCount
  201. if (!staffCount.maxNum || !staffCount.webMaxNum || !staffCount.wxMaxNum) {
  202. util.showToast('请选择一个授权');
  203. return false
  204. }
  205. return true;
  206. },
  207. /**
  208. * @desc : 设置保存参数
  209. * @author : 周兴
  210. * @date : 2024/4/1
  211. */
  212. setParams(params) {
  213. let summaryInfo = this.data.summaryInfo
  214. let curentAdItem = this.data.curentAdItem
  215. let cpEndDate = this.data.cpEndDate
  216. if (!summaryInfo || !cpEndDate) return;
  217. params.webMaxNum = summaryInfo.webMaxNum
  218. params.wxMaxNum = summaryInfo.wxMaxNum
  219. params.endDate = summaryInfo.endDate
  220. params.gradeCode = app.globalData.company.gradeCode
  221. params.cpId = app.globalData.company.cpId
  222. params.tradeNo = this.generateRandomNo();
  223. params.wxUserId = app.globalData.user.userId
  224. params.tradeAmount = summaryInfo.amount
  225. params.buyBeginDate = summaryInfo.buyBeginDate;
  226. params.buyEndDate = summaryInfo.endDate
  227. params.extendDays = summaryInfo.extendDays;
  228. params.buyLong = curentAdItem.activityItemName
  229. return params;
  230. },
  231. /**
  232. * @desc : 保存数据
  233. * @author : 周兴
  234. * @date : 2024/5/17
  235. */
  236. saveData(params) {
  237. return this.excute(this.data.service, this.data.service.reNewCompany, this.data.params).then(res => {
  238. if (res.data.code == Constants.SUCESS_CODE) {
  239. // 成功后跳转支付
  240. this.toPay(res.data.data);
  241. }
  242. })
  243. },
  244. /**
  245. * @desc : 查询当前用户授权数
  246. * @author : 周兴
  247. * @date : 2024/4/1
  248. */
  249. getStaffCount() {
  250. let service = app.globalData['commonService']
  251. this.excute(service, service.selectUserCount, {}).then(res => {
  252. if (res.data.code == Constants.SUCESS_CODE) {
  253. if (res.data && res.data.data) {
  254. let currentUserCount = res.data.data;
  255. console.log('currentUserCount', currentUserCount);
  256. this.setData({
  257. currentUserCount: currentUserCount
  258. })
  259. }
  260. }
  261. });
  262. },
  263. /**
  264. * @desc : 查询活动
  265. * @author : 周兴
  266. * @date : 2024/4/1
  267. */
  268. getActivity() {
  269. let params = {
  270. appCode: Constants.APP_CODE,
  271. activityTypeList: [Constants.kindCode.activityGrade, Constants.kindCode.activityMenu],
  272. gradeCode: app.globalData.company.gradeCode
  273. }
  274. let service = app.globalData['activityService']
  275. this.excute(service, service.selectActivityItems, params).then(res => {
  276. if (res.data.code == Constants.SUCESS_CODE) {
  277. if (res.data && res.data.data) {
  278. let activityTable = res.data.data;
  279. this.setData({
  280. activityTable: activityTable
  281. })
  282. }
  283. }
  284. });
  285. },
  286. /**
  287. * 生命周期函数--监听页面加载
  288. */
  289. onLoad(options) {
  290. this.setData({
  291. companyName: app.globalData.company.cpName,
  292. staffName: app.globalData.user.staffName,
  293. cpEndDate: app.globalData.company.endDate,
  294. webMaxNum: app.globalData.company.webMaxNum,
  295. wxMaxNum: app.globalData.company.wxMaxNum,
  296. })
  297. // 获取活动
  298. this.getActivity();
  299. // 获取当前用户授权数
  300. this.getStaffCount();
  301. },
  302. })