C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

262 rindas
7.0 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. const that = this
  132. console.log(app.globalData.mouldType, "mouldType")
  133. if (app.globalData.mouldType == 0) {
  134. that.setData({
  135. selectedColor: `${app.globalData.styleLsit.t_in_std.styleClass}`,
  136. list: [{
  137. "pagePath": "/index/index",
  138. "iconPath": `${app.globalData.styleLsit.t_in.icon}`,
  139. "selectedIconPath": `${app.globalData.styleLsit.t_in_std.icon}`,
  140. "text": "首页"
  141. },
  142. {
  143. "pagePath": "/index/searchbar",
  144. "iconPath": `${app.globalData.styleLsit.t_md.icon}`,
  145. "selectedIconPath": `${app.globalData.styleLsit.t_md_std.icon}`,
  146. "text": "门店"
  147. },
  148. {
  149. "pagePath": "/index/passCar",
  150. "iconPath": `${app.globalData.styleLsit.t_tc.icon}`,
  151. "selectedIconPath": `${app.globalData.styleLsit.t_tc_std.icon}`,
  152. "text": "停车"
  153. },
  154. {
  155. "pagePath": "/index/user",
  156. "iconPath": `${app.globalData.styleLsit.t_uc.icon}`,
  157. "selectedIconPath": `${app.globalData.styleLsit.t_uc_std.icon}`,
  158. "text": "我的"
  159. }
  160. ],
  161. })
  162. } else if (app.globalData.mouldType == 1) {
  163. that.setData({ //getTabBar().
  164. selectedColor: `${app.globalData.styleLsit.t_in_std.styleClass}`,
  165. list: [{
  166. "pagePath": "/pages/theme/index1/index",
  167. "iconPath": `${app.globalData.styleLsit.t_in.icon}`,
  168. "selectedIconPath": `${app.globalData.styleLsit.t_in_std.icon}`,
  169. "text": "首页"
  170. },
  171. {
  172. "pagePath": "/index/searchbar",
  173. "iconPath": `${app.globalData.styleLsit.t_md.icon}`,
  174. "selectedIconPath": `${app.globalData.styleLsit.t_md_std.icon}`,
  175. "text": "门店"
  176. },
  177. {
  178. "pagePath": "/index/passCar",
  179. "iconPath": `${app.globalData.styleLsit.t_tc.icon}`,
  180. "selectedIconPath": `${app.globalData.styleLsit.t_tc_std.icon}`,
  181. "text": "停车"
  182. },
  183. {
  184. "pagePath": "/index/user",
  185. "iconPath": `${app.globalData.styleLsit.t_uc.icon}`,
  186. "selectedIconPath": `${app.globalData.styleLsit.t_uc_std.icon}`,
  187. "text": "我的"
  188. }
  189. ],
  190. })
  191. }
  192. },
  193. getTemplateId() {
  194. // console.log("隐藏")
  195. // wx.hideTabBar()
  196. Http.get({
  197. url: config.api.templateId,
  198. // data: {
  199. // pageNum: 1,
  200. // pageSize: 100
  201. // }
  202. }).then(res => {
  203. const {
  204. code,
  205. data
  206. } = res
  207. if (code == 200) {
  208. this.setData({
  209. templateId: data || ''
  210. })
  211. this.setWxMessage()
  212. } else {
  213. return
  214. }
  215. })
  216. },
  217. setWxMessage() {
  218. let tmplIds = []
  219. this.data.templateId.map(res => {
  220. tmplIds.push(res.templateId)
  221. })
  222. wx.requestSubscribeMessage({
  223. tmplIds: tmplIds,
  224. success(res) {
  225. console.log("我重复订阅")
  226. let _statue = null
  227. tmplIds.map((item, index) => { //判读用户是否点击了确定
  228. if (res[item] == "accept") {
  229. _statue = 'ok'
  230. }
  231. })
  232. if (_statue == 'ok') {
  233. Http.post({
  234. url: config.api.wxMsg
  235. }).then(res => {
  236. wx.setStorageSync({
  237. key: 'ifShowTab',
  238. data: true,
  239. })
  240. console.log(res)
  241. })
  242. return
  243. }
  244. },
  245. complete() {
  246. }
  247. })
  248. },
  249. }
  250. })