index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. import http from "../../utils/http"
  5. import util from "../../utils/util"
  6. Page({
  7. data: {
  8. checked: false,
  9. show:false,
  10. menuH: '32px',
  11. safeTop: `40px`,
  12. lastAddress: '',
  13. list:[],
  14. finish: false,
  15. loading: false,
  16. page: 1,
  17. orderCount: [],
  18. token: wx.getStorageSync('token'),
  19. code: '',
  20. config: ''
  21. },
  22. // 服务时间
  23. toServerTime(){
  24. util.authSkip('/service/serverTime/serverTime')
  25. },
  26. detail(e){
  27. util.skip('/pages/orderDetail/orderDetail?id='+e.currentTarget.dataset.id)
  28. },
  29. // 事件处理函数
  30. onChange({ detail }) {
  31. if(!wx.getStorageSync('token')) {
  32. util.skip('/service/login/login')
  33. return
  34. }
  35. http.post('skill/updateskillinfo',{type: 'update', is_rest: Number(!detail)}).then(res => {
  36. this.setData({
  37. checked: detail
  38. })
  39. })
  40. },
  41. onClose(){
  42. this.setData({
  43. show: false
  44. })
  45. },
  46. notice(){
  47. wx.requestSubscribeMessage({
  48. tmplIds: [app.globalData.templateconfig.skill_order_template,app.globalData.templateconfig.skill_sales_template],
  49. success :(res) =>{
  50. console.log(res)
  51. },
  52. fail :(e) =>{
  53. console.log(e)
  54. },
  55. complete :(res) =>{
  56. this.changeAddress()
  57. }
  58. })
  59. },
  60. changeAddress(){
  61. if(!wx.getStorageSync('token')) {
  62. util.skip('/service/login/login')
  63. return
  64. }
  65. http.post('skill/updateskillinfo',{
  66. type: 'update',
  67. province: this.data.address.province,
  68. city: this.data.address.city,
  69. district: this.data.address.district,
  70. address: this.data.address.name,
  71. lng: this.data.address.lng,
  72. lat: this.data.address.lat,
  73. }).then(res => {
  74. this.setData({
  75. show: true,
  76. lastAddress: this.data.address.city + ' ' +this.data.address.name
  77. })
  78. })
  79. },
  80. getInfo(){
  81. if(!wx.getStorageSync('token')) return
  82. http.post('skill/updateskillinfo','',!this.data.code).then(res => {
  83. if(res.data){
  84. this.setData({
  85. checked: res.data.is_rest === 0,
  86. lastAddress: res.data.city+ ' ' + res.data.address,
  87. code: res.data.code
  88. })
  89. }
  90. })
  91. http.post('skill/skillhome','',!this.data.orderCount).then(res => {
  92. this.setData({
  93. orderCount: res.data.orderCount
  94. })
  95. })
  96. },
  97. order(){
  98. wx.switchTab({
  99. url: '/pages/order/order'
  100. })
  101. },
  102. reload(){
  103. this.setData({
  104. list: [],
  105. page: 1,
  106. finish: false
  107. })
  108. this.getList()
  109. },
  110. more(){
  111. this.setData({
  112. page: ++this.data.page
  113. })
  114. this.getList()
  115. },
  116. getList(){
  117. if(!wx.getStorageSync('token')) return
  118. if(this.data.finish){
  119. return
  120. }
  121. if(this.data.loading){
  122. return
  123. }
  124. this.setData({
  125. loading: true
  126. })
  127. let data = {
  128. page: this.data.page,
  129. not_finish: 1
  130. }
  131. http.post('order/skillorderlist', data).then(res => {
  132. if(res.data.length === 0){
  133. this.setData({
  134. finish: true
  135. })
  136. }
  137. let arr = this.data.list.concat(res.data)
  138. this.setData({
  139. list: arr
  140. })
  141. }).finally(res => {
  142. this.setData({
  143. loading: false
  144. })
  145. })
  146. },
  147. knowLocation(){
  148. wx.navigateTo({
  149. url: '/service/login/login'
  150. })
  151. },
  152. toTraining() {
  153. wx.navigateTo({
  154. url: '/pages/training/training'
  155. })
  156. },
  157. testbtn(){
  158. this.setData({
  159. loading:true
  160. })
  161. setTimeout(()=>
  162. {
  163. this.setData({
  164. loading:false
  165. })
  166. }, 2000)
  167. console.log(this.data.loading)
  168. },
  169. onLoadAddress(option){
  170. this.setData({
  171. address: app.globalData.address
  172. })
  173. },
  174. onLoadConfig(option){
  175. this.setData({
  176. config: app.globalData.config
  177. })
  178. },
  179. onLoad() {
  180. this.setData({
  181. safeTop: `${app.globalData.safeTop}px`,
  182. menuH: `${app.globalData.menuH}px`,
  183. })
  184. },
  185. onShow(){
  186. this.setData({
  187. token: wx.getStorageSync('token')
  188. })
  189. this.getInfo()
  190. this.reload()
  191. },
  192. /**
  193. * 用户点击右上角分享
  194. */
  195. onShareAppMessage() {
  196. return {}
  197. }
  198. })