index.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. // pages/store/index.js
  2. /**
  3. * 店铺管理
  4. */
  5. import * as API_Shop from '../../api/shop.js'
  6. import * as Common from '../../utils/common.js'
  7. import * as Util from '../../utils/util.js'
  8. import * as API_Passport from '../../api/passport.js'
  9. const app = getApp()
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. shopLogo: '',
  16. changeShopShow: false,
  17. changeShopValue: '',
  18. shops: [],
  19. todayOrderNum: 0,
  20. todayOrderTotal: 0,
  21. saleOrderTotal: 0,
  22. boolOnline: false,
  23. loaded:false,
  24. shopAdminMemberId: null,
  25. userId: null
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function(options) {
  31. const that=this
  32. },
  33. /**
  34. * 生命周期函数--监听页面初次渲染完成
  35. */
  36. onReady: function() {
  37. },
  38. attached:function(){
  39. },
  40. /**
  41. * 生命周期函数--监听页面显示
  42. */
  43. onShow: function() {
  44. console.log('onshow')
  45. let that = this
  46. that.getCurrentShopData()
  47. },
  48. /**
  49. * 生命周期函数--监听页面隐藏
  50. */
  51. onHide: function() {
  52. },
  53. /**
  54. * 生命周期函数--监听页面卸载
  55. */
  56. onUnload: function() {
  57. },
  58. /**
  59. * 页面相关事件处理函数--监听用户下拉动作
  60. */
  61. onPullDownRefresh: function() {
  62. },
  63. /**
  64. * 页面上拉触底事件的处理函数
  65. */
  66. onReachBottom: function() {
  67. },
  68. /**
  69. * 用户点击右上角分享
  70. */
  71. onShareAppMessage: function() {
  72. },
  73. gridClick(e) {
  74. const {
  75. name
  76. } = e.currentTarget.dataset
  77. switch (name) {
  78. case 'product':
  79. {
  80. wx.switchTab({
  81. url: '/pages/goods/goods-list',
  82. })
  83. break
  84. }
  85. case 'business':
  86. {
  87. wx.navigateTo({
  88. url: '/pages/store/businessSetting',
  89. })
  90. break
  91. }
  92. case 'orderquery':
  93. {
  94. wx.switchTab({
  95. url: '/pages/order/index',
  96. })
  97. break
  98. }
  99. case 'shopsetting':
  100. {
  101. wx.navigateTo({
  102. url: '/pages/shop/shop-edit',
  103. })
  104. break
  105. }
  106. case 'aftersale':{
  107. wx.navigateTo({
  108. url: '/pages/aftersale/index',
  109. })
  110. break
  111. }
  112. case 'withdrawApply':{
  113. wx.navigateTo({
  114. url: '/pages/fund/withdrawApply',
  115. })
  116. break
  117. }
  118. case 'withdrawAccount':{
  119. wx.navigateTo({
  120. url: '/pages/fund/withdrawAccount',
  121. })
  122. break
  123. }
  124. case 'bill':{
  125. wx.navigateTo({
  126. url: '/pages/bill/index',
  127. })
  128. }
  129. case 'statistic':{
  130. wx.navigateTo({
  131. url: '/pages/statistic/statisticNav',
  132. })
  133. }
  134. }
  135. },
  136. getO2OShops() {
  137. API_Shop.getO2OShops({
  138. contains_current: 1
  139. }).then(res => {
  140. this.setData({
  141. shops: [...res],
  142. changeShopShow: true
  143. })
  144. })
  145. },
  146. changeShopShowClose(e) {
  147. this.setData({
  148. changeShopShow: false
  149. })
  150. },
  151. onChangeShop(e) {
  152. const {
  153. value
  154. } = e.detail
  155. this.setData({
  156. changeShopValue: value
  157. })
  158. const that = this
  159. API_Shop.changeLoginShop(value).then(res => {
  160. const {
  161. access_token,
  162. refresh_token,
  163. access_token_timeout,
  164. refresh_token_timeout
  165. } = res
  166. const authorInfo=app.globalData.authorInfo
  167. const now=Date.parse(new Date())/1000
  168. app.globalData.authorInfo={...authorInfo,
  169. 'access_token':access_token,
  170. 'refresh_token':refresh_token,'refresh_token_timeout':now+refresh_token_timeout-1000,'access_token_timeout':now+access_token_timeout-1000}
  171. wx.setStorageSync('authorInfo', app.globalData.authorInfo)
  172. that.getCurrentShopData()
  173. that.setData({
  174. changeShopShow: false
  175. })
  176. })
  177. },
  178. /** 加载店铺信息 **/
  179. getCurrentShopData(){
  180. const that=this
  181. Common.getCurrentShopData().then(res => {
  182. console.log('res',res)
  183. that.setData({
  184. shopLogo: app.globalData.sellerShop.shop_logo,
  185. shopName: app.globalData.sellerShop.shop_name,
  186. startTime: app.globalData.sellerShop.start_time,
  187. endTime: app.globalData.sellerShop.end_time,
  188. business_date: app.globalData.sellerShop.business_date,
  189. shop_state: app.globalData.sellerShop.shop_state,
  190. bool_o2o: app.globalData.authorInfo.bool_o2o,
  191. shopAdminMemberId: app.globalData.sellerShop.member_id,
  192. userId: app.globalData.authorInfo.uid
  193. })
  194. var curDate = new Date();
  195. //星期几判定
  196. let businessDateOpen = false;
  197. let business_date = app.globalData.sellerShop.business_date
  198. const checkcodes = business_date.split('')
  199. const today = curDate.getDay();
  200. let index = 0;
  201. switch (today){
  202. case 0: //星期日
  203. index = 6
  204. break;
  205. default:
  206. index = today - 1;
  207. break;
  208. }
  209. if (checkcodes[index] === "1") {
  210. businessDateOpen = true;
  211. }
  212. //营业时间判定
  213. let seOpen = false;
  214. //今天日期
  215. const curDay = curDate.getFullYear() + "-" + (curDate.getMonth() + 1) + "-" + curDate.getDate();
  216. const startDay = curDay + " " + app.globalData.sellerShop.start_time;
  217. const endDay = curDay + " " + app.globalData.sellerShop.end_time;
  218. var sd = new Date(Date.parse(startDay.replace(/-/g,"/")));
  219. var ed = new Date(Date.parse(endDay.replace(/-/g,"/")));
  220. if (curDate>sd && curDate<ed){
  221. seOpen = true;
  222. }
  223. if (businessDateOpen && seOpen && app.globalData.sellerShop.shop_state === "1"){
  224. that.setData({
  225. boolOnline: true
  226. });
  227. } else {
  228. that.setData({
  229. boolOnline: false
  230. });
  231. }
  232. console.log('begininit')
  233. that.getTabBar().init()
  234. //数据加载完成后1秒展现
  235. setTimeout(function() {that.setData({
  236. loaded:true,
  237. todayOrderNum: app.globalData.todayOrderNum,
  238. todayOrderTotal: app.globalData.todayOrderTotal,
  239. saleOrderTotal: app.globalData.saleOrderTotal
  240. })
  241. let i = 0;
  242. if(app.globalData.todayOrderNum>0||app.globalData.todayOrderTotal>0){
  243. numDH()
  244. }
  245. function numDH() {
  246. clearTimeout()
  247. if (i < 20) {
  248. setTimeout(function () {
  249. that.setData({
  250. todayOrderNum: i,
  251. todayOrderTotal: i,
  252. })
  253. i++
  254. numDH();
  255. }, 20)
  256. } else {
  257. that.setData({
  258. todayOrderNum: app.globalData.todayOrderNum,
  259. todayOrderTotal: app.globalData.todayOrderTotal,
  260. })
  261. }
  262. }
  263. }, 1000);
  264. }).catch(err=>{
  265. wx.showToast({
  266. title:err.message,
  267. icon:'none'
  268. })
  269. })
  270. }
  271. })