designerlist.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. const app = getApp();
  2. var utils = require("../../../utils/http"),
  3. page = 1;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. canIUseGetUserProfile: false,
  10. shareobj: {},
  11. employeeflag: false, //false是用户,true是员工
  12. top: app.globalData.statusBarHeight,
  13. hgt: app.globalData.titleBarHeight,
  14. companyobj: {},
  15. datashow: false,
  16. sourceflag: false,
  17. houseflag: false,
  18. likestyle: '',
  19. likehouse: '',
  20. stylearr: [],
  21. housearr: [],
  22. designlist: [],
  23. phoneFlag: app.globalData.phone, //true是有手机号,false是没有手机号
  24. type: '',
  25. orgarr: [],
  26. orgobj: {},
  27. noworg: {
  28. id: '',
  29. name: ''
  30. },
  31. orgName:'',
  32. orgId:'',
  33. orgshow: false,
  34. levelIds: ['1'],
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. wx.showLoading({
  41. title: '加载中...',
  42. })
  43. if (options.type) {
  44. this.setData({
  45. type: options.type
  46. })
  47. }
  48. this.setData({
  49. phoneFlag: app.globalData.phone
  50. })
  51. this.houseinfofun();
  52. this.orgfun();
  53. },
  54. dothis(){},
  55. orgfun() {
  56. const that = this;
  57. utils.$post({
  58. url: app.globalData.webUrl + 'client/designer/designer_org',
  59. header: {
  60. 'Authorization': 'bearer ' + app.globalData.token
  61. },
  62. data: {},
  63. success: function (res) {
  64. if (res.data.code == "0") {
  65. that.setData({
  66. orgobj: res.data.data,
  67. orgarr: res.data.data
  68. })
  69. }
  70. }
  71. })
  72. },
  73. handleLevel(e) {
  74. let id = e.currentTarget.dataset.id;
  75. this.setDepartData(this.data.orgobj, id);
  76. },
  77. setDepartData(list, id, level) {
  78. list.forEach(item => {
  79. if (id == item.id) {
  80. if (!item.children || !item.children.length) {
  81. wx.showToast({
  82. title: '没有下级部门了',
  83. icon: 'none',
  84. duration: 1000
  85. })
  86. } else {
  87. if (level) {
  88. this.setData({
  89. orgarr: item.children,
  90. levelIds: this.data.levelIds,
  91. })
  92. } else {
  93. this.data.levelIds.push(id);
  94. this.setData({
  95. orgarr: item.children,
  96. levelIds: this.data.levelIds,
  97. })
  98. }
  99. }
  100. return;
  101. } else {
  102. if (item.children && item.children.length) {
  103. this.setDepartData(item.children, id, level);
  104. }
  105. }
  106. })
  107. },
  108. lastLevel() {
  109. if (this.data.levelIds.length == 2) {
  110. this.setData({
  111. orgarr: this.data.orgobj,
  112. levelIds: ['1'],
  113. })
  114. } else {
  115. this.data.levelIds.splice(this.data.levelIds.length - 1, 1);
  116. this.setDepartData(this.data.orgobj, this.data.levelIds[this.data.levelIds.length - 1], 'lastlevel');
  117. }
  118. },
  119. radioChange(e) {
  120. let data = e.detail.value.split('~');
  121. let obj = {
  122. name: data[1],
  123. id: data[0]
  124. };
  125. this.setData({
  126. noworg: obj
  127. })
  128. },
  129. showorgtap(){
  130. this.setData({
  131. orgshow:true
  132. })
  133. },
  134. closeMask() {
  135. this.setData({
  136. orgshow: false,
  137. levelIds: ['1'],
  138. noworg: {
  139. id: '',
  140. name: ''
  141. },
  142. orgarr:this.data.orgobj
  143. })
  144. },
  145. confirmDepart() {
  146. this.setData({
  147. orgName: this.data.noworg.name,
  148. orgId: this.data.noworg.id,
  149. orgshow: false,
  150. levelIds: ['1'],
  151. noworg: {
  152. id: '',
  153. name: ''
  154. },
  155. orgarr:this.data.orgobj
  156. });
  157. this.designlistfun();
  158. },
  159. /**
  160. * 生命周期函数--监听页面初次渲染完成
  161. */
  162. onReady: function () {
  163. },
  164. showstyletap() {
  165. this.setData({
  166. sourceflag: true
  167. })
  168. },
  169. housetap() {
  170. this.setData({
  171. houseflag: true
  172. })
  173. },
  174. setsourcetap(e) {
  175. if (!e.detail) {
  176. this.setData({
  177. sourceflag: false
  178. })
  179. return false;
  180. }
  181. this.setData({
  182. likestyle: e.detail,
  183. sourceflag: false
  184. })
  185. this.designlistfun();
  186. },
  187. sethousetap(e) {
  188. if (!e.detail) {
  189. this.setData({
  190. houseflag: false
  191. })
  192. return false;
  193. }
  194. this.setData({
  195. likehouse: e.detail,
  196. houseflag: false
  197. })
  198. this.designlistfun();
  199. },
  200. setinitap() {
  201. this.setData({
  202. likehouse: '',
  203. likestyle: '',
  204. orgName:'',
  205. orgId:'',
  206. })
  207. this.designlistfun();
  208. },
  209. houseinfofun() {
  210. this.designlistfun();
  211. const that = this;
  212. utils.$post({
  213. url: app.globalData.webUrl + 'api/designer/select',
  214. header: {
  215. 'Authorization': 'bearer ' + app.globalData.token
  216. },
  217. data: {},
  218. success: function (res) {
  219. wx.hideLoading()
  220. let stylearr = [],
  221. housearr = [];
  222. if (res.data.code == "0") {
  223. for (let i in res.data.data.decostyles) {
  224. stylearr.push(res.data.data.decostyles[i].name);
  225. }
  226. for (let i in res.data.data.housetype) {
  227. housearr.push(res.data.data.housetype[i].name);
  228. }
  229. that.setData({
  230. stylearr: stylearr,
  231. housearr: housearr
  232. })
  233. }
  234. }
  235. })
  236. },
  237. designlistfun() {
  238. const that = this;
  239. page = 1;
  240. wx.showLoading({
  241. title: '加载中...',
  242. })
  243. utils.$post({
  244. url: app.globalData.webUrl + 'client/designer/index',
  245. header: {
  246. 'Authorization': 'bearer ' + app.globalData.token
  247. },
  248. data: {
  249. at: that.data.likestyle,
  250. house: that.data.likehouse,
  251. limit: 10,
  252. page: 1,
  253. org_id:this.data.orgId
  254. },
  255. success: function (res) {
  256. if (res.data.code == "0") {
  257. that.setData({
  258. datashow: true,
  259. designlist: res.data.data
  260. })
  261. }
  262. wx.hideLoading()
  263. }
  264. })
  265. },
  266. apointap: function (e) {
  267. const that = this;
  268. let item = this.data.designlist[e.currentTarget.dataset.idx];
  269. utils.$post({
  270. url: app.globalData.webUrl + 'client/designer/designer_make',
  271. header: {
  272. 'Authorization': 'bearer ' + app.globalData.token
  273. },
  274. data: {
  275. designer_id: item.designer_id,
  276. designer_name: item.name,
  277. share_uid: app.globalData.shareuserid
  278. },
  279. success: function (res) {
  280. if (res.data.code == "0") {
  281. wx.showToast({
  282. title: res.data.msg,
  283. icon: 'none',
  284. duration: 2000
  285. })
  286. }
  287. }
  288. })
  289. },
  290. getPhoneNumberTap: function (res) {
  291. var that = this;
  292. console.log(res)
  293. if (res.detail.errMsg == 'getPhoneNumber:ok') {
  294. utils.$post({
  295. url: app.globalData.webUrl + 'api/users/setUserMobile',
  296. data: {
  297. encryptedData: res.detail.encryptedData,
  298. iv: res.detail.iv
  299. },
  300. header: {
  301. 'Authorization': 'bearer ' + app.globalData.token
  302. },
  303. success: function (r) {
  304. if (r.data.code == '0') {
  305. // wx.showLoading({
  306. // title: '加载中',
  307. // })
  308. app.globalData.phone = true;
  309. that.setData({
  310. phoneFlag: false
  311. })
  312. that.apointap(res);
  313. } else {
  314. that.setData({
  315. errorText: r.data.msg,
  316. errorflag: true
  317. })
  318. }
  319. }
  320. })
  321. }
  322. },
  323. designertap: function (e) {
  324. let item = this.data.designlist[e.currentTarget.dataset.idx];
  325. wx.navigateTo({
  326. url: '/customer/pages/designermsg/designermsg?did=' + item.id + "&sid=" + item.id + '&type=' + this.data.type
  327. })
  328. },
  329. /**
  330. * 生命周期函数--监听页面显示
  331. */
  332. onShow: function () {
  333. },
  334. golastap: function () {
  335. wx.reLaunch({
  336. url: '/pages/index/index?state=1',
  337. })
  338. },
  339. goindextap: function () {
  340. wx.reLaunch({
  341. url: '/pages/index/index?state=1',
  342. })
  343. },
  344. /**
  345. * 生命周期函数--监听页面隐藏
  346. */
  347. onHide: function () {
  348. },
  349. dothis() {},
  350. /**
  351. * 生命周期函数--监听页面卸载
  352. */
  353. onUnload: function () {
  354. },
  355. /**
  356. * 页面相关事件处理函数--监听用户下拉动作
  357. */
  358. onPullDownRefresh: function () {
  359. this.designlistfun();
  360. wx.stopPullDownRefresh();
  361. },
  362. /**
  363. * 页面上拉触底事件的处理函数
  364. */
  365. onReachBottom: function () {
  366. const that = this;
  367. page = page * 1 + 1;
  368. wx.showLoading({
  369. title: '加载中...',
  370. })
  371. utils.$post({
  372. url: app.globalData.webUrl + 'client/designer/index',
  373. header: {
  374. 'Authorization': 'bearer ' + app.globalData.token
  375. },
  376. data: {
  377. at: that.data.likestyle,
  378. house: that.data.likehouse,
  379. limit: 10,
  380. page: page,
  381. org_id:this.data.orgId
  382. },
  383. success: function (res) {
  384. wx.hideLoading();
  385. if (res.data.code == "0") {
  386. let designlist = that.data.designlist;
  387. designlist = designlist.concat(res.data.data);
  388. that.setData({
  389. designlist: designlist
  390. })
  391. }
  392. }
  393. })
  394. },
  395. onShareAppMessage: function (e) {
  396. // 公司名设计师:设计师名
  397. let that = this;
  398. let title = "设计大师-" + app.globalData.companyobj.company_name,
  399. img = app.globalData.imgUrl + "/xcx/designerlisticon.jpg",
  400. pathurl = '/share/pages/designerlist/designerlist?uid=' + (app.globalData.sharepersonobj&&app.globalData.sharepersonobj.id?app.globalData.sharepersonobj.id:app.globalData.personMsg.id) + '&ctp=' + app.globalData.clientype;
  401. if (!!e.target && e.target.dataset.type == 'designermsg') {
  402. let idx = e.target.dataset.idx;
  403. title = (this.data.designlist[idx].name ? this.data.designlist[idx].name : this.data.designlist[idx].opt_name) + '-' + app.globalData.companyobj.company_name;
  404. if (this.data.designlist[idx].headimgurl) {
  405. img = this.data.designlist[idx].headimgurl;
  406. }
  407. pathurl = '/share/pages/designermsg/designermsg?uid=' + (app.globalData.sharepersonobj&&app.globalData.sharepersonobj.id?app.globalData.sharepersonobj.id:app.globalData.personMsg.id) + '&did=' + this.data.designlist[idx].id + '&ctp=' + app.globalData.clientype;
  408. }
  409. return {
  410. title: title,
  411. imageUrl: img,
  412. path: pathurl
  413. }
  414. }
  415. })