decorateguide.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. const app = getApp();
  2. var utils = require("../../utils/http"),
  3. casepage = 1;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. nowstyle: '',
  10. stylelist: [],
  11. square_start: '', //面积开始值
  12. square_end: '', //面积结束值
  13. nowcommunity: '',
  14. communitylist: [],
  15. nowhousetype: '',
  16. housetypelist: [],
  17. imgUrl: app.globalData.imgUrl,
  18. caselist: [],
  19. keyword: '',
  20. datashow: false,
  21. loginFlag:true,
  22. mobileflag:false,
  23. canIUseGetUserProfile: false,
  24. shareobj:{},
  25. employeeflag:false,//false是用户,true是员工
  26. communityflag:false,
  27. nowcommunitname:'',
  28. type:'',
  29. typearr:[
  30. {id:1,name:'效果案例',type:1},
  31. {id:2,name:'实景案例',type:2}
  32. ],
  33. noweffect:''
  34. },
  35. /**
  36. * 生命周期函数--监听页面加载
  37. */
  38. onLoad: function (options) {
  39. wx.showLoading({
  40. title: '加载中...',
  41. })
  42. if(options.type){
  43. this.setData({
  44. type:options.type
  45. })
  46. }
  47. this.casestylefun();
  48. this.housestylefun();
  49. this.casecommunityfun();
  50. this.caselistfun();
  51. },
  52. seteffectap(e){
  53. this.setData({
  54. noweffect:e.currentTarget.dataset.type
  55. })
  56. this.caselistfun();
  57. },
  58. casestylefun: function () {
  59. var that = this;
  60. utils.$get({
  61. url: app.globalData.webUrl + 'api/stylelist',
  62. header: {
  63. 'Authorization': 'bearer ' + app.globalData.token
  64. },
  65. data: {},
  66. success: function (res) {
  67. if (res.data.code == '0') {
  68. that.setData({
  69. stylelist: res.data.data
  70. })
  71. }
  72. }
  73. })
  74. },
  75. housestylefun: function () {
  76. var that = this;
  77. utils.$get({
  78. url: app.globalData.webUrl + 'api/material/housetypelist',
  79. header: {
  80. 'Authorization': 'bearer ' + app.globalData.token
  81. },
  82. data: {},
  83. success: function (res) {
  84. if (res.data.code == '0') {
  85. that.setData({
  86. housetypelist: res.data.data
  87. })
  88. }
  89. }
  90. })
  91. },
  92. onChoose(e) {
  93. var that=this;
  94. that.setData({
  95. nowcommunity:e.detail.item.currentTarget.dataset.cid,
  96. nowcommunitname:e.detail.item.currentTarget.dataset.item.name,
  97. communityflag:false
  98. })
  99. wx.showLoading({
  100. title: '加载中...',
  101. })
  102. that.caselistfun();
  103. },
  104. casecommunityfun: function () {
  105. var that = this;
  106. utils.$get({
  107. url: app.globalData.webUrl + 'api/communitylist',
  108. header: {
  109. 'Authorization': 'bearer ' + app.globalData.token
  110. },
  111. data: {},
  112. success: function (res) {
  113. if (res.data.code == '0') {
  114. that.setData({
  115. communitylist: res.data.data
  116. })
  117. }
  118. that.getCitys();
  119. }
  120. })
  121. },
  122. getCitys() {
  123. const _this = this
  124. const cities = this.data.communitylist;
  125. // 按拼音排序
  126. cities.sort((c1, c2) => {
  127. let pinyin1 = c1.pinyin;
  128. let pinyin2 = c2.pinyin;
  129. return pinyin1.localeCompare(pinyin2)
  130. })
  131. // 添加首字母
  132. const map = new Map()
  133. for (const city of cities) {
  134. const alpha = city.pinyin.charAt(0).toUpperCase()
  135. if (!map.has(alpha)) map.set(alpha, [])
  136. map.get(alpha).push({ name: city.name,id: city.id})
  137. }
  138. const keys = []
  139. for (const key of map.keys()) {
  140. keys.push(key)
  141. }
  142. keys.sort()
  143. const list = []
  144. for (const key of keys) {
  145. list.push({
  146. alpha: key,
  147. subItems: map.get(key)
  148. })
  149. }
  150. for(let i=0;i<list.length;i++){
  151. for(let k=0;k<list[i].subItems.length;k++){
  152. for(let j=0;j<cities.length;j++){
  153. if(list[i].subItems[k].name==cities[j].name){
  154. list[i].subItems[k].case_num=cities[j].case_num;
  155. list[i].id=cities[j].id;
  156. }
  157. }
  158. }
  159. }
  160. _this.setData({list:list})
  161. },
  162. selectareatap: function (e) {
  163. this.setData({
  164. square_start: e.currentTarget.dataset.start,
  165. square_end: e.currentTarget.dataset.end,
  166. })
  167. this.caselistfun();
  168. },
  169. caselistfun: function (e) {
  170. var that = this;
  171. casepage = 1;
  172. utils.$get({
  173. url: app.globalData.webUrl + 'client/caselist',
  174. header: {
  175. 'Authorization': 'bearer ' + app.globalData.token
  176. },
  177. data: {
  178. page: 1,
  179. uid: app.globalData.personMsg.id,
  180. commu_id: that.data.nowcommunity, // 小区id
  181. style_id: that.data.nowstyle, //风格id
  182. square_start: that.data.square_start, //面积开始值
  183. square_end: that.data.square_end, //面积结束值
  184. keyword: that.data.keyword,
  185. housetype_id: that.data.nowhousetype,
  186. case_type:this.data.noweffect,
  187. },
  188. success: function (res) {
  189. that.setData({
  190. datashow: true
  191. })
  192. if (res.data.code == '0') {
  193. that.setData({
  194. caselist: res.data.data,
  195. })
  196. }
  197. setTimeout(function () {
  198. wx.hideLoading()
  199. }, 1000)
  200. },
  201. fail() {
  202. wx.hideLoading()
  203. }
  204. })
  205. },
  206. setstyletap: function (e) {
  207. this.setData({
  208. nowstyle: e.currentTarget.dataset.type
  209. })
  210. this.caselistfun();
  211. },
  212. setcommunitytap: function (e) {
  213. this.setData({
  214. nowcommunity: e.currentTarget.dataset.type,
  215. // communityflag:true,
  216. nowcommunitname: e.currentTarget.dataset.text,
  217. })
  218. this.caselistfun();
  219. },
  220. opencommunitytap:function(){
  221. this.setData({
  222. communityflag:true,
  223. })
  224. },
  225. dothis:function(){},
  226. openVRLink(e) {
  227. let id = e.currentTarget.dataset.id;
  228. let vrlink = e.currentTarget.dataset.vrlink;
  229. wx.navigateTo({
  230. url: '/pages/other/other?type=565&vrlink=' + encodeURIComponent(vrlink) + '&cty=materialCase' + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype + '&aid=' + id,
  231. })
  232. },
  233. colsecommunitytap:function(){
  234. this.setData({
  235. communityflag:false
  236. })
  237. },
  238. sethousetypetap: function (e) {
  239. this.setData({
  240. nowhousetype: e.currentTarget.dataset.type
  241. })
  242. this.caselistfun();
  243. },
  244. casemsgtap: function (e) {
  245. wx.navigateTo({
  246. url: '/pages/decorateguidemsg/decorateguidemsg?cid=' + e.currentTarget.dataset.cid+"&type="+this.data.type
  247. })
  248. },
  249. /**
  250. * 生命周期函数--监听页面初次渲染完成
  251. */
  252. onReady: function () {
  253. },
  254. /**
  255. * 生命周期函数--监听页面显示
  256. */
  257. onShow: function () {
  258. },
  259. /**
  260. * 生命周期函数--监听页面隐藏
  261. */
  262. onHide: function () {
  263. },
  264. /**
  265. * 生命周期函数--监听页面卸载
  266. */
  267. onUnload: function () {
  268. },
  269. /**
  270. * 页面相关事件处理函数--监听用户下拉动作
  271. */
  272. onPullDownRefresh: function () {
  273. var that = this;
  274. casepage = 1;
  275. utils.$get({
  276. url: app.globalData.webUrl + 'client/caselist',
  277. header: {
  278. 'Authorization': 'bearer ' + app.globalData.token
  279. },
  280. data: {
  281. page: 1,
  282. uid: app.globalData.personMsg.id,
  283. commu_id: that.data.nowcommunity, // 小区id
  284. style_id: that.data.nowstyle, //风格id
  285. square_start: that.data.square_start, //面积开始值
  286. square_end: that.data.square_end, //面积结束值
  287. keyword: that.data.keyword,
  288. housetype_id: that.data.nowhousetype,
  289. case_type:this.data.noweffect,
  290. },
  291. success: function (res) {
  292. wx.stopPullDownRefresh()
  293. if (res.data.code == '0') {
  294. that.setData({
  295. caselist: res.data.data
  296. })
  297. }
  298. setTimeout(function () {
  299. wx.hideLoading()
  300. }, 1000)
  301. }
  302. })
  303. },
  304. /**
  305. * 页面上拉触底事件的处理函数
  306. */
  307. onReachBottom: function () {
  308. var that = this;
  309. casepage = casepage * 1 + 1;
  310. utils.$get({
  311. url: app.globalData.webUrl + 'client/caselist',
  312. header: {
  313. 'Authorization': 'bearer ' + app.globalData.token
  314. },
  315. data: {
  316. page: casepage,
  317. uid: app.globalData.personMsg.id,
  318. commu_id: that.data.nowcommunity, // 小区id
  319. style_id: that.data.nowstyle, //风格id
  320. square_start: that.data.square_start, //面积开始值
  321. square_end: that.data.square_end, //面积结束值
  322. keyword: that.data.keyword,
  323. housetype_id: that.data.nowhousetype,
  324. case_type:this.data.noweffect,
  325. },
  326. success: function (res) {
  327. let caselist = that.data.caselist;
  328. if (res.data.code == '0') {
  329. caselist = caselist.concat(res.data.data);
  330. that.setData({
  331. caselist: caselist
  332. })
  333. }
  334. setTimeout(function () {
  335. wx.hideLoading()
  336. }, 1000)
  337. }
  338. })
  339. },
  340. addsharetap: function (type) {
  341. let that = this;
  342. utils.$post({
  343. url: app.globalData.webUrl + 'api/share/addlog',
  344. header: {
  345. 'Authorization': 'bearer ' + app.globalData.token
  346. },
  347. data: {
  348. id: '0',
  349. type: type,
  350. },
  351. success: function (r) {}
  352. })
  353. },
  354. /**
  355. * 用户点击右上角分享
  356. */
  357. onShareAppMessage: function() {
  358. this.addsharetap('toolAll');
  359. return {
  360. title: app.globalData.personMsg.binded.name + "的装修案例",
  361. imageUrl: app.globalData.imgUrl + "xcx/caseposter.jpg",
  362. path: '/share/pages/caselist/caselist?u=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype + '&c=&s=&st=&e=&h='
  363. }
  364. }
  365. })