scene.js 18.9 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 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
const navStyle = "background-color: transparent;";
import util from "../../utils/util";
import { trackData } from "../../utils/data";
// import { IMG_URL } from '~/utils/constantData.js'
// wx.$imgUrl = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/ai-card/'
import { senceData } from "./constant/data";
// `${IMG_URL}index/car2.png`,
//本地图片路径
let IMG_URLLocal = "../../../images/";
// import { productBysceneApi, unreadApi, pageApi, readApi, tagApi } from '~/api/index.js'

let IMG_URL = wx.$imgUrl;
Page({
  // behaviors: [kfMixin],
  /**
   * 页面的初始数据
   */
  data: {
    navStyle,
    // IMGURL: wx.$imgUrl,
    IMG_URL,
    // IMG_URLLocal,
    actClass: "right",
    guideSrcIndex: 1,
    guideShow: false,
    dataArr: [
      {
        src: `${IMG_URL}index/car1.png`,
        name: "新车洽谈场景",
        msg: "1.0 新车权益销售",
      },
      {
        src: `${IMG_URL}index/car2.png`,
        name: "新车交付场景",
        msg: "1.1 新车精品升级",
      },
      {
        src: `${IMG_URL}index/car3.png`,
        name: "0-12个月",
        msg: "1.2 新车线上转化",
      },
      {
        src: `${IMG_URL}index/car4.png`,
        name: "12个月以上",
        msg: "1.3 存量用户众筹",
      },
    ],
    apiData: [],
    actNum: 3, //car 场景选择
    wrapactiveNavIdx: 0, // 产品选择
    tabIndx: 1,
    navList: ["看线索", "看产品"],
    typeList: [
      {
        0: "无电话",
        1: "有电话",
        2: "联系电话",
        selectIndex: 2,
        key: "hasPhone",
      },
      {
        0: "非意向客户",
        1: "是意向客户",
        2: "意向客户",
        selectIndex: 2,
        key: "starTag",
      },
      {
        0: "来自访客",
        1: "来自门店",
        2: "线索来源",
        selectIndex: 2,
        key: "clueSource",
      },
      {
        2: "重置",
        selectIndex: 2,
      },
    ],
    clueList: [],
    // 预估弹框
    visible: false,
    isReset: false,
    formData: {
      sales: 100,
      flow: 10000,
    },
    lastFormData: {
      sales: 100,
      flow: 10000,
    },
    isFirst: true,
    // tabList: pageData.tabList,
    // 定义数据
    senceData,
    isShow: false,
    // 看线索部分
    unreadClueCount: 0,
    cluePageSize: 10,
    clueCurrentPage: 1,
    hasPhoneNumber: false,
    trackList: [
      ['EQUITYCARD'],
      ['SOLARFILM'],
      ['PAINTPROTECT', 'CHANGEFILM'],
      ['CARBEAUTY', 'SEATVENTILATE', 'ARNAVIGATION', 'LIGHT', 'NAVIGATIONARROUND'],
      ['LOSSPGASE']
    ]
  },

  //引导图
  guideFn() {
    if (this.data.guideSrcIndex === 5) {
      this.setData({
        guideShow: false,
      });
      return;
    }
    this.setData({
      guideSrcIndex: ++this.data.guideSrcIndex,
    });
    // console.log('guideSrcIndex',this.data.guideSrcIndex)
  },
  // navbar高度设置
  navbarReady(e) {
    let { height, statusBarHeight } = e.detail;
    this.setData({
      // tabBarStyle: height / 2 + statusBarHeight,
      headerHeight: height / 2 + statusBarHeight + 88,
      // headerHeight: height / 2 + statusBarHeight + 88 * 2
    });
    // console.log(e)
    // console.log(this.data.headerHeight)
  },
  // headTabFn(e){
  //   // console.log("name",e.currentTarget.dataset.name)
  //   let name = e.currentTarget.dataset.name
  //   this.setData({
  //     actClass:name
  //   })
  // },
  // 选车场景切换
  selectCar(e) {
    console.log("e: ", e);
    let { num, scenestatus } = e.currentTarget.dataset;
    // console.log('actNum: ', actNum);
    // if(scenestatus == 1){

    // }
    // 场景切换默认埋点第一个产品
    const trackName = this.data.trackList[num][0]
    wx.$Track.sendTrack(trackData[trackName]);
    this.setData({
      actNum: num,
      wrapactiveNavIdx:0
    });
  },
  // 头部看线索,产品切换
  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,
    });
    //标记线索已读
    if (e.detail == 0 && first) {
      first = false;
      readApi(param);
    }
  },
  gotoApply(e) {
    let { type, item } = e.currentTarget.dataset;
    // let {  } = e.currentTarget.dataset
    if (type == "active") {
      let { userInfo } = wx.$storage.get();
      let pMerchantName = userInfo.subLoginUser.merchantName;
      let pMerchantId = userInfo.subLoginUser.merchantId;
      let sceneActive;
      switch (this.data.actNum) {
        case 0:
          sceneActive = 1;
          break;
        case 1:
          sceneActive = 2;
          break;
        case 2:
          sceneActive = 3;
          break;
        case 3:
          sceneActive = 4;
          break;
      }
      // let pMerchantId = userInfo.subLoginUser.merchantId

      // console.log("type,item: ", type, item);
      const params = {
        merchantInfo: {
          pMerchantId,
          pMerchantName,
          merchantId: item.visitList[0].merchantId,
          merchantName: item.visitList[0].merchantName,
        },
        sceneActive,
        // sceneCodeList: ['SC001', 'SC002','SC003','SC004']
      };
      //申请活动
      wx.$router.go("packageOutput.openBusiness", params);
    } else {
      //申请门店
      // let { type, item } = e.currentTarget.dataset
      wx.$router.go("apply", item?.clueId || "");
    }
    // wx.$router.go('apply',1235)
  },
  getMore(e) {
    console.log("显示更多数据");
    let index = e.currentTarget.dataset.outidx;
    console.log("index: ", index);
    let completeStatus = `clueList[${index}].getMoreFlag`;
    this.setData({
      [completeStatus]: !this.data.clueList[index].getMoreFlag,
    });
  },
  // 跳转咨询页面
  goConsult() {
    console.log("跳转到咨询页面");
    wx.pro.openCustomerServiceChat({
      extInfo: { url: "https://work.weixin.qq.com/kfid/kfcf7b721472201345e" },
      corpId: "ww047bdc0f1e76cc13",
      complete: (r) => {
        console.log(r);
      },
    });
  },
  // 预估弹框
  showCalculate() {
    this.setData({
      visible: !this.data.visible,
      isReset: false,
    });
  },
  clickDialog(e) {
    console.log(e.changedTouches[0].clientY);
    if (e.changedTouches[0].clientY < 471) {
      this.setData({
        visible: false,
        isReset: false,
        formData: this.data.lastFormData,
      });
    }
  },
  // 提交测算
  submit(e) {
    console.log(e);
    let sales = e ? +e.detail.value.sales : this.data.formData.sales;
    let flow = e ? +e.detail.value.flow : this.data.formData.flow;
    console.log("flow", sales, flow);
    const reg = /^[1-9]\d*$/;
    console.log(reg.test(sales), flow, "---");
    if (!reg.test(sales)) {
      wx.showToast({
        title: "门店月平均新车销量应为正整数",
        icon: "none",
        duration: 2000,
      });
      return;
    }
    if (!reg.test(flow)) {
      wx.showToast({
        title: "3年内售后存量用户应为正整数",
        icon: "none",
        duration: 2000,
      });
      return;
    }
    this.setData({
      "lastFormData.sales": sales,
      "lastFormData.flow": flow,
    });
    const _this = this;
    // this.data.tabList.forEach((item, index) => {
    //   item.productList.forEach((i, lastIndex) => {
    //     if (i.profit) {
    //       let name = `tabList[${index}].productList[${lastIndex}].profit`;
    //       let profit = _this.formula(i.productType, sales, flow);
    //       console.log(name, profit);
    //       this.setData({
    //         [name]: profit,

    //       });
    //     }
    //   });
    // });
    this.data.senceData.forEach((item, index) => {
      item.productList.forEach((i, lastIndex) => {
        if (i.profit) {
          let sale = `senceData[${index}].productList[${lastIndex}].sale`;
          let name = `senceData[${index}].productList[${lastIndex}].profit`;
          let flowKey = `senceData[${index}].productList[${lastIndex}].flow`;
          let profit = _this.formula(i.productType, sales, flow);
          console.log(name, profit);
          this.setData({
            [name]: profit,
            [sale]: sales,
            [flowKey]: flow,
          });
        }
      });
    });

    // 触发自定义事件  利润  数量
    // this.triggerEvent('countProfit', profit, sales)

    // let type = this.getProductType(sceneIndex, tabIndex);
    // let profit = this.formula(type, sales, flow);
    // console.log('profit: ', profit);

    this.setData({
      visible: false,
    });
    // this.showCase();
    // if (!this.data.isFirst) {
    wx.showToast({
      title: "测算结果已在页面内同步展示",
      icon: "none",
      duration: 2000,
    });
    // } else {
    //   this.setData({
    //     isFirst: false
    //   })
    // }
  },
  // // 获取场景下的产品类型
  // getProductType(sceneIndex, tabIndex) {
  //   let typeArray = [
  //     ["benefitCard"], //数字无忧权益卡
  //     ["sunMembrane"], //汽车太阳膜
  //     ["protectMembrane", "colorMembrane"], //'漆面保护膜','改色膜'
  //     ["digitBeauty", "chair", "ar", "lamp", "navigation"], //'数字化美容','座椅通风','AR导航','氛围灯','360全景导航'
  //   ];
  //   return typeArray[sceneIndex][tabIndex];
  // },
  // 计算公式,参数:productType
  formula(productType, sales, flow) {
    let profit = 0;
    switch (productType) {
      case "benefitCard":
        // 数字无忧权益卡
        profit = (sales * 0.5 * 2000 * 12).toFixed(0);
        break;
      case "sunMembrane":
        // 汽车太阳膜
        profit = (sales * 0.8 * 0.7 * 1500 * 12).toFixed(0);
        break;
      case "protectMembrane":
        // 漆面保护膜
        profit = (sales * 0.05 * 3000 * 12).toFixed(0);
        break;
      case "colorMembrane":
        // 改色膜
        profit = (sales * 0.05 * 5000 * 12).toFixed(0);
        break;
      case "digitBeauty":
        // 数字化美容
        profit = (sales * 0.2 * 300 * 12).toFixed(0);
        break;
      case "chair":
        // 座椅通风
        profit = (flow * 2580 * 0.9 * 0.01).toFixed(0);
        break;
      case "ar":
        // AR导航
        profit = (flow * 1680 * 0.9 * 0.015).toFixed(0);
        break;
      case "lamp":
        // 氛围灯
        profit = (flow * 2680 * 0.9 * 0.015).toFixed(0);
        break;
      case "navigation":
        // 360全景导航
        profit = (flow * 2880 * 0.9 * 0.015).toFixed(0);
        break;
    }
    console.log(profit.length);
    console.log(productType, sales, flow, profit);
    if (profit.length > 9) {
      return (profit / 10000).toFixed(0) + "万";
    } else {
      return profit;
    }
  },
  reset() {
    this.setData({
      isReset: false,
      formData: {
        sales: 100,
        flow: 10000,
      },
    });
  },
  focus() {
    this.setData({
      isReset: true,
    });
    return false;
  },
  // 更新手机号
  updatePhoneNumber(e) {
    if (e.detail) {
      this.setData({
        hasPhoneNumber: true,
      });
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.hideShareMenu({
      menus: ['shareAppMessage', 'shareTimeline']
    })
    // console.log('options: ', options);
    // let { sessionId } = wx.$storage.get()
    // // console.log("sessionId: ", sessionId);
    // let param = {
    //   sessionId
    // }
    // 看产品
    this.compositionData(senceData, []);
    // productBysceneApi(param).then(res => {
    //   let { code, data } = res

    //   if (code == 0) {
    //     this.setData({
    //       apiData: data
    //     })
    //     this.compositionData(senceData, this.data.apiData)
    //     // this.getFirstSenceIndex();
    //   }
    // })
    // 看线索
    // this.getClueInit()

    //第一次进来储缓存,以后不再用引导图
    let firstLogin = wx.$storage.get("firstLogin");
    if (!firstLogin) {
      this.setData({
        guideShow: true,
      });
      wx.$storage.set("firstLogin", "firstLogin");
    }
    if (util.getUserInfo().phone) {
      this.setData({
        hasPhoneNumber: true,
      });
    }
  },
  onRoute(options) {
    console.log(options, "options");
    if (options.actNum) {
      const trackName = this.data.trackList[options.actNum][options.activeNavIdx]
      console.log(trackName)
      wx.$Track.sendTrack(trackData[trackName]);
    } else {
      // 无参数默认埋点
      wx.$Track.sendTrack(trackData.CARBEAUTY);
    }
    this.setData({
      actNum: options.actNum,
      wrapactiveNavIdx: options.activeNavIdx,
    });
  },
  //接口数据,本地数据对接
  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,
    });
  },

  // 看线索相关
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.prompt = this.selectComponent("#toast");
  },
  showToast: function (e) {
    let { type, item } = e.currentTarget.dataset;
    console.log("type,item: ", type, item);
    let tipObj = {};
    if (item.starTag == 1) {
      tipObj = {
        type: "fail",
        title: "取消标记为意向客户",
      };
    } else {
      tipObj = {
        type: "success",
        title: "成功标记为意向客户",
      };
    }
    this.prompt.showToast({
      type: tipObj.type,
      title: tipObj.title,
      duration: 1000,
      compelete: function () {
        console.log("toast框隐藏之后,会调用该函数");
        //例如:跳转页面wx.navigateTo({ url: 'xxx' });
      },
    });

    //切换收藏标记
    let index = e.currentTarget.dataset.outidx;
    let completeStatus = `clueList[${index}].like`;
    this.setData({
      [completeStatus]: !this.data.clueList[index].like,
    });
    //发请求
    let { sessionId } = wx.$storage.get();
    let params = {
      clueId: item.clueId,
      sessionId,
    };
    this.getTagApi(params);
  },
  filterTypeFn(e) {
    let { typeList } = this.data;
    let index = e.currentTarget.dataset.index;
    // console.log('index: ', index);
    // let itemList = []
    // let params = {
    //   clueSource: '',
    //   hasPhone: '',
    //   starTag: ''
    // }
    // console.log('index: ', index)
    // 重置筛选
    if (index == 3) {
      typeList.forEach((item) => {
        item.selectIndex = 2;
      });
      this.setData({
        typeList,
      });
      return this.getPageApi();
    }

    let itemList = Object.values(typeList[index]).slice(0, 2);
    itemList.push("全部");
    let _this = this;
    wx.pro.showActionSheet({
      itemList,
      success(res) {
        //  选中全部
        let selectIndex = res.tapIndex;
        // console.log('selectIndex: ', selectIndex);
        typeList[index].selectIndex = selectIndex;
        let params = typeList.reduce((obj, item, index) => {
          console.log(" item: ", item);
          if (item["key"]) {
            // selectIndex = index == 2 ? selectIndex + 1 : selectIndex
            // console.log('selectIndex: ', selectIndex);
            let itemIndx = item.selectIndex;
            // console.log('itemIndx: ', itemIndx);
            // key: 'clueSource'
            if (item["key"] == "clueSource") {
              itemIndx += 1;
            }
            obj[item["key"]] = itemIndx == 2 || itemIndx == 3 ? "" : itemIndx;
          }
          return obj;
        }, {});
        console.log(params);
        // let num
        // if (index == 2) {
        //   num = res.tapIndex + 1
        // } else {
        //   num = res.tapIndex
        // }

        // switch (index) {
        //   case 0:
        //     params.hasPhone = num
        //     break
        //   case 1:
        //     params.starTag = num
        //     break
        //   case 2:
        //     params.clueSource = num
        //     break
        // }
        _this.setData({ typeList });
        _this.getPageApi(params);
      },
      fail(res) {
        console.log(res.errMsg);
      },
    });
  },
  // // 打电话
  // phoneCallFn(e) {
  //   let { phone } = e.currentTarget.dataset
  //   console.log('phone: ', phone)
  //   wx.phoneCall(phone)
  // },
  // // 复制号码
  // setCopyDataFn(e) {
  //   let { phone } = e.currentTarget.dataset
  //   wx.setCopyData(phone)
  // },
  getClueInit(param) {
    // console.log(22222)
    this.getUnreadApi(param);
    this.getPageApi(param);
  },
  //未读消息
  async getUnreadApi(param) {
    let { code, data } = await unreadApi(param);
    if (code == 0) {
      this.setData({
        unreadClueCount: data.unreadClueCount,
      });
    }
  },
  //获取浏览线索数据列表
  async getPageApi(param) {
    let { cluePageSize, clueCurrentPage } = this.data;
    let params = {
      ...param,
      pageSize: 1000,
      currentPage: clueCurrentPage,
    };
    let { code, data } = await pageApi(params);
    if (code == 0) {
      let arr = data.list.map((item) => {
        if (item.visitList.length > 5) {
          item.getMoreFlag = true;
        }
        return item;
      });
      this.setData({
        clueList: arr,
      });
    }
  },
  //喜欢收藏功能
  async getTagApi(param) {
    let res = await tagApi(param);
    console.log("res: ", res);
    this.getPageApi(param);
  },
  onReachBottom() {
    console.log("滑到底部了");
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // setTimeout(()=>{
    //   console.log('this.data.tabBarStyle',this.data.tabBarStyle,this.data.headerHeight)
    // })
  },
  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 });
      }, 500);
    };
  })(),
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

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

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

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  onShareTimeline: function () {},
});