You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

752 lines
18 KiB

  1. const Http = require('../../utils/HttpBasics.js')
  2. const config = require('../../config/config.js')
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. tempFilePaths: [],
  10. BtempFilePaths: [],
  11. // typeIndex: 0, //类型下标
  12. timeIndex: 0, //时间下标
  13. // typeArray: ['优惠券 >', '代金卷 >',],
  14. timeArray: ['按日期 >', '按领取天数 >'],
  15. useLimitRuleLsit: ['限制领取该券总数量', '只限制券包中未使用的该券数量'],
  16. refundText: ['是', '否'],
  17. refundIndex: 0, //0 =>是 1=>否
  18. beginTime: '请选择时间',
  19. endTime: '请选择时间',
  20. numDays: "", //按天数
  21. title: '', //标题
  22. faceValue: 0, //面值
  23. selling: 0, //售价\
  24. bank: 0, //库存
  25. everyday: 0, //每人限领
  26. explain: '',
  27. ifUpdata: false, //判断是否修改
  28. id: '', //修改id
  29. examineColor_back: '',
  30. putApplyStatus: 0, //0未提交审批 1待审批 2审批成功 3审批驳回
  31. putApplyText: "待审批通过",
  32. noUpdata: true,
  33. couponId: '',
  34. useLimitRule: 0
  35. },
  36. addPicture() {
  37. const num = this.data.tempFilePaths.length
  38. if (num == 5) {
  39. wx.showToast({
  40. title: '主图限制为5张!',
  41. icon: 'error'
  42. })
  43. console.log(this.data.tempFilePaths, 'tempFilePaths');
  44. return
  45. }
  46. wx.navigateTo({
  47. url: '/pages/upload/upload?save=1',
  48. })
  49. },
  50. BaddPicture() {
  51. const num = this.data.BtempFilePaths.length
  52. if (num == 5) {
  53. wx.showToast({
  54. title: '主图限制为5张!',
  55. icon: 'error'
  56. })
  57. console.log(this.data.BtempFilePaths, 'BtempFilePaths');
  58. return
  59. }
  60. wx.navigateTo({
  61. url: '/pages/upload/upload?save=2',
  62. })
  63. },
  64. /**
  65. * 取消
  66. */
  67. goBack() {
  68. wx.navigateBack({
  69. delta: 1
  70. })
  71. },
  72. /**
  73. * 保存
  74. */
  75. save() {
  76. wx.showLoading({
  77. title: '加载中',
  78. })
  79. if (this.data.timeIndex == 0) {
  80. if (this.data.beginTime.indexOf('请选择时间') != -1) {
  81. wx.showToast({
  82. title: '请选择开始时间',
  83. icon: 'none',
  84. duration: 2000
  85. })
  86. return
  87. }
  88. if (this.data.endTime.indexOf('请选择时间') != -1) {
  89. wx.showToast({
  90. title: '请选择结束时间',
  91. icon: 'none',
  92. duration: 2000
  93. })
  94. return
  95. }
  96. } else {
  97. if (this.data.numDays == '') {
  98. wx.showToast({
  99. title: '请输入有效期',
  100. icon: 'none',
  101. duration: 2000
  102. })
  103. return
  104. }
  105. }
  106. let _that = this
  107. let postData = {
  108. title: _that.data.title,
  109. type: "6",
  110. priceStr: _that.data.faceValue,
  111. salePriceStr: _that.data.selling,
  112. inventory: _that.data.bank,
  113. useLimitQuantity: _that.data.everyday,
  114. validStartDate: _that.data.timeIndex == 0 ? _that.data.beginTime + ' 00:00:00' : '',
  115. validEndDate: _that.data.timeIndex == 0 ? _that.data.endTime + ' 23:59:59' : '',
  116. validDays: _that.data.numDays,
  117. remark: _that.data.explain,
  118. subTitle: '', //不用管管副标题 B端没用
  119. sendType: "1",
  120. remainInventory: _that.data.bank, //剩余库存
  121. autoRefund: _that.data.refundIndex, //是否退款
  122. useLimitRule: (_that.data.useLimitRule * 1) + 1
  123. }
  124. if (this.data.timeIndex == 0) {
  125. //1是时间类型 2是领取后多少天有效
  126. postData.validType = '1'
  127. } else {
  128. postData.validType = '2'
  129. }
  130. if (postData.title == '' || postData.priceStr == 0 || postData.inventory == 0 || postData.useLimitQuantity == 0 || postData.validStartDate == '请选择时间' || postData.validEndDate == '请选择时间' || postData.html == '') {
  131. console.log(postData, 'postData');
  132. wx.hideLoading();
  133. wx.showToast({
  134. title: '请输入完整信息',
  135. icon: 'none',
  136. duration: 2000
  137. })
  138. return
  139. }
  140. if (parseInt(postData.priceStr) < parseInt(postData.salePriceStr)) {
  141. wx.hideLoading();
  142. wx.showToast({
  143. title: '面值必须小于售价',
  144. icon: 'none',
  145. duration: 2000
  146. })
  147. return
  148. }
  149. if (parseInt(postData.inventory) < parseInt(postData.useLimitQuantity)) {
  150. wx.hideLoading();
  151. wx.showToast({
  152. title: '库存必须大于每人限领',
  153. icon: 'none',
  154. duration: 2000
  155. })
  156. return
  157. }
  158. const beginTime = new Date(_that.data.beginTime)
  159. const endTime = new Date(_that.data.endTime)
  160. if (beginTime > endTime) {
  161. wx.showToast({
  162. title: '起始时间必须小于结束时间',
  163. icon: 'none',
  164. duration: 2000
  165. })
  166. return
  167. }
  168. if (_that.data.tempFilePaths.length < 1) {
  169. wx.showToast({
  170. title: '请至少上传一张主图!',
  171. icon: 'none',
  172. duration: 2000
  173. })
  174. return
  175. }
  176. // if (_that.data.selling<=0){
  177. // wx.showToast({
  178. // title: '售价必须大于0',
  179. // icon: 'none',
  180. // duration: 2000
  181. // })
  182. // return
  183. // }
  184. // console.log(beginTime, endTime)
  185. // 编辑
  186. if (_that.data.ifUpdata || _that.data.id != '') {
  187. // if (_that.data.receiptUrl.indexOf('//tmp') != -1 || _that.data.receiptUrl.indexOf('"http://tmp') != -1) {
  188. // console.log(1234568);
  189. // wx.uploadFile({
  190. // url: config.api.imgUpload,
  191. // filePath: _that.data.receiptUrl,
  192. // name: 'file',
  193. // header: {
  194. // 'token': app.globalData.token
  195. // },
  196. // success(res) {
  197. // const data = res.data
  198. // console.log(data, 'data');
  199. // // console.log(JSON.parse(res.data).data.url ,"????hhahah66666")
  200. // postData.coverImg = _that.data.receiptUrl
  201. // postData.coverPicture = JSON.stringify([_that.data.receiptUrl])
  202. // postData.id = _that.data.id
  203. // Http.post({
  204. // url: config.api.updataCoupon,
  205. // data: postData
  206. // }).then(res => {
  207. // const {
  208. // code,
  209. // data
  210. // } = res
  211. // if (code == 200) {
  212. // wx.hideLoading();
  213. // wx.showToast({
  214. // title: '保存成功',
  215. // icon: "none",
  216. // duration: 1000,
  217. // })
  218. // }
  219. // }).catch(res => {
  220. // wx.hideLoading();
  221. // wx.showToast({
  222. // title: `${res.message}`,
  223. // icon: "none",
  224. // duration: 1000,
  225. // })
  226. // })
  227. // },
  228. // fail(res) {
  229. // wx.hideLoading();
  230. // wx.showToast({
  231. // title: '请上传主图',
  232. // icon: "none",
  233. // duration: 1000
  234. // })
  235. // }
  236. // })
  237. // }
  238. postData.coverImg = _that.data.tempFilePaths[0]
  239. postData.coverPicture = JSON.stringify(_that.data.tempFilePaths)
  240. postData.detailPicture = JSON.stringify(_that.data.BtempFilePaths)
  241. postData.id = _that.data.id
  242. Http.post({
  243. url: config.api.updataCoupon,
  244. data: postData
  245. }).then(res => {
  246. const {
  247. code,
  248. data
  249. } = res
  250. console.log(code, data, "666")
  251. _that.setData({
  252. id: data
  253. })
  254. if (code == 200) {
  255. wx.hideLoading();
  256. wx.showToast({
  257. title: '保存成功',
  258. icon: "none",
  259. duration: 1000,
  260. success() {
  261. setTimeout(() => {
  262. wx.navigateBack()
  263. }, 1000);
  264. }
  265. })
  266. }
  267. }).catch(res => {
  268. wx.hideLoading();
  269. wx.showToast({
  270. title: `${res.message}`,
  271. icon: "none",
  272. duration: 1000
  273. })
  274. })
  275. } else {
  276. // 新建
  277. console.log(1234567);
  278. postData.coverImg = _that.data.tempFilePaths[0]
  279. postData.coverPicture = JSON.stringify(_that.data.tempFilePaths)
  280. postData.detailPicture = JSON.stringify(_that.data.BtempFilePaths)
  281. console.log(postData, 'postData');
  282. Http.post({
  283. url: config.api.addCoupon,
  284. data: postData
  285. }).then(res => {
  286. const {
  287. code,
  288. data
  289. } = res
  290. if (code == 200) {
  291. _that.setData({
  292. id: data
  293. })
  294. wx.hideLoading();
  295. wx.showToast({
  296. title: '保存成功',
  297. icon: "none",
  298. duration: 1000,
  299. success() {
  300. setTimeout(() => {
  301. wx.navigateBack()
  302. }, 1000);
  303. }
  304. })
  305. }
  306. }).catch(res => {
  307. wx.hideLoading();
  308. wx.showToast({
  309. title: `${res.message}`,
  310. icon: "none",
  311. duration: 1000,
  312. })
  313. })
  314. }
  315. },
  316. /**
  317. * 提交审批
  318. */
  319. examine() {
  320. wx.showLoading({
  321. title: '加载中',
  322. })
  323. if (this.data.putApplyStatus == 1) {
  324. wx.hideLoading();
  325. wx.showToast({
  326. title: "待审批请勿重复提交",
  327. icon: 'none',
  328. duration: 2000,
  329. })
  330. return
  331. }
  332. if (this.data.id != '') {
  333. let postData = {
  334. id: this.data.id,
  335. remark: ''
  336. }
  337. Http.post({
  338. url: config.api.submitExamine,
  339. data: postData
  340. }).then(res => {
  341. const {
  342. code,
  343. message
  344. } = res;
  345. console.log(code, message)
  346. if (code == 200) {
  347. wx.hideLoading();
  348. wx.showToast({
  349. title: message,
  350. icon: 'none',
  351. duration: 2000,
  352. success: (res => {
  353. this.goBack()
  354. })
  355. })
  356. }
  357. })
  358. } else {
  359. wx.hideLoading();
  360. wx.showToast({
  361. title: '请先保存再提交审核',
  362. icon: 'error',
  363. duration: 2000
  364. })
  365. }
  366. },
  367. /**
  368. * 获取卷标题
  369. */
  370. getTitle(e) {
  371. this.setData({
  372. title: e.detail.value
  373. })
  374. },
  375. /**
  376. * 获取面值
  377. */
  378. getfaceValue(e) {
  379. this.setData({
  380. faceValue: e.detail.value
  381. })
  382. },
  383. /**
  384. * 获取售价
  385. */
  386. getselling(e) {
  387. this.setData({
  388. selling: e.detail.value
  389. })
  390. },
  391. /**
  392. * 获取库存
  393. */
  394. getbank(e) {
  395. this.setData({
  396. bank: e.detail.value
  397. })
  398. },
  399. /**
  400. * 每人限领
  401. */
  402. geteveryday(e) {
  403. this.setData({
  404. everyday: e.detail.value
  405. })
  406. },
  407. /**
  408. * 购买须知
  409. */
  410. getexplain(e) {
  411. this.setData({
  412. explain: e.detail.value
  413. })
  414. },
  415. /**
  416. * 选择天数获取天数
  417. */
  418. getNumDays(e) {
  419. this.setData({
  420. numDays: e.detail.value
  421. })
  422. },
  423. //删除图片
  424. pictureDel(e) {
  425. const index = e.currentTarget.dataset.index
  426. const tempFilePaths = this.data.tempFilePaths
  427. tempFilePaths.splice(index, 1)
  428. this.setData({
  429. tempFilePaths,
  430. })
  431. },
  432. //删除图片
  433. BpictureDel(e) {
  434. const index = e.currentTarget.dataset.index
  435. const BtempFilePaths = this.data.BtempFilePaths
  436. BtempFilePaths.splice(index, 1)
  437. this.setData({
  438. BtempFilePaths
  439. })
  440. },
  441. //卷类型选择器:
  442. bindPickerChange: function (e) {
  443. console.log('picker发送选择改变,携带值为', e.detail.value)
  444. this.setData({
  445. tpyeIndex: e.detail.value
  446. })
  447. },
  448. //先领规则
  449. setUseLimitRule: function (e) {
  450. console.log('picker发送选择改变,携带值为', e.detail.value)
  451. this.setData({
  452. useLimitRule: e.detail.value
  453. })
  454. },
  455. //时间类型
  456. timeChange: function (e) {
  457. console.log('picker发送选择改变,携带值为', e.detail.value)
  458. this.setData({
  459. timeIndex: e.detail.value
  460. })
  461. },
  462. //过期是否退款类型
  463. refundChange: function (e) {
  464. console.log('picker发送选择改变,携带值为', e.detail.value)
  465. this.setData({
  466. refundIndex: e.detail.value
  467. })
  468. },
  469. setDeginTime: function (e) {
  470. console.log('picker发送选择改变,携带值为', e.detail.value)
  471. this.setData({
  472. beginTime: e.detail.value
  473. })
  474. },
  475. setEndTime: function (e) {
  476. console.log('picker发送选择改变,携带值为', e.detail.value)
  477. this.setData({
  478. endTime: e.detail.value
  479. })
  480. },
  481. setRefund: function (e) {
  482. console.log('picker发送选择改变,携带值为', e.detail.value)
  483. this.setData({
  484. endTime: e.detail.value
  485. })
  486. },
  487. /**
  488. * 上架
  489. */
  490. putaway() {
  491. if (this.data.bank <= 0) {
  492. wx.showToast({
  493. title: '库存不能为0',
  494. icon: 'none',
  495. duration: 2000
  496. })
  497. return
  498. }
  499. wx.showLoading({
  500. title: '加载中',
  501. })
  502. let postData = {
  503. couponIds: this.data.id,
  504. channelId: "1",
  505. beginTime: "",
  506. endTime: ""
  507. }
  508. Http.post({
  509. url: config.api.addbatch,
  510. data: postData
  511. }).then(res => {
  512. const {
  513. code,
  514. data
  515. } = res
  516. if (code == 200) {
  517. wx.hideLoading();
  518. wx.showToast({
  519. title: '上架成功',
  520. icon: 'none',
  521. duration: 2000
  522. })
  523. } else {
  524. wx.hideLoading();
  525. wx.showToast({
  526. title: res.message,
  527. icon: 'none',
  528. duration: 2000,
  529. })
  530. }
  531. })
  532. },
  533. /**
  534. * 下架
  535. */
  536. soldOut() {
  537. wx.showLoading({
  538. title: '加载中',
  539. })
  540. let postData = {
  541. id: this.data.id,
  542. status: "1",
  543. }
  544. Http.post({
  545. url: config.api.soldOut,
  546. data: postData
  547. }).then(res => {
  548. const {
  549. code,
  550. data
  551. } = res
  552. if (code == 200) {
  553. wx.hideLoading();
  554. wx.showToast({
  555. title: '下架成功',
  556. icon: 'none',
  557. duration: 2000,
  558. success: (res => {
  559. this.goBack()
  560. })
  561. })
  562. } else {
  563. wx.hideLoading();
  564. wx.showToast({
  565. title: res.message,
  566. icon: 'none',
  567. duration: 2000,
  568. })
  569. }
  570. })
  571. },
  572. /**
  573. * 作废
  574. */
  575. cancellation() {
  576. wx.showLoading({
  577. title: '加载中',
  578. })
  579. let postData = {
  580. id: this.data.couponId != '' ? this.data.couponId : this.data.id,
  581. status: "1",
  582. }
  583. Http.post({
  584. url: config.api.cancellation,
  585. data: postData
  586. }).then(res => {
  587. const {
  588. code,
  589. data
  590. } = res
  591. if (code == 200) {
  592. wx.hideLoading();
  593. wx.showToast({
  594. title: '作废成功',
  595. icon: 'none',
  596. duration: 2000,
  597. success: (res => {
  598. this.goBack()
  599. })
  600. })
  601. } else {
  602. wx.hideLoading();
  603. wx.showToast({
  604. title: res.message,
  605. icon: 'none',
  606. duration: 2000,
  607. })
  608. }
  609. })
  610. },
  611. /**
  612. * 审批历史记录
  613. */
  614. lookExamine() {
  615. console.log("查看审批历史")
  616. wx.navigateTo({
  617. url: `/pages/lookExamine/lookExamine?id=${this.data.id}`,
  618. })
  619. },
  620. /**
  621. * 生命周期函数--监听页面加载
  622. */
  623. onLoad: function (options) {
  624. const storTempData = wx.getStorageSync('tmepdata')
  625. console.log(storTempData);
  626. if (storTempData) {
  627. let tempData = JSON.parse(storTempData)
  628. console.log(tempData)
  629. this.setData({
  630. title: tempData.title,
  631. faceValue: tempData.priceStr,
  632. selling: tempData.salePriceStr,
  633. bank: tempData.remainInventory,
  634. everyday: tempData.useLimitQuantity,
  635. timeIndex: tempData.validType - 1,
  636. explain: tempData.remark,
  637. numDays: tempData.numDays,
  638. beginTime: tempData.validStartDate,
  639. endTime: tempData.validEndDate,
  640. status: tempData.status,
  641. ifUpdata: true,
  642. id: tempData.id,
  643. couponId: tempData.couponId,
  644. refundIndex: tempData.autoRefund,
  645. putApplyStatus: tempData.putApplyStatus, //0未提交审批 1待审批 2审批成功 3审批驳回
  646. channel: tempData.channel, //已上架按钮判断条件 1是已上架,
  647. noUpdata: tempData.noUpdata, //是否能修改
  648. useLimitRule: (tempData.useLimitRule * 1) - 1,
  649. })
  650. if (tempData.coverPicture) {
  651. this.setData({
  652. tempFilePaths: JSON.parse(tempData.coverPicture),
  653. })
  654. } else {
  655. this.setData({
  656. tempFilePaths: tempData.coverImg,
  657. })
  658. }
  659. if (tempData.detailPicture) {
  660. this.setData({
  661. BtempFilePaths: JSON.parse(tempData.detailPicture)
  662. })
  663. }
  664. console.log(this.data.channel, "channel")
  665. if (this.data.putApplyStatus == 1) {
  666. this.setData({
  667. examineColor_back: 'background-color: yellow;color: red;',
  668. putApplyText: "待审批通过",
  669. })
  670. } else if (this.data.putApplyStatus == 3) {
  671. this.setData({
  672. examineColor_back: 'background-color: red;color: #fff;',
  673. putApplyText: "审批未通过",
  674. })
  675. } else if (this.data.putApplyStatus == 2) {
  676. this.setData({
  677. examineColor_back: 'background-color: green;color: #fff;',
  678. putApplyText: "审批已通过",
  679. })
  680. }
  681. } else {
  682. this.setData({
  683. tempFilePaths: [options.res]
  684. })
  685. }
  686. },
  687. /**
  688. * 生命周期函数--监听页面初次渲染完成
  689. */
  690. onReady: function () {
  691. },
  692. /**
  693. * 生命周期函数--监听页面显示
  694. */
  695. onShow: function () { },
  696. /**
  697. * 生命周期函数--监听页面隐藏
  698. */
  699. onHide: function () {
  700. },
  701. /**
  702. * 生命周期函数--监听页面卸载
  703. */
  704. onUnload: function () {
  705. console.log("123456789")
  706. if (wx.getStorageSync('tmepdata')) {
  707. wx.removeStorageSync('tmepdata')
  708. }
  709. },
  710. /**
  711. * 页面相关事件处理函数--监听用户下拉动作
  712. */
  713. onPullDownRefresh: function () {
  714. },
  715. /**
  716. * 页面上拉触底事件的处理函数
  717. */
  718. onReachBottom: function () {
  719. },
  720. /**
  721. * 用户点击右上角分享
  722. */
  723. onShareAppMessage: function () {
  724. }
  725. })