123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637 |
- // index/pages/casemsg/casemsg.js
- const app = getApp();
- var utils = require("../../utils/http")
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- top: app.globalData.statusBarHeight,
- hgt: app.globalData.titleBarHeight,
- imgUrl: app.globalData.imgUrl,
- companyobj: app.globalData.companyobj,
- communityht: '',
- cid: '',
- casemsgobj: {},
- page: 1,
- shareid: '',
- loginFlag: true,
- mobileflag: false,
- canIUseGetUserProfile: false,
- contentmsg: '',
- articlelogin: true,
- datashow: false,
- mobile: false,
- personMsg: app.globalData.personMsg,
- caselist: [],
- leftcaselist: [],
- rightcaselist: [],
- sharepersonMsg: app.globalData.sharepersonobj,
- employeeflag: false, //false是用户,true是员工
- showAddress: false,
- imgarr: [],
- type: '',//为空就是从微官网进来的,否则就是从工具中进来
- ctype: '',
- priceflag: false,
- swiperIndex:0,
- tab: [{
- name: 'VR案例',
- type: 'vr',
- count: 0
- }, {
- name: '视频案例',
- type: 'video',
- count: 0
- }],
- activeType: '',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var that = this;
- wx.showLoading({
- title: '加载中...',
- })
- if (!!options.scene && !that.data.cid) {
- options = unescape(options.scene);
- let arr = options.split('&');
- let obj = {};
- for (let i = 0; i < arr.length; i++) {
- let arr1 = arr[i].split('=');
- obj[arr1[0]] = arr1[1];
- }
- this.setData({
- cid: obj.cid,
- })
- app.globalData.clientype = obj.cli;
- that.logindata();
- } else {
- this.setData({
- cid: options.cid,
- companyobj: app.globalData.companyobj,
- employeeflag: (!!app.globalData.personMsg.binded && app.globalData.personMsg.binded.state == '在职') ? true : false
- })
- that.casemsgfun('1');
- }
- if (options.type) {
- this.setData({
- type: options.type
- })
- }
- this.setData({
- personMsg: app.globalData.personMsg,
- sharepersonMsg: app.globalData.sharepersonobj,
- top: app.globalData.statusBarHeight,
- hgt: app.globalData.titleBarHeight,
- imgUrl: app.globalData.imgUrl,
- companyobj: app.globalData.companyobj,
- })
- wx.showLoading({
- title: '加载中...',
- })
- },
- logindata: function () {
- var that = this;
- wx.showLoading();
- wx.login({
- success: function (data) {
- if (data.errMsg == 'login:ok') {
- utils.$post({
- url: app.globalData.webUrl + 'api/users/code2session',
- data: {
- client_type: that.data.clientype,
- code: data.code,
- },
- success: function (r) {
- if (r.data.code == '0') {
- app.globalData.sharepersonobj = r.data.share;
- app.globalData.token = r.data.token;
- that.sharecompany();
- that.casemsgfun('1');
- if (r.data.user != null && (!!r.data.user.headimgurl && r.data.user.headimgurl != "" || !!r.data.user.nickname && r.data.user.nickname != "" && r.data.user.nickname != '游客')) {
- app.globalData.use_id = r.data.user.id;
- app.globalData.personMsg = r.data.user;
- app.globalData.userflag = false; //有个人信息
- var nickname = r.data.user.nickname;
- var phone = r.data.user.phone;
- that.setData({
- loginFlag: true,
- datashow: true,
- })
- if (r.data.user.phone != '') {
- app.globalData.personMsg = r.data.user;
- that.setData({
- mobileflag: false
- })
- } else {
- that.setData({
- phoneFlag: true
- })
- }
- } else {
- wx.hideLoading();
- that.setData({
- articlelogin: false,
- loginFlag: false
- })
- }
- } else {
- wx.hideLoading();
- that.setData({
- articlelogin: false,
- loginFlag: true
- })
- }
- }
- })
- } else {
- wx.hideLoading();
- that.setData({
- articlelogin: false,
- loginFlag: true
- })
- }
- }
- })
- },
- designertap(){
- if(!!this.data.casemsgobj.designer_id){
- if(this.data.type){
- wx.navigateTo({
- url: '/customer/pages/designermsg/designermsg?did='+this.data.casemsgobj.designer_id+"&sid="+this.data.casemsgobj.designer_id+'&type=1'
- })
- }else{
- wx.navigateTo({
- url: '/share/pages/designermsg/designermsg?did='+this.data.casemsgobj.designer_id+"&type=3"
- })
- }
- }
- },
- 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.currentUserId = res.data.data.employee_id;
- app.globalData.companyobj=res.data.data;
- that.setData({
- companyobj: res.data.data
- })
- }
- },
- complete(res) {
- wx.hideLoading()
- }
- })
- },
- phonrtap: function () {
- wx.makePhoneCall({
- phoneNumber: app.globalData.sharepersonobj.phone //仅为示例,并非真实的电话号码
- })
- },
- priceshowtap() {
- this.setData({
- priceflag: true
- })
- },
- swiperChange (e) {
- let type = e.detail.currentItemId.split('-')[0];
- this.setData({
- activeType: type
- })
- },
- closepricetap() {
- this.setData({
- priceflag: false
- })
- },
- setypetap(e) {
- this.setData({
- ctype: e.currentTarget.dataset.type
- })
- },
- prelookimgtap() {
- 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链接列表
- })
- },
- pricetap: function () {
- wx.navigateTo({
- url: '/customer/pages/figureprice/figureprice',
- })
- },
- designTap: function () {
- wx.navigateTo({
- url: '/customer/pages/findesign/findesign',
- })
- },
- handleSwitch(e) {
- let type = e.currentTarget.dataset.type;
- let swiperIndex=0;
- if (type == 'vr') {
- swiperIndex = 0;
- } else if (type == 'video') {
- swiperIndex = !!this.data.casemsgobj.vr_case?1:0;
- }
- this.setData({
- swiperIndex: swiperIndex,
- activeType: type,
- })
- },
- openVRLink(e) {
- let type = e.currentTarget.dataset.type;
- if (type == 1) {
- let vrlink = this.data.casemsgobj.vr_case;
- wx.navigateTo({
- url: '/pages/other/other?type=565&vrlink=' + encodeURIComponent(vrlink) + '&cty=materialCase' + '&uid=' + (app.globalData.shareuserid?app.globalData.shareuserid:app.globalData.personMsg.id) + '&ctp=' + app.globalData.clientype + '&aid=' + this.data.casemsgobj.id,
- })
- } else {
- let vrlink = e.currentTarget.dataset.vrlink;
- let aid = e.currentTarget.dataset.id;
- wx.navigateTo({
- url: '/pages/other/other?type=565&vrlink=' + encodeURIComponent(vrlink) + '&cty=materialCase' + '&uid=' + (app.globalData.shareuserid?app.globalData.shareuserid:app.globalData.personMsg.id) + '&ctp=' + app.globalData.clientype + '&aid=' + aid,
- })
- }
- },
- casemsgfun: function (type) {
- var that = this;
- utils.$get({
- url: app.globalData.webUrl + 'client/casedetail',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- id: that.data.cid
- },
- success: function (res) {
- setTimeout(function () {
- wx.hideLoading()
- }, 500)
- let tab=that.data.tab;
- if (res.data.code == '0') {
- wx.setNavigationBarTitle({
- title: res.data.data.title
- })
- if (!res.data.data.desc) {
- if (!res.data.data.real_case) {
- that.setData({
- ctype: ''
- })
- } else {
- that.setData({
- ctype: 2
- })
- }
- } else {
- if (res.data.data.desc != '<p><br></p>') {
- that.setData({
- ctype: 1
- })
- } else {
- that.setData({
- ctype: 2
- })
- }
- }
- if(!!res.data.data.video_case){
- tab[1].count=1;
- that.setData({
- tab: tab,
- activeType:'video'
- })
- }
- if(!!res.data.data.vr_case){
- tab[0].count=1;
- that.setData({
- tab: tab,
- activeType:'vr'
- })
- }
- let length = res.data.data.desc.length / 3;
- let str = res.data.data.desc.substring(0, length);
- that.setData({
- casemsgobj: res.data.data,
- contentmsg: str,
- caselist: res.data.data.designer_related_cases,
- leftcaselist: [],
- rightcaselist: [],
- })
- if (res.data.data.from == 1) {
- that.setData({
- imgarr: JSON.parse(res.data.data.img_content)
- })
- }
- var article = res.data.data.desc;
- that.setData({
- contentmsg: str
- })
- if (res.data.data.designer_related_cases.length > 0) {
- that.imgload();
- }
- }
- }
- })
- },
- prelook(e) {
- let arr = [];
- for (let i in this.data.imgarr) {
- arr.push(app.globalData.imgUrl + this.data.imgarr[i].img);
- }
- wx.previewImage({
- current: e.currentTarget.dataset.img, // 当前显示图片的 http 链接
- urls: arr // 需要预览的图片 http 链接列表
- })
- },
- showAddressName(e) {
- let type = e.currentTarget.dataset.type;
- if (type == 'hide') {
- this.setData({
- showAddress: false
- })
- } else {
- this.setData({
- showAddress: true
- })
- }
- },
- getPhoneNumberTap: function (res) {
- var that = this;
- 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') {
- // wx.showLoading({
- // title: '加载中',
- // })
- if (res.currentTarget.dataset.type == 1) {
- that.orderfun();
- }
- app.globalData.phone = true;
- } else {
- that.setData({
- errorText: r.data.msg,
- errorflag: true
- })
- }
- }
- })
- }
- },
- orderfun() {
- const that = this;
- utils.$post({
- url: app.globalData.webUrl + 'client/material/designer_reserve',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- id:that.data.cid,
- designer_id:that.data.casemsgobj.designer_id?that.data.casemsgobj.designer_id:'',
- type:'materialCase',
- share_uid:app.globalData.shareuserid
- },
- success: function (res) {
- if (res.data.code == '0') {
- wx.showToast({
- title: res.data.msg,
- icon: "none",
- duration: 2000
- });
- }
- }
- })
- },
- imgload: function () {
- var that = this;
- var leftlist = that.data.leftcaselist;
- var rightlist = that.data.rightcaselist;
- var indexlist = that.data.caselist;
- if (indexlist.length == 0) {
- return false;
- }
- if (leftlist.length == 0) {
- leftlist.push(indexlist[0]);
- indexlist.shift();
- that.setData({
- caselist: indexlist,
- leftcaselist: leftlist,
- rightcaselist: rightlist
- })
- } else {
- var leftheight, rightheight;
- const query = wx.createSelectorQuery()
- query.select('.leftcasebox').boundingClientRect();
- query.exec(function (res) {
- leftheight = res[0].height;
- const queryright = wx.createSelectorQuery()
- queryright.select('.rightcasebox').boundingClientRect();
- queryright.exec(function (rs) {
- leftlist = that.data.leftcaselist;
- rightlist = that.data.rightcaselist;
- indexlist = that.data.caselist;
- rightheight = rs[0].height;
- if (leftheight <= rightheight) {
- leftlist.push(indexlist[0]);
- indexlist.shift();
- } else {
- rightlist.push(indexlist[0]);
- indexlist.shift();
- }
- that.setData({
- caselist: indexlist,
- leftcaselist: leftlist,
- rightcaselist: rightlist
- })
- })
- })
- }
- },
- casemsgtap: function (e) {
- wx.redirectTo({
- url: '/pages/decorateguidemsg/decorateguidemsg?cid=' + e.currentTarget.dataset.cid + "&uid=" + app.globalData.shareuserid
- })
- },
- precasetap: function () {
- if (!this.data.casemsgobj.preid) {
- wx.showToast({
- title: '已经第一篇了!',
- icon: 'none',
- duration: 2000
- })
- return false
- }
- wx.redirectTo({
- url: '/share/pages/materialcase/materialcase?type=3&cid=' + this.data.casemsgobj.preid + '&uid=' + this.data.shareid
- })
- },
- nextcasetap: function () {
- if (!this.data.casemsgobj.nextid) {
- wx.showToast({
- title: '已经到头了!',
- icon: 'none',
- duration: 2000
- })
- return false
- }
- wx.redirectTo({
- url: '/share/pages/materialcase/materialcase?type=3&cid=' + this.data.casemsgobj.nextid + '&uid=' + this.data.shareid
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- lasttap: function () {
- wx.reLaunch({
- url: '/pages/index/index'
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.setData({
- personMsg: app.globalData.personMsg,
- sharepersonMsg: app.globalData.sharepersonobj,
- top: app.globalData.statusBarHeight,
- hgt: app.globalData.titleBarHeight,
- imgUrl: app.globalData.imgUrl,
- companyobj: app.globalData.companyobj,
- })
- },
- otherlistfun: function () {
- var that = this;
- var page = that.data.page;
- page = page * 1 + 1;
- utils.$post({
- url: app.globalData.webUrl + 'client/designercases',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- page: page,
- limit: 4,
- designer_id: that.data.casemsgobj.designer_id,
- material_case_id:this.data.cid
- },
- success: function (res) {
- that.setData({
- page: page
- })
- if (res.data.code == '0') {
- var caselist = that.data.caselist;
- var arrflag = false;
- if (res.data.data.length == 0) {
- wx.showToast({
- title: '暂无更多数据',
- icon: 'none',
- duration: 2000
- })
- } else {
- if (caselist.length != 0) {
- arrflag = true;
- }
- caselist = caselist.concat(res.data.data);
- that.setData({
- caselist: caselist
- });
- if (!arrflag) {
- that.imgload();
- }
- }
- }
- }
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- addsharetap: function () {
- let that = this;
- utils.$post({
- url: app.globalData.webUrl + 'api/share/addlog',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- id: that.data.cid,
- type: 'materialCase',
- },
- success: function (r) {}
- })
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- this.addsharetap();
- var img = this.data.casemsgobj.cover_img;
- img = img.replace('http://o.nczyzs.com/', 'https://o.nczyzs.com/');
- return {
- title: this.data.casemsgobj.title,
- imageUrl: img,
- path: '/share/pages/materialcase/materialcase?cid=' + this.data.cid + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype
- }
- }
- })
|