index.js 10 KB
/*
 * @Description:
 * @Author: huyue
 * @Date: 2022-08-30 11:26:21
 * @LastEditors: huyue
 * @LastEditTime: 2022-09-09 14:41:59
 */
// pages/tab/index/index.js
import { menuMixin } from "../../../mixins/index";
import Draw from "../../../utils/Draw";
import { ssoApi, entmicroApi } from "../../../api/api";
import util from "../../../utils/util";
import { trackData } from "../../../utils/data";
Page({
  behaviors: [menuMixin],
  /**
   * 页面的初始数据
   */
  data: {
    introduceName: "",
    tabList: [
      {
        name: "公司介绍",
        icon: "icon-company",
        icon1: "icon-company1",
      },
      {
        name: "方案介绍",
        icon: "icon-product",
        icon1: "icon-product1",
      },
      {
        name: "视频直播",
        icon: "icon-video",
        icon1: "icon-video",
      },
      // {
      //   name: "合作申请",
      //   icon: "icon-cooperation",
      //   icon1: "icon-cooperation",
      // },
    ],
    curTabIndex: 0,
    // 0-员工,1-代理商
    customerType: 0,
    // 是否授权昵称
    hasUserInfo: false,
    // 是否授权手机号
    hasPhoneNumber: false,
    curTab: [trackData.COMPANY, trackData.CUBE],
    // 员工名片信息
    cardInfo: null,
    defaultInfo: {
      staffName: '虚拟员工',
      operation: '虚拟职位',
      staffPhone: 'xxxxxxxx',
      image: 'https://img.zcool.cn/community/01e47e60ab5b4011013eaf70962e3f.jpg@520w_390h_1c_1e_2o_100sh.jpg',
      qrCode: 'https://img.zcool.cn/community/01e47e60ab5b4011013eaf70962e3f.jpg@520w_390h_1c_1e_2o_100sh.jpg'
    },
    banner: ['company-img3.png', 'company-img31.png'],
    current: 0,
    clueList: ['clue-img2.webp', 'clue-img3.webp', 'clue-img4.webp', 'clue-img5.webp', 'clue-img6.webp', 'clue-img7.webp', 'clue-img8.webp', 'clue-img9.webp', 'clue-img10.webp', 'clue-img11.webp', 'clue-img12.webp', 'clue-img13.webp'],
    clueCurrent: 0,
    awardBanner: [{src: 'company-img7.png', name: '组织荣誉'}, {src: 'company-img71.png', name: '行业奖项'}],
    awardCurrent: 0
  },
  introduce(e) {
    const curTabIndex = e.currentTarget.dataset.index;
    // 视频直播和合作申请是跳转新页面,不需要设置激活样式
    // 0-公司介绍 1-方案介绍 2-视频直播 3-合作申请
    switch (curTabIndex) {
      case 2:
        wx.openChannelsActivity({
          finderUserName: 'sphPIdcy0NVpuao',
          feedId: 'export/UzFfAgtgekIEAQAAAAAAOQ8BJrsjzwAAAAstQy6ubaLX4KHWvLEZgBPEmIEUOQV4c62CzNPgMJqRnrGh3TfaajoIU4mGBiio'
        })
        wx.$Track.sendTrack(trackData.VIDEO);
        break;
      default:
        this.setData({
          curTabIndex: curTabIndex,
        });
        wx.$Track.sendTrack(this.data.curTab[this.data.curTabIndex]);
    }
  },

  // 跳转咨询页面
  goConsult() {
    console.log("跳转到咨询页面");
    wx.openCustomerServiceChat({
      extInfo: {url: 'https://work.weixin.qq.com/kfid/kfcdc6d35b59631ce3c'},
      corpId: 'ww2318dc9e5d23230b',
      complete: r => {
        console.log(r)
      }
    })
  },

  // 更新手机号
  updatePhoneNumber(e) {
    if (e.detail) {
      this.setData({
        hasPhoneNumber: true,
      });
    }
  },

  // 政府与行业资质轮播切换
  changePage(e) {
    let current = e.detail.current
    this.setData({
      current: current
    })
  },
  // 荣誉与奖项轮播切换
  changeBanner(e) {
    let awardCurrent = e.detail.current
    this.setData({
      awardCurrent: awardCurrent
    })
  },
  tapBanner(e) {
    console.log(e)
    let current = e.target.dataset.current
    this.setData({
      awardCurrent: current
    })
  },
  // 智能线索轮播切换
  clueChange(e) {
    let clueCurrent = e.detail.current
    this.setData({
      clueCurrent: clueCurrent
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.$util.showLoading('加载中...')
    getApp()
      .login()
      .then(({ data }) => {
        wx.hideLoading()
        if (data && data.nickName) {
          this.setData({
            hasUserInfo: true,
          });
        } else {
          this.setData({
            hasUserInfo: false
          })
        }
        
        if (data && data.phone) {
          this.setData({
            hasPhoneNumber: true,
          });
        }
        this.getCardDetail();
      });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const options = wx.getEnterOptionsSync()
    wx.$trackData = options.query
    if (wx.$trackData.merchant) {
      wx.$Track.sendTrack(this.data.curTab[this.data.curTabIndex])        
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: `您好,我向你推荐了广联数科${this.data.cardInfo.staffName}的智能名片~`,
      imageUrl: this.data.shareImg,
      path:
        "pages/tab/index/index?cardId=" +
        util.getStorageSync("scene").cardId,
    };
  },
  setShareInfo(data = {}) {
    const canvasWidth = 208,
      canvasHeight = 166,
      textBaseline = "top";
    const draw_function = new Draw(this, {
      width: canvasWidth,
      height: canvasHeight,
      // pixelRatio: 2,
      // backgroundColor: '#096'
    });
    const drawCard = (callBack) => {
      let index = 0;
      const iconWidth = 9,
        iconHeight = 9,
        iconX = 18,
        iconY = 79,
        imgList = [
          {
            url: "https://img02.glsx.com.cn/weapp/resource/miniprogram/ai-card/share/bg.png",
            x: 0,
            y: 0,
            width: canvasWidth,
            height: 124,
          },
          {
            url: "https://img02.glsx.com.cn/weapp/resource/miniprogram/ai-card/share/logo.png",
            x: 15,
            y: 18,
            width: 152,
            height: 10,
          },
          // 头像的
          {
            // url: "https://img.zcool.cn/community/01e47e60ab5b4011013eaf70962e3f.jpg@520w_390h_1c_1e_2o_100sh.jpg",
            url: data.image,
            x: 154,
            y: 36,
            width: 36,
            height: 36,
          },
          {
            url: "https://img02.glsx.com.cn/weapp/resource/miniprogram/ai-card/share/icon-phone.png",
            x: iconX,
            y: iconY,
            width: iconWidth,
            height: iconHeight,
          },
          {
            url: "https://img02.glsx.com.cn/weapp/resource/miniprogram/ai-card/share/icon-address.png",
            x: iconX,
            y: iconY + 13,
            width: iconWidth,
            height: iconHeight,
          },
          {
            url: "https://img02.glsx.com.cn/weapp/resource/miniprogram/ai-card/share/btn.png",
            x: 64,
            y: 138,
            width: 80,
            height: 24,
          },
        ],
        textList = [
          {
            text: data.staffName,
            x: 18,
            y: 36,
            color: "#2D2D33",
            fontWeight: 600,
            fontSize: 14,
          },
          {
            text: data.operation,
            x: 22 + draw_function.getTextWidth(data.staffName, 14),
            y: 40,
            color: "#6E6E7A",
            fontWeight: 400,
            fontSize: 8,
          },
          {
            text: data.staffPhone,
            x: 30,
            y: 80,
            color: "#6E6E7A",
            fontSize: 7,
          },
          {
            text: "深圳市南山区留仙大道3370号南山智园崇文园区1号楼14层",
            x: 30,
            y: 94,
            color: "#6E6E7A",
            fontSize: 7,
            lineNum: 2,
            width: 185,
            lineHeight: 9,
          },
        ];
      const drawImages = (callBack) => {
        draw_function.drawImages(imgList[index], () => {
          index += 1;
          if (index != imgList.length) drawImages(callBack);
          else callBack();
        });
      };
      drawImages(() => {
        try {
          textList.map((e, ind) => {
            e.textBaseline = textBaseline;
            draw_function.drawText(e);
            if (ind == textList.length - 1) throw true;
          });
        } catch (error) {
          draw_function.toDataURL(({ path }) => {
            this.setData({
              shareImg: path,
            });
          });
        }
      });
    };
    drawCard();
  },
  // 获取用户昵称
  getUserProfile(e) {
    this.setData({
      hasUserInfo: true,
    });
    // 推荐使用 wx.getUserProfile 获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
    // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
    wx.getUserProfile({
      desc: "用于完善资料", // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
      success: (res) => {
        ssoApi
          .authUserInfo({
            ...res,
          })
          .then(({ code }) => {
            if (code == "0") {
              getApp()
                .login()
                .then(({ data }) => {
                  this.setData({
                    userInfo: data,
                    // hasUserInfo: true
                  });
                });
            }
          });
      },
    });
  },
  // 获取员工名片信息
  getCardDetail() {
    console.log(util.getStorageSync('scene'), wx.$trackData.cardId)
    const scene = util.getStorageSync('scene');
    let params = {
      cardId: wx.$trackData.cardId || scene.cardId
    };
    entmicroApi.getCardDetail(params).then(({data, code, message}) => {
      if (code == -1) {
        wx.showToast({
          title: message,
          icon: 'none',
          duration: 2000
        })
      }
      this.setData({
        cardInfo: data || this.data.defaultInfo
      })
      this.setShareInfo(this.data.cardInfo);
    });
  },
});