Action.js 7.49 KB
// pages/crowdfunding/components/Action/Action.js
import { centsToyuan, toUnicode } from "~/utils/format";
import { shopmallApi } from "../../api/index";
import USER from '~/api/usersApi/index'
Component({
    options: {
        styleIsolation: "shared",
    },
    /**
     * 组件的属性列表
     */
    properties: {
        isImAction: {
            type: Boolean,
            value: false,
        },
        isShow: {
            type: Boolean,
            value: true,
        },
        isSpecial: {
            type: Boolean,
            value: false,
        },
        detail: {
            type: Object,
            value: () => { },
            observer(n) {
                if (n?.id) {
                    const isShowHome = wx.$storage.get('userInfo')
                    const thisPage = wx.$router.getPageInstance(),
                        params = thisPage.options,
                        systemInfo = wx.$storage.get("system_info");
                    let expressFee = n.expressFee || 0,
                        [price, decimal] = centsToyuan(n.retailPrice + expressFee)
                            .toString()
                            .split(".");
                    if (!decimal) decimal = "00";
                    n.price = price;
                    n.decimal = decimal;
                    n.isStaffLoginLink = params.isStaffLoginLink;
                    //buyFlag 1是未购买或者未限购,2是已购买且达到购买上限,3是已购买且未达到购买上限
                    let formList = [];
                    if (n.selectCarNumberFlag && n.selectCarNumberFlag == 2)
                        formList.push({
                            key: "plateNo",
                            maxlength: 10,
                            name: "车牌号",
                            type: 'plate'
                        });
                    if (n.selectVehicleTypeFlag && n.selectVehicleTypeFlag == 2) {
                        formList.push(
                            ...[
                                {
                                    route: "carBrands",
                                    name: "品牌",
                                    key: "carBrandsText",
                                },
                                {
                                    route: "carSeries",
                                    name: "车型",
                                    key: "carTypeText",
                                },
                            ]
                        );
                    }
                    let list = [
                        {
                            key: "formDescribeFirst",
                            maxlength: 40,
                            name: n.formDescribeFirst,
                        },
                        {
                            key: "formDescribeSecond",
                            maxlength: 40,
                            name: n.formDescribeSecond,
                        },
                        {
                            key: "formDescribeThird",
                            maxlength: 40,
                            name: n.formDescribeThird,
                        },
                    ];

                    this.setData({
                        systemInfo,
                        isShowHome: isShowHome ? false : true,
                        show: true,
                        detail: n,
                        formList: [...formList, ...list],
                        linkParams: params
                    });
                }
            },
        },
        videoFullscreen: Boolean,
    },

    /**
     * 组件的初始数据
     */
    data: {
        flag: true,
        showPoster: false,
        isGhRenewal: false,
        posterImg: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/expandedGold/poster_38.png',
    },

    /**
     * 组件的方法列表
     */
    methods: {
        onClickHide() {
            this.setData({
                showPoster: false,
            });
        },
        stopclick() {
            return;
        },
        jumpHome() {
            const index = 3-wx.$util.judgeMerchantForXubao()
            wx.redirectTo({
                url: `/pages/tab/shopMall/index?tabIndex=${index}`,
            })
        },
        getPoster() {
            let { id } = this.data.detail;

            let userInfo = wx.$storage.get("userInfo");
            let { phone, nickName, logo } = userInfo;
            let shareStaffType = 1;
            wx.$api.showLoading();
            shopmallApi
                .getPoster({
                    id,
                    nickName: toUnicode(nickName),
                    phone,
                    imageUrl: encodeURIComponent(logo),
                    shareStaffType,
                })
                .then((res) => {
                    wx.hideLoading();
                    console.log(res);
                    const posterImg = res.data;
                    this.setData({
                        showPoster: true,
                        posterImg,
                    });
                });
        },
        toChineseStr(unicodeStr) {
            if (!unicodeStr) {
              return '';
            }
            if(unicodeStr.indexOf('@')==-1){
              return unicodeStr
            }
            unicodeStr = unicodeStr.split('@');
            console.log(unicodeStr, 'unicodeStr');
            let chineseStr = '';
            for (let i = 1, iLength = unicodeStr.length; i < iLength; i++) {
              chineseStr += String.fromCharCode(parseInt(unicodeStr[i], 16));
            }
            return chineseStr.trim();
          },
        /**手机号授权 */
        async getPhoneNumber({ detail }) {
            const sessionId = wx.$util.getSessionId()
            if (!sessionId) return
            const res = await USER.authUserPhone(detail, sessionId)
            const {linkParams:{id,shareStaffUuid}} = this.data
            const params = {
                customerName: res.data.nickName,
                customerPhone: res.data.phone,
                shareName: shareStaffUuid,
                activityId: id
            }
            shopmallApi.recordSave
                (params)
                .then(({
                    data,
                    code,
                    message
                }) => {
                    console.log(code, data, message);
                    this.setData({
                        isGhRenewal: true
                    })
                    wx.$api.hideLoading()
                })

        },
        closeDialog() {
            this.setData({
                isGhRenewal: false
            })
        },
        submit() {
            let { detail, formList, linkParams, videoFullscreen, isSpecial, detail: { ghExclusiveFlag } } = this.data,
                B_USER_INFO = wx.$storage.get("userInfo"),
                appEnter = wx.getEnterOptionsSync();
            if (appEnter.scene === 1154) {
                wx.$eventbus.emit("showTimeLineToast");
                return;
            }
            if (detail.isStaffLoginLink) return;
            // if (B_USER_INFO)
            //   wx.$router.reLaunch(
            //     "/packageStoreAssistant/packageAuth/pages/authentication/loading/loading"
            //   );
            else
                wx.$router.go("/pages/crowdfunding/payModal/payModal", {
                    linkParams,
                    list: formList,
                    detail,
                    videoFullscreen,
                    isSpecial
                });
        },
    },
});