25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

829 satır
20 KiB

  1. const config = require('../../config/config.js')
  2. const Http = require('../../utils/http.js')
  3. const HttpBasics = require('../../utils/HttpBasics.js')
  4. const util = require('../../utils/util.js')
  5. const changeNum = require('../../utils/changeNum.js')
  6. import * as echarts from '../../ec-canvas/echarts';
  7. var app = getApp()
  8. function setOption(chart, xdata, ydata) {
  9. const option = {
  10. title: {
  11. padding: [10, 0, 0, 20],
  12. textStyle: {
  13. fontSize: 14,
  14. color: '#FF6A6A'
  15. },
  16. },
  17. backgroundColor: "#fff",
  18. color: ["#006EFF", "#67E0E3", "#9FE6B8"],
  19. animation: true,
  20. grid: {
  21. top: '3%',
  22. left: "5%",
  23. right: "7%",
  24. bottom: "4%",
  25. containLabel: true,
  26. },
  27. xAxis: {
  28. type: 'category',
  29. boundaryGap: false,
  30. data: xdata,
  31. splitLine: {
  32. show: false
  33. }, //去除网格线
  34. axisLine: {
  35. show: false
  36. },
  37. axisTick: {
  38. show: false
  39. }
  40. },
  41. yAxis: [{
  42. splitLine: {
  43. lineStyle: {
  44. type: 'none'
  45. }
  46. },
  47. axisLine: {
  48. show: false
  49. },
  50. axisTick: {
  51. show: false
  52. },
  53. axisLabel: {
  54. rotate: 40,
  55. formatter: function (a, b) {
  56. return a
  57. }
  58. },
  59. type: 'value',
  60. }],
  61. series: [{
  62. type: 'line',
  63. data: ydata,
  64. smooth: true, //这句就是让曲线变平滑的
  65. lineStyle: {
  66. normal: {
  67. color: '#33cdff',
  68. }
  69. },
  70. areaStyle: {
  71. normal: {
  72. color: new echarts.graphic.LinearGradient(
  73. 0, 0, 0, 1, [{
  74. offset: 0,
  75. color: '#FFF'
  76. }, {
  77. offset: 1,
  78. color: '#52A0FD'
  79. }]
  80. )
  81. }
  82. },
  83. }]
  84. };
  85. chart.setOption(option)
  86. console.log(chart)
  87. }
  88. /**
  89. * 交易记录
  90. */
  91. function getBarOption(x, y) {
  92. return {
  93. color: ['#FF6A6A'],
  94. fontSize: "14rpx",
  95. grid: {
  96. top: '3%',
  97. left: "5%",
  98. right: "7%",
  99. bottom: "4%",
  100. containLabel: true,
  101. },
  102. xAxis: {
  103. axisLine: {
  104. show: false
  105. },
  106. axisTick: {
  107. show: false
  108. },
  109. type: 'category',
  110. boundaryGap: false,
  111. data: x
  112. },
  113. yAxis: {
  114. axisLine: {
  115. show: false
  116. },
  117. axisTick: {
  118. show: false
  119. },
  120. type: 'value',
  121. splitLine: {
  122. lineStyle: {
  123. type: 'none'
  124. }
  125. },
  126. axisLabel: {
  127. rotate: 40,
  128. }
  129. },
  130. series: [{
  131. data: y,
  132. type: 'line',
  133. smooth: true,
  134. lineStyle: {
  135. normal: {
  136. color: '#FF6A6A',
  137. }
  138. },
  139. areaStyle: {}
  140. }]
  141. };
  142. };
  143. /**
  144. * 核销记录
  145. */
  146. function getScatterOption(x, y) {
  147. return {
  148. color: '#FFCE00',
  149. fontSize: "14rpx",
  150. grid: {
  151. top: '3%',
  152. left: "5%",
  153. right: "7%",
  154. bottom: "4%",
  155. containLabel: true,
  156. },
  157. xAxis: {
  158. axisLine: {
  159. show: false
  160. },
  161. axisTick: {
  162. show: false
  163. },
  164. type: 'category',
  165. boundaryGap: false,
  166. data: x
  167. },
  168. yAxis: {
  169. axisLine: {
  170. show: false
  171. },
  172. axisTick: {
  173. show: false
  174. },
  175. type: 'value',
  176. splitLine: {
  177. lineStyle: {
  178. type: 'none'
  179. }
  180. },
  181. axisLabel: {
  182. rotate: 40,
  183. }
  184. },
  185. series: [{
  186. data: y,
  187. type: 'line',
  188. smooth: true,
  189. areaStyle: {}
  190. }]
  191. };
  192. };
  193. /**
  194. * 获取交易记录
  195. */
  196. function getTabletListOrder() {
  197. let newArr = {
  198. xList: [],
  199. amountList: []
  200. }
  201. return new Promise((resolve, reject) => {
  202. Http.getRequest(config.api.dateAmountRecordListOrder, app.globalData.token, '', {}, (res) => {
  203. // 日期
  204. res.data && res.data.map(file => {
  205. newArr.xList.push(file.mouthAndDate)
  206. newArr.amountList.push(file.amountStr)
  207. })
  208. resolve(newArr);
  209. })
  210. })
  211. };
  212. /**
  213. * 获取核销记录
  214. */
  215. function getTabletListVerify() {
  216. let newArr = {
  217. xList: [],
  218. amountList: []
  219. }
  220. return new Promise((resolve, reject) => {
  221. Http.getRequest(config.api.dateAmountRecordListVerified, app.globalData.token, '', {}, (res) => {
  222. // 日期
  223. res.data && res.data.map(file => {
  224. newArr.xList.push(file.mouthAndDate)
  225. newArr.amountList.push(file.amountStr)
  226. })
  227. resolve(newArr)
  228. })
  229. })
  230. };
  231. Page({
  232. data: {
  233. isOpen: false,
  234. token: '',
  235. currentIndex: 0,
  236. userInfo: {},
  237. recordMoney: 0,
  238. posMoney: 0,
  239. recordData: [],
  240. userInfoLoadIf: false,
  241. ec: {
  242. lazyLoad: true
  243. },
  244. classIfyList: [{
  245. text: '收银台',
  246. icon: 'iconfont icon-shouyintai1',
  247. id: 3
  248. },
  249. {
  250. text: '会员核销',
  251. icon: 'iconfont icon-hexiao',
  252. id: 0
  253. },
  254. {
  255. text: '消费卡收款',
  256. icon: 'iconfont icon-shouye1',
  257. id: 1
  258. },
  259. {
  260. text: '当日解单',
  261. icon: 'iconfont icon-shoufukuan',
  262. id: 2
  263. },
  264. {
  265. text: '会员积分',
  266. icon: 'iconfont icon-jifen',
  267. id: 4
  268. },
  269. {
  270. text: '会员赠券',
  271. icon: 'iconfont icon-quan',
  272. id: 5
  273. },
  274. {
  275. text: '营销结算',
  276. icon: 'iconfont icon-jiesuan',
  277. id: 6
  278. },
  279. {
  280. text: '商户建券',
  281. icon: 'iconfont icon-lingquanzhongxin',
  282. id: 7
  283. },
  284. {
  285. text: '商品配送',
  286. icon: 'iconfont icon-wuliu',
  287. id: 8
  288. },
  289. {
  290. text: '活动发奖',
  291. icon: 'iconfont icon-lingquanzhongxin',
  292. id: 9
  293. },
  294. {
  295. text: '军团订单',
  296. icon: 'iconfont icon-quan',
  297. id: 10
  298. }
  299. ],
  300. amountMoney: '',
  301. djZmoney: '',
  302. writeOffMoney: '',
  303. getFullYear: new Date().getFullYear(),
  304. getMonth: new Date().getMonth() + 1,
  305. getDate: new Date().getDate(),
  306. dateTime: '',
  307. show: null,
  308. billList: [],
  309. ifShowChart: null,
  310. ifShowChart1: null,
  311. ifShowChart2: null,
  312. ifShowChart3: null,
  313. ecBar: {
  314. lazyLoad: true
  315. },
  316. ecScatter: {
  317. lazyLoad: true
  318. },
  319. djArr: [],
  320. djMoney: [],
  321. count: ''
  322. },
  323. async toggle() {
  324. this.setData({
  325. isOpen: !this.data.isOpen,
  326. })
  327. },
  328. //获取商户信息
  329. getUserInfo() {
  330. return new Promise((resolve, reject) => {
  331. Http.getRequest(config.api.userDetail, app.globalData.token, '', {}, (res) => {
  332. resolve(res.data);
  333. })
  334. })
  335. },
  336. //今日交易额
  337. getUnverifiedAmountOnDate() {
  338. let {
  339. getFullYear,
  340. getMonth,
  341. getDate,
  342. amountMoney,
  343. writeOffMoney
  344. } = this.data
  345. let dateTimer = getFullYear + '-' + getMonth + '-' + getDate
  346. Http.getRequest(config.api.getUnverifiedAmountOnDate, app.globalData.token, '', {
  347. date: dateTimer
  348. }, (res) => {
  349. console.log(res)
  350. this.setData({
  351. amountMoney: res.data.amount,
  352. count: res.data.orderCount,
  353. })
  354. })
  355. },
  356. //今日核销额
  357. getVerifiedAmountOnDate() {
  358. let {
  359. getFullYear,
  360. getMonth,
  361. getDate
  362. } = this.data
  363. let dateTimer = getFullYear + '-' + getMonth + '-' + getDate
  364. Http.getRequest(config.api.getVerifiedAmountOnDate, app.globalData.token, '', {
  365. date: dateTimer
  366. }, (res) => {
  367. this.setData({
  368. writeOffMoney: res.data.amount
  369. })
  370. })
  371. },
  372. onPullDownRefresh: function () {
  373. let that = this;
  374. that.getUnverifiedAmountOnDate()
  375. that.getVerifiedAmountOnDate();
  376. // that.getpaybill();
  377. if (that.oneComponent) {
  378. that.getrecordData();
  379. }
  380. if (that.posComponent) {
  381. that.getPosData()
  382. }
  383. if (that.jiaoyiComponent) {
  384. that.getTabletListOrder();
  385. }
  386. if (that.hexiaoComponent) {
  387. that.getTabletListVerify();
  388. }
  389. wx.hideNavigationBarLoading();
  390. wx.stopPullDownRefresh();
  391. },
  392. onLoad: function (options) {
  393. HttpBasics.get({
  394. url: config.api.getAppMouldType
  395. }).then(res => {
  396. app.globalData.mouldType = res.data.mouldType
  397. })
  398. var that = this;
  399. this.checkuserstatus()
  400. },
  401. onReady() {
  402. this.posComponent = this.selectComponent('#mychart-pos');
  403. this.oneComponent = this.selectComponent('#mychart-pament');
  404. this.jiaoyiComponent = this.selectComponent('#mychart-jiaoyi');
  405. this.hexiaoComponent = this.selectComponent('#mychart-hexiao');
  406. this.getrecordData();
  407. this.getTabletListOrder();
  408. this.getTabletListVerify();
  409. this.getUserInfo().then(res => {
  410. this.setData({
  411. userInfo: res,
  412. userInfoLoadIf: true
  413. })
  414. app.globalData.merchant = res;
  415. wx.setNavigationBarTitle({
  416. title: res.mall_name + "(" + res.merchant_name + ")"
  417. })
  418. wx.setStorageSync("linkPhone", res.merchant.linkPhone);
  419. this.getPosData()
  420. })
  421. app.globalData.userInfo = this.getUserInfo;
  422. },
  423. /**
  424. * gotolook
  425. */
  426. gotobill: function (e) {
  427. console.log(e)
  428. let owe = e.currentTarget.dataset.data.owe;
  429. let status = e.currentTarget.dataset.data.status;
  430. let receivedate = e.currentTarget.dataset.data.receiveDate;
  431. let starttime = e.currentTarget.dataset.data.starttime;
  432. let endtime = e.currentTarget.dataset.data.endtime;
  433. let id = e.currentTarget.dataset.data.id;
  434. var transactionId = e.currentTarget.dataset.data.transactionId;
  435. var priceDetail = e.currentTarget.dataset.data.priceDetail;
  436. var freeze = e.currentTarget.dataset.data.freeze;
  437. let pay = e.currentTarget.dataset.data.pay ? e.currentTarget.dataset.data.pay : 0;
  438. let latePayPrice = e.currentTarget.dataset.data.latePayPrice ? e.currentTarget.dataset.data.latePayPrice : 0;
  439. let serviceChargePay = e.currentTarget.dataset.data.serviceChargePay ? e.currentTarget.dataset.data.serviceChargePay : 0;
  440. if (starttime && endtime) {
  441. var end = starttime + "至" + endtime;
  442. } else {
  443. var end = "";
  444. }
  445. if (transactionId) {
  446. var tradeTime = e.currentTarget.dataset.data.tradeTime;
  447. } else {
  448. var tradeTime = e.currentTarget.dataset.data.payDate;
  449. }
  450. console.log(e.currentTarget.dataset.data, tradeTime, 6666666)
  451. var billTypeValue = e.currentTarget.dataset.data.billTypeValue;
  452. let receivePay = e.currentTarget.dataset.data.receivePay;
  453. wx.navigateTo({
  454. url: `/pages/bill/billdetail/index?owe=${owe}&receivedate=${receivedate}&status=${status}&end=${end}&id=${id}&tradeTime=${tradeTime}&transactionId=${transactionId}&priceDetail=${priceDetail}&billTypeValue=${billTypeValue}&receivePay=${receivePay}&freeze=${freeze}&pay=${pay}&latePayPrice=${latePayPrice}&serviceChargePay=${serviceChargePay}`,
  455. })
  456. },
  457. /**
  458. * 核销记录
  459. */
  460. hexiaoInit: function (heXiaox, heXiaoYiy) {
  461. this.hexiaoComponent.init((canvas, width, height) => {
  462. const barChart = echarts.init(canvas, null, {
  463. width: width,
  464. height: height
  465. });
  466. canvas.setChart(barChart);
  467. barChart.setOption(getScatterOption(heXiaox, heXiaoYiy));
  468. return barChart;
  469. });
  470. },
  471. /**
  472. * 交易记录
  473. */
  474. jiaoyiInit: function (jiaoYix, jiaoYiy) {
  475. this.jiaoyiComponent.init((canvas, width, height) => {
  476. const barChart = echarts.init(canvas, null, {
  477. width: width,
  478. height: height
  479. });
  480. canvas.setChart(barChart);
  481. barChart.setOption(getBarOption(jiaoYix, jiaoYiy));
  482. return barChart;
  483. });
  484. },
  485. init_one: function (xdata, ydata) { //初始化第一个图表
  486. console.log(this.oneComponent, xdata, ydata)
  487. this.oneComponent.init((canvas, width, height) => {
  488. const chart = echarts.init(canvas, null, {
  489. width: width,
  490. height: height
  491. });
  492. console.log(chart, xdata, ydata)
  493. setOption(chart, xdata, ydata)
  494. this.chart = chart;
  495. return chart;
  496. });
  497. },
  498. init_pos: function (xdata, ydata) { //初始化第一个图表
  499. console.log(this.posComponent, xdata, ydata)
  500. this.posComponent.init((canvas, width, height) => {
  501. const chart = echarts.init(canvas, null, {
  502. width: width,
  503. height: height
  504. });
  505. console.log(chart, xdata, ydata)
  506. setOption(chart, xdata, ydata)
  507. this.chart = chart;
  508. return chart;
  509. });
  510. },
  511. toWriteoff(e) {
  512. console.log(e)
  513. let id = e.currentTarget.dataset.id
  514. console.log(id)
  515. if (id == 0) {
  516. HttpBasics.get({
  517. url: `${config.api.getByKey}?key=canVierfyByCode`
  518. }).then(res => {
  519. console.log(res, 'res');
  520. if (res.data && res.data == 1) {
  521. wx.navigateTo({
  522. url: '/pages/scan/scan'
  523. })
  524. } else {
  525. wx.navigateTo({
  526. url: '/pages/scanII/scan'
  527. })
  528. }
  529. console.log(this.data);
  530. }).catch(err => {
  531. console.log(err, 'err');
  532. })
  533. } else if (id == 1) {
  534. // 优惠卡收款
  535. wx.navigateTo({
  536. url: '/pages/cardReceive/cardReceive',
  537. })
  538. } else if (id == 2) {
  539. wx.navigateTo({
  540. url: '/pages/main/solution/solution',
  541. })
  542. } else if (id == 3) {
  543. wx.navigateTo({
  544. url: '/pages/payment/index',
  545. })
  546. } else if (id == 4) {
  547. wx.navigateTo({
  548. url: '/pages/creditSelect/index',
  549. })
  550. } else if (id == 5) {
  551. wx.navigateTo({
  552. url: '/pages/incouponSelect/index',
  553. })
  554. } else if (id == 6) {
  555. wx.navigateTo({
  556. url: '/pages/marktingsettlement/index',
  557. })
  558. } else if (id == 7) {//用户发卷
  559. wx.navigateTo({
  560. url: '/pages/sendDiscounts/sendDiscounts',
  561. })
  562. } else if (id == 8) {//商品配送
  563. wx.navigateTo({
  564. url: '/pages/delivery/delivery',
  565. })
  566. } else if (id == 9) {//活动返现
  567. wx.navigateTo({
  568. url: '/pages/cashContent/cashContent',
  569. })
  570. } else if (id == 10) {//线下抽奖
  571. wx.navigateTo({
  572. url: '/pages/raffle/index',
  573. })
  574. }
  575. },
  576. toTran(e) {
  577. let type = e.currentTarget.dataset.type
  578. wx.navigateTo({
  579. url: `./transaction/transaction?type=${type}`,
  580. })
  581. },
  582. onShow() {
  583. let that = this;
  584. /**
  585. * 交易记录
  586. */
  587. if (that.oneComponent) {
  588. that.getrecordData();
  589. }
  590. if(that.posComponent) {
  591. that.getPosData()
  592. }
  593. if (that.jiaoyiComponent) {
  594. that.getTabletListOrder();
  595. }
  596. if (that.hexiaoComponent) {
  597. that.getTabletListVerify();
  598. }
  599. /**
  600. * 获得交易记录和核销额
  601. */
  602. that.getUnverifiedAmountOnDate();
  603. that.getVerifiedAmountOnDate();
  604. // that.getpaybill();
  605. that.setData({
  606. currentIndex: 0
  607. })
  608. },
  609. getpaybill: function () {
  610. let that = this;
  611. that.getUserInfo().then(res => {
  612. Http.postRequest(config.api.listBillOweAndWaitPay, app.globalData.token, '', {
  613. merchantId: res.merchant_id,
  614. tenantId: res.tenant_id,
  615. }, (res) => {
  616. console.log(res);
  617. if (res) {
  618. res.data.map(file => {
  619. if (file.starttime && file.endtime) {
  620. file.end = file.starttime.substring(0, 7).replace(/-/g, ".") + "-" + file.endtime.substring(0, 7).replace(/-/g, ".");
  621. } else {
  622. file.end = "";
  623. file.endtime = ""
  624. }
  625. file.receiveDate = util.fmtDate(file.receiveDate);
  626. })
  627. that.setData({
  628. billList: res.data,
  629. djArr: res.data.filter(item => item.status == 2),
  630. })
  631. that.data.djMoney = that.data.djArr.map(item => parseInt(item.owe / 100))
  632. let money = 0
  633. that.data.djMoney.filter(function (item, index) {
  634. money += item;
  635. })
  636. that.setData({
  637. djZmoney: changeNum.changePeoNumber(money)
  638. })
  639. }
  640. })
  641. })
  642. },
  643. getTabletListVerify: function () {
  644. let that = this;
  645. getTabletListVerify()
  646. .then(res => {
  647. if (res.xList.length > 0 && res.amountList.length > 0) {
  648. that.setData({
  649. ifShowChart1: 'show1'
  650. })
  651. that.hexiaoInit(res.xList, res.amountList)
  652. } else {
  653. /**
  654. * 判断是否显示数据表
  655. */
  656. that.setData({
  657. ifShowChart1: 'show'
  658. })
  659. }
  660. })
  661. },
  662. /**
  663. * 交易
  664. */
  665. getTabletListOrder: function () {
  666. let that = this;
  667. getTabletListOrder()
  668. .then(res => {
  669. console.log(res);
  670. if (res.xList.length > 0 && res.amountList.length > 0) {
  671. that.jiaoyiInit(res.xList, res.amountList)
  672. that.setData({
  673. ifShowChart: 'show1'
  674. })
  675. } else {
  676. /**
  677. * 判断是否显示数据表
  678. */
  679. that.setData({
  680. ifShowChart: 'show'
  681. })
  682. }
  683. })
  684. },
  685. /**
  686. * 收银记录
  687. */
  688. getrecordData() {
  689. let _this = this;
  690. HttpBasics.get({
  691. url: config.api.getMicroPayAmountOnDate
  692. })
  693. .then(res => {
  694. _this.setData({
  695. recordMoney: res.data.amount
  696. })
  697. })
  698. .catch(err => {
  699. wx.showToast({
  700. title: err.message,
  701. icon: 'none',
  702. duration: 2000,
  703. mask: false
  704. });
  705. });
  706. HttpBasics.get({
  707. url: config.api.listMicropay
  708. })
  709. .then(res => {
  710. let dataX = [];
  711. let dataY = [];
  712. if (res.data && res.data.length > 0) {
  713. _this.setData({
  714. ifShowChart2: "show1"
  715. })
  716. res.data.map((item, index) => {
  717. dataX.push(item.mouthAndDate)
  718. dataY.push(Number(item.amountStr))
  719. })
  720. _this.init_one(dataX, dataY)
  721. } else {
  722. _this.setData({
  723. ifShowChart2: "show"
  724. })
  725. }
  726. })
  727. .catch(err => {
  728. wx.showToast({
  729. title: err.message,
  730. icon: 'none',
  731. duration: 2000,
  732. mask: false
  733. });
  734. });
  735. },
  736. /**
  737. * pos交易流水
  738. */
  739. getPosData() {
  740. let _this = this;
  741. // 创建一个新的Date对象
  742. // var currentDate = new Date();
  743. // // 提取年、月、日信息
  744. // var year = currentDate.getFullYear().toString(); // 四位数表示年份
  745. // var month = (currentDate.getMonth() + 1).toString().padStart(2, '0'); // 补零后两位数表示月份(注意月份从0开始计算)
  746. // var dayEnd = currentDate.getDate().toString().padStart(2, '0'); // 补零后两位数表示天数
  747. // var dayStart = (currentDate.getDate()-10).toString().padStart(2, '0'); // 补零后两位数表示天数
  748. // // 构造最终结果字符串
  749. // var formattedDateStart = `${year}-${month}-${dayStart} 00:00:00`;
  750. // var formattedDateEnd = `${year}-${month}-${dayEnd} 23:59:59`;
  751. HttpBasics.get({
  752. url: config.api.dateMerchantOrderlist + `?phone=${wx.getStorageSync("linkPhone")}`
  753. })
  754. .then(res => {
  755. let dataX = [];
  756. let dataY = [];
  757. if (res.data) {
  758. for (var i in res.data) {
  759. dataX.push(i)
  760. dataY.push(Number(res.data[i]?.list[0]?.amount || 0))
  761. }
  762. var lastKey = Object.keys(res.data).pop();
  763. _this.setData({
  764. posMoney: res.data[lastKey]?.list[0]?.amount || 0
  765. })
  766. _this.setData({
  767. ifShowChart3: "show1"
  768. })
  769. _this.init_pos(dataX, dataY)
  770. } else {
  771. _this.setData({
  772. ifShowChart3: "show"
  773. })
  774. }
  775. })
  776. .catch(err => {
  777. wx.showToast({
  778. title: err.message,
  779. icon: 'none',
  780. duration: 2000,
  781. mask: false
  782. });
  783. });
  784. },
  785. toTran(e) {
  786. let type = e.currentTarget.dataset.type
  787. wx.navigateTo({
  788. url: `./transaction/transaction?type=${type}`,
  789. })
  790. },
  791. toRecord() {
  792. wx.navigateTo({
  793. url: `../record/list/index`,
  794. })
  795. },
  796. toPos(){
  797. wx.navigateTo({
  798. url: `../pos/list/index`,
  799. })
  800. },
  801. checkuserstatus() {
  802. let _this = this;
  803. HttpBasics.get({
  804. url: config.api.checkPhoneStatus
  805. })
  806. .then(res => {
  807. })
  808. .catch(err => {
  809. wx.redirectTo({
  810. url: `/pages/getuserinfo/index`
  811. })
  812. });
  813. },
  814. })