123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876 |
- // share/pages/shareCard/shareCard.js
- var app = getApp();
- var utils = require("../../../utils/http");
- let evpage = 1, casepage = 1;
- let time = 0;
- var timer = null;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- canIUseGetUserProfile: false,
- shareobj: {},
- employeeflag: false,//false是用户,true是员工
- top: app.globalData.statusBarHeight,
- hgt: app.globalData.titleBarHeight,
- companyobj: {},
- loginFlag: false,
- phoneFlag: false,
- imgUrl: app.globalData.imgUrl,
- mineinfo: {
- name: ''
- },
- logcount: 0,
- imgarr: [],
- type: 1,
- evidencetype: '',
- evidencelist: [],
- leftevidencelist: [],
- rightevidencelist: [],
- catetype: '',
- datashow: true,
- nowstyle: '',
- stylelist: [],
- square_start: '', //面积开始值
- square_end: '', //面积结束值
- nowcommunity: '',
- communitylist: [],
- nowhousetype: '',
- housetypelist: [],
- caselist: [],
- keyword: '',
- datashow: false,
- communityflag: false,
- isAgree: false,
- nowcommunitname: '',
- fromType: '',
- typearr: [
- { id: 1, name: '效果案例', type: 1 },
- { id: 2, name: '实景案例', type: 2 }
- ],
- noweffect: '',
- prelook: '',
- timeline: app.globalData.timeline
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (opts) {
- var that = this;
- time = 0;
- if (opts.type == 'share') {
- this.setData({
- prelook: "share"
- })
- }
- if (app.globalData.timeline != 2) {
- wx.showLoading();
- }
- if (wx.getUserProfile) {
- this.setData({
- canIUseGetUserProfile: true
- })
- }
- that.setData({
- top: app.globalData.statusBarHeight,
- hgt: app.globalData.titleBarHeight,
- imgUrl: app.globalData.imgUrl,
- fromType: opts.ftype
- })
- app.globalData.clientype = opts.ctp;
- if (opts.empid) {
- app.globalData.sharempid = opts.empid;
- }
- app.globalData.shareuserid = opts.uid;
- },
- //用户同意隐私协议
- agreePrivacy() {
- this.setData({
- isAgree: true
- })
- this.loginfun();
- },
- 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
- })
- app.globalData.sharempid = res.data.data.employee_id;
- }
- },
- complete(res) {
- wx.hideLoading()
- }
- })
- },
- loginfun: function (e) {
- var that = this;
- wx.showLoading({
- title: '加载中...',
- })
- if (!!e) {
- this.setData({
- type: e
- })
- }
- wx.login({
- success: function (data) {
- if (data.errMsg == 'login:ok') {
- utils.$post({
- url: app.globalData.webUrl + 'api/users/code2session',
- data: {
- code: data.code,
- share: app.globalData.shareuserid,
- clien_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();
- if (r.data.share) {
- app.globalData.vrString = r.data.share.str;
- }
- that.setData({
- sharepersonMsg: app.globalData.sharepersonobj,
- })
- if (!!r.data.user.phone) {
- that.setData({
- loginFlag: false,
- phoneFlag: false,
- employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
- })
- app.globalData.personMsg = r.data.user;
- app.globalData.use_id = r.data.user.id;
- var obj = {
- detail: 1
- }
- that.cardfun(obj);
- } else {
- that.cardfun();
- wx.hideLoading();
- that.setData({
- loginFlag: false,
- phoneFlag: true
- })
- }
- }
- }
- })
- }
- }
- })
- },
- cardfun() {
- const that = this;
- utils.$post({
- url: app.globalData.webUrl + 'client/card/info',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- user: app.globalData.shareuserid,
- },
- success: function (res) {
- wx.hideLoading();
- if (res.data.code == 0) {
- that.setData({
- mineinfo: res.data.data,
- logcount: res.data.logcount,
- imgarr: res.data.log
- })
- }
- that.evidenceCate();
- that.evidencelist();
- that.casestylefun();
- that.housestylefun();
- that.casecommunityfun();
- that.caselistfun();
- }
- })
- },
- setypetap(e) {
- this.setData({
- type: e.target.dataset.num
- })
- if (e.target.dataset.num == 3) {
- this.evidencelist();
- }
- },
- preimgtap() {
- if (!this.data.mineinfo.qrcode) {
- wx.showToast({
- title: '员工二维码为空!',
- icon: 'none',
- duration: 2000
- })
- return false;
- }
- let img = app.globalData.imgUrl + '/' + this.data.mineinfo.qrcode;
- wx.previewImage({
- current: img, // 当前显示图片的 http 链接
- urls: [img] // 需要预览的图片 http 链接列表
- })
- },
- copytap() {
- if (!this.data.mineinfo.wx) {
- wx.showToast({
- title: '员工微信为空!',
- icon: 'none',
- duration: 2000
- })
- return false;
- }
- wx.setClipboardData({
- data: this.data.mineinfo.wx,
- success(res) {
- }
- })
- },
- callphonetap() {
- wx.makePhoneCall({
- phoneNumber: this.data.mineinfo.phone //仅为示例,并非真实的电话号码
- })
- },
- openVRLink(e) {
- let vrlink = e.currentTarget.dataset.vrlink;
- let id = e.currentTarget.dataset.id;
- wx.navigateTo({
- url: '/pages/other/other?type=vr&vrurl=' + escape(vrlink) + '&cty=materialCase' + '&uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype + '&aid=' + id,
- })
- },
- viewAuthorization() {
- return new Promise(function (resolve, reject) {
- wx.getSetting({
- success(res) {
- if (res.authSetting['scope.addPhoneContact']) {
- resolve({ authorize: true })
- } else {
- wx.openSetting({
- success(res) {
- if (res.authSetting['scope.addPhoneContact']) {
- wx.authorize({
- scope: 'scope.addPhoneContact',
- success: function (res) {
- console.log('success:', res);
- resolve({ authorize: true })
- },
- fail: function (error) {
- console.log('error:', error);
- reject({ authorize: false })
- }
- })
- } else {
- wx.authorize({
- scope: 'scope.addPhoneContact',
- success: function (res) {
- console.log('success:', res);
- resolve({ authorize: true })
- },
- fail: function (error) {
- console.log('error:', error);
- reject({ authorize: false })
- }
- })
- }
- },
- fail() {
- wx.authorize({
- scope: 'scope.addPhoneContact',
- success: function (res) {
- console.log('success:', res);
- resolve({ authorize: true })
- },
- fail: function (error) {
- console.log('error:', error);
- reject({ authorize: false })
- }
- })
- }
- })
- }
- }
- })
- })
- },
- async savenumtap() {
- let res = await this.viewAuthorization();
- if (res.authorize) {
- wx.addPhoneContact({
- firstName: this.data.mineinfo.name,
- photoFilePath: this.data.mineinfo.headimgurl,
- mobilePhoneNumber: this.data.mineinfo.phone,
- weChatNumber: this.data.mineinfo.wx,
- addressStreet: this.data.mineinfo.company_address,
- organization: this.data.mineinfo.company_name,
- title: this.data.mineinfo.position
- })
- return;
- }
- },
- evidenceCate: function () {
- var that = this;
- utils.$get({
- url: app.globalData.webUrl + 'client/material/evidenceCate',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {},
- success: function (res) {
- that.setData({
- evidencetype: res.data.data
- })
- }
- })
- },
- seteffectap(e) {
- this.setData({
- noweffect: e.currentTarget.dataset.type
- })
- this.caselistfun();
- },
- setevitap(e) {
- this.setData({
- catetype: e.currentTarget.dataset.eid
- })
- this.evidencelist();
- },
- evidencelist: function () {
- const that = this;
- evpage = 1;
- utils.$get({
- url: app.globalData.webUrl + 'client/evidencelist',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- uid: app.globalData.personMsg.id,
- page: 1,
- cate: that.data.catetype,
- },
- success: function (res) {
- setTimeout(function () {
- wx.hideLoading()
- }, 1000)
- if (res.data.code == '0') {
- that.setData({
- evidencelist: res.data.data,
- leftevidencelist: [],
- rightevidencelist: [],
- datashow: true
- })
- that.imgload();
- }
- },
- fail() {
- wx.hideLoading()
- }
- })
- },
- publictap: function (e) {
- wx.navigateTo({
- url: '/share/pages/publicpraisemsg/publicpraisemsg?type=3&eid=' + e.currentTarget.dataset.eid + "&uid=" + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype
- })
- },
- imgload: function () {
- var that = this;
- var leftlist = that.data.leftevidencelist;
- var rightlist = that.data.rightevidencelist;
- var indexlist = that.data.evidencelist;
- if (indexlist.length == 0) {
- return false;
- }
- if (!indexlist[0]) {
- return false;
- }
- if (leftlist.length == 0) {
- leftlist.push(indexlist[0]);
- indexlist.shift();
- that.setData({
- evidencelist: indexlist,
- leftevidencelist: leftlist,
- rightevidencelist: rightlist
- })
- } else {
- var leftheight, rightheight;
- wx.createSelectorQuery().select('.leftpublicpraisebox').boundingClientRect(function (res) {
- leftheight = res.height;
- wx.createSelectorQuery().select('.rightpublicpraisebox').boundingClientRect(function (rs) {
- leftlist = that.data.leftevidencelist;
- rightlist = that.data.rightevidencelist;
- indexlist = that.data.evidencelist;
- rightheight = rs.height;
- if (leftheight <= rightheight) {
- leftlist.push(indexlist[0]);
- indexlist.shift();
- } else {
- rightlist.push(indexlist[0]);
- indexlist.shift();
- }
- that.setData({
- evidencelist: indexlist,
- leftevidencelist: leftlist,
- rightevidencelist: rightlist
- })
- }).exec();
- }).exec();
- }
- },
- setliketap() {
- var that = this;
- utils.$get({
- url: app.globalData.webUrl + 'client/card/like',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- employee_id: app.globalData.sharempid
- },
- success: function (res) {
- let mineinfo = that.data.mineinfo;
- if (res.data.code == '0') {
- mineinfo.likes = mineinfo.likes * 1 + 1;
- that.setData({
- mineinfo: mineinfo
- })
- }
- }
- })
- },
- casestylefun: function () {
- var that = this;
- utils.$get({
- url: app.globalData.webUrl + 'client/stylelist',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {},
- success: function (res) {
- if (res.data.code == '0') {
- that.setData({
- stylelist: res.data.data
- })
- }
- }
- })
- },
- housestylefun: function () {
- var that = this;
- utils.$get({
- url: app.globalData.webUrl + 'client/material/housetypelist',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {},
- success: function (res) {
- if (res.data.code == '0') {
- that.setData({
- housetypelist: res.data.data
- })
- }
- }
- })
- },
- onChoose(e) {
- var that = this;
- that.setData({
- nowcommunity: e.detail.item.currentTarget.dataset.cid,
- nowcommunitname: e.detail.item.currentTarget.dataset.item.name,
- communityflag: false
- })
- wx.showLoading({
- title: '加载中...',
- })
- that.caselistfun();
- },
- casecommunityfun: function () {
- var that = this;
- utils.$get({
- url: app.globalData.webUrl + 'client/communitylist',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {},
- success: function (res) {
- if (res.data.code == '0') {
- that.setData({
- communitylist: res.data.data
- })
- }
- that.getCitys();
- }
- })
- },
- getCitys() {
- const _this = this
- const cities = this.data.communitylist;
- // 按拼音排序
- 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++) {
- 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].case_num;
- list[i].id = cities[j].id;
- }
- }
- }
- }
- _this.setData({ list: list })
- },
- selectareatap: function (e) {
- this.setData({
- square_start: e.currentTarget.dataset.start,
- square_end: e.currentTarget.dataset.end,
- })
- this.caselistfun();
- },
- caselistfun: function (e) {
- var that = this;
- casepage = 1;
- utils.$get({
- url: app.globalData.webUrl + 'client/caselist',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- page: 1,
- commu_id: that.data.nowcommunity, // 小区id
- style_id: that.data.nowstyle, //风格id
- square_start: that.data.square_start, //面积开始值
- square_end: that.data.square_end, //面积结束值
- keyword: that.data.keyword,
- housetype_id: that.data.nowhousetype,
- case_type: this.data.noweffect,
- },
- success: function (res) {
- that.setData({
- datashow: true
- })
- if (res.data.code == '0') {
- that.setData({
- caselist: res.data.data,
- })
- }
- setTimeout(function () {
- wx.hideLoading()
- }, 1000)
- },
- fail() {
- wx.hideLoading()
- }
- })
- },
- setstyletap: function (e) {
- this.setData({
- nowstyle: e.currentTarget.dataset.type
- })
- this.caselistfun();
- },
- setcommunitytap: function (e) {
- this.setData({
- nowcommunity: e.currentTarget.dataset.type,
- // communityflag:true,
- nowcommunitname: e.currentTarget.dataset.text,
- })
- this.caselistfun();
- },
- opencommunitytap: function () {
- this.setData({
- communityflag: true,
- })
- },
- dothis: function () { },
- colsecommunitytap: function () {
- this.setData({
- communityflag: false
- })
- },
- sethousetypetap: function (e) {
- this.setData({
- nowhousetype: e.currentTarget.dataset.type
- })
- this.caselistfun();
- },
- casemsgtap: function (e) {
- wx.navigateTo({
- url: '/index/pages/casemsg/casemsg?cid=' + e.currentTarget.dataset.cid,
- })
- },
- backTap: function () {
- if (this.data.fromType) {
- wx.navigateBack({
- delta: 1,
- })
- }
- // else {
- // wx.reLaunch({
- // url: '/pages/index/index?state=1',
- // })
- // }
- },
- casemsgtap: function (e) {
- wx.navigateTo({
- url: '/share/pages/materialcase/materialcase?type=3&cid=' + e.currentTarget.dataset.cid + '&uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype
- })
- },
- getPhoneNumberTap: function (res) {
- var that = this;
- that.setData({
- phoneFlag: false,
- })
- if (res.detail.errMsg == 'getPhoneNumber:ok') {
- utils.$post({
- url: app.globalData.webUrl + 'api/users/setUserMobile',
- data: {
- encryptedData: res.detail.encryptedData,
- iv: res.detail.iv
- },
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- success: function (r) {
- if (r.data.code == '0') {
- app.globalData.phone = true;
- that.setData({
- phoneFlag: false,
- })
- }
- }
- })
- }
- },
- searchplacetap() {
- if (!this.data.mineinfo.company_vr_address) {
- wx.showToast({
- title: 'VR链接为空!',
- icon: 'none',
- duration: 2000
- })
- return false;
- }
- app.globalData.vraddress = this.data.mineinfo.company_vr_address;
- let str = escape(app.globalData.vraddress);
- wx.navigateTo({
- url: '/pages/other/other?type=vr&ctp=' + app.globalData.clientype + '&uid=' + app.globalData.shareuserid + '&vrurl=' + str + '&aid=' + this.data.mineinfo.employee_id + '&cty=employeeCard',
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.setData({
- timeline: app.globalData.timeline
- })
- if (app.globalData.timeline == 2) {
- wx.hideLoading()
- }
- timer = setInterval(function () {
- time = time * 1 + 1;
- }, 1000)
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- if (timer) {
- clearInterval(timer)
- }
- this.visitimefun();
- },
- visitimefun() {
- if (!this.data.isAgree) {
- return false;
- }
- const that = this;
- utils.$post({
- url: app.globalData.webUrl + 'client/index/visit_due_time',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- id: that.data.mineinfo.employee_id,
- pipe_type: 'card',
- time: time,
- },
- success: function (res) {
- }
- })
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- this.visitimefun();
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- const that = this;
- if (this.data.type == 3) {
- evpage = evpage * 1 + 1;
- utils.$get({
- url: app.globalData.webUrl + 'client/evidencelist',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- page: evpage,
- cate: that.data.catetype,
- },
- success: function (res) {
- if (res.data.code == '0') {
- let evidencelist = that.data.evidencelist;
- var arrflag = false
- if (evidencelist.length != 0) {
- arrflag = true;
- }
- for (let i = 0; i < res.data.data.length; i++) {
- evidencelist.push(res.data.data[i])
- }
- that.setData({
- evidencelist: evidencelist
- })
- if (!arrflag) {
- that.imgload();
- }
- }
- }
- })
- } else if (this.data.type == 2) {
- casepage = casepage * 1 + 1;
- utils.$get({
- url: app.globalData.webUrl + 'client/caselist',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- page: casepage,
- commu_id: that.data.nowcommunity, // 小区id
- style_id: that.data.nowstyle, //风格id
- square_start: that.data.square_start, //面积开始值
- square_end: that.data.square_end, //面积结束值
- keyword: that.data.keyword,
- housetype_id: that.data.nowhousetype,
- case_type: this.data.noweffect,
- },
- success: function (res) {
- let caselist = that.data.caselist;
- if (res.data.code == '0') {
- caselist = caselist.concat(res.data.data);
- that.setData({
- caselist: caselist
- })
- }
- setTimeout(function () {
- wx.hideLoading()
- }, 1000)
- }
- })
- }
- },
- 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: function () {
- var that = this;
- that.addsharetap('card');
- wx.showShareMenu({
- withShareTicket: true,
- menus: ['shareAppMessage', 'shareTimeline']
- })
- return {
- title: this.data.mineinfo.name + "的个人名片",
- imageUrl: app.globalData.imgUrl + "/xcx/sharenamecard.png",
- path: '/share/pages/shareCard/shareCard?uid=' + app.globalData.shareuserid + '&empid=' + app.globalData.sharempid + '&ctp=' + app.globalData.clientype,
- };
- },
- onShareTimeline: function () {
- var that = this;
- that.addsharetap('card');
- app.globalData.shareuserid = app.globalData.personMsg.id;
- return {
- title: this.data.mineinfo.name + "的个人名片",
- query: 'uid=' + app.globalData.shareuserid + '&empid=' + app.globalData.personMsg.binded.id + '&ctp=' + app.globalData.clientype + '&type=share',
- imageUrl: app.globalData.imgUrl + "/xcx/sharenamecard.png",
- }
- }
- })
|