C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
5.9 KiB

  1. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  2. let ifStoreApp = extConfig.attr.ifStoreApp;
  3. const Http = require("../utils/HttpBasics");
  4. var config = require("../config/config.js");
  5. let app = getApp();
  6. Component({
  7. data: {
  8. home_a_img:[],
  9. selected: 0,
  10. "color": "#abb1be",
  11. "selectedColor": "#FD782D",
  12. "list": [{
  13. "pagePath": "/index/index",
  14. "iconPath": "../assets/images/home.png",
  15. "selectedIconPath": "../assets/images/home-a.png",
  16. "text": "首页"
  17. },
  18. {
  19. "pagePath": "/index/searchbar",
  20. "iconPath": "../assets/images/mendian.png",
  21. "selectedIconPath": "../assets/images/mendian-a.png",
  22. "text": "门店"
  23. },
  24. {
  25. "pagePath": "/index/passCar",
  26. "iconPath": "../assets/images/park.png",
  27. "selectedIconPath": "../assets/images/park-a.png",
  28. "text": "停车"
  29. },
  30. {
  31. "pagePath": "/index/user",
  32. "iconPath": "../assets/images/user.png",
  33. "selectedIconPath": "../assets/images/user-a.png",
  34. "text": "我的"
  35. }
  36. ]
  37. },
  38. created(){
  39. this.getType()
  40. },
  41. // lifetimes: {
  42. // attached: function () {
  43. // // 在组件实例进入页面节点树时执行
  44. // },
  45. // },
  46. attached() {
  47. if (ifStoreApp == 1) {
  48. this.setData({
  49. list: [{
  50. "pagePath": "/index/index",
  51. "iconPath": "../assets/images/home.png",
  52. "selectedIconPath": "../assets/images/home-a.png",
  53. "text": "首页"
  54. },
  55. {
  56. "pagePath": "/index/user",
  57. "iconPath": "../assets/images/user.png",
  58. "selectedIconPath": "../assets/images/user-a.png",
  59. "text": "我的"
  60. }
  61. ]
  62. })
  63. } else if (ifStoreApp == 2) {
  64. this.setData({
  65. list: [{
  66. "pagePath": "/index/index",
  67. "iconPath": "../assets/images/home.png",
  68. "selectedIconPath": "../assets/images/home-a.png",
  69. "text": "首页"
  70. },
  71. {
  72. "pagePath": "/index/searchbar",
  73. "iconPath": "../assets/images/mendian.png",
  74. "selectedIconPath": "../assets/images/mendian-a.png",
  75. "text": "门店"
  76. },
  77. {
  78. "pagePath": "/index/user",
  79. "iconPath": "../assets/images/user.png",
  80. "selectedIconPath": "../assets/images/user-a.png",
  81. "text": "我的"
  82. }
  83. ]
  84. })
  85. }
  86. },
  87. methods: {
  88. switchTab(e) {
  89. // this.setData({
  90. // list: this.data.home_a_img
  91. // })
  92. // console.log(this.data.home_a_img)
  93. const data = e.currentTarget.dataset;
  94. this.setData({
  95. selected: data.index
  96. })
  97. console.log(data.index)
  98. const url = data.path;
  99. if (data.index == 0 || data.index == 3) {
  100. this.getTemplateId()
  101. }
  102. wx.switchTab({
  103. url
  104. });
  105. },
  106. /**
  107. * 获取全局样式
  108. */
  109. getType() {
  110. Http.get({
  111. url: config.api.setType,
  112. data: {}
  113. }).then(res => {
  114. const {
  115. code,
  116. data
  117. } = res
  118. if (code == 200) {
  119. app.globalData.styleLsit = data
  120. this.setTabStyle()
  121. }
  122. // console.log(this.data.list[0].selectedIconPath, '99999999999999999999999999999999999999999')
  123. })
  124. },
  125. // 初始换底部导航栏
  126. setTabStyle: function () {
  127. this.getTabBar().setData({
  128. selectedColor: `${app.globalData.styleLsit.t_in_std.styleClass}`,
  129. list: [{
  130. "pagePath": "/index/index",
  131. "iconPath": `${app.globalData.styleLsit.t_in.icon}`,
  132. "selectedIconPath": `${app.globalData.styleLsit.t_in_std.icon}`,
  133. "text": "首页"
  134. },
  135. {
  136. "pagePath": "/index/searchbar",
  137. "iconPath": `${app.globalData.styleLsit.t_md.icon}`,
  138. "selectedIconPath": `${app.globalData.styleLsit.t_md_std.icon}`,
  139. "text": "门店"
  140. },
  141. {
  142. "pagePath": "/index/passCar",
  143. "iconPath": `${app.globalData.styleLsit.t_tc.icon}`,
  144. "selectedIconPath": `${app.globalData.styleLsit.t_tc_std.icon}`,
  145. "text": "停车"
  146. },
  147. {
  148. "pagePath": "/index/user",
  149. "iconPath": `${app.globalData.styleLsit.t_uc.icon}`,
  150. "selectedIconPath": `${app.globalData.styleLsit.t_uc_std.icon}`,
  151. "text": "我的"
  152. }
  153. ],
  154. })
  155. },
  156. getTemplateId() {
  157. // console.log("隐藏")
  158. // wx.hideTabBar()
  159. Http.get({
  160. url: config.api.templateId,
  161. data: {
  162. pageNum: 1,
  163. pageSize: 100
  164. }
  165. }).then(res => {
  166. const {
  167. code,
  168. data
  169. } = res
  170. if (code == 200) {
  171. this.setData({
  172. templateId: data.list
  173. })
  174. this.setWxMessage()
  175. } else {
  176. return
  177. }
  178. })
  179. },
  180. setWxMessage() {
  181. let tmplIds = []
  182. this.data.templateId.map(res => {
  183. tmplIds.push(res.templateId)
  184. })
  185. wx.requestSubscribeMessage({
  186. tmplIds: tmplIds,
  187. success(res) {
  188. console.log("我重复订阅")
  189. let _statue = null
  190. tmplIds.map((item, index) => { //判读用户是否点击了确定
  191. if (res[item] == "accept") {
  192. _statue = 'ok'
  193. }
  194. })
  195. if (_statue == 'ok') {
  196. Http.post({
  197. url: config.api.wxMsg
  198. }).then(res => {
  199. wx.setStorageSync({
  200. key: 'ifShowTab',
  201. data: true,
  202. })
  203. console.log(res)
  204. })
  205. return
  206. }
  207. // for (let i = 0; i < tmplIds.length;i++){
  208. // if (res.tmplIds[i] == 'accept'){
  209. // console.log("发送")
  210. // }
  211. // }
  212. },
  213. complete(){
  214. }
  215. })
  216. },
  217. }
  218. })