帖子
帖子
用户
博客
课程
显示全部楼层
63
帖子
0
勋章
327
Y币

[开发工具] 不能识别到data定义的属性

[复制链接]
发表于 2022-3-28 11:01:36
624124da51a5c.png
如图执行完打印程序,下一个代码就报错找不到data里面定影的postdata,我定义了这个属性了的
380
帖子
4
勋章
6
Y币
是不是异步函数,作用域的问题,外面加个that = this ;
63
帖子
0
勋章
327
Y币
不是的
我在外面加了
getOldLoan(showProgress){
                        let that = this;




console.log("ret200"+JSON.stringify(res))                                               
                        that.data.postdata = res.data;
                                                console.log("ret200"+JSON.stringify(this.data.postdata))

依然报同样的错误
技术支持-F · 2022-3-28 11:05是不是异步函数,作用域的问题,外面加个that = this ;
380
帖子
4
勋章
6
Y币
发完整代码
一众科技 · 2022-3-28 11:12不是的
我在外面加了
getOldLoan(showProgress){
63
帖子
0
勋章
327
Y币
回复里面无法发送大量代码,也不能发文件,已经拖客服发过去了
63
帖子
0
勋章
327
Y币
<template name='tpl'>
    <view class="page">
        <view class="a_box">
            <view class="a_one">
                <text class="a_bt">必填信息</text>
            </view>
            <view class="a_one">
                <text class="a_zi">姓名</text>
                <input class="a_int" data-id="loanName" placeholder="请填写姓名" value={loanName} maxlength="4" oninput="insertInput"></input>
            </view>        
            <view class="a_one">
                <text class="a_zi">性别</text>
                <radio-group class="radio-group" data-id="sex" onChange={this.radiogroupChanged}>
                    <label>
                        <radio checked color="#ffad00"  value={sex} />
                        <text></text>
                    </label>
                    <label>
                        <radio color="#ffad00" value={sex} />
                        <text></text>
                    </label>
                </radio-group>

            </view>
            <view class="a_one">
                <text class="a_zi">年龄</text>
                <input class="a_int" data-id="age" placeholder="请填写年龄" value={age} keyboard-type="number" maxlength="2" oninput="insertInput"></input>
            </view>  
            <view class="a_one">
                <text class="a_jj">紧急联系人1</text>            
            </view>
            <view class="a_one">
                <text class="a_zi">姓名</text>
                <input class="a_int" data-id="contactFirstName" placeholder="请填写姓名" value={contactFirstName}  maxlength="11" oninput="insertInput" ></input>
            </view>
            <view class="a_one">
                <text class="a_zi">电话</text>
                <input class="a_int" data-id="contactFirst" placeholder="请填写电话" value={contactFirst}  maxlength="11" oninput="insertInput" ></input>
            </view>
            <view class="a_one">
                <text class="a_zi">关系</text>
                <input class="a_int" data-id="contactFirstRelation" placeholder="请填写关系" value={contactFirstRelation}  maxlength="11" oninput="insertInput" ></input>
            </view>
            <view class="a_one">
                <text class="a_jj">紧急联系人2</text>            
            </view>
            <view class="a_one">
                <text class="a_zi">姓名</text>
                <input class="a_int" data-id="contactSecondName" placeholder="请填写姓名" value={contactSecondName}  maxlength="11" oninput="insertInput" ></input>
            </view>
            <view class="a_one">
                <text class="a_zi">电话</text>
                <input class="a_int" data-id="contactSecondPhone" placeholder="请填写电话" value={contactSecondPhone}  maxlength="11" oninput="insertInput" ></input>
            </view>
            <view class="a_one">
                <text class="a_zi">关系</text>
                <input class="a_int" data-id="contactSecondRelation" placeholder="请填写关系" value={contactSecondRelation}  maxlength="11" oninput="insertInput" ></input>
            </view>           

        </view>

        <!-- btn -->
        <view class="flex1"></view>
        <view class="footer">
            <text v class="btn btn_orange" onclick="fnSubmit">去完善证件信息</text>
        </view>
    </view>
</template>
<script>
import $util from '../../utils/util.js'
import {md5} from '../../script/md5.js'
export default {
    name: 'address_edit',
    data() {
        return{
            id: null,
            loanName: '流过',
            productId: null,
            sex: '男',
            age: '12',
            contactFirstName: '是的',
            contactFirstRelation: '姐弟',
            contactFirst: '15655555555',
            contactSecondName: '第三',
            contactSecondRelation: '姐弟',
            contactSecondPhone: '15455555555',
            postdata: null
        }
    },
    computed:{
        imgHeight(){
            return Math.floor((api.winWidth - 4*15)/3);
        }
    },
    methods: {
        apiready(){
            this.data.ip = api.loadSecureValue({ sync: true, key: 'devIp' });
            let pageParam = api.pageParam;
            this.data.productId = pageParam.id;
            this.getOldLoan(true)
            api.addEventListener({
                name:'useraddress'
            }, (ret)=>{
                this.getOldLoan(true)
            });

        },
        radiogroupChanged(e) {
            console.log(e.detail.value);
            let value = e.detail.value;
            this.data.sex = value;
        },
        insertInput(e){
            let id = e.currentTarget.dataset.id;
            let value = e.detail.value;
            if (id == 'loanName') {
                this.data.loanName = value;
            } else if (id == 'sex') {
                this.data.sex = value;
            } else if (id == 'contactSecondPhone') {
                this.data.contactSecondPhone = value;
            } else if (id == 'contactSecondRelation') {
                this.data.contactSecondRelation = value;
            } else if (id == 'contactSecondName') {
                this.data.contactSecondName = value;
            } else if (id == 'contactFirst') {
                this.data.contactFirst = value;
            } else if (id == 'contactFirstRelation') {
                this.data.contactFirstRelation = value;
            } else if (id == 'contactFirstName') {
                this.data.contactFirstName = value;
            } else if (id == 'age') {
                this.data.age = value;
            }
        },
        fnChooseStr(e){
            let code = e.detail.code;
            let val = e.detail.value;
            this.data.quid = code.join(",");
            this.data.qustr = val.join(",");
        },
        onswitchchange(e){
            this.data.def = e.detail.value;
        },
        isMobile(str) {
            var mobileReg = /^1(3[0-9|4[0-9|5[0-9|6[0-9|7[0-9|8[0-9|9[0-9])\d{8}$/;
            return mobileReg.test(str);
        },
        fnSubmit(){            
            let loanName = this.data.loanName ;
            let sex = this.data.sex ;
            let age = this.data.age ;
            let contactSecondPhone = this.data.contactSecondPhone;
            let contactSecondRelation = this.data.contactSecondRelation;
            let contactSecondName = this.data.contactSecondName;
            let contactFirst = this.data.contactFirst;
            let contactFirstRelation = this.data.contactFirstRelation;
            let contactFirstName = this.data.contactFirstName;

            if (!loanName) {
                $util.toast('请输入本人姓名~');
                return;
            }
            if (!age) {
                $util.toast('请输入年龄~');
                return;
            }
            if (!contactSecondRelation) {
                $util.toast('请输入与联系人2关系~');
                return;
            }

            if (loanName.length > 4) {
                $util.toast('姓名不得超过4个字符~');
                return;
            }
            if (loanName.length < 2) {
                $util.toast('姓名不得少于2个字符~');
                return;
            }
            if (!sex) {
                $util.toast('请选择性别~');
                return;
            }
            if (!this.isMobile(contactSecondPhone)) {
                $util.toast('请输入正确的联系人2手机号~');
                return;
            }
            if (!this.isMobile(contactFirst)) {
                $util.toast('请输入正确的联系人1手机号~');
                return;
            }
            if (!contactFirstName) {
                $util.toast('请输入联系人1姓名');
                return;
            }
            if (!contactFirstRelation) {
                $util.toast('请输入联系人1关系~');
                return;
            }
            if (!contactSecondName) {
                $util.toast('请输入联系人2姓名~');
                return;
            }
            this.data.postdata.contactSecondName=contactSecondName;
            this.data.postdata.contactFirstRelation= contactFirstRelation;
            this.data.postdata.loanName=loanName;
            this.data.postdata.contactSecondRelation= contactSecondRelation
            this.data.postdata.contactFirstName= contactFirstName;
            this.data.postdata.contactFirst= contactFirst;
            this.data.postdata.contactSecondPhone= contactSecondPhone;
            this.data.postdata.sex= sex;
            this.data.postdata.age= age;
            this.data.postdata.productId = api.pageParam.id;            

            let url = this.data.ip+"/api/user/loan";
            let arr = new Array(5);
            let clientType = api.systemType;
            let version = api.appVersion;
            let device = api.deviceId;
            let devicetype = api.deviceModel;
            arr[0] = 'clienttype=' + clientType;
            arr[1] = 'version=' + version;
            arr[2] = 'device=' + device;
            arr[3] = 'devicetype=' + devicetype;
            arr.sort();
            arr[4] = 'wisdom';
            var jmstr = arr.toString().replace(/,/g, '');
            var sign = md5(jmstr);
            let bodydata =  this.data.postdata
            $util.ajax({
                url: url,
                method: 'post',
                headers: {
                    'clienttype': api.systemType,
                    'version': api.appVersion,
                    'device': api.deviceId,
                    'devicetype': api.deviceModel,
                    'sign': sign,
                    'jmstr': jmstr,
                },
                data: {body: bodydata}
            }, function(res, err){
                if (res) {
                    if (res.code == 200) {
                        bodydata.formId = res.data;
                        $util.openWin({
                            name: 'apply_'+bodydata.formId,
                            url: '../sfz/sfz.stml',
                            title: '上传证件',
                            pageParam: {
                                postdata: bodydata
                            }
                        });

                    } else {
                        $util.toast(res.msg);
                    }
                } else {
                    $util.toast('网络错误');
                }
            });
        },
        getOldLoan(showProgress){
            let that = this;
            if (showProgress) {
                $util.showProgress();
            }
            let url = this.data.ip+"/api/user/getLoan";
            let arr = new Array(5);
            let clientType = api.systemType;
            let version = api.appVersion;
            let device = api.deviceId;
            let devicetype = api.deviceModel;
            arr[0] = 'clienttype=' + clientType;
            arr[1] = 'version=' + version;
            arr[2] = 'device=' + device;
            arr[3] = 'devicetype=' + devicetype;
            arr.sort();
            arr[4] = 'wisdom';
            var jmstr = arr.toString().replace(/,/g, '');
            var sign = md5(jmstr);
            let bodydata =  {'productId': this.data.productId}
            $util.ajax({
                url: url,
                method: 'post',
                headers: {
                    'clienttype': api.systemType,
                    'version': api.appVersion,
                    'device': api.deviceId,
                    'devicetype': api.deviceModel,
                    'sign': sign,
                    'jmstr': jmstr,
                },
                data: {body: bodydata}
            }, function(res, err){
                if (res) {                  
                    if (res.code == 200 && res.data) {
                        console.log("ret200"+JSON.stringify(res))                       
                        that.data.postdata = res.data;
                        console.log("ret200"+JSON.stringify(this.data.postdata))
                    }
                }
                if (showProgress) {
                    $util.hideProgress();
                }
            });
        }

    }

}
</script>
<style>
.radio-group {
    flex-direction:row;
}
label {
    margin: 5px;
}
.page {
    height: 100%;
    background-color: #f6f6f6;
}
.a_box{
    padding: 0 15px;
    background-color: white;
}
.a_one{
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    height: 51px;
    border-top: 1px solid #f8f8f8;
}
.a_img{

    height: 65px;
}

.a_zi{
    font-size: 16px;
    color: #333333;
}

.a_bt{
    font-size: 16px;
    color: #ffad00;
}
.a_jj{
    font-size: 12px;
    color: #ffad00;
}
.a_int{
    width: 210px;
    height: 30px;
    text-align: right;
    color: #333333;
    border: none;
}
.qu_box{
    flex-direction: row;
    align-items: center;
}
.a_picker{
    flex-direction: row;
    justify-content: flex-end;
    align-items: center;
}
.a_gor{
    width: 10px;
    height: 10px;
    margin-left: 8px;
}
/* 备注 */
.bei_zi{
    font-size: 14px;
    margin: 15px 15px 4px;
    color: #6C7279;
}
.bei_box{
    height: 122px;
    box-sizing: border-box;
    padding: 15px;
    background-color: white;
}
.bei_area{
    width: 100%;
    height: 100%;
    border: none;
}
.flex1{
    flex: 1;
}
/* btn */
.footer{
    flex-direction: row;
    padding: 15px;
}
.btn{
    flex: 1;
    height: 45px;
    border-radius: 4px;
    font-weight:bold;
    text-align: center;
    line-height: 45px;
    font-size: 16px;
    color: white;
}
.btn:active{
    opacity: 0.7;
}
.btn_orange{
    background-color: #ffad00;
    margin-right: 15px;
}
.btn_red{
    background-color: #ff6600;
}
.image{
    margin-left: 15px;
    margin-top: 25px;
}
</style>


380
帖子
4
勋章
6
Y币
加了理论上是没问题的,新建个页面,单独测试这个代码片段查看,排除其他代码干扰
一众科技 · 2022-3-28 11:28必填信息
            
            
63
帖子
0
勋章
327
Y币
一个非常不友好修改方法解决了此问题,将那段ajax放在apiready就可以了
技术支持-F · 2022-3-28 11:34加了理论上是没问题的,新建个页面,单独测试这个代码片段查看,排除其他代码干扰
您需要登录后才可以回帖 登录

本版积分规则