index.js 13.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
/*
 * @Description:
 * @Author: huyue
 * @Date: 2022-08-30 11:26:21
 * @LastEditors: huyue
 * @LastEditTime: 2022-12-20 11:13:44
 */
// pages/tab/index/index.js
import Draw from '../../../utils/Draw'
import { entmicroApi } from '../../../api/api'
import { commonMixin } from '../../../mixins/index'
import { trackData } from '../../../utils/data'
// import { senceData, productData } from './constant/senceData'
// import { subscriptionBannerUrl, subscriptionSystemData } from './constant/systemData'
// import {scenceList} from "./constant/data"
let leftMenuIndex = 0
Page({
  behaviors: [commonMixin],
  /**
   * 页面的初始数据
   */
  data: {
    isStaff: false,
    tabList: [
      {
        name: '公司介绍',
        icon: 'icon-company',
        icon1: 'icon-company1'
      },
      {
        name: '营销增值服务',
        icon: 'icon-product',
        icon1: 'icon-product1'
      },
      {
        name: '客户数字化',
        icon: 'icon-measure',
        icon1: 'icon-measure'
      }
      // {
      //   id: 3,
      //   name: '视频直播',
      //   icon: 'icon-video',
      //   icon1: 'icon-video'
      // }
    ],
    curTabIndex: 0,
    // 员工名片信息
    cardInfo: null,
    defaultInfo: {
      staffName: '普俊鹏',
      operation: '总经理助理',
      staffPhone: '18566760303',
      image: `https://wx.glsx.com.cn/upload/biz/a9e8be9a-4bb3-49e5-bbe2-74834a49250a.jpg`,
      qrCode: 'https://wework.qpic.cn/wwpic/999822_iZhMe8pJTduYBbN_1665471085/0'
    },
    // 是否授权手机号
    hasPhoneNumber: false,
    curTab: [trackData.HOME, trackData.SYSTEM_SUB, trackData.COMPANY, trackData.VIDEO],
    secondTab: [trackData.FINE, trackData.CUSTOMERSONLINE, trackData.CROWDFUNDING, trackData.CARDAMAGE],
    shareDisabled: true,
    autoplay: true,
    // 增值转化模块
    systemData: [],
    productData: [],
    activityList: [],
    // subscriptionBannerUrl: Object.freeze(subscriptionBannerUrl),
    // subscriptionSystemData: Object.freeze(subscriptionSystemData),
    showCooperate: false,
    // scenceList: scenceList,

    // bannerUrl:'https://img02.glsx.com.cn/weapp/resource/saas/business-assistant/index/banner/banner0.png'
  },
  // 一级菜单
  introduce(e) {
    console.log(e)
    const curTabIndex = e.currentTarget.dataset.index
    const ids = e.currentTarget.dataset.name.id
    this.setData({
      autoplay: false
    })
    // 视频直播是跳转新页面,不需要设置激活样式
    // 0-增值转化 1-系统订阅 2-公司介绍 3-视频直播
    switch (ids) {
      case 0:
        this.setData({
          curTabIndex: curTabIndex,
          autoplay: true
        })
        wx.$Track.sendTrack(this.data.curTab[this.data.curTabIndex])
        break
      case 3:
        wx.openChannelsUserProfile({
          finderUserName: 'sphPIdcy0NVpuao'
        })
        wx.$Track.sendTrack(trackData.VIDEO)
        break
      default:
        this.setData({
          curTabIndex: curTabIndex
        })
        wx.$Track.sendTrack(this.data.curTab[this.data.curTabIndex])
    }
  },

  // 咨询
  handleOpen(e) {},

  // 更新手机号
  updatePhoneNumber(e) {
    console.log(e);
    const {phone} = wx.$storage.get('aicard_user_info')
    console.log(this.data.cardInfo.staffPhone, phone);
    if (this.data.cardInfo.staffPhone === phone) {
      this.setData({
        isStaff: true,
        phoneNumber: phone
      })
    }
    if (e.detail) {
      this.setData({
        hasPhoneNumber: true
      })
      // this.checkCooperate()
    }
  },
  // 获取跳转门店助手、生意助手判断
  checkCooperate() {
    const userInfo = wx.$storage.get('aicard_user_info')
    if (userInfo) {
      const {openId} = userInfo
      entmicroApi.checkCooperate({openId}).then(res => {
        this.setData({
          showCooperate: res
        })
      })
    } else {
      this.setData({
        showCooperate: false
      })
    }
  },

  // 获取二级菜单下标
  getCurrentScen(e) {
    const index = e.detail
    wx.$Track.sendTrack(this.data.secondTab[index])
  },

  proClick(e) {
    const { info, sceneCode } = e.detail
    let obj = {
      hasPhoneNumber: this.data.hasPhoneNumber,
      id:info.id,
      sceneCode
    }
    wx.$router.go('/packagesList/pages/productDetail/productDetail', obj)
  },
  // 跳转视频详情
  videoClick(e) {
    const { info, sceneCode } = e.detail
    // 一级菜单ID
    const typeId = this.data.curTabIndex == 0 ? this.data.productDataId : this.data.systemDataId
    const obj = {
      hasPhoneNumber: this.data.hasPhoneNumber,
      id:info.info.id,
      tabsActive: info.tabsActive,
      sceneCode,
      typeId
    }
    wx.$router.go('/packagesList/pages/videoDetal/videoDetal', obj)
  },

  // 跳转活动页
  activityClick(e) {
    const { hasPhoneNumber } = this.data
    const id = e.detail
    wx.$router.go('/packagesList/pages/activityDetail/activityDetail', { hasPhoneNumber, id })
  },

  // 场景跳转
  senceClick(e) {
    // 如果有sceneCode,并且没有配置banner跳转 isBannerLink 1-有配置 2-没有配置
    if (!e.detail.sceneCode || e.detail.isBannerLink != 1) return
    const { hasPhoneNumber } = this.data
    // 获取场景
    let systemItem = this.data.systemData.find(item => item.sceneCode == e.detail.sceneCode)
    let productItem = this.data.productData.find(item => item.sceneCode == e.detail.sceneCode)
    // let id = ''
    // const itemList = systemItem ? systemItem : productItem
    // const subList = itemList.subList.length ? itemList.subList[0] : null
    // const productList = subList ? subList.productList : itemList.productList
    // id = productList.length ? productList[0]?.id : ''
    let obj = systemItem || productItem
    const id = obj?.subList.length ? obj?.subList[0]?.productList[0]?.id : obj?.productList[0]?.id
    if (!id) return
    wx.$router.go('/packagesList/pages/productDetail/productDetail', { hasPhoneNumber, id })
  },
  // 获取全部活动列表
  getActivityRecord() {
    entmicroApi.getActivityRecord({}).then(({ data, code, message }) => {
      if (code == -1) {
        wx.showToast({
          title: message,
          icon: 'none',
          duration: 2000
        })
      }
      this.setData({
        activityList: data
      })
    })
  },

  disagreeClick() {
    console.log(this.selectComponent('.userInfo'));
    this.selectComponent('.userInfo').returnAdd()
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const app = getApp()
    app.getBaseData().then(res => {
      const productData = res[0].subList
      const systemData = res[1].subList
      this.setData({
        [`tabList[1].name`]: res[0].name,
        [`tabList[2]name`]: res[1].name,
        systemData,
        systemDataId: res[1].id,
        productData,
        productDataId: res[0].id,
      })
    })
    app.login()
      .then(({ data }) => {
        if (data && data.phone) {
          this.setData({
            hasPhoneNumber: true,
            phoneNumber: data.phone
          })
          this.checkCooperate()
        }
        this.getCardDetail()
        this.getActivityRecord()
      })
    wx.hideShareMenu({
      menus: ['shareAppMessage']
    })
  },

  addAll(data) {
    for (let i in data) {
      let arr = [],
        m = [],
        n = []
      data[i].map(item => {
        arr = arr.concat(item.productList)
        m = item.videoList
        n = item.posterList
      })
      const allData = {
        name: '全部',
        productList: arr,
        videoList: m,
        posterList: n
      }
      data[i].unshift(allData)
    }
    return data
  },

  // 咨询
  handleOpen() {
    this.setData({
      showCustomer: true
    })
  },

  closeQR() {
    this.setData({
      showCustomer: false
    })
  },

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

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const app = getApp()
    const userInfo = wx.$util.getUserInfo()
    this.setData({
      hasPhoneNumber: !!(userInfo && userInfo.phone)
    })
    // this.checkCooperate()
    const options = wx.getEnterOptionsSync()
    wx.$trackData = options.query
    if (wx.$trackData.merchant) {
      wx.$Track.sendTrack(this.data.curTab[this.data.curTabIndex])
      if (this.data.curTabIndex == 0) {
        wx.$Track.sendTrack(this.data.secondTab[0])
      }
    }
    console.log(this.data.isStaff,this.data.cardInfo);
    if (!this.data.isStaff && this.data.cardInfo) {
      if (this.data.cardInfo.staffPhone === this.data.phoneNumber) {
        this.setData({
          isStaff: true
        })
      }
    }
  },

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

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

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

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

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    const cardId = wx.$storage.get('scene').cardId
    // merchantId 兼容旧链接
    const merchant = wx.$storage.get('scene').merchant || wx.$storage.get('scene').merchantId
    const shareType = 'SHARE_HOME'
    return {
      title: `您好,我向你推荐了广联数科${this.data.cardInfo.staffName}的智能名片~`,
      imageUrl: this.data.shareImg,
      path: `pages/tab/index/index?cardId=${cardId}&merchant=${merchant}&shareType=${shareType}`
    }
  },
  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/new-logo.png',
            x: 18,
            y: 13,
            width: 105,
            height: 12
          },
          // 头像的
          {
            // url: "https://img.zcool.cn/community/01e47e60ab5b4011013eaf70962e3f.jpg@520w_390h_1c_1e_2o_100sh.jpg",
            url: data.image,
            x: 154,
            y: 13,
            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: 40,
            color: '#2D2D33',
            fontWeight: 600,
            fontSize: 14
          },
          {
            text: data.operation,
            x: 22 + draw_function.getTextWidth(data.staffName, 14),
            y: 44,
            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,
                shareDisabled: false
              },
              () => {
                wx.showShareMenu({
                  menus: ['shareAppMessage']
                })
              }
            )
          })
        }
      })
    }
    drawCard()
  },

  // 获取员工名片信息
  getCardDetail() {
    // this.setData({
    //   'tabList[3].isShow': wx.showMeasure
    // })
    const scene = wx.$storage.get('scene')
    let params = {
      cardId: wx.$trackData.cardId || scene.cardId
    }
    entmicroApi.getCardDetail(params).then(({ data, code, message }) => {
      wx.hideLoading()
      if (code == -1) {
        wx.showToast({
          title: message,
          icon: 'none',
          duration: 2000
        })
      }
      const cardInfo = data || this.data.defaultInfo
      this.setData(
        {
          cardInfo
        },
        () => {
          this.setShareInfo(cardInfo)
        }
      )
      console.log(cardInfo.staffPhone,this.data.phoneNumber);
      if (cardInfo.staffPhone === this.data.phoneNumber) {
        this.setData({
          isStaff: true
        })
      }
    })
  },

  /** 系统订阅 */
  sysMenuClick(e) {
    const {id} = e.detail
    leftMenuIndex = id
  }
})