index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. // pages/index/index.js
  2. import {
  3. Home
  4. } from '../../utils/home.js';
  5. var home = new Home(); //实例化 首页 对象\
  6. var app = getApp();
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. goodsType:[["课程","教程","商品"]],
  13. goodsTypeIndex:0,
  14. temp: [],
  15. isShow_goodsType:false,
  16. isShow_goods: false,
  17. isShow_campusName:false,
  18. picker_01_data: [],
  19. nickName: "",
  20. avatarUrl: "",
  21. qkong: false,
  22. campusNameListIndex: 0,
  23. selectType: true,
  24. goodsListIndex: 0,
  25. goodsList: [
  26. []
  27. ],
  28. //课程隐藏数量
  29. num_: 0,
  30. //销售金额
  31. sellPrice: 0,
  32. //商品数量
  33. num: 0,
  34. //预收
  35. prePrice: 0,
  36. //微信
  37. weichatPay: 0,
  38. //口碑
  39. aliPay: 0,
  40. //现金
  41. cashPay: 0,
  42. //微店
  43. weidianPay: 0,
  44. //押金抵扣
  45. pledgeDeduction: 0,
  46. //校区合作
  47. campusPay: '',
  48. //备注
  49. comment: '',
  50. userName: '',
  51. mobile: '',
  52. pnumber: 1,
  53. Gender: 'female',
  54. casIndex: 0,
  55. casIndexx: 0,
  56. hiddenName: false,
  57. isDelivery: '已交付',
  58. deliverys: false,
  59. inputValue: null,
  60. weichatPay: 0,
  61. aliPay: 0,
  62. cashPay: 0,
  63. weidianPay: 0,
  64. pledgeDeduction: 0,
  65. campusPay: 0,
  66. jiaofeiren: '',
  67. items: [{
  68. value: '新',
  69. },
  70. {
  71. value: '老',
  72. },
  73. {
  74. value: 'U转吉',
  75. },
  76. {
  77. value: '吉转吉',
  78. },
  79. {
  80. value: '无',
  81. }
  82. ]
  83. },
  84. showPicker_campusName: function () {
  85. this.setData({
  86. isShow_campusName: true
  87. })
  88. },
  89. //选择校区
  90. // bindCasPickerChange: function (e) {
  91. // this.setData({
  92. // campusNameListIndex: e.detail.value
  93. // })
  94. // },
  95. sureCallBack_campusName(e) {
  96. let that = this
  97. that.setData({
  98. isShow_campusName: false,
  99. campusNameListIndex: e.detail.choosedIndexArr[0]
  100. })
  101. },
  102. cancleCallBack_campusName() {
  103. let that=this
  104. that.data.isShow_campusName=false,
  105. that.setData({
  106. isShow_campusName: false,
  107. })
  108. },
  109. showPicker_goodsList: function() {
  110. let that=this
  111. that.data.isShow_goods= true
  112. that.setData({
  113. isShow_goods: true
  114. })
  115. },
  116. sureCallBack_goods(e) {
  117. let that = this
  118. if (that.data.objectGoodsList[e.detail.choosedIndexArr[0]].goods_tags == '商品') {
  119. that.setData({
  120. selectType: true,
  121. num_: 0
  122. })
  123. } else {
  124. that.setData({
  125. selectType: false,
  126. isDelivery: '已交付',
  127. num_: 1,
  128. num: 0
  129. })
  130. }
  131. that.setData({
  132. isShow_goods: false,
  133. goodsListIndex: e.detail.choosedIndexArr[0]
  134. })
  135. that.sellPrice()
  136. },
  137. cancleCallBack_goods() {
  138. this.setData({
  139. isShow_goods: false,
  140. })
  141. },
  142. showPicker_goodsTypeList: function () {
  143. this.setData({
  144. isShow_goodsType: true
  145. })
  146. },
  147. sureCallBack_goodsType(e) {
  148. let that = this
  149. // if (that.data.goodsType[0][e.detail.choosedIndexArr[0]] == '商品') {
  150. // that.setData({
  151. // selectType: true,
  152. // num_: 0,
  153. // goodsListIndex:0
  154. // })
  155. // } else {
  156. // that.setData({
  157. // selectType: false,
  158. // isDelivery: '已交付',
  159. // num_: 1,
  160. // num: 0,
  161. // goodsListIndex: 0
  162. // })
  163. // }
  164. that.setData({
  165. goodsListIndex: 0
  166. })
  167. that.data.goodsTypeIndex=e.detail.choosedIndexArr[0]
  168. that.setData({
  169. isShow_goodsType: false,
  170. goodsTypeIndex: e.detail.choosedIndexArr[0]
  171. })
  172. that.getGoodList()
  173. },
  174. cancleCallBack_goodsType() {
  175. this.setData({
  176. isShow_goodsType: false,
  177. })
  178. },
  179. //填写缴费人
  180. inputStudentName: function(e) {
  181. let that = this
  182. that.setData({
  183. studentName: e.detail.value
  184. })
  185. },
  186. //选择学生状态
  187. radioChange: function(e) {
  188. let that = this
  189. this.setData({
  190. studentStatus: e.detail.value,
  191. })
  192. },
  193. //选择商品
  194. bindPickerChangeGoodsList: function(e) {
  195. let that = this
  196. if (that.data.objectGoodsList[e.detail.value].goods_tags == '商品') {
  197. that.setData({
  198. selectType: true,
  199. num_: 0
  200. })
  201. } else {
  202. that.setData({
  203. selectType: false,
  204. isDelivery: '已交付',
  205. num_: 1,
  206. num: 0
  207. })
  208. }
  209. this.setData({
  210. goodsListIndex: e.detail.value
  211. })
  212. that.sellPrice()
  213. },
  214. //销售金额计算
  215. sellPrice: function() {
  216. let that = this
  217. var sellPrice = that.data.objectGoodsList[that.data.goodsListIndex]['goods_price'] * that.data.num + that.data.objectGoodsList[that.data.goodsListIndex]['goods_price'] * that.data.num_
  218. that.setData({
  219. sellPrice: sellPrice,
  220. })
  221. },
  222. /**
  223. * 交付
  224. */
  225. delivery: function(e) {
  226. var that = this;
  227. var b = this.data.isDelivery == "已交付" ? "未交付" : "已交付";
  228. if (b) {
  229. that.setData({
  230. isDelivery: b,
  231. 'inputValue': '',
  232. weichatPay: 0,
  233. aliPay: 0,
  234. cashPay: 0,
  235. weidianPay: 0,
  236. pledgeDeduction: 0,
  237. campusPay: 0,
  238. prePrice: 0
  239. })
  240. } else {
  241. that.setData({
  242. isDelivery: b,
  243. 'inputValue': '',
  244. })
  245. }
  246. },
  247. deliveryChange: function() {
  248. },
  249. /**
  250. * 数量 input 数量 监听
  251. */
  252. numberInput: function(event) {
  253. let that = this;
  254. var inputSearch = event.detail.value;
  255. if (inputSearch.length > 0) {
  256. that.setData({
  257. deliverys: true,
  258. num: event.detail.value,
  259. prePrice: 0
  260. })
  261. } else {
  262. that.setData({
  263. deliverys: false,
  264. num: event.detail.value
  265. })
  266. }
  267. that.sellPrice()
  268. },
  269. /**
  270. * 预收金额
  271. */
  272. prePriceInput: function() {
  273. let that = this
  274. if (that.data.num < 1) {
  275. let prePrice = 0
  276. prePrice = parseFloat(that.data.weichatPay) + parseFloat(that.data.aliPay) + parseFloat(that.data.cashPay) + parseFloat(that.data.weidianPay) + parseFloat(that.data.pledgeDeduction) + parseFloat(that.data.campusPay)
  277. that.setData({
  278. prePrice: prePrice
  279. })
  280. }
  281. },
  282. /**
  283. * 微信支付
  284. */
  285. weichatPayInput: function(e) {
  286. let that = this
  287. that.setData({
  288. weichatPay: that.checkInputText(e.detail.value)
  289. })
  290. that.prePriceInput()
  291. },
  292. /**
  293. * 支付宝支付 口碑支付
  294. */
  295. aliPayInput: function(e) {
  296. let that = this
  297. that.setData({
  298. aliPay: that.checkInputText(e.detail.value)
  299. })
  300. that.prePriceInput()
  301. },
  302. /**
  303. * 现金支付
  304. */
  305. cashPayInput: function(e) {
  306. let that = this
  307. that.setData({
  308. cashPay: that.checkInputText(e.detail.value)
  309. })
  310. that.prePriceInput()
  311. },
  312. /**
  313. * 微店支付
  314. */
  315. weidianPayInput: function(e) {
  316. let that = this
  317. that.setData({
  318. weidianPay: that.checkInputText(e.detail.value)
  319. })
  320. that.prePriceInput()
  321. },
  322. /**
  323. * 押金抵扣
  324. */
  325. pledgeDeductionInput: function(e) {
  326. let that = this
  327. that.setData({
  328. pledgeDeduction: that.checkInputText(e.detail.value)
  329. })
  330. that.prePriceInput()
  331. },
  332. /**
  333. * 合作校前台支付
  334. */
  335. campusPayInput: function(e) {
  336. let that = this
  337. that.setData({
  338. campusPay: that.checkInputText(e.detail.value)
  339. })
  340. that.prePriceInput()
  341. },
  342. /**
  343. * 备注
  344. */
  345. commentInput: function(e) {
  346. let that = this
  347. that.setData({
  348. comment: e.detail.value
  349. })
  350. },
  351. time: function() {
  352. let that = this
  353. //获取当前时间戳
  354. var timestamp = Date.parse(new Date());
  355. timestamp = timestamp / 1000;
  356. //获取当前时间
  357. var n = timestamp * 1000;
  358. var date = new Date(n);
  359. //年
  360. var Y = date.getFullYear();
  361. //月
  362. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  363. //日
  364. var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  365. //时
  366. var h = date.getHours();
  367. //分
  368. var m = date.getMinutes();
  369. //秒
  370. var s = date.getSeconds();
  371. that.setData({
  372. Y: Y,
  373. M: M,
  374. D: D,
  375. })
  376. },
  377. //获取商品列表
  378. getGoodList: function() {
  379. let that = this
  380. var param = {goods_type:that.data.goodsType[0][that.data.goodsTypeIndex]}
  381. home.getGoodList(param, (res) => {
  382. that.setData({
  383. objectGoodsList: res.data
  384. })
  385. var glist = [[]];
  386. res.data.forEach((res) => {
  387. let that = this
  388. //var a = that.data.goodsList
  389. glist[0].push(res.goods_name)
  390. if (that.data.objectGoodsList[that.data.goodsListIndex].goods_tags == '商品') {
  391. that.setData({
  392. selectType: true
  393. })
  394. } else {
  395. that.setData({
  396. selectType: false
  397. })
  398. }
  399. })
  400. that.setData({ goodsList:glist})
  401. that.sellPrice()
  402. })
  403. },
  404. //提交
  405. submit: function() {
  406. let that = this
  407. if (that.data.studentName) {
  408. if (that.data.studentStatus) {
  409. if (that.data.num || that.data.isDelivery || that.data.objectGoodsList[that.data.goodsListIndex].goods_tags == '课程') {
  410. if (that.data.prePrice || (that.data.weichatPay || that.data.aliPay || that.data.cashPay || that.data.weidianPay || that.data.pledgeDeduction || that.data.campusPay)) {
  411. var total = parseFloat(that.data.weichatPay) + parseFloat(that.data.aliPay) + parseFloat(that.data.cashPay) + parseFloat(that.data.weidianPay) + parseFloat(that.data.pledgeDeduction) + parseFloat(that.data.campusPay);
  412. if (that.data.sellPrice == total || that.data.isDelivery == "未交付") {
  413. var isDelivery = that.data.isDelivery;
  414. var prePrice = that.data.prePrice;
  415. if (that.data.objectGoodsList[that.data.goodsListIndex].goods_type == '课程') {
  416. isDelivery = '已交付'
  417. prePrice = 0
  418. }
  419. var param = {
  420. //最终缔结人ID
  421. user_id: that.data.user_id,
  422. //最终缔结人姓名
  423. user_name: that.data.user_name,
  424. //校区
  425. campusName: that.data.campusNameList[0][that.data.campusNameListIndex],
  426. //缴费人
  427. studentName: that.data.studentName,
  428. //学生状态
  429. studentStatus: that.data.studentStatus,
  430. //商品
  431. goods: that.data.goodsList[0][that.data.goodsListIndex],
  432. //销售金额
  433. sellPrice: that.data.sellPrice,
  434. //数量
  435. num: that.data.num,
  436. //交付 未交付
  437. isDelivery: isDelivery,
  438. //预收
  439. prePrice: prePrice,
  440. //微信
  441. weichatPay: that.data.weichatPay,
  442. //口碑
  443. aliPay: that.data.aliPay,
  444. //现金
  445. cashPay: that.data.cashPay,
  446. //微店
  447. weidianPay: that.data.weidianPay,
  448. //押金抵扣
  449. pledgeDeduction: that.data.pledgeDeduction,
  450. //校区合作
  451. campusPay: that.data.campusPay,
  452. //备注
  453. comment: that.data.comment,
  454. }
  455. home.submit(param, (res) => {
  456. let that = this
  457. if (res.code == 1) {
  458. wx.showToast({
  459. title: res.msg,
  460. icon: 'none',
  461. duration: 1000,
  462. mask: true,
  463. success: function(res) {},
  464. fail: function(res) {},
  465. complete: function(res) {
  466. that.setData({
  467. //最终缔结人ID
  468. user_id: '',
  469. //最终缔结人姓名
  470. user_name: '',
  471. //校区
  472. campusName: that.data.campusNameList[that.data.campusNameListIndex],
  473. campusNameListIndex: 0,
  474. //缴费人
  475. studentName: '',
  476. //学生状态
  477. studentStatus: '',
  478. //商品
  479. goods: that.data.goodsList[0][that.data.goodsListIndex],
  480. goodsListIndex: 0,
  481. //销售金额
  482. sellPrice: 0,
  483. //数量
  484. num: 0,
  485. //交付 未交付
  486. isDelivery: '已交付',
  487. //预收
  488. prePrice: 0,
  489. //微信
  490. weichatPay: 0,
  491. //口碑
  492. aliPay: 0,
  493. //现金
  494. cashPay: 0,
  495. //微店
  496. weidianPay: 0,
  497. //押金抵扣
  498. pledgeDeduction: 0,
  499. //校区合作
  500. campusPay: 0,
  501. //备注
  502. comment:'',
  503. qkong: true,
  504. jiaofeiren: '',
  505. deliverys: false
  506. })
  507. that.onShow()
  508. },
  509. })
  510. } else if (res.code == 0) {
  511. wx.showToast({
  512. title: res.msg,
  513. icon: 'none',
  514. duration: 1000,
  515. mask: true,
  516. success: function(res) {},
  517. fail: function(res) {},
  518. complete: function(res) {},
  519. })
  520. }
  521. })
  522. } else if (that.data.sellPrice < total) {
  523. wx.showToast({
  524. title: '支付金额大于销售金额',
  525. icon: 'none',
  526. image: '',
  527. duration: 1000,
  528. mask: true,
  529. success: function(res) {},
  530. fail: function(res) {},
  531. complete: function(res) {},
  532. })
  533. } else if (that.data.sellPrice > total) {
  534. wx.showToast({
  535. title: '支付金额小于销售金额',
  536. icon: 'none',
  537. image: '',
  538. duration: 1000,
  539. mask: true,
  540. success: function(res) {},
  541. fail: function(res) {},
  542. complete: function(res) {},
  543. })
  544. }
  545. } else {
  546. wx.showToast({
  547. title: '请填写支付金额',
  548. icon: 'none',
  549. image: '',
  550. duration: 1000,
  551. mask: true,
  552. success: function(res) {},
  553. fail: function(res) {},
  554. complete: function(res) {},
  555. })
  556. }
  557. } else {
  558. wx.showToast({
  559. title: '请填写商品数量',
  560. icon: 'none',
  561. image: '',
  562. duration: 1000,
  563. mask: true
  564. })
  565. }
  566. } else {
  567. wx.showToast({
  568. title: '请选择学生状态',
  569. icon: 'none',
  570. image: '',
  571. duration: 1000,
  572. mask: true,
  573. success: function(res) {},
  574. fail: function(res) {},
  575. complete: function(res) {},
  576. })
  577. }
  578. } else {
  579. wx.showToast({
  580. title: '请填写缴费人姓名',
  581. icon: 'none',
  582. image: '',
  583. duration: 1000,
  584. mask: true,
  585. success: function(res) {},
  586. fail: function(res) {},
  587. complete: function(res) {},
  588. })
  589. }
  590. },
  591. //获取校区列表
  592. campus: function() {
  593. var that = this
  594. var params = {}
  595. home.campus(params, (res) => {
  596. var list=[[]]
  597. list[0]=res.data
  598. that.setData({
  599. campusNameList: list
  600. })
  601. })
  602. },
  603. onLoad: function() {
  604. },
  605. /**
  606. * 生命周期函数--监听页面初次渲染完成
  607. */
  608. onReady: function() {
  609. },
  610. /**
  611. * 生命周期函数--监听页面显示
  612. */
  613. onShow: function() {
  614. let that = this
  615. that.time()
  616. that.prePriceInput()
  617. that.campus()
  618. var user_name = wx.getStorage({
  619. key: 'user_name',
  620. success: function(res) {
  621. that.setData({
  622. user_name: res.data
  623. })
  624. },
  625. })
  626. wx.getStorage({
  627. key: 'user_id',
  628. success: function(res) {
  629. that.setData({
  630. user_id: res.data
  631. })
  632. },
  633. })
  634. that.setData({
  635. objectGoodsList: [],
  636. goodsList: [
  637. []
  638. ]
  639. })
  640. home.getTime({}, (res) => {
  641. that.setData({
  642. goodsType: res.data.cates,
  643. })
  644. that.getGoodList();
  645. })
  646. },
  647. /**
  648. * 生命周期函数--监听页面隐藏
  649. */
  650. onHide: function() {
  651. },
  652. /**
  653. * 生命周期函数--监听页面卸载
  654. */
  655. onUnload: function() {
  656. },
  657. /**
  658. * 页面相关事件处理函数--监听用户下拉动作
  659. */
  660. onPullDownRefresh: function() {
  661. },
  662. /**
  663. * 页面上拉触底事件的处理函数
  664. */
  665. onReachBottom: function() {
  666. },
  667. //检查输入文本,限制只能为数字并且数字最多带2位小数
  668. checkInputText: function (text) {
  669. var reg = /^(\.*)(\d+)(\.?)(\d{0,2}).*$/g;
  670. if (reg.test(text)) { //正则匹配通过,提取有效文本
  671. text = text.replace(reg, '$2$3$4');
  672. } else { //正则匹配不通过,直接清空
  673. text = '';
  674. }
  675. if (text.substr(0,2) == '00') {
  676. text = text.substr(1, text.length);
  677. }
  678. if (text.substr(0, 1) == '0' && text.substr(1, 1) != '0' && text.substr(1, 1) != '.' && text.length>=2){
  679. text = text.substr(1, text.length);
  680. }
  681. return text; //返回符合要求的文本(为数字且最多有带2位小数)
  682. }
  683. })