designerlist.js 12 KB

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