index.js 5.2 KB

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