123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- const app=getApp();
- var utils = require("../../../utils/http");
- const util = require("../../../utils/util");
- let page=1,time = 0,timer = null;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- ordertype:'time',
- constructlist:[],
- site_id:'',
- sitename:'',
- casecommunitylist:[],
- list: [],
- filtrateflag:false,
- datashow:false,
- loginFlag:false,
- phoneFlag:false,
- canIUseGetUserProfile: false,
- shareobj:{},
- employeeflag:false,//false是用户,true是员工
- top:app.globalData.statusBarHeight,
- hgt:app.globalData.titleBarHeight,
- companyobj:{},
- imgUrl:app.globalData.imgUrl
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- const that=this;
- wx.hideHomeButton();
- time = 0;
- this.setData({
- top:app.globalData.statusBarHeight,
- hgt:app.globalData.titleBarHeight,
- })
- app.globalData.clientype=options.ctp;
- app.globalData.shareuserid = options.uid;
- if (wx.getUserProfile) {
- this.setData({
- canIUseGetUserProfile: true
- })
- }
- wx.showLoading({
- title: '加载中...',
- })
- that.login();
-
- },
- sharecompany:function (){
- const that=this;
- utils.$post({
- url: app.globalData.webUrl + 'client/index/content_belong_company',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- client_type:app.globalData.clientype,
- uid: app.globalData.shareuserid
- },
- success: function (res) {
- if(res.data.code=='0'){
- app.globalData.companyobj=res.data.data;
- that.setData({
- companyobj:res.data.data
- })
- }
- },
- complete(res) {
- wx.hideLoading()
- }
- })
- },
- login: function () {
- var that = this;
- wx.login({
- success: function (data) {
- if (data.errMsg == 'login:ok') {
- utils.$post({
- method: "POST", //TESTAPIURL APIURL/users/auth
- url: app.globalData.webUrl + 'api/users/code2sessionmini',
- data: {
- code: data.code,
- share: app.globalData.shareuserid,
- client_type:app.globalData.clientype
- },
- success: function (r) {
- if (r.data.code == '0') {
- app.globalData.sharepersonobj = r.data.share;
- app.globalData.token = r.data.token;
- that.sharecompany();
- that.setData({
- shareobj:app.globalData.sharepersonobj
- })
- util.toolfun(4);
- app.globalData.personMsg = r.data.user;
- app.globalData.companyname=r.data.company;
- app.globalData.official_openid = r.data.official_openid;
- app.globalData.agentEmployeEid = r.data.agent_employee_id;
- if (!!r.data.user.phone) {
- that.setData({
- datashow: true,
- loginFlag: false,
- phoneFlag:false,
- employeeflag:(!!r.data.user.binded&&r.data.user.binded.state=='在职')?true:false
- })
- if (!!r.data.user.binded && r.data.user.binded.state == '在职'){
- app.globalData.currentUserId = r.data.user.binded.id;
- }
- app.globalData.personMsg = r.data.user;
- app.globalData.userflag = false; //有个人信息
- var nickname = r.data.user.nickname;
- var phone = r.data.user.phone;
- app.globalData.phone = false; //没有手机号
- that.unreadMsg();
- } else {
- that.unreadMsg();
- wx.hideLoading();
- that.setData({
- loginFlag: false,
- phoneFlag: true
- })
- }
-
- } else {
- setTimeout(function () {
- wx.hideLoading()
- }, 500)
- }
- }
- })
- }
- }
- })
- },
- prelooktap(){
- if(!app.globalData.sharepersonobj.qrcode){
- wx.showToast({
- title: "当前专属客服的二维码为空!",
- icon: 'none',
- duration: 2000
- })
- return false;
- }
- wx.previewImage({
- current: app.globalData.imgUrl+app.globalData.sharepersonobj.qrcode, // 当前显示图片的http链接
- urls: [app.globalData.imgUrl+app.globalData.sharepersonobj.qrcode]// 需要预览的图片http链接列表
- })
- },
- unreadMsg(){
- this.constructfun();
- this.casecommunityfun();
- },
- golastap:function(){
- wx.navigateBack({
- delta: 1,
- success:function(r){
- },
- fail:function(r){
- wx.reLaunch({
- url: '/pages/index/index?state=1',
- })
- },
- })
- },
- goindextap:function(){
- if(!this.data.employeeflag){
- wx.reLaunch({
- url: '/pages/index/index?state=1',
- })
- }else{
- wx.reLaunch({
- url: '/pages/consoledesk/consoledesk',
- })
- }
- },
- callphonetap:function(){
- console.log()
- wx.makePhoneCall({
- phoneNumber: app.globalData.sharepersonobj.phone //仅为示例,并非真实的电话号码
- })
- },
- constructfun() {
- const that = this;
- page = 1;
- utils.$post({
- url: app.globalData.webUrl + 'client/construction/index',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- page: 1,
- limit: 10,
- community_id: this.data.site_id,
- order: this.data.ordertype == 'time' ? 'new' : 'hot'
- },
- success: function (res) {
- wx.hideLoading();
- if (res.data.code == 0) {
- that.setData({
- constructlist: res.data.data,
- })
- }
- }
- })
- },
- casecommunityfun: function () {
- var that = this;
- utils.$get({
- url: app.globalData.webUrl + 'client/construction/communitylist',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {},
- success: function (res) {
- if (res.data.code == '0') {
- that.setData({
- casecommunitylist: res.data.data
- })
- that.getCitys();
- }
- }
- })
- },
- getCitys() {
- const _this = this
- const cities = this.data.casecommunitylist;
- // 按拼音排序
- cities.sort((c1, c2) => {
- let pinyin1 = c1.pinyin;
- let pinyin2 = c2.pinyin;
- return pinyin1.localeCompare(pinyin2)
- })
- // 添加首字母
- const map = new Map()
- for (const city of cities) {
- const alpha = city.pinyin.charAt(0).toUpperCase()
- if (!map.has(alpha)) map.set(alpha, [])
- map.get(alpha).push({ name: city.name, id: city.id })
- }
- const keys = []
- for (const key of map.keys()) {
- keys.push(key)
- }
- keys.sort()
- const list = []
- for (const key of keys) {
- list.push({
- alpha: key,
- subItems: map.get(key)
- })
- }
- for (let i = 0; i < list.length; i++) {
- list[i].subItems[0].case_num = '0';
- for (let k = 0; k < list[i].subItems.length; k++) {
- for (let j = 0; j < cities.length; j++) {
- if (list[i].subItems[k].name == cities[j].name) {
- list[i].subItems[k].case_num = cities[j].construction_count;
- list[i].id = cities[j].id;
- }
- }
- }
- }
- _this.setData({ list: list })
- },
- onChoose(e) {
- var that = this;
- console.log(e)
- that.setData({
- site_id: e.detail.item.currentTarget.dataset.cid,
- sitename: e.detail.item.currentTarget.dataset.item.name
- })
- that.constructfun();
- },
- setordertypetap(e) {
- this.setData({
- ordertype: e.currentTarget.dataset.type
- })
- this.constructfun();
- },
- allfiltratetap: function () {
- this.casecommunityfun();
- this.setData({
- filtrateflag: true
- })
- },
- sitetap(e) {
- wx.navigateTo({
- url: '/share/pages/constructsite/constructsite?type=3&cid=' + e.currentTarget.dataset.cid+'&uid='+app.globalData.shareuserid+'&ctp='+app.globalData.clientype,
- })
- },
- closefiltratetap: function () {
- this.setData({
- filtrateflag: false
- })
- },
- dothis(){},
- deltap(e) {
- var that = this;
- that.setData({
- site_id: '',
- sitename: ''
- })
- that.constructfun();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- timer = setInterval(function () {
- time = time * 1 + 1;
- }, 1000)
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- if (timer) {
- clearInterval(timer)
- }
- this.setimetap();
- },
- setimetap(){
- const that = this;
- utils.$post({
- url: app.globalData.webUrl + 'client/index/visit_due_time',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- id: that.data.companyobj.employee_id,
- pipe_type: 'toolAll',
- time: time,
- },
- success: function (res) {
- }
- })
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- this.setimetap();
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- this.constructfun();
- wx.stopPullDownRefresh()
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- const that = this;
- page = page * 1 + 1;
- utils.$post({
- url: app.globalData.webUrl + 'client/construction/index',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- page: page,
- limit: 10,
- community_id: this.data.site_id,
- order: this.data.ordertype == 'time' ? 'new' : 'hot'
- },
- success: function (res) {
- wx.hideLoading();
- let constructlist = that.data.constructlist;
- if (res.data.code == 0) {
- constructlist = that.data.constructlist;
- constructlist = constructlist.concat(res.data.data);
- that.setData({
- constructlist: constructlist,
- })
- }
- }
- })
- },
- addsharetap: function (type) {
- let that = this;
- utils.$post({
- url: app.globalData.webUrl + 'api/share/addlog',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- id: '0',
- type: type,
- },
- success: function (r) {}
- })
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- this.addsharetap('toolAll');
- return {
- title: '在施工地-'+this.data.companyobj.company_name,
- imageUrl: app.globalData.imgUrl + 'xcx/aaa/constructcover.png',
- path: '/share/pages/constructsitelist/constructsitelist?uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype
- }
- }
- })
|