activity.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  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 config = require('@/config/config.js');
  13. const app = getApp()
  14. Page({
  15. mixins: [mixins],
  16. /**
  17. * 页面的初始数据
  18. */
  19. data: {
  20. imageUrl: config.image_url + '/static/img/',
  21. // 是否加载完毕
  22. loadFlag: false,
  23. // 是否显示vip
  24. showVip: false,
  25. // 升级标识
  26. upgradeFlag: false,
  27. gradeCode: null,
  28. freeFlag: false,
  29. // 企业名称
  30. companyName: null,
  31. cpManager: null,
  32. cpPhone: null,
  33. webMaxNum: null,
  34. wxMaxNum: null,
  35. cpEndDate: null,
  36. activityTable: null,
  37. vipTable: [],
  38. readFlag: false,
  39. staffCount: {
  40. maxNum: 1,
  41. webMaxNum: 0,
  42. wxMaxNum: 0
  43. },
  44. curentAdItem: null,
  45. // 选择的vip报表
  46. chooseVipFlag: false,
  47. summaryInfo: {},
  48. routeObjName: 'company',
  49. pageFlag: false,
  50. // 当前用户授权数
  51. currentUserCount: null,
  52. //按钮
  53. buttonSaveList: [
  54. { code: 'save', title: mixins.$t('buyNow'), width: '120rpx' }
  55. ],
  56. noticeInfo: Constants.noticeInfo,
  57. funcMenu: [
  58. {
  59. title: '订单开单',
  60. icon: 'btn-account-receivable.png',
  61. },
  62. {
  63. title: '销售出库',
  64. icon: 'btn-shipped.png',
  65. },
  66. {
  67. title: '销售退货',
  68. icon: 'btn-stored.png',
  69. },
  70. {
  71. title: '销售跟踪',
  72. icon: 'btn-shipped-out.png',
  73. },
  74. {
  75. title: '采购订单',
  76. icon: 'btn-account-receivable.png',
  77. },
  78. {
  79. title: '采购入库',
  80. icon: 'btn-shipped.png',
  81. },
  82. {
  83. title: '采购退货',
  84. icon: 'btn-stored.png',
  85. },
  86. {
  87. title: '以销定采',
  88. icon: 'btn-shipped-out.png',
  89. },
  90. ],
  91. funcMenuFlg: false,
  92. userEndDate: null,
  93. // 优惠劵数量获取 积分策略 积分
  94. integral: 0,
  95. viewHeight: 205,
  96. couponList: [],
  97. couponUse: {},
  98. // 策略
  99. integralTacticItem: {},
  100. },
  101. /**
  102. * @desc : 选择活动明细
  103. * @author : 周兴
  104. * @date : 2024/4/1
  105. */
  106. chooseAdItem(e) {
  107. let item = e.currentTarget.dataset.item;
  108. let summaryInfo = this.data.summaryInfo
  109. // 计算截止日期
  110. let months = item.validLong + item.extraLong
  111. let endDate = app.globalData.company.endDate
  112. // 升级需要从当天开始算
  113. if (this.data.upgradeFlag) {
  114. endDate = new Date()
  115. }
  116. endDate = new Date(endDate).addMonths(months).addDays(-1)
  117. summaryInfo.endDate = endDate.toDateStr();
  118. this.setData({
  119. curentAdItem: item,
  120. summaryInfo: summaryInfo
  121. })
  122. // 计算金额
  123. this.countSummaryAmount(item);
  124. },
  125. /**
  126. * @desc : 选择VIP报表明细
  127. * @author : 周兴
  128. * @date : 2024/4/1
  129. */
  130. chooseVipItem(e) {
  131. let item = e.currentTarget.dataset.item
  132. let index = e.currentTarget.dataset.index
  133. let vipTable = this.data.vipTable
  134. item.chooseVipFlag = !item.chooseVipFlag
  135. vipTable[index] = item
  136. this.setData({
  137. chooseVipFlag: !this.data.chooseVipFlag,
  138. vipTable,
  139. })
  140. // 计算金额
  141. this.countSummaryAmountSTD();
  142. },
  143. /**
  144. * @desc : 勾选已阅读表示
  145. * @author : 周兴
  146. * @date : 2024/5/17
  147. */
  148. handleChangeCheckbox(e) {
  149. this.setData({
  150. readFlag: e.detail
  151. })
  152. },
  153. /**
  154. * @desc : 计算金额
  155. * @author : 周兴
  156. * @date : 2024/4/1
  157. */
  158. countSummaryAmount() {
  159. let _this = this
  160. let item = this.data.curentAdItem;
  161. if (!item) return;
  162. let staffCount = this.data.staffCount;
  163. let summaryInfo = this.data.summaryInfo
  164. let amount = 0;
  165. // 先清空
  166. summaryInfo.amountInfo = '';
  167. // 共通用户
  168. if (staffCount.maxNum) {
  169. summaryInfo.amountInfo = item.stdPrice + '(打包价格)*' + staffCount.maxNum
  170. amount += item.stdPrice * staffCount.maxNum
  171. }
  172. // 手机端用户
  173. if (staffCount.wxMaxNum) {
  174. if (summaryInfo.amountInfo) {
  175. summaryInfo.amountInfo += ' + '
  176. }
  177. summaryInfo.amountInfo += item.wxPrice + '(手机端价格)*' + staffCount.wxMaxNum
  178. amount += item.wxPrice * staffCount.wxMaxNum
  179. }
  180. // 电脑端用户
  181. if (staffCount.webMaxNum) {
  182. if (summaryInfo.amountInfo) {
  183. summaryInfo.amountInfo += ' + '
  184. }
  185. summaryInfo.amountInfo += item.webPrice + '(电脑端价格)*' + staffCount.webMaxNum
  186. amount += item.webPrice * staffCount.webMaxNum
  187. }
  188. if (summaryInfo.amountInfo) {
  189. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  190. summaryInfo.amount = amount;
  191. }
  192. // 积分转成现金
  193. let integralRateVal = Number((_this.data.integral / _this.data.integralTacticItem.exchangeRate).toFixed(2))
  194. // 折扣--数据库的值不能超过10
  195. let discount = _this.data.couponUse.discount ? _this.data.couponUse.discount / 10 : 1
  196. if (_this.data.integral > Math.ceil(_this.data.integralTacticItem.exchangeRate * summaryInfo.amount)) {
  197. _this.setData({
  198. integral: Math.ceil(_this.data.integralTacticItem.exchangeRate * summaryInfo.amount)
  199. })
  200. summaryInfo.amount = 0.00
  201. } else {
  202. summaryInfo.amount = Number((summaryInfo.amount - integralRateVal) * discount.toFixed(2))
  203. }
  204. this.setData({
  205. summaryInfo: summaryInfo
  206. })
  207. // 统计两端用户数
  208. this.countStaffInfo();
  209. },
  210. /**
  211. * @desc : 获取标准版的价格显示
  212. * @author : 周兴
  213. * @date : 2024/4/1
  214. */
  215. countSummaryAmountSTD() {
  216. let _this = this
  217. let item = this.data.curentAdItem;
  218. let vipTable = this.data.vipTable
  219. let summaryInfo = this.data.summaryInfo
  220. let amount = 0;
  221. // 先清空
  222. summaryInfo.amountInfo = '';
  223. let extendDays = null;
  224. // 服务器的时间
  225. let nowDate = new Date(this.data.currentDate.toDateStr());
  226. extendDays = new Date(summaryInfo.userEndDate).dayDiff(nowDate) + 1;
  227. if (summaryInfo.wxMaxNum >= 0) {
  228. // 购买授权
  229. if (this.data.buyUser) {
  230. summaryInfo.amountInfo += item.wxPrice + '(元) '
  231. } else {
  232. summaryInfo.amountInfo += item.wxPrice + '(元) ' +
  233. ' * 1(年) * ' + summaryInfo.wxMaxNum + '(个)'
  234. }
  235. amount += item.wxPrice * summaryInfo.wxMaxNum
  236. }
  237. // vip报表
  238. if (vipTable && vipTable.length > 0) {
  239. vipTable.forEach(vipItem => {
  240. if (vipItem.chooseVipFlag) {
  241. summaryInfo.amountInfo += ' + ' + vipItem.wxPrice + '(元/' + vipItem.activityItemDescribe + ') ';
  242. summaryInfo.amountInfo = '( ' + summaryInfo.amountInfo + ' ) ';
  243. amount += vipItem.wxPrice;
  244. }
  245. })
  246. }
  247. // 购买授权
  248. if (this.data.buyUser) {
  249. summaryInfo.amountInfo += ' / 365(天) * ' + extendDays + '(天) * ' + summaryInfo.wxMaxNum + '(个)'
  250. if (summaryInfo.amountInfo) {
  251. amount = (amount / 365 * extendDays).toFixed(2);
  252. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  253. summaryInfo.amount = amount;
  254. }
  255. this.setData({
  256. userEndDate: summaryInfo.userEndDate
  257. })
  258. } else {
  259. // 续费
  260. if (summaryInfo.amountInfo) {
  261. amount = (amount).toFixed(2);
  262. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  263. summaryInfo.amount = amount;
  264. }
  265. let userEndDate = new Date(summaryInfo.userEndDate).addMonths(12).addDays(-1)
  266. this.setData({
  267. userEndDate: userEndDate.toDateStr()
  268. })
  269. }
  270. // 积分转成现金
  271. let integralRateVal = Number((_this.data.integral / _this.data.integralTacticItem.exchangeRate).toFixed(2))
  272. // 折扣--数据库的值不能超过10
  273. let discount = _this.data.couponUse.discount ? _this.data.couponUse.discount / 10 : 1
  274. if (_this.data.integral > Math.ceil(_this.data.integralTacticItem.exchangeRate * summaryInfo.amount)) {
  275. _this.setData({
  276. integral: Math.ceil(_this.data.integralTacticItem.exchangeRate * summaryInfo.amount)
  277. })
  278. summaryInfo.amount = 0.00
  279. } else {
  280. summaryInfo.amount = Number((summaryInfo.amount - integralRateVal) * discount.toFixed(2))
  281. }
  282. // 计算一授权一天的单价
  283. if (summaryInfo.userEndDate) {
  284. let price = (summaryInfo.amount / summaryInfo.wxMaxNum / extendDays).toFixed(2);
  285. summaryInfo.priceInfo = price
  286. summaryInfo.extendDays = extendDays
  287. }
  288. this.setData({
  289. summaryInfo: summaryInfo
  290. })
  291. },
  292. /**
  293. * @desc : 统计电脑端和手机端的用户数
  294. * @author : 周兴
  295. * @date : 2024/4/1
  296. */
  297. countStaffInfo() {
  298. let summaryInfo = this.data.summaryInfo;
  299. let staffCount = this.data.staffCount;
  300. if (!staffCount) {
  301. return;
  302. }
  303. let webNum = staffCount.webMaxNum + staffCount.maxNum
  304. let wxNum = staffCount.wxMaxNum + staffCount.maxNum
  305. summaryInfo.staffInfo = '可配置手机端授权' + wxNum + '个;电脑端授权' + webNum + '个(包含当前用户)'
  306. summaryInfo.webMaxNum = webNum
  307. summaryInfo.wxMaxNum = wxNum
  308. // 升级从当天算
  309. if (this.data.upgradeFlag) {
  310. summaryInfo.buyBeginDate = new Date().addDays(1).toDateStr();
  311. summaryInfo.extendDays = new Date(summaryInfo.endDate).dayDiff(new Date().addDays(1));
  312. } else {
  313. summaryInfo.buyBeginDate = new Date(this.data.cpEndDate).addDays(1).toDateStr();
  314. summaryInfo.extendDays = new Date(summaryInfo.endDate).dayDiff(new Date(this.data.cpEndDate).addDays(1));
  315. }
  316. // 计算一授权一天的单价
  317. let price = (summaryInfo.amount / (webNum + wxNum) / summaryInfo.extendDays).toFixed(2);
  318. summaryInfo.priceInfo = price
  319. this.setData({
  320. summaryInfo: summaryInfo
  321. })
  322. },
  323. /**
  324. * @desc : 修改用户数
  325. * @author : 周兴
  326. * @date : 2024/4/1
  327. */
  328. changeStaffCount(e) {
  329. let staffCount = this.data.staffCount
  330. let ds = e.currentTarget.dataset
  331. if (ds.type == 'wx') {
  332. staffCount.wxMaxNum = e.detail
  333. } else if (ds.type == 'web') {
  334. staffCount.webMaxNum = e.detail
  335. } else {
  336. staffCount.maxNum = e.detail
  337. }
  338. this.setData({
  339. staffCount: staffCount
  340. })
  341. // 计算金额
  342. this.countSummaryAmount();
  343. },
  344. /**
  345. * @desc : 保存
  346. * @author : 周兴
  347. * @date : 2024/4/1
  348. */
  349. handleSave() {
  350. let summaryInfo = this.data.summaryInfo;
  351. let currentUserCount = this.data.currentUserCount
  352. if (!currentUserCount) {
  353. return;
  354. }
  355. if (this.data.gradeCode == Constants.gradeCode.STD) {
  356. // 必须要选择一个授权
  357. if (Number(summaryInfo.wxMaxNum) <= 0 && this.data.buyUser) {
  358. util.showToast('请选择一个授权');
  359. return false
  360. }
  361. // 功能包
  362. let chooseVipFlag = false
  363. this.data.vipTable.forEach(it => {
  364. if (it.chooseVipFlag) {
  365. chooseVipFlag = true
  366. return
  367. }
  368. })
  369. if (Number(summaryInfo.wxMaxNum) <= 0 && !this.data.buyUser && !chooseVipFlag) {
  370. util.showToast('请选择一个授权或功能包');
  371. return false
  372. }
  373. // 判断数量是否超出续约授权
  374. if (currentUserCount.wxNum > summaryInfo.wxMaxNum && summaryInfo.reCountFlag
  375. && currentUserCount.wxNum > 1 && currentUserCount.wxNum - summaryInfo.wxMaxNum > 1) {
  376. let staffInfo = [{ wxMaxNum: Number(this.data.wxMaxNum), title: '当前授权', wxTitle: '手机授权', code: 'current', userTitle: '当前用户' }, { wxMaxNum: this.data.buyUser ? summaryInfo.wxMaxNum : summaryInfo.wxMaxNum + 1, title: '续费授权', wxTitle: '手机授权', code: 'renew' }]
  377. this.save({ saveFlag: false, url: '/package-basic-data/pages/activity/detail/detail?staffInfo=' + JSON.stringify(staffInfo) });
  378. } else {
  379. this.save({});
  380. }
  381. } else {
  382. // 判断数量是否超出续约授权
  383. if (currentUserCount.wxNum > summaryInfo.wxMaxNum || currentUserCount.webNum > summaryInfo.webMaxNum) {
  384. let staffInfo = [{ wxMaxNum: this.data.wxMaxNum, webMaxNum: this.data.webMaxNum, title: '当前授权', wxTitle: '手机授权', webTitle: (app.globalData.company.gradeCode == Constants.gradeCode.STD) ? '' : '电脑授权', code: 'current', userTitle: '当前用户' }, { wxMaxNum: summaryInfo.wxMaxNum, webMaxNum: summaryInfo.webMaxNum, title: '续费授权', wxTitle: '手机授权', webTitle: '电脑授权', code: 'renew' }]
  385. this.save({ saveFlag: false, url: '/package-basic-data/pages/activity/detail/detail?staffInfo=' + JSON.stringify(staffInfo) });
  386. } else {
  387. this.save({});
  388. }
  389. }
  390. },
  391. /**
  392. * @desc : 改变用户授权数
  393. * @author : 周兴
  394. * @date : 2024/4/1
  395. */
  396. changeUserSTD(e) {
  397. let summaryInfo = this.data.summaryInfo
  398. summaryInfo.wxMaxNum = e.detail
  399. this.setData({
  400. summaryInfo: summaryInfo
  401. })
  402. wx.nextTick(() => {
  403. // 计算金额
  404. this.countSummaryAmountSTD();
  405. });
  406. },
  407. /**
  408. * @desc : 校验
  409. * @author : 周兴
  410. * @date : 2024/4/1
  411. */
  412. validData() {
  413. // 专业版校验
  414. if (this.data.gradeCode == Constants.gradeCode.PRO) {
  415. // if (!this.data.readFlag) {
  416. // util.showToast('请勾选阅读须知');
  417. // return false;
  418. // }
  419. let curentAdItem = this.data.curentAdItem;
  420. if (!curentAdItem) {
  421. util.showToast('请选择活动');
  422. return false
  423. }
  424. // 必须要选择一个授权
  425. let staffCount = this.data.staffCount
  426. if (!staffCount.maxNum && !staffCount.webMaxNum && !staffCount.wxMaxNum) {
  427. util.showToast('请选择一个授权');
  428. return false
  429. }
  430. } else {
  431. let curentAdItem = this.data.curentAdItem;
  432. if (!curentAdItem) {
  433. util.showToast('请选择活动');
  434. return false
  435. }
  436. }
  437. return true;
  438. },
  439. /**
  440. * @desc : 设置保存参数
  441. * @author : 周兴
  442. * @date : 2024/4/1
  443. */
  444. setParams(params) {
  445. let summaryInfo = this.data.summaryInfo
  446. let curentAdItem = this.data.curentAdItem
  447. let cpEndDate = this.data.cpEndDate
  448. if (!summaryInfo || !cpEndDate) return;
  449. params.endDate = summaryInfo.endDate
  450. params.userEndDate = summaryInfo.userEndDate
  451. params.gradeCode = this.data.gradeCode
  452. params.cpId = app.globalData.company.cpId
  453. params.tradeNo = this.generateRandomNo();
  454. params.wxUserId = app.globalData.user.userId
  455. params.tradeAmount = summaryInfo.amount
  456. params.buyBeginDate = summaryInfo.buyBeginDate;
  457. params.buyEndDate = summaryInfo.endDate
  458. params.extendDays = summaryInfo.extendDays;
  459. if (this.data.gradeCode == Constants.gradeCode.STD) {
  460. params.buyEndDate = summaryInfo.userEndDate
  461. params.endDate = app.globalData.company.endDate
  462. params.wxMaxNum = summaryInfo.wxMaxNum
  463. if (!summaryInfo.reCountFlag && summaryInfo.wxMaxNumSocial) {
  464. params.wxMaxNum = summaryInfo.wxMaxNum + summaryInfo.wxMaxNumSocial
  465. }
  466. let funPackage = app.globalData.company.funPackage ? [...app.globalData.company.funPackage] : []
  467. params.funPackage = funPackage
  468. // 选中的功能包的数据
  469. let activityIds = []
  470. let itemIds = []
  471. this.data.vipTable.forEach(it => {
  472. if (it.chooseVipFlag) {
  473. activityIds.push(it.activityId)
  474. itemIds.push(it.itemId)
  475. }
  476. })
  477. if (activityIds.length > 0) {
  478. params.activityIds = activityIds
  479. params.activityItemIds = itemIds
  480. }
  481. // 续费的时候需要传
  482. // 购买授权
  483. if (this.data.buyUser) {
  484. params.reNew = app.globalData.company.reNew
  485. } else {
  486. let funPackages = []
  487. this.data.vipTable.forEach(it => {
  488. if (it.chooseVipFlag) {
  489. funPackages.push({
  490. activityId: it.activityId,
  491. funUuids: it.funUuids
  492. })
  493. }
  494. })
  495. let renew = {
  496. "user_end_date": this.data.userEndDate,
  497. "wx_max_num": summaryInfo.wxMaxNum + 1,
  498. "fun_package": funPackages.length > 0 ? funPackages : null,
  499. }
  500. params.reNew = renew
  501. // 续费时候保持原来的 微信人数
  502. params.wxMaxNum = summaryInfo.wxMaxNumSocial
  503. }
  504. params.webMaxNum = 0
  505. params.remarks = summaryInfo.amountInfo
  506. // 交易类型-续费
  507. params.tradeType = '交易类型-续费'
  508. } else {
  509. params.webMaxNum = summaryInfo.webMaxNum
  510. params.wxMaxNum = summaryInfo.wxMaxNum
  511. }
  512. params.buyLong = curentAdItem.activityItemName
  513. // 操作员
  514. params.staffNameFrom = app.globalData.user.staffName
  515. // 优惠券使用id 金额大于0
  516. params.couponUseId = this.data.couponUse.useId && Number(summaryInfo.amount) > 0
  517. ? this.data.couponUse.useId : null
  518. params.integral = this.data.integral
  519. return params;
  520. },
  521. /**
  522. * @desc : 保存数据
  523. * @author : 周兴
  524. * @date : 2024/5/17
  525. */
  526. saveData(params) {
  527. return this.excute(this.data.service, this.data.service.reNewCompany, this.data.params).then(res => {
  528. if (res.data.code == Constants.SUCESS_CODE && Number(this.data.summaryInfo.amount) > 0) {
  529. // 成功后跳转支付
  530. this.toPay(res.data.data);
  531. }else {
  532. // 调转主页
  533. wx.reLaunch({
  534. url: '/pages/welcome/welcome',
  535. })
  536. }
  537. })
  538. },
  539. /**
  540. * @desc : 查询当前用户授权数
  541. * @author : 周兴
  542. * @date : 2024/4/1
  543. */
  544. getStaffCount() {
  545. let service = app.globalData['commonService']
  546. this.excute(service, service.selectUserCount, {}).then(res => {
  547. if (res.data.code == Constants.SUCESS_CODE) {
  548. if (res.data && res.data.data) {
  549. let currentUserCount = res.data.data;
  550. this.setData({
  551. currentUserCount: currentUserCount,
  552. //服务器的时间
  553. currentDate: new Date(currentUserCount.currentDate)
  554. })
  555. }
  556. }
  557. this.setData({
  558. loadFlag: true
  559. })
  560. });
  561. },
  562. /**
  563. * @desc : 关闭所有的tip
  564. * @date : 2024/5/24 15:49
  565. * @author : 王英杰
  566. */
  567. closeAllTips() {
  568. this.closeTips(['tipIntegral'])
  569. },
  570. /**
  571. * @desc : 优惠劵数量获取 积分策略 积分
  572. * @author : 刘尧
  573. * @date : 2024/7/29 15:54
  574. */
  575. getCouponUse() {
  576. let _this = this
  577. this.setData({
  578. loading: true
  579. })
  580. let params = {
  581. couponStatus: Constants.couponStatus.unused,
  582. flgValid: true,
  583. cpId: app.globalData.company.cpId,
  584. }
  585. let service = app.globalData['couponUseService']
  586. this.excute(service, service.listByCondUse, params).then(res => {
  587. if (res.data && res.data.data) {
  588. // 优惠劵数量获取
  589. if (res.data.data.list && res.data.data.list.length > 0) {
  590. this.setData({
  591. couponList: res.data.data.list,
  592. couponUse: res.data.data.list[0],
  593. viewHeight: this.data.viewHeight + 45
  594. })
  595. }
  596. // 积分
  597. if (res.data.data.integral) {
  598. this.setData({
  599. integral: res.data.data.integral,
  600. viewHeight: this.data.viewHeight + 45
  601. })
  602. }
  603. // 积分策略
  604. if (res.data.data.listIntegralTactic && res.data.data.listIntegralTactic.length > 0) {
  605. this.setData({
  606. integralTacticItem: res.data.data.listIntegralTactic[0],
  607. })
  608. }
  609. }
  610. // 获取活动
  611. _this.getActivity()
  612. });
  613. },
  614. /**
  615. * @desc : 查询活动
  616. * @author : 周兴
  617. * @date : 2024/4/1
  618. */
  619. getActivity() {
  620. let params = {
  621. appCode: Constants.APP_CODE,
  622. activityStatus: Constants.kindCode.activityStatus,
  623. cpId: app.globalData.company.cpId,
  624. gradeCode: this.data.gradeCode
  625. }
  626. // 标准版
  627. if (this.data.gradeCode == Constants.gradeCode.STD) {
  628. if (this.data.buyUser) {
  629. params.activityTypeList = [Constants.kindCode.activityGrade];
  630. } else {
  631. params.activityTypeList = [Constants.kindCode.activityGrade, Constants.kindCode.activityFunc];
  632. }
  633. } else {
  634. params.activityTypeList = [Constants.kindCode.activityGrade, Constants.kindCode.activityVip];
  635. }
  636. let service = app.globalData['activityService']
  637. this.excute(service, service.selectActivityItems, params).then(res => {
  638. if (res.data.code == Constants.SUCESS_CODE) {
  639. if (res.data && res.data.data) {
  640. let activityTable = res.data.data;
  641. // 如果是标准版,需要进行截止日期的处理
  642. if (this.data.gradeCode == Constants.gradeCode.STD) {
  643. this.setData({
  644. activityTable: activityTable.filter(it => it.activityType == Constants.kindCode.activityGrade),
  645. vipTable: activityTable.filter(it => it.activityType == Constants.kindCode.activityFunc),
  646. })
  647. this.handleDataStd(activityTable);
  648. } else {
  649. this.setData({
  650. activityTable: activityTable
  651. })
  652. }
  653. }
  654. }
  655. this.setData({
  656. loading: false
  657. })
  658. });
  659. },
  660. /**
  661. * @desc : 标准版处理数据
  662. * @author : 周兴
  663. * @date : 2024/4/1
  664. */
  665. handleDataStd(activityTable) {
  666. if (activityTable && activityTable.length > 0) {
  667. let item = activityTable[0]
  668. this.setData({
  669. curentAdItem: item
  670. })
  671. let summaryInfo = this.data.summaryInfo
  672. let months = item.validLong + item.extraLong
  673. //服务器的时间
  674. let endDate = this.data.currentDate.addMonths(months).addDays(-1)
  675. let dayDiffs = null;
  676. if (summaryInfo.userEndDate) {
  677. dayDiffs = new Date(summaryInfo.userEndDate).dayDiff(this.data.currentDate)
  678. }
  679. // 如果截止日期是空,就取活动中的截止日期
  680. if (!summaryInfo.userEndDate || !dayDiffs || dayDiffs < 0) {
  681. summaryInfo.userEndDate = endDate.toDateStr();
  682. // 重新统计,到期续费或者第一次购买用户
  683. summaryInfo.reCountFlag = true;
  684. summaryInfo.wxMaxNum = summaryInfo.wxMaxNumSocial
  685. this.setData({
  686. showVip: true
  687. })
  688. } else {
  689. // 如果没有购买,需要显示
  690. if (!app.globalData.company.vip) {
  691. this.setData({
  692. showVip: true
  693. })
  694. }
  695. }
  696. summaryInfo.buyBeginDate = this.data.currentDate.toDateStr();
  697. this.setData({
  698. summaryInfo: summaryInfo
  699. })
  700. wx.nextTick(() => {
  701. // 计算金额
  702. this.countSummaryAmountSTD();
  703. });
  704. }
  705. },
  706. /**
  707. * 生命周期函数--监听页面加载
  708. */
  709. onLoad(options) {
  710. // 升级
  711. if (options && options.upgrade) {
  712. wx.setNavigationBarTitle({
  713. title: mixins.$t('updateSpecialized'),
  714. })
  715. this.setData({
  716. gradeCode: Constants.gradeCode.PRO,
  717. upgradeFlag: true
  718. })
  719. } else {
  720. // 购买授权 和续费
  721. if (options.buyUser) {
  722. wx.setNavigationBarTitle({
  723. title: mixins.$t('buyUser'),
  724. })
  725. } else {
  726. wx.setNavigationBarTitle({
  727. title: mixins.$t('reNew'),
  728. })
  729. }
  730. this.setData({
  731. gradeCode: app.globalData.company.gradeCode,
  732. buyUser: options.buyUser
  733. })
  734. }
  735. this.setData({
  736. companyName: app.globalData.company.cpName,
  737. cpManager: app.globalData.company.cpManager,
  738. cpPhone: app.globalData.company.cpPhone,
  739. cpEndDate: app.globalData.company.endDate,
  740. webMaxNum: app.globalData.company.webMaxNum,
  741. wxMaxNum: app.globalData.company.wxMaxNum,
  742. })
  743. // 如果是标准版,需要获取用户授权数(手机)
  744. let summaryInfo = {}
  745. if (app.globalData.company.gradeCode == Constants.gradeCode.STD && !options.buyUser) {
  746. summaryInfo.wxMaxNum = app.globalData.company.wxMaxNum
  747. summaryInfo.reCountFlag = true
  748. } else {
  749. summaryInfo.wxMaxNum = 1
  750. }
  751. summaryInfo.wxMaxNumSocial = this.data.wxMaxNum
  752. // 续费用户到期日期
  753. summaryInfo.userEndDate = app.globalData.company.userEndDate
  754. this.setData({
  755. summaryInfo: summaryInfo,
  756. })
  757. // 获取活动
  758. // this.getActivity();
  759. // 获取当前用户授权数
  760. this.getStaffCount();
  761. // 优惠劵数量获取 积分策略 积分
  762. this.getCouponUse()
  763. },
  764. /**
  765. * 六大功能的切换
  766. */
  767. funcClick(e) {
  768. let funcMenuFlg = !this.data.funcMenuFlg
  769. if (funcMenuFlg) {
  770. this.setData({
  771. funcMenu: [
  772. {
  773. title: '订单开单',
  774. icon: 'btn-account-receivable.png',
  775. },
  776. {
  777. title: '销售出库',
  778. icon: 'btn-shipped.png',
  779. },
  780. {
  781. title: '销售退货',
  782. icon: 'btn-stored.png',
  783. },
  784. {
  785. title: '销售跟踪',
  786. icon: 'btn-shipped-out.png',
  787. },
  788. {
  789. title: '采购订单',
  790. icon: 'btn-account-receivable.png',
  791. },
  792. {
  793. title: '采购入库',
  794. icon: 'btn-shipped.png',
  795. },
  796. {
  797. title: '采购退货',
  798. icon: 'btn-stored.png',
  799. },
  800. {
  801. title: '以销定采',
  802. icon: 'btn-shipped-out.png',
  803. },
  804. {
  805. title: '库存查询',
  806. icon: 'btn-account-receivable.png',
  807. },
  808. {
  809. title: '入库办理',
  810. icon: 'btn-shipped.png',
  811. },
  812. {
  813. title: '出库办理',
  814. icon: 'btn-stored.png',
  815. },
  816. {
  817. title: '库存盘点',
  818. icon: 'btn-shipped-out.png',
  819. },
  820. {
  821. title: '资金账户',
  822. icon: 'btn-account-receivable.png',
  823. },
  824. {
  825. title: '资金转账',
  826. icon: 'btn-shipped.png',
  827. },
  828. {
  829. title: '收款单',
  830. icon: 'btn-stored.png',
  831. },
  832. {
  833. title: '付款单',
  834. icon: 'btn-shipped-out.png',
  835. },
  836. {
  837. title: '日结对账',
  838. icon: 'btn-account-receivable.png',
  839. },
  840. {
  841. title: '资金日记账',
  842. icon: 'btn-shipped.png',
  843. },
  844. {
  845. title: '供应商往来',
  846. icon: 'btn-stored.png',
  847. },
  848. ],
  849. })
  850. } else {
  851. this.setData({
  852. funcMenu: [
  853. {
  854. title: '订单开单',
  855. icon: 'btn-account-receivable.png',
  856. },
  857. {
  858. title: '销售出库',
  859. icon: 'btn-shipped.png',
  860. },
  861. {
  862. title: '销售退货',
  863. icon: 'btn-stored.png',
  864. },
  865. {
  866. title: '销售跟踪',
  867. icon: 'btn-shipped-out.png',
  868. },
  869. {
  870. title: '采购订单',
  871. icon: 'btn-account-receivable.png',
  872. },
  873. {
  874. title: '采购入库',
  875. icon: 'btn-shipped.png',
  876. },
  877. {
  878. title: '采购退货',
  879. icon: 'btn-stored.png',
  880. },
  881. {
  882. title: '以销定采',
  883. icon: 'btn-shipped-out.png',
  884. },
  885. ],
  886. })
  887. }
  888. this.setData({
  889. funcMenuFlg
  890. })
  891. },
  892. })