文件
xionggeshop/xgsc.gynhc.com_wx/pages/app/commission/apply.vue
2026-09-14 17:24:53 +08:00

457 行
11 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<!-- 申请分销商 / 我的资料 / 汇付进件 -->
<template>
<view class="apply-page brand-page">
<view class="page-wrap">
<shopro-navbar variant="gradient" :backText="pageTitle"></shopro-navbar>
<scroll-view scroll-y class="page-scroll" :scroll-into-view="scrollIntoView" scroll-with-animation>
<view class="page-content">
<view v-if="showBanner" class="banner-box brand-card">
<image
class="banner-img"
:src="formHeadImg"
mode="aspectFill"
@error="onBannerError"
></image>
</view>
<view class="notice-card brand-card" v-if="noticeText" :class="noticeType">
<text class="notice-icon">{{ noticeIcon }}</text>
<text class="notice-text">{{ noticeText }}</text>
</view>
<view class="section-card brand-card" v-if="formList.length">
<view class="section-head">
<text class="section-title">{{ shopSectionTitle }}</text>
<text class="section-sub" v-if="formReadonly">只读</text>
</view>
<u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType">
<block v-for="(form, index) in formList" :key="index">
<u-form-item
v-if="form.type === 'input'"
:labelStyle="labelStyle"
label-width="150"
label-position="left"
:label="form.name"
:prop="`value${index}`"
>
<view v-if="formReadonly" class="readonly-value">{{ displayValue(index) }}</view>
<u-input
v-else
:placeholder="`请输入${form.name}`"
:placeholderStyle="placeholderStyle"
v-model="model['value' + index]"
type="text"
:custom-style="inputStyle"
></u-input>
</u-form-item>
<u-form-item
v-if="form.type === 'number'"
:labelStyle="labelStyle"
label-position="left"
:label="form.name"
:prop="`value${index}`"
label-width="150"
>
<view v-if="formReadonly" class="readonly-value">{{ displayValue(index) }}</view>
<u-input
v-else
:placeholder="`请输入${form.name}`"
:placeholderStyle="placeholderStyle"
v-model="model['value' + index]"
type="number"
:custom-style="inputStyle"
></u-input>
</u-form-item>
<u-form-item
v-if="form.type === 'image'"
:labelStyle="labelStyle"
:prop="`value${index}`"
:label="form.name"
label-position="top"
label-width="150"
:borderBottom="true"
>
<u-upload
:deletable="!formReadonly"
:placeholderStyle="placeholderStyle"
:showProgress="false"
@on-uploaded="uploadSuccess($event, `value${index}`)"
@on-remove="uploadRemove($event, `value${index}`)"
:file-list="model[`valueList${index}`]"
:action="`${$API_URL}/index/upload`"
width="148"
height="148"
maxCount="1"
></u-upload>
</u-form-item>
</block>
</u-form>
</view>
<view class="footer-card brand-card" v-if="showSubmitBtn">
<view class="agreement u-flex" v-if="protocol">
<u-checkbox v-model="model.agreement" activeColor="#1677FF" shape="circle" @change="onAgreement"></u-checkbox>
<view class="agreement-text" @tap="$Router.push({ path: '/pages/public/richtext', query: { id: protocol.richtext_id } })">
我已阅读并遵守
<text class="text-underline">{{ protocol.name }}</text>
</view>
</view>
<button class="u-reset-button save-btn brand-btn-primary" @tap="onSubmit" :disabled="isFormEnd">
{{ submitBtnText }}
</button>
</view>
<view class="scroll-bottom-safe"></view>
</view>
</scroll-view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
formList: [],
formHeadImg: '',
protocol: null,
isFormEnd: false,
hasPostBtn: false,
formReadonly: false,
pageMode: 'apply',
hasSavedData: false,
agentStatus: '',
bannerLoadFailed: false,
scrollIntoView: '',
defaultHeadImg: '',
errorType: ['message'],
labelStyle: {
'font-size': '28rpx',
'font-weight': '500',
color: '#1F2937'
},
inputStyle: {
background: '#F9FAFB',
borderRadius: '12rpx',
padding: '0 24rpx',
height: '88rpx'
},
placeholderStyle: 'font-size: 28rpx;color:#9CA3AF;',
model: {},
inputNumber: [
{
required: true,
message: '内容不能为空!',
trigger: ['change', 'blur']
}
],
inputImage: [
{
required: true,
message: '请上传图片',
trigger: ['change', 'blur']
}
],
rules: {}
};
},
computed: {
pageTitle() {
if (this.pageMode === 'profile') return '我的资料';
if (this.pageMode === 'pending') return '申请资料';
return '申请分销商';
},
shopSectionTitle() {
if (this.pageMode === 'profile') return '分销商资料';
return '申请信息';
},
submitBtnText() {
return '确认提交';
},
showSubmitBtn() {
return this.hasPostBtn && this.pageMode === 'apply';
},
showBanner() {
return (
this.pageMode === 'apply' &&
this.formHeadImg &&
this.formHeadImg !== this.defaultHeadImg &&
!this.bannerLoadFailed
);
},
noticeType() {
if (this.pageMode === 'profile') return 'is-info';
if (this.pageMode === 'pending') return 'is-warn';
return 'is-primary';
},
noticeIcon() {
if (this.pageMode === 'profile') return 'ℹ';
if (this.pageMode === 'pending') return '⏳';
return '✎';
},
noticeText() {
if (this.pageMode === 'profile') return '您已是分销商,以下为您的资料';
if (this.pageMode === 'pending') return '资料审核中,暂不可修改';
if (this.showSubmitBtn && this.pageMode === 'apply' && this.agentStatus === 'needinfo') return '请完善资料后提交申请';
if (this.showSubmitBtn && this.pageMode === 'apply') return '提交申请后,请到「提现」页完成分账进件绑定';
return '';
}
},
onLoad() {
this.defaultHeadImg = this.$IMG_URL + '/imgs/commission/apply_bg.png';
this.formHeadImg = this.defaultHeadImg;
this.getFrom();
},
methods: {
uploadSuccess(e, value) {
this.model[value] = e[0].response.data.url;
},
uploadRemove(index, value) {
this.model[value] = '';
},
onAgreement(e) {
this.model.agreement = e.value;
},
displayValue(index) {
const val = this.model['value' + index];
return val !== '' && val != null ? val : '—';
},
onBannerError() {
this.bannerLoadFailed = true;
},
getFrom() {
let that = this;
that.$http('commission.form').then(res => {
if (res.code !== 1) {
that.$u.toast(res.msg || '加载申请表单失败');
return;
}
that.protocol = res.data.apply_protocol;
that.formList = res.data.apply_info || [];
that.hasSavedData = !!res.data.has_saved_apply_info;
that.agentStatus = res.data.agent_status || '';
that.pageMode = res.data.page_mode || 'apply';
that.formReadonly = that.pageMode !== 'apply' || !!res.data.form_readonly;
that.hasPostBtn = res.data.apply_status === true;
if (res.data.background_image) {
that.bannerLoadFailed = false;
that.formHeadImg = res.data.background_image;
}
that.initRules();
that.$nextTick(() => {
if (that.$refs.uForm) {
that.$refs.uForm.setRules(that.rules);
}
});
});
},
initRules() {
let that = this;
that.formList.forEach((item, index) => {
that.model = {
...that.model,
[`value${index}`]: item.value ? item.value : ''
};
that.model.agreement = false;
if (item.type === 'input' || item.type === 'number') {
that.rules = {
...that.rules,
[`value${index}`]: that.inputNumber
};
}
if (item.type === 'image') {
if (item.value) {
let arr = [{ url: item.value }];
that.model = {
...that.model,
[`valueList${index}`]: arr
};
}
that.rules = {
...that.rules,
[`value${index}`]: that.inputImage
};
}
});
},
applyCommission(data) {
let that = this;
that.isFormEnd = true;
const payload = { data: data };
that.$http('commission.apply', payload, '申请中...').then(res => {
that.isFormEnd = false;
if (res.code === 1) {
uni.showToast({
title: res.msg,
success: () => {
that.$Router.back();
}
});
}
}).catch(() => {
that.isFormEnd = false;
});
},
onSubmit() {
let that = this;
const submitApply = () => {
let formData = that.formList.map((item, index) => ({
...item,
value: that.model[`value${index}`] != null ? that.model[`value${index}`] : item.value
}));
that.applyCommission(formData);
};
if (!this.$refs.uForm) {
submitApply();
return;
}
this.$refs.uForm.validate(valid => {
if (!valid) {
this.$u.toast('请完善表单');
return;
}
if (!this.model.agreement && this.protocol) {
return this.$u.toast('请勾选协议');
}
submitApply();
});
}
}
};
</script>
<style lang="scss" scoped>
.apply-page {
height: 100vh;
}
.page-wrap {
background: $brand-header-gradient;
height: 100%;
display: flex;
flex-direction: column;
}
.page-scroll {
flex: 1;
height: 0;
}
.page-content {
padding: 16rpx $brand-page-gutter 0;
box-sizing: border-box;
}
.banner-box {
height: 200rpx;
margin-bottom: 20rpx;
overflow: hidden;
.banner-img {
width: 100%;
height: 100%;
display: block;
}
}
.notice-card {
display: flex;
align-items: flex-start;
padding: 24rpx 28rpx;
margin-bottom: 20rpx;
font-size: 26rpx;
line-height: 1.5;
.notice-icon {
flex-shrink: 0;
margin-right: 12rpx;
font-size: 28rpx;
}
&.is-info {
background: #f0f9ff;
border: 1rpx solid #bae6fd;
color: #0369a1;
}
&.is-warn {
background: #fffbeb;
border: 1rpx solid #fde68a;
color: #b45309;
}
&.is-primary {
background: $brand-primary-light;
border: 1rpx solid rgba(22, 119, 255, 0.2);
color: $brand-primary-dark;
}
}
.section-card {
padding: 28rpx 28rpx 8rpx;
margin-bottom: 0;
}
.section-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8rpx;
}
.section-title {
font-size: 30rpx;
font-weight: 600;
color: $brand-text;
}
.section-sub {
font-size: 22rpx;
color: $brand-text-muted;
padding: 4rpx 12rpx;
background: #f3f4f6;
border-radius: 8rpx;
}
.readonly-value {
flex: 1;
font-size: 28rpx;
color: $brand-text;
line-height: 1.5;
padding: 16rpx 0;
word-break: break-all;
}
.footer-card {
margin-top: 24rpx;
padding: 28rpx;
}
.agreement {
margin-bottom: 24rpx;
.agreement-text {
font-size: 24rpx;
font-weight: 500;
color: $brand-primary;
margin-left: 8rpx;
.text-underline {
text-decoration: underline;
}
}
}
.save-btn {
width: 100%;
height: 88rpx;
line-height: 88rpx;
font-size: 30rpx;
font-weight: 600;
border-radius: 44rpx;
}
.scroll-bottom-safe {
height: calc(40rpx + env(safe-area-inset-bottom));
}
</style>