activity.js 32 KB

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