C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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