C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
7.1 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. if (app.globalData.token) {
  40. this.getType()
  41. }
  42. },
  43. // lifetimes: {
  44. // attached: function () {
  45. // // 在组件实例进入页面节点树时执行
  46. // },
  47. // },
  48. attached() {
  49. if (ifStoreApp == 1) {
  50. this.setData({
  51. list: [{
  52. "pagePath": "/index/index",
  53. "iconPath": "../assets/images/home.png",
  54. "selectedIconPath": "../assets/images/home-a.png",
  55. "text": "首页"
  56. },
  57. {
  58. "pagePath": "/index/user",
  59. "iconPath": "../assets/images/user.png",
  60. "selectedIconPath": "../assets/images/user-a.png",
  61. "text": "我的"
  62. }
  63. ]
  64. })
  65. } else if (ifStoreApp == 2) {
  66. this.setData({
  67. list: [{
  68. "pagePath": "/index/index",
  69. "iconPath": "../assets/images/home.png",
  70. "selectedIconPath": "../assets/images/home-a.png",
  71. "text": "首页"
  72. },
  73. {
  74. "pagePath": "/index/searchbar",
  75. "iconPath": "../assets/images/mendian.png",
  76. "selectedIconPath": "../assets/images/mendian-a.png",
  77. "text": "门店"
  78. },
  79. {
  80. "pagePath": "/index/user",
  81. "iconPath": "../assets/images/user.png",
  82. "selectedIconPath": "../assets/images/user-a.png",
  83. "text": "我的"
  84. }
  85. ]
  86. })
  87. }
  88. },
  89. methods: {
  90. switchTab(e) {
  91. // this.setData({
  92. // list: this.data.home_a_img
  93. // })
  94. // console.log(this.data.home_a_img)
  95. const data = e.currentTarget.dataset;
  96. this.setData({
  97. selected: data.index
  98. })
  99. console.log(data.index)
  100. const url = data.path;
  101. if (data.index == 0 || data.index == 3) {
  102. this.getTemplateId()
  103. }
  104. wx.switchTab({
  105. url
  106. });
  107. },
  108. /**
  109. * 获取全局样式
  110. */
  111. getType() {
  112. Http.get({
  113. url: config.api.setType,
  114. data: {
  115. mouldType: app.globalData.mouldType
  116. }
  117. }).then(res => {
  118. const {
  119. code,
  120. data
  121. } = res
  122. if (code == 200) {
  123. app.globalData.styleLsit = data
  124. this.setTabStyle()
  125. }
  126. // console.log(this.data.list[0].selectedIconPath, '99999999999999999999999999999999999999999')
  127. })
  128. },
  129. // 初始换底部导航栏
  130. setTabStyle: function() {
  131. console.log(app.globalData.mouldType, "mouldType")
  132. if (app.globalData.mouldType == 0) {
  133. this.getTabBar().setData({
  134. selectedColor: `${app.globalData.styleLsit.t_in_std.styleClass}`,
  135. list: [{
  136. "pagePath": "/index/index",
  137. "iconPath": `${app.globalData.styleLsit.t_in.icon}`,
  138. "selectedIconPath": `${app.globalData.styleLsit.t_in_std.icon}`,
  139. "text": "首页"
  140. },
  141. {
  142. "pagePath": "/index/searchbar",
  143. "iconPath": `${app.globalData.styleLsit.t_md.icon}`,
  144. "selectedIconPath": `${app.globalData.styleLsit.t_md_std.icon}`,
  145. "text": "门店"
  146. },
  147. {
  148. "pagePath": "/index/passCar",
  149. "iconPath": `${app.globalData.styleLsit.t_tc.icon}`,
  150. "selectedIconPath": `${app.globalData.styleLsit.t_tc_std.icon}`,
  151. "text": "停车"
  152. },
  153. {
  154. "pagePath": "/index/user",
  155. "iconPath": `${app.globalData.styleLsit.t_uc.icon}`,
  156. "selectedIconPath": `${app.globalData.styleLsit.t_uc_std.icon}`,
  157. "text": "我的"
  158. }
  159. ],
  160. })
  161. } else if (app.globalData.mouldType == 1) {
  162. this.getTabBar().setData({
  163. selectedColor: `${app.globalData.styleLsit.t_in_std.styleClass}`,
  164. list: [{
  165. "pagePath": "/pages/theme/index1/index",
  166. "iconPath": `${app.globalData.styleLsit.t_in.icon}`,
  167. "selectedIconPath": `${app.globalData.styleLsit.t_in_std.icon}`,
  168. "text": "首页"
  169. },
  170. {
  171. "pagePath": "/index/searchbar",
  172. "iconPath": `${app.globalData.styleLsit.t_md.icon}`,
  173. "selectedIconPath": `${app.globalData.styleLsit.t_md_std.icon}`,
  174. "text": "门店"
  175. },
  176. {
  177. "pagePath": "/index/passCar",
  178. "iconPath": `${app.globalData.styleLsit.t_tc.icon}`,
  179. "selectedIconPath": `${app.globalData.styleLsit.t_tc_std.icon}`,
  180. "text": "停车"
  181. },
  182. {
  183. "pagePath": "/index/user",
  184. "iconPath": `${app.globalData.styleLsit.t_uc.icon}`,
  185. "selectedIconPath": `${app.globalData.styleLsit.t_uc_std.icon}`,
  186. "text": "我的"
  187. }
  188. ],
  189. })
  190. }
  191. },
  192. getTemplateId() {
  193. // console.log("隐藏")
  194. // wx.hideTabBar()
  195. Http.get({
  196. url: config.api.templateId,
  197. data: {
  198. pageNum: 1,
  199. pageSize: 100
  200. }
  201. }).then(res => {
  202. const {
  203. code,
  204. data
  205. } = res
  206. if (code == 200) {
  207. this.setData({
  208. templateId: data.list
  209. })
  210. this.setWxMessage()
  211. } else {
  212. return
  213. }
  214. })
  215. },
  216. setWxMessage() {
  217. let tmplIds = []
  218. this.data.templateId.map(res => {
  219. tmplIds.push(res.templateId)
  220. })
  221. wx.requestSubscribeMessage({
  222. tmplIds: tmplIds,
  223. success(res) {
  224. console.log("我重复订阅")
  225. let _statue = null
  226. tmplIds.map((item, index) => { //判读用户是否点击了确定
  227. if (res[item] == "accept") {
  228. _statue = 'ok'
  229. }
  230. })
  231. if (_statue == 'ok') {
  232. Http.post({
  233. url: config.api.wxMsg
  234. }).then(res => {
  235. wx.setStorageSync({
  236. key: 'ifShowTab',
  237. data: true,
  238. })
  239. console.log(res)
  240. })
  241. return
  242. }
  243. },
  244. complete() {
  245. }
  246. })
  247. },
  248. }
  249. })