index.js 14.3 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 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
const navStyle = 'background-color: transparent;'
import { IMG_URL } from '~/utils/constantData.js'
// import Util from '~/utils/util.js'
import { deleteSecond } from '~/utils/format'
// import { senceData } from './constant/data'
// import { scenceList } from './constant/data'
// import { senceData, productData } from './constant/senceData'
// import { subscriptionBannerUrl, subscriptionSystemData } from './constant/systemData'
import { getMockData } from '~/api/api'
const IMAGES = Object.freeze({
  arrow: `${IMG_URL}/index/point.png`,
  actArrow: `${IMG_URL}/index/actArrow.png`
})
// `${IMG_URL}index/car2.png`,
//本地图片路径
let IMG_URLLocal = '../../../images/'
import { productBysceneApi, pageApi, tagApi, battleMessageApi, getActivityRecordApi } from '~/api/index.js'
let leftMenuIndex = 0
Page({
  // behaviors: [kfMixin],
  /**
   * 页面的初始数据
   */
  data: {
    IMAGES,
    navStyle,
    IMG_URL,
    IMG_URLLocal,
    actClass: "right",
    guideSrcIndex: 1,
    guideShow: false,
    dataArr: [],
    apiData: [],
    actNum: 3, //car 场景选择
    tabIndx: 0,
    // navList: ['看线索', '看产品'],
    navList: ["看产品", "客户数字化"],
    isShowService: false,
    navBarBoxStyle: "justify-content: start;",
    navTitleStyle: "width: 80%",

    // 固定按钮
    btnList: [
      {
        imgSrc: "contact",
        name: "在线客服",
        bindtap: "goConsult",
      },
      {
        imgSrc: "bus-pro",
        name: "申请业务",
        bindtap: "openBus",
      },
      // {
      //   imgSrc: 'bus-pro',
      //   name: '申请产品',
      //   bindtap: 'openPro',
      //   isHide: false
      // },
      {
        imgSrc: "valuation",
        name: "预估产值",
        bindtap: "showCalculate",
        isHide: false,
      },
    ],

    // 预估弹框
    // visible: false,
    isReset: false,
    formData: {
      sales: 100,
      flow: 10000,
    },
    lastFormData: {
      sales: 100,
      flow: 10000,
    },
    isFirst: true,
    // tabList: pageData.tabList,
    // 定义数据
    // scenceList,
    // senceData,
    isShow: false,
    // productData,
    activityList: [],
    // 视频播放地址
    videoSrc: "",
    videoTitle: "",
    headerHeight: 0,
    unreadClueCount: 0,
    img_version: "0.1.1",
    // subscriptionBannerUrl: Object.freeze(subscriptionBannerUrl),
    // subscriptionSystemData: Object.freeze(subscriptionSystemData),
    systemData: [],
    productData: [],
  },
  proClick(e) {
    // let { detail } = e;
    // //登录的用户手机号
    // let userInfo = wx.$storage.get("userInfo");
    // let obj = {
    //   actNum: isNaN(detail.scenIndex) ? 99 : detail.scenIndex, //选中的场景 没有就是订阅系统的
    //   sceneid99: detail.sceneid,
    //   activeNavIdx: detail.id, //选中的产品,
    //   phone: userInfo.phone,
    // };
    let userInfo = wx.$storage.get("userInfo");
    const { info, sceneCode } = e.detail
    let obj = {
      phone: userInfo.phone,
      id:info.id,
      sceneCode
    }
    wx.$router.go("/packagesList/pages/productDetail/productDetail", obj);
  },
  // 跳转视频详情
  videoClick(e) {
    const { info, sceneCode } = e.detail
    let userInfo = wx.$storage.get("userInfo");
    // 一级菜单ID
    const typeId = this.data.tabIndx == 0 ? this.data.productDataId : this.data.systemDataId
    const obj = {
      phone: userInfo.phone,
      id: info.info.id,
      tabsActive: info.tabsActive,
      sceneCode,
      typeId
    }
    wx.$router.go("/packagesList/pages/videoDetal/videoDetal", obj);
  },

  // 跳转众筹活动页
  activityClick(e) {
    const id = e.detail;
    wx.$router.go("/packagesList/activityDetail/activityDetail", { id });
  },

  // 场景跳转
  senceClick(e) {
    // let { scenIndex } = this.data;
    // let userInfo = wx.$storage.get("userInfo");
    // let obj = {
    //   actNum: scenIndex, //选中的场景
    //   activeNavIdx: 0, //选中的产品
    //   phone: userInfo.phone,
    // };
    // wx.$router.go("/pages/viewProdBanner/index", obj);
    // const { scenIndex } = e.detail;
    // let userInfo = wx.$storage.get("userInfo");
    // wx.$router.go("/packagesList/pages/scenarioDetail/scenarioDetail", {
    //   actNum: scenIndex,
    //   phone: userInfo.phone,
    // });
     // 如果没有sceneCode,或者没有配置banner跳转 isBannerLink 1-有配置 2-没有配置
     if (!e.detail.sceneCode || e.detail.isBannerLink == 2) return
     let userInfo = wx.$storage.get("userInfo");
     // 获取场景
     let systemItem = this.data.systemData.find(item => item.sceneCode == e.detail.sceneCode)
     let productItem = this.data.productData.find(item => item.sceneCode == e.detail.sceneCode)
     //  const id = systemItem?.productList[0].id || productItem?.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', { phone: userInfo.phone, id })
  },
  // 获取全部活动列表
  getActivityRecord() {
    getActivityRecordApi({}).then(({ data, code, message }) => {
      if (code == -1) {
        wx.showToast({
          title: message,
          icon: "none",
          duration: 2000,
        });
      }
      this.setData({
        activityList: data,
      });
    });
  },
  //引导图
  guideFn() {
    if (this.data.guideSrcIndex === 4) {
      this.setData({
        guideShow: false,
      });
      //显示tabar
      wx.pro.showTabBar();
      return;
    }
    this.setData({
      guideSrcIndex: ++this.data.guideSrcIndex,
    });
    // console.log('guideSrcIndex',this.data.guideSrcIndex)
  },
  // navbar高度设置
  navbarReady(e) {
    let { height, statusBarHeight } = e.detail;
    this.setData({
      headerHeight: height / 2 + statusBarHeight,
      // headerHeight: height / 2 + statusBarHeight + 88 * 2
    });
  },
  selectCar(e) {
    let actNum = e.detail;
    this.setData({
      actNum,
    });
  },
  // 头部看线索,产品切换
  changeTabIndx(e) {
    // console.log('e.detail: ', e.detail)
    let { sessionId } = wx.$storage.get();
    // console.log("sessionId: ", sessionId);
    let param = {
      sessionId,
    };

    let first = true;
    this.setData({
      tabIndx: e.detail,
    });
    this.btnIsHide();
  },
  //看产品下拉刷新
  refresherrefresh() {
    let { tabIndx } = this.data;
    if (tabIndx == 0) {
      // 看产品
      this.getProductByscene();
      // // 看线索
      // this.getClueInit()
      wx.pro.showToast({
        title: "刷新成功",
        icon: "loading",
        duration: 1500,
      });
    }
  },
  // 跳转咨询页面
  goConsult() {
    // console.log('跳转到咨询页面')
    wx.pro.openCustomerServiceChat({
      extInfo: { url: "https://work.weixin.qq.com/kfid/kfcf7b721472201345e" },
      corpId: "ww047bdc0f1e76cc13",
      complete: (r) => {
        // console.log(r)
      },
    });
  },
  // 申请业务、
  openBus() {
    wx.$router.go("/packagesList/apply/pages/apply");
  },
  // 预估产值
  showCalculate() {
    wx.$router.go("measure");
    // this.setData({
    //   visible: !this.data.visible,
    //   isReset: false
    // })
  },
  // reset() {
  //   this.setData({
  //     isReset: false,
  //     formData: {
  //       sales: 100,
  //       flow: 10000
  //     }
  //   })
  // },
  focus() {
    this.setData({
      isReset: true,
    });
    return false;
  },

  // 固定按钮
  btnIsHide() {
    this.setData({
      ["btnList[2].isHide"]: this.data.tabIndx != 0,
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log('options: ', options);
    let { sessionId } = wx.$storage.get();
    // console.log("sessionId: ", sessionId);
    let param = {
      sessionId,
    };
    // 看产品
    this.getProductByscene();
    // // 看线索
    // this.getClueInit()
    // 获取看产值数据
    const app = getApp()
    app.getBaseData().then(res => {
      const productData = res[0].subList
      const systemData = res[1].subList
      this.setData({
        systemData,
        systemDataId: res[1].id,
        productData,
        productDataId: res[0].id,
        ['navList[0]']: res[0].name || '看产品',
        ['navList[1]']: res[1].name || '客户数字化'
      })
    })

    this.setData({
      productData: this.addAll(this.data.productData),
    });
    this.getActivityRecord();
    // //第一次进来储缓存,以后不再用引导图
    let firstLogin = wx.$storage.get("firstLogin");
    if (!firstLogin) {
      //第一次隐藏tabar
      wx.pro.hideTabBar();
      this.setData({
        guideShow: true,
      });
      wx.$storage.set("firstLogin", "firstLogin");
    }
    if (this.data.guideShow) {
      wx.$storage.set("disLikeRecordFlag", true);
      let disLikeRecordFlag = wx.$storage.get("disLikeRecordFlag");
      this.setData({
        disLikeRecordFlag,
      });
    }

    //视频弹窗
    wx.$eventbus.on("getvideo", (e) => {
      // console.log('getvideo event bus: ', e);
      let url = wx.$util.getCurrentPageUrl();
      if (url == "/pages/tab/index/index") {
        let obj = {
          videoTitle: e.title,
          videoSrc: e.src,
        };
        this.getVideoUrl(obj);
        wx.nextTick(() => {
          this.videocomp.play();
        });
      }
    });
  },

  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;
  },
  //接口数据,本地数据对接
  compositionData(localData, apiData) {
    localData.forEach((item, index) => {
      apiData.forEach((inner, idx) => {
        if (item.name == inner.stage) {
          item.sceneStatus = inner.sceneStatus;

          item.productList.forEach((outChild, outIndex) => {
            inner.productList.forEach((innerChild, innerIndex) => {
              if (outChild.proName == innerChild.productName) {
                outChild.productStatus = innerChild.productStatus;
              }
            });
          });
        }
      });
    });
    // console.log('localData, apiData: ', localData);
    // this.setData({
    //   senceData: localData
    // })
  },
  getFirstSenceIndex(param) {
    let actTndex = this.data.apiData.findIndex((item) => item.sceneStatus == 1);
    // console.log('actTndex: ', actTndex);
    this.setData({
      actNum: actTndex,
    });
  },
  // 看产品接口
  getProductByscene() {
    productBysceneApi().then((res) => {
      let { code, data } = res;

      if (code == 0) {
        this.setData({
          apiData: data,
        });
        // this.compositionData(senceData, this.data.apiData)
        // this.getFirstSenceIndex();
      }
    });
  },
  // 看线索相关
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.prompt = this.selectComponent("#toast");
    this.videocomp = this.selectComponent("#videocomp");
  },

  // //点击收藏提示框
  showToggleToast(e) {
    let tipObj = e.detail;
    this.prompt.showToast({
      type: tipObj.type,
      title: tipObj.title,
      duration: 1000,
      compelete: function () {
        // console.log("toast框隐藏之后,会调用该函数");
        //例如:跳转页面wx.navigateTo({ url: 'xxx' });
      },
    });
  },
  onReachBottom() {
    console.log("滑到底部了");
  },
  // 展示海报
  getSharePost(merchantId) {
    battleMessageApi({ serviceMerchantId: merchantId })
      .then((result) => {
        console.log(result);
        let posterId = wx.$storage.get("posterId");
        console.log(posterId);
        if (posterId == result.valueUrl) return;
        // 为2是已经展示过了
        wx.$storage.set("posterId", result.valueUrl);
        let updatedTime = deleteSecond(result.createdTime);
        console.log(updatedTime);
        this.setData({
          posterItem: {
            activityName: result.activityName,
            // posterUrl: 'https://wx.glsx.com.cn/upload/biz/598888808108396544.png',
            posterUrl: result.valueUrl,
            // crowdFundActivityId: item.valueUrl,
            updatedTime,
            type: "warReport",
          },
        });
        // if (result.status && result.status != 2) {
        // }
        // debugger
      })
      .catch((err) => {});
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function () {
    let { userInfo } = wx.$storage.get();
    !userInfo.isSuper && this.getSharePost(userInfo.subLoginUser.merchantId);
    let { serviceMerchatList } = (await getMockData()) || {
      serviceMerchatList: [],
    };
    this.setData({
      isShowService: serviceMerchatList.includes(userInfo.merchantId + ""),
    });
  },
  // 节流函数
  throttle(fn, gaptime) {
    if (gaptime == null || gaptime == undefined) {
      gaptime = 200;
    }
    let _lastTime = null;
    return function () {
      let _nowTime = +new Date();
      if (_nowTime - _lastTime > gaptime || !_lastTime) {
        fn.apply(this, arguments);
        _lastTime = _nowTime;
      }
    };
  },
  onPageScroll: (function () {
    let timer = null;
    return function (e) {
      // console.log("在滚动");
      // 监听页面的滚动开始和结束
      clearTimeout(timer);
      timer = setTimeout(() => {
        // console.log("滚动结束");
        wx.$eventbus.emit("evt_page_scroll", { scrollTop: e.scrollTop });
      }, 300);
    };
  })(),
  //设置视频url
  getVideoUrl(params) {
    this.setData(params);
  },
  //申请活动
  gotoApply() {
    wx.$router.go("/packagesList/apply/pages/apply");
  },

  /** 客户数字化 */
  sysMenuClick(e) {
    console.log(e);
    const { id } = e.detail;
    leftMenuIndex = id;
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

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

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

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  onShareTimeline: function () {},
});