mall_client/zyhs3_uniapp/pages/licai/mine/account/change.vue

308 lines
8.2 KiB
Vue

<style>
page {
background: #fff;
}
</style>
<style lang="scss" scoped>
@import "@/static/scss/global.scss";
.form_wraper {
// height: 100vh;
padding: 20rpx 30rpx;
box-sizing: border-box;
}
</style>
<template>
<view>
<view class="form_wraper bg-w">
<u--form labelPosition="left" ref="form1" labelWidth="100">
<u-form-item label="当前余额" borderBottom v-if="asstype === '10'">
<u--input v-model="currentBalance" disabled disabledColor="#ffffff" border="none" placeholder="0.00" style="color:#999999"></u--input>
</u-form-item>
<u-form-item label="当前消费券" borderBottom v-if="asstype === '9'">
<u--input v-model="currentConsumeBalance" disabled disabledColor="#ffffff" border="none" placeholder="0.00" style="color:#999999"></u--input>
</u-form-item>
<u-form-item label="收款人编号" borderBottom>
<u--input v-model="formData.payeeUserName" border="none" placeholder="请输入收款人编号">
</u--input>
<u-button slot="right" @tap="handlerCheck" text="校验" type="success" size="mini"></u-button>
</u-form-item>
<u-form-item label="账号昵称" prop="nickname" borderBottom>
<u--input v-model="nickname" disabledColor="#ffffff" disabled placeholder="账号昵称"
border="none"></u--input>
</u-form-item>
<u-form-item label="转账金额" borderBottom>
<u--input v-model="formData.transferAmount" border="none" type="number"
placeholder="请输入转账金额"></u--input>
</u-form-item>
<u-form-item label="备注" prop="form.remar">
<u--input v-model="formData.remark" disabledColor="#ffffff" placeholder="请输入备注"
border="none"></u--input>
</u-form-item>
</u--form>
<u-gap height="140rpx"></u-gap>
<u-button @click="handlerChange" type="primary" :text="button_text" color="#4BB22E"></u-button>
<u-toast ref="uToast"></u-toast>
<PayModal ref="payModal" payType="change" @handlerClose="handlerClose"
@handlerConfirmChange="handlerConfirmChange" @handlerInput="handlerInput" confirmText="确认转账"
:show="show"></PayModal>
</view>
</view>
</template>
<script>
import {
changeCoupon,
checkFirstApi
} from "@/api/system/user.js";
import {
handleTransferAccounts,
handleTransferConsume,
myAssetDetail
} from "@/api/system/api.js";
import PayModal from "@/components/payModal/payModal.vue";
import url from "@/common/http/url.js";
export default {
components: {
PayModal,
},
data() {
return {
show: false,
userInfo: JSON.parse(uni.getStorageSync("App-UserInfo")),
nickname: "", //转账人昵称
formData: {
remark: "",
initiatorUserName: "",
initiatorPhone: "",
phoneCode: "",
payeeUserName: "",
transferAmount: "",
changeassettype: "",
},
button_text: "",
asstype: 0,
assetMap: {
"asset_10": "0.00",
"asset_9": "0.00",
},
currentBalance: "0.00",
currentConsumeBalance: "0.00",
};
},
onLoad(e) {
this.formData.initiatorUserName = this.userInfo.username;
this.formData.initiatorPhone = this.userInfo.mobile;
this.asstype = e.asstype;
this.formData.changeassettype = this.asstype;
if (this.asstype === "3") {
this.button_text = "购买券转账";
} else if (this.asstype === "4") {
this.button_text = "土地兑付转账";
} else if (this.asstype === "5") {
this.button_text = "槟榔券转账";
} else if (this.asstype === "6") {
this.button_text = "槟榔兑付转账";
} else if (this.asstype === "10") {
this.button_text = "余额转账";
} else if (this.asstype === "9") {
this.button_text = "消费券转账";
} else {
this.button_text = "转账";
}
this.getAssetList();
console.log(e);
},
methods: {
async getAssetList() {
try {
const resp = await myAssetDetail();
resp.forEach(asset => {
this.assetMap['asset_' + asset.assetType] = Number(asset.value).toFixed(2);
});
if (this.asstype === "10") {
this.currentBalance = this.assetMap['asset_10'] || "0.00";
}
if (this.asstype === "9") {
this.currentConsumeBalance = this.assetMap['asset_9'] || "0.00";
}
} catch (e) {
// ignore
}
},
handlerCheck() {
let userName = this.formData.payeeUserName;
if (!userName) return this.$msg("请输入收款人编号");
this.$http("GET", url.user.getUserInfo, {
username: userName,
}).then(({
code,
data
}) => {
if (code == 200) {
if (data == null) {
this.$msg("用户不存在");
} else {
this.nickname = data.nickname;
}
}
});
},
handlerChange() {
let {
formData
} = this.$data;
if (!formData.initiatorUserName) return this.$toast("请输入收款人编号");
if (!formData.transferAmount) return this.$toast("请输入转账金额");
if (formData.transferAmount == 0) return this.$toast("转账金额不能为0");
// if (this.asstype === "4") return this.checkFirst();
this.$refs.payModal.handlerSend();
this.show = true;
},
//位置:"商家入驻"-->我的--"我的资产"---"兑付转账" 原来的接口需要再第二步执行,第一步需要请求接口http://127.0.0.1:8093/asset/dashangChange
checkFirst() {
uni.showLoading({
mask: true,
});
const form = {
...this.formData,
phoneCode: 111111
};
checkFirstApi(form)
.then((re) => {
changeCoupon({
...form,
...re.data
})
.then((res) => {
uni.hideLoading();
uni.showToast({
icon: "none",
title: res.msg,
});
})
.catch((er) => {
uni.hideLoading();
uni.showToast({
icon: "none",
title: er.msg || "当前错误",
});
});
})
.catch((err) => {
uni.hideLoading();
uni.showToast({
icon: "none",
title: err.msg || "当前错误",
});
});
},
handlerInput(e) {
console.log(e);
this.formData.phoneCode = e;
},
handlerClose() {
this.show = false;
},
handlerConfirmChange() {
// console.log('=========111111111111111===========');
uni.$u.debounce(() => {
// console.log('=========22222222222222===========');
if (this.asstype == 10) {
//新余额转账
let data = {
username: this.formData.payeeUserName,
changeMoney: this.formData.transferAmount,
code:this.formData.phoneCode
}
handleTransferAccounts(data)
.then((resp) => {
this.show = false;
uni.showToast({
icon: "none",
title: resp,
success: () => {
setTimeout(() => {
uni.navigateBack();
}, 2000);
},
});
})
.catch((err) => {
console.log("22222", err);
uni.showToast({
icon: "none",
title: err.message || "当前错误",
});
});
return;
}
if (this.asstype == 9) {
//新余额转账
let data = {
username: this.formData.payeeUserName,
changeMoney: this.formData.transferAmount,
code:this.formData.phoneCode
}
handleTransferConsume(data)
.then((resp) => {
this.show = false;
uni.showToast({
icon: "none",
title: resp,
success: () => {
setTimeout(() => {
uni.navigateBack();
}, 2000);
},
});
})
.catch((err) => {
console.log("22222", err);
uni.showToast({
icon: "none",
title: err.message || "当前错误",
});
});
return;
}
changeCoupon(this.formData)
.then((res) => {
console.log("22222", res);
let {
code,
msg
} = res;
if (code == 200) {
this.show = false;
uni.showToast({
icon: "none",
title: msg,
success: () => {
setTimeout(() => {
uni.navigateBack();
}, 2000);
},
});
} else {
uni.showToast({
icon: "none",
title: res.msg || "当前错误",
});
}
})
.catch((err) => {
console.log("22222", err);
// this.show = false
});
}, 500, true);
},
},
};
</script>