scheduling.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. var updateTimer;
  4. Page({
  5. data: {
  6. updateTime:{},
  7. datas: {},
  8. buttonText: "",
  9. buttonClass: "button-warn",
  10. checkIndex:null,
  11. oid:'',
  12. optionId:''
  13. },
  14. onLoad: function (options) {
  15. this.setData({oid:options.oid,optionId:options.optionId})
  16. this.getInfo()
  17. },
  18. checkClick(e){
  19. let index = e.currentTarget.dataset.index;
  20. if(this.data.datas.status != 2 || this.data.datas.alipays[index].actnum <= 0) return false
  21. if(index == this.checkIndex){
  22. this.setData({checkIndex:null})
  23. }else{
  24. this.setData({checkIndex:index})
  25. }
  26. },
  27. getInfo(){
  28. let that = this;
  29. util.ajax({
  30. func: "v2/articleSchedule/option/detail",
  31. data:{optionId:that.data.optionId,oid:that.data.oid}
  32. }, function (res) {
  33. if (res.code == 0 ) {
  34. let datas = res.data;
  35. datas.endSaleTimeLong = res.data.endSaleTimeLong - res.data.saleTimeLong;
  36. that.setData({ buttonText: util.decode(datas.status, 0, "待审核", 1, "审核通过", 2, "确定", 3, "已下架", 4, "已删除", 5, "未开始",6, "已结束",7, "已满额", "") });
  37. let buttonClass = datas.status == 2? 'button-warn': 'disabled';
  38. that.setData({datas,buttonClass});
  39. that.updateTime();
  40. }else{
  41. util.showTips(res.reason);
  42. }
  43. })
  44. },
  45. activeLogoBinderror(e){
  46. var datas = this.data.datas;
  47. datas.logo = '/images/noimg.png'
  48. this.setData({datas});
  49. },
  50. submit(){
  51. if(this.data.datas.status != 2) return false;
  52. if(this.data.checkIndex == null){
  53. util.showTips('请选择场次');
  54. return false;
  55. }
  56. let that = this,data = this.data.datas.alipays[this.data.checkIndex];
  57. wx.showModal({
  58. title: '提示',
  59. content: '你确定选择此排期吗?选择后\n自动调换过去。',
  60. success (res) {
  61. if (res.confirm) {
  62. util.ajax({
  63. func: "v2/articleSchedule/option/exchange",
  64. data:{optionId:that.data.optionId,oid:that.data.oid,nSid:data.sid,nPid:data.pid}
  65. }, function (res) {
  66. if (res.code == 0 ) {
  67. wx.navigateTo({
  68. url: '/pages/order/scheduling/schedulingOk?orderid=' + res.data.orderid
  69. })
  70. }else{
  71. util.showTips(res.reason);
  72. }
  73. })
  74. } else if (res.cancel) {
  75. }
  76. }
  77. })
  78. },
  79. updateTime() {
  80. var self = this,
  81. lag = (self.data.datas.saleTimeLong ? self.data.datas.saleTimeLong : 0) / 1000,
  82. lag2 = (self.data.datas.endSaleTimeLong ? self.data.datas.endSaleTimeLong: 0) / 1000;
  83. let second, minite, hour, day, buttonClass = self.data.buttonClass, buttonText = self.data.buttonText;
  84. if (lag > 0) {
  85. second = Math.floor(lag % 60);
  86. minite = Math.floor((lag / 60) % 60);
  87. hour = Math.floor(lag / 3600);
  88. day = Math.floor((lag / 3600) / 24);
  89. self.data.updateTime.title = "距离开始";
  90. buttonText = '未开始';
  91. self.data.datas.saleTimeLong = self.data.datas.saleTimeLong - 1000;
  92. } else if (lag2 > 0) {
  93. second = Math.floor(lag2 % 60);
  94. minite = Math.floor((lag2 / 60) % 60);
  95. hour = Math.floor(lag2 / 3600);
  96. day = Math.floor((lag2 / 3600) / 24);
  97. self.data.updateTime.title = "距离结束";
  98. self.data.datas.endSaleTimeLong = self.data.datas.endSaleTimeLong - 1000;
  99. if(self.data.datas.status == 2 || self.data.datas.status == 5){
  100. self.data.datas.status = 2;
  101. buttonClass = "button-warn";
  102. buttonText = "确定";
  103. }
  104. } else {//已结束lag和log2都小于=0
  105. buttonClass = "disabled";
  106. self.data.datas.status = 6;
  107. self.data.updateTime.title = "已结束";
  108. buttonText = "已结束";
  109. }
  110. if (lag > 0 || lag2 > 0){
  111. self.data.updateTime.hour = isTimeLeng(hour);
  112. self.data.updateTime.minite = isTimeLeng(minite);
  113. self.data.updateTime.second = isTimeLeng(second);
  114. }
  115. self.setData({ datas: self.data.datas, updateTime: self.data.updateTime, buttonClass: buttonClass, buttonText: buttonText });
  116. clearTimeout(updateTimer);
  117. updateTimer = setTimeout(function () {
  118. self.updateTime();
  119. }, 1000);
  120. function isTimeLeng(val) {
  121. var s = val.toString();
  122. return s.length == 1 ? "0" + val : val;
  123. }
  124. },
  125. })