index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // index.js
  2. let myPro = require("../../../../utils/wxRequest.js");
  3. let util = require("../../../../utils/util.js");
  4. Page({
  5. data: {
  6. begin_at: null,
  7. end_at: null,
  8. status: 1, // 1正常 0禁用
  9. showBegin: false,
  10. showEnd: false,
  11. currentBegin: null,
  12. currentEnd: null,
  13. id: null
  14. },
  15. onLoad: function (options) {
  16. // Do some initialize when page load.
  17. let that = this;
  18. if(options.id){
  19. that.getDetail(options.id);
  20. that.setData({
  21. id: options.id
  22. });
  23. };
  24. },
  25. onShow: function () {
  26. // Do something when page show.
  27. let that = this;
  28. },
  29. onReady: function () {
  30. // Do something when page ready.
  31. },
  32. onHide: function () {
  33. // Do something when page hide.
  34. },
  35. onUnload: function () {
  36. // Do something when page close.
  37. },
  38. onPullDownRefresh: function () {
  39. // Do something when pull down.
  40. },
  41. onReachBottom: function () {
  42. // Do something when page reach bottom.
  43. },
  44. onShareAppMessage: function () {
  45. // return custom share data when user share.
  46. },
  47. onPageScroll: function () {
  48. // Do something when page scroll
  49. },
  50. onResize: function () {
  51. // Do something when page resize
  52. },
  53. // 详情
  54. getDetail(id){
  55. let that = this;
  56. let params = {
  57. id: id
  58. };
  59. myPro.wxRequest("store/businessHours/detail","GET",params).then(res=>{
  60. that.setData({
  61. begin_at: res.result.begin_at,
  62. end_at: res.result.end_at,
  63. status: res.result.status,
  64. currentBegin: res.result.begin_at,
  65. currentEnd: res.result.end_at
  66. });
  67. }).catch(err=>{
  68. console.log('报错信息',err);
  69. wx.showToast({
  70. title: err,
  71. icon: "none"
  72. })
  73. })
  74. },
  75. // 开店时间
  76. beginTimeFun(){
  77. let that = this;
  78. that.setData({
  79. showBegin: true
  80. })
  81. },
  82. confirmBeginTime(event){
  83. // console.log('开始时间',event)
  84. let that = this;
  85. that.setData({
  86. begin_at: event.detail,
  87. showBegin: false
  88. });
  89. },
  90. closeBeginTimePop(){
  91. let that = this;
  92. that.setData({
  93. showBegin: false
  94. })
  95. },
  96. // 闭店时间
  97. endTimeFun(){
  98. let that = this;
  99. that.setData({
  100. showEnd: true
  101. })
  102. },
  103. confirmEndTime(event){
  104. // console.log('闭店时间',event)
  105. let that = this;
  106. that.setData({
  107. end_at: event.detail,
  108. showEnd: false
  109. })
  110. },
  111. closeEndTimePop(){
  112. let that = this;
  113. that.setData({
  114. showEnd: false
  115. })
  116. },
  117. // 状态
  118. onChangeStatus(event){
  119. let that = this;
  120. that.setData({
  121. status: event.detail
  122. });
  123. },
  124. // 提交
  125. bindTijiao(){
  126. let that = this;
  127. if(!that.data.begin_at || !that.data.end_at){
  128. wx.showToast({
  129. title: "请检查信息是否完整",
  130. icon: "none"
  131. });
  132. return;
  133. }else{
  134. let params = {
  135. begin_at: that.data.begin_at,
  136. end_at: that.data.end_at,
  137. status: that.data.status
  138. };
  139. // 编辑
  140. if(that.data.id){
  141. params.id = that.data.id;
  142. myPro.wxRequest("store/businessHours/edit","POST",params).then(res=>{
  143. wx.showToast({
  144. title: res.msg,
  145. icon: "none"
  146. });
  147. wx.navigateBack();
  148. }).catch(err=>{
  149. console.log('报错信息',err);
  150. wx.showToast({
  151. title: err,
  152. icon: "none"
  153. });
  154. });
  155. }else{
  156. // 新增
  157. myPro.wxRequest("store/businessHours/create","POST",params).then(res=>{
  158. wx.showToast({
  159. title: res.msg,
  160. icon: "none"
  161. });
  162. wx.navigateBack();
  163. }).catch(err=>{
  164. console.log('报错信息',err);
  165. wx.showToast({
  166. title: err,
  167. icon: "none"
  168. });
  169. });
  170. }
  171. }
  172. }
  173. });