activity.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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. loadFlag:false,
  21. // 是否显示vip
  22. showVip:false,
  23. // 升级标识
  24. upgradeFlag: false,
  25. gradeCode: null,
  26. freeFlag: false,
  27. // 企业名称
  28. companyName: null,
  29. cpManager: null,
  30. cpPhone: null,
  31. webMaxNum: null,
  32. wxMaxNum: null,
  33. cpEndDate: null,
  34. activityTable: null,
  35. vipTable: null,
  36. readFlag: false,
  37. staffCount: {
  38. maxNum: 1,
  39. webMaxNum: 0,
  40. wxMaxNum: 0
  41. },
  42. curentAdItem: null,
  43. // 选择的vip报表
  44. chooseVipFlag:false,
  45. summaryInfo: {},
  46. routeObjName: 'company',
  47. pageFlag: false,
  48. // 当前用户授权数
  49. currentUserCount: null,
  50. //按钮
  51. buttonSaveList: [
  52. { code: 'save', title: mixins.$t('save'), width: '120rpx' }
  53. ],
  54. noticeInfo: Constants.noticeInfo
  55. },
  56. /**
  57. * @desc : 选择活动明细
  58. * @author : 周兴
  59. * @date : 2024/4/1
  60. */
  61. chooseAdItem(e) {
  62. let item = e.currentTarget.dataset.item;
  63. let summaryInfo = this.data.summaryInfo
  64. // 计算截止日期
  65. let months = item.validLong + item.extraLong
  66. let endDate = app.globalData.company.endDate
  67. // 升级需要从当天开始算
  68. if (this.data.upgradeFlag) {
  69. endDate = new Date()
  70. }
  71. endDate = new Date(endDate).addMonths(months).addDays(-1)
  72. summaryInfo.endDate = endDate.toDateStr();
  73. this.setData({
  74. curentAdItem: item,
  75. summaryInfo: summaryInfo
  76. })
  77. // 计算金额
  78. this.countSummaryAmount(item);
  79. },
  80. /**
  81. * @desc : 选择VIP报表明细
  82. * @author : 周兴
  83. * @date : 2024/4/1
  84. */
  85. chooseVipItem(e) {
  86. let item = e.currentTarget.dataset.item;
  87. // let summaryInfo = this.data.summaryInfo
  88. // // 计算截止日期
  89. // let months = item.validLong + item.extraLong
  90. // let endDate = app.globalData.company.endDate
  91. // // 升级需要从当天开始算
  92. // if (this.data.upgradeFlag) {
  93. // endDate = new Date()
  94. // }
  95. // endDate = new Date(endDate).addMonths(months).addDays(-1)
  96. // summaryInfo.endDate = endDate.toDateStr();
  97. this.setData({
  98. chooseVipFlag: !this.data.chooseVipFlag,
  99. // summaryInfo: summaryInfo
  100. })
  101. // 计算金额
  102. this.countSummaryAmountSTD();
  103. },
  104. /**
  105. * @desc : 勾选已阅读表示
  106. * @author : 周兴
  107. * @date : 2024/5/17
  108. */
  109. handleChangeCheckbox(e) {
  110. console.log('ee', e);
  111. this.setData({
  112. readFlag: e.detail
  113. })
  114. },
  115. /**
  116. * @desc : 计算金额
  117. * @author : 周兴
  118. * @date : 2024/4/1
  119. */
  120. countSummaryAmount() {
  121. let item = this.data.curentAdItem;
  122. if(!item)return;
  123. let staffCount = this.data.staffCount;
  124. let summaryInfo = this.data.summaryInfo
  125. let amount = 0;
  126. // 先清空
  127. summaryInfo.amountInfo = '';
  128. // 共通用户
  129. if (staffCount.maxNum) {
  130. summaryInfo.amountInfo = item.stdPrice + '(打包价格)*' + staffCount.maxNum
  131. amount += item.stdPrice * staffCount.maxNum
  132. }
  133. // 手机端用户
  134. if (staffCount.wxMaxNum) {
  135. if (summaryInfo.amountInfo) {
  136. summaryInfo.amountInfo += ' + '
  137. }
  138. summaryInfo.amountInfo += item.wxPrice + '(手机端价格)*' + staffCount.wxMaxNum
  139. amount += item.wxPrice * staffCount.wxMaxNum
  140. }
  141. // 电脑端用户
  142. if (staffCount.webMaxNum) {
  143. if (summaryInfo.amountInfo) {
  144. summaryInfo.amountInfo += ' + '
  145. }
  146. summaryInfo.amountInfo += item.webPrice + '(电脑端价格)*' + staffCount.webMaxNum
  147. amount += item.webPrice * staffCount.webMaxNum
  148. }
  149. if (summaryInfo.amountInfo) {
  150. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  151. summaryInfo.amount = amount;
  152. }
  153. this.setData({
  154. summaryInfo: summaryInfo
  155. })
  156. // 统计两端用户数
  157. this.countStaffInfo();
  158. },
  159. /**
  160. * @desc : 获取标准版的价格显示
  161. * @author : 周兴
  162. * @date : 2024/4/1
  163. */
  164. countSummaryAmountSTD() {
  165. let item = this.data.curentAdItem;
  166. let vipTable = this.data.vipTable
  167. let summaryInfo = this.data.summaryInfo
  168. let amount = 0;
  169. // 先清空
  170. summaryInfo.amountInfo = '';
  171. let extendDays = null;
  172. let nowDate = new Date(new Date().toDateStr());
  173. if (summaryInfo.reCountFlag) {
  174. // 手机端用户
  175. if (summaryInfo.wxMaxNum) {
  176. summaryInfo.amountInfo += item.wxPrice + '(元) * ' + summaryInfo.wxMaxNum + '(个) '
  177. amount += item.wxPrice * summaryInfo.wxMaxNum
  178. }
  179. // vip报表
  180. if(this.data.chooseVipFlag && vipTable && vipTable.length > 0){
  181. let vipItem = vipTable[0]
  182. summaryInfo.amountInfo += + ' + ' +vipItem.wxPrice + '(元/VIP) ';
  183. amount += vipItem.wxPrice;
  184. }
  185. if (summaryInfo.amountInfo) {
  186. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  187. summaryInfo.amount = amount;
  188. }
  189. extendDays = new Date(summaryInfo.userEndDate).dayDiff(nowDate) + 1;
  190. } else {
  191. extendDays = new Date(summaryInfo.userEndDate).dayDiff(nowDate) + 1;
  192. if (summaryInfo.wxMaxNum) {
  193. summaryInfo.amountInfo += item.wxPrice + '(元) '
  194. amount += item.wxPrice * summaryInfo.wxMaxNum
  195. }
  196. // vip报表
  197. if(this.data.chooseVipFlag && vipTable && vipTable.length > 0){
  198. let vipItem = vipTable[0]
  199. console.log('vipItem.wxPrice',vipItem.wxPrice);
  200. summaryInfo.amountInfo += ' + ' + vipItem.wxPrice + '(元/VIP) ';
  201. summaryInfo.amountInfo = '( ' + summaryInfo.amountInfo + ' ) ';
  202. amount += vipItem.wxPrice;
  203. }
  204. summaryInfo.amountInfo += ' / 365(天) * ' + extendDays + '(天) * ' + summaryInfo.wxMaxNum + '(个)'
  205. if (summaryInfo.amountInfo) {
  206. amount = (amount / 365 * extendDays) .toFixed(2);
  207. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  208. summaryInfo.amount = amount;
  209. }
  210. }
  211. // 计算一授权一天的单价
  212. if (summaryInfo.userEndDate) {
  213. let price = (summaryInfo.amount / summaryInfo.wxMaxNum / extendDays).toFixed(2);
  214. summaryInfo.priceInfo = price
  215. summaryInfo.extendDays = extendDays
  216. }
  217. this.setData({
  218. summaryInfo: summaryInfo
  219. })
  220. },
  221. /**
  222. * @desc : 统计电脑端和手机端的用户数
  223. * @author : 周兴
  224. * @date : 2024/4/1
  225. */
  226. countStaffInfo() {
  227. let summaryInfo = this.data.summaryInfo;
  228. let staffCount = this.data.staffCount;
  229. if (!staffCount) {
  230. return;
  231. }
  232. let webNum = staffCount.webMaxNum + staffCount.maxNum
  233. let wxNum = staffCount.wxMaxNum + staffCount.maxNum
  234. summaryInfo.staffInfo = '可配置手机端授权' + wxNum + '个;电脑端授权' + webNum + '个(包含当前用户)'
  235. summaryInfo.webMaxNum = webNum
  236. summaryInfo.wxMaxNum = wxNum
  237. // 升级从当天算
  238. if (this.data.upgradeFlag) {
  239. summaryInfo.buyBeginDate = new Date().addDays(1).toDateStr();
  240. summaryInfo.extendDays = new Date(summaryInfo.endDate).dayDiff(new Date().addDays(1));
  241. } else {
  242. summaryInfo.buyBeginDate = new Date(this.data.cpEndDate).addDays(1).toDateStr();
  243. summaryInfo.extendDays = new Date(summaryInfo.endDate).dayDiff(new Date(this.data.cpEndDate).addDays(1));
  244. }
  245. // 计算一授权一天的单价
  246. let price = (summaryInfo.amount / (webNum + wxNum) / summaryInfo.extendDays).toFixed(2);
  247. summaryInfo.priceInfo = price
  248. this.setData({
  249. summaryInfo: summaryInfo
  250. })
  251. },
  252. /**
  253. * @desc : 修改用户数
  254. * @author : 周兴
  255. * @date : 2024/4/1
  256. */
  257. changeStaffCount(e) {
  258. let staffCount = this.data.staffCount
  259. let ds = e.currentTarget.dataset
  260. if (ds.type == 'wx') {
  261. staffCount.wxMaxNum = e.detail
  262. } else if (ds.type == 'web') {
  263. staffCount.webMaxNum = e.detail
  264. } else {
  265. staffCount.maxNum = e.detail
  266. }
  267. this.setData({
  268. staffCount: staffCount
  269. })
  270. // 计算金额
  271. this.countSummaryAmount();
  272. },
  273. /**
  274. * @desc : 保存
  275. * @author : 周兴
  276. * @date : 2024/4/1
  277. */
  278. handleSave() {
  279. let summaryInfo = this.data.summaryInfo;
  280. let currentUserCount = this.data.currentUserCount
  281. if (!currentUserCount) {
  282. return;
  283. }
  284. if (this.data.gradeCode == Constants.gradeCode.STD) {
  285. // 判断数量是否超出续约授权
  286. if (currentUserCount.wxNum > summaryInfo.wxMaxNum && summaryInfo.reCountFlag) {
  287. let staffInfo = [{ wxMaxNum: this.data.wxMaxNum, title: '当前授权', wxTitle: '手机授权', code: 'current', userTitle: '当前用户' }, { wxMaxNum: summaryInfo.wxMaxNum, title: '续费授权', wxTitle: '手机授权', code: 'renew' }]
  288. this.save({ saveFlag: false, url: '/package-basic-data/pages/activity/detail/detail?staffInfo=' + JSON.stringify(staffInfo) });
  289. } else {
  290. this.save({});
  291. }
  292. } else {
  293. // 判断数量是否超出续约授权
  294. if (currentUserCount.wxNum > summaryInfo.wxMaxNum || currentUserCount.webNum > summaryInfo.webMaxNum) {
  295. 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' }]
  296. this.save({ saveFlag: false, url: '/package-basic-data/pages/activity/detail/detail?staffInfo=' + JSON.stringify(staffInfo) });
  297. } else {
  298. this.save({});
  299. }
  300. }
  301. },
  302. /**
  303. * @desc : 改变用户授权数
  304. * @author : 周兴
  305. * @date : 2024/4/1
  306. */
  307. changeUserSTD(e) {
  308. let summaryInfo = this.data.summaryInfo
  309. summaryInfo.wxMaxNum = e.detail
  310. this.setData({
  311. summaryInfo: summaryInfo
  312. })
  313. // 计算金额
  314. this.countSummaryAmountSTD();
  315. },
  316. /**
  317. * @desc : 校验
  318. * @author : 周兴
  319. * @date : 2024/4/1
  320. */
  321. validData() {
  322. // 专业版校验
  323. if (this.data.gradeCode == Constants.gradeCode.PRO) {
  324. if (!this.data.readFlag) {
  325. util.showToast('请勾选阅读须知');
  326. return false;
  327. }
  328. let curentAdItem = this.data.curentAdItem;
  329. if (!curentAdItem) {
  330. util.showToast('请选择活动');
  331. return false
  332. }
  333. // 必须要选择一个授权
  334. let staffCount = this.data.staffCount
  335. if (!staffCount.maxNum && !staffCount.webMaxNum && !staffCount.wxMaxNum) {
  336. util.showToast('请选择一个授权');
  337. return false
  338. }
  339. } else {
  340. let curentAdItem = this.data.curentAdItem;
  341. if (!curentAdItem) {
  342. util.showToast('请选择活动');
  343. return false
  344. }
  345. }
  346. return true;
  347. },
  348. /**
  349. * @desc : 设置保存参数
  350. * @author : 周兴
  351. * @date : 2024/4/1
  352. */
  353. setParams(params) {
  354. let summaryInfo = this.data.summaryInfo
  355. let curentAdItem = this.data.curentAdItem
  356. let cpEndDate = this.data.cpEndDate
  357. console.log('summaryInfo', summaryInfo);
  358. if (!summaryInfo || !cpEndDate) return;
  359. params.endDate = summaryInfo.endDate
  360. params.userEndDate = summaryInfo.userEndDate
  361. params.gradeCode = this.data.gradeCode
  362. params.cpId = app.globalData.company.cpId
  363. params.tradeNo = this.generateRandomNo();
  364. params.wxUserId = app.globalData.user.userId
  365. params.tradeAmount = summaryInfo.amount
  366. params.buyBeginDate = summaryInfo.buyBeginDate;
  367. params.buyEndDate = summaryInfo.endDate
  368. params.extendDays = summaryInfo.extendDays;
  369. if (this.data.gradeCode == Constants.gradeCode.STD) {
  370. params.buyEndDate = summaryInfo.userEndDate
  371. params.endDate = app.globalData.company.endDate
  372. params.wxMaxNum = summaryInfo.wxMaxNum
  373. if(this.data.showVip && this.data.chooseVipFlag){
  374. params.vip = true;
  375. }else if(!this.data.showVip && app.globalData.company.vip){
  376. params.vip = true;
  377. }
  378. if(this.data.chooseVipFlag){
  379. params.vip = true;
  380. }
  381. if (!summaryInfo.reCountFlag && summaryInfo.wxMaxNumSocial) {
  382. params.wxMaxNum = summaryInfo.wxMaxNum + summaryInfo.wxMaxNumSocial
  383. }
  384. } else {
  385. params.webMaxNum = summaryInfo.webMaxNum
  386. params.wxMaxNum = summaryInfo.wxMaxNum
  387. }
  388. params.buyLong = curentAdItem.activityItemName
  389. return params;
  390. },
  391. /**
  392. * @desc : 保存数据
  393. * @author : 周兴
  394. * @date : 2024/5/17
  395. */
  396. saveData(params) {
  397. return this.excute(this.data.service, this.data.service.reNewCompany, this.data.params).then(res => {
  398. if (res.data.code == Constants.SUCESS_CODE) {
  399. // 成功后跳转支付
  400. this.toPay(res.data.data);
  401. }
  402. })
  403. },
  404. /**
  405. * @desc : 查询当前用户授权数
  406. * @author : 周兴
  407. * @date : 2024/4/1
  408. */
  409. getStaffCount() {
  410. let service = app.globalData['commonService']
  411. this.excute(service, service.selectUserCount, {}).then(res => {
  412. if (res.data.code == Constants.SUCESS_CODE) {
  413. if (res.data && res.data.data) {
  414. let currentUserCount = res.data.data;
  415. console.log('currentUserCount', currentUserCount);
  416. this.setData({
  417. currentUserCount: currentUserCount
  418. })
  419. }
  420. }
  421. this.setData({
  422. loadFlag:true
  423. })
  424. });
  425. },
  426. /**
  427. * @desc : 查询活动
  428. * @author : 周兴
  429. * @date : 2024/4/1
  430. */
  431. getActivity() {
  432. let params = {
  433. appCode: Constants.APP_CODE,
  434. gradeCode: this.data.gradeCode
  435. }
  436. // 标准版
  437. if (this.data.gradeCode == Constants.gradeCode.STD) {
  438. params.activityTypeList = [Constants.kindCode.activityGrade, Constants.kindCode.activityVip];
  439. } else {
  440. params.activityTypeList = [Constants.kindCode.activityGrade];
  441. }
  442. let service = app.globalData['activityService']
  443. this.excute(service, service.selectActivityItems, params).then(res => {
  444. if (res.data.code == Constants.SUCESS_CODE) {
  445. if (res.data && res.data.data) {
  446. let activityTable = res.data.data;
  447. // 如果是标准版,需要进行截止日期的处理
  448. if (this.data.gradeCode == Constants.gradeCode.STD) {
  449. this.setData({
  450. activityTable:activityTable.filter(it=>it.activityType == Constants.kindCode.activityGrade),
  451. vipTable:activityTable.filter(it=>it.activityType == Constants.kindCode.activityVip),
  452. })
  453. this.handleDataStd(activityTable);
  454. }else{
  455. this.setData({
  456. activityTable: activityTable
  457. })
  458. }
  459. }
  460. }
  461. });
  462. },
  463. /**
  464. * @desc : 标准版处理数据
  465. * @author : 周兴
  466. * @date : 2024/4/1
  467. */
  468. handleDataStd(activityTable) {
  469. if (activityTable && activityTable.length > 0) {
  470. let item = activityTable[0]
  471. this.setData({
  472. curentAdItem: item
  473. })
  474. let summaryInfo = this.data.summaryInfo
  475. let months = item.validLong + item.extraLong
  476. let endDate = new Date().addMonths(months).addDays(-1)
  477. let dayDiffs = null;
  478. if (summaryInfo.userEndDate) {
  479. dayDiffs = new Date(summaryInfo.userEndDate).dayDiff(new Date(new Date().toDateStr()))
  480. }
  481. // 如果截止日期是空,就取活动中的截止日期
  482. if (!summaryInfo.userEndDate || !dayDiffs || dayDiffs < 0) {
  483. summaryInfo.userEndDate = endDate.toDateStr();
  484. // 重新统计,到期续费或者第一次购买用户
  485. summaryInfo.reCountFlag = true;
  486. summaryInfo.wxMaxNum = summaryInfo.wxMaxNumSocial
  487. this.setData({
  488. showVip:true
  489. })
  490. }else{
  491. // 如果没有购买,需要显示
  492. if(!app.globalData.company.vip){
  493. this.setData({
  494. showVip:true
  495. })
  496. }
  497. }
  498. summaryInfo.buyBeginDate = new Date().toDateStr();
  499. console.log('summaryInfo', summaryInfo.userEndDate, endDate, months);
  500. this.setData({
  501. summaryInfo: summaryInfo
  502. })
  503. // 计算金额
  504. this.countSummaryAmountSTD();
  505. }
  506. },
  507. /**
  508. * 生命周期函数--监听页面加载
  509. */
  510. onLoad(options) {
  511. console.log('options', options);
  512. // 升级
  513. if (options && options.upgrade) {
  514. wx.setNavigationBarTitle({
  515. title: mixins.$t('updateSpecialized'),
  516. })
  517. this.setData({
  518. gradeCode: Constants.gradeCode.PRO,
  519. upgradeFlag: true
  520. })
  521. } else {
  522. wx.setNavigationBarTitle({
  523. title: mixins.$t('reNew'),
  524. })
  525. this.setData({
  526. gradeCode: app.globalData.company.gradeCode
  527. })
  528. }
  529. this.setData({
  530. companyName: app.globalData.company.cpName,
  531. cpManager: app.globalData.company.cpManager,
  532. cpPhone: app.globalData.company.cpPhone,
  533. cpEndDate: app.globalData.company.endDate,
  534. webMaxNum: app.globalData.company.webMaxNum,
  535. wxMaxNum: app.globalData.company.wxMaxNum,
  536. })
  537. // 如果是标准版,需要获取用户授权数(手机)
  538. let summaryInfo = {}
  539. summaryInfo.wxMaxNum = 1
  540. summaryInfo.wxMaxNumSocial = this.data.wxMaxNum
  541. // 续费用户到期日期
  542. summaryInfo.userEndDate = app.globalData.company.userEndDate
  543. this.setData({
  544. summaryInfo: summaryInfo
  545. })
  546. // 获取活动
  547. this.getActivity();
  548. // 获取当前用户授权数
  549. this.getStaffCount();
  550. },
  551. })