This commit is contained in:
浅念
2025-12-26 11:53:13 +08:00
parent 4d6c0d6901
commit ea2e2fec25
6 changed files with 253 additions and 126 deletions
+141 -45
View File
@@ -2,11 +2,33 @@
<view class="publish-page">
<uni-nav-bar leftText=" " :fixed="true" :border="false" @clickLeft="leftClick" color="#000000" backgroundColor="#fff" :statusBar="true" title="样机发布"></uni-nav-bar>
<view class="form-card">
<view class="select-input gradient-bg" @click="onSelectCategory()">
<view class="select-input gradient-bg position" @click="onSelectCategory()">
<view class="category-content">
<text class="category-text">{{form.category || '请输入/选择型号'}}</text>
</view>
<u-icon name="arrow-down" color="#3BC8BE" size="20"></u-icon>
<!-- 型号选择弹层 -->
<view v-if="showSelect1" class="select-popup">
<!-- 点击空白处关闭下拉 -->
<view class="popup-mask" @click="showSelect1=false"></view>
<view class="popup-panel" @click.stop>
<view class="popup-header">
<input class="popup-search" v-model="searchKey1" placeholder="搜索型号" />
<text class="popup-close" @click="showSelect1=false">取消</text>
</view>
<scroll-view scroll-y class="popup-list">
<view
v-for="item in filteredCategories"
:key="item.id"
class="popup-item"
@click.stop="selectCategory(item)"
>
{{ item.model }} ({{item.product_name}})
</view>
<view v-if="!filteredCategories.length" class="popup-empty">暂无数据</view>
</scroll-view>
</view>
</view>
</view>
<view class="conts mag-top">
<view class="">
@@ -36,11 +58,19 @@
</view>
</picker>
</view>
<view class="mag-top">
<input class="uni-input" focus v-model="form.price" @focus="checkLogin()" placeholder="请输入折扣价格" />
<view class="mag-top prices">
<input
class="uni-input"
type="digit"
:value="form.price"
placeholder="请输入折扣价格"
@input="onPriceInput"
@blur="onPriceBlur"
/>
<text>元</text>
</view>
<view class="mag-top">
<view style="margin-bottom: 10rpx;">是否包邮:</view>
<view style="margin-bottom: 10rpx;"><span style="color: red;">*</span> 是否包邮:</view>
<uni-data-checkbox v-model="form.is_free" :localdata="freeshipping" />
</view>
@@ -65,27 +95,7 @@
</view>
</view>
<!-- 型号选择弹层 -->
<view v-if="showSelect1" class="select-popup">
<view class="popup-mask" @click="showSelect1=false"></view>
<view class="popup-panel">
<view class="popup-header">
<input class="popup-search" v-model="searchKey1" placeholder="搜索型号" />
<text class="popup-close" @click="showSelect1=false">取消</text>
</view>
<scroll-view scroll-y class="popup-list">
<view
v-for="item in filteredCategories"
:key="item.id"
class="popup-item"
@click="selectCategory(item)"
>
{{ item.model }}
</view>
<view v-if="!filteredCategories.length" class="popup-empty">暂无数据</view>
</scroll-view>
</view>
</view>
<view class="foot">
<view class="agreement">
@@ -94,16 +104,16 @@
<text>我已阅读并同意</text>
<text class="link" @click.stop="viewAgreement">《发布协议》</text>
</label>
<button class="primary-btn gradient-btn" @click="submitForm">立即发布</button>
<button class="primary-btn gradient-btn" :disabled="userinfo.is_release!=1" @click="submitForm">立即发布</button>
</view>
</view>
<u-popup :show="show" :closeOnClickOverlay="false" :round="10" mode="center">
<view class="cont-text" >
<rich-text :nodes="viewAgreementcont"></rich-text>
</view>
<view class="cent">
<button class="btn1" @click="show = !show">取消</button>
<button class="btn" @click="agreementbtn">确定</button>
<view class="cents">
<button class="btns1" @click="show = !show">取消</button>
<button class="btns" @click="agreementbtn">确定</button>
</view>
</u-popup>
<u-popup :show="showlogin" :closeOnClickOverlay="false" :round="20" mode="center">
@@ -141,6 +151,7 @@ export default {
showSelect2:false,
searchKey1:'',
productcontents:'',
userinfo:'',
skudetils:'',
// 单选数据源
freeshipping: [ {
@@ -172,7 +183,7 @@ export default {
content:'',
media:[],
price:'',
is_free:1
is_free:''
},
selfChecked: false,
showlogin:false,
@@ -197,6 +208,7 @@ export default {
}
},
onLoad() {
this.getinfo()
},
onShow() {
@@ -204,6 +216,15 @@ export default {
// this.syncTabbar()
},
methods:{
getinfo(){
request({
url:'common/user/info',
method:'POST',
}).then(res => {
this.userinfo=res.data.data.user
uni.setStorageSync('is_release', res.data.data.user.is_release);
})
},
onSelectCategory() {
if (!uni.getStorageSync('is_login')) {
this.showlogin = true
@@ -261,8 +282,10 @@ export default {
this.form.category = item.model || ''
this.form.sku_id = item.id || ''
// 处理富文本,让图片自适应
this.productcontents = this.processRichText(item.desc || '')
console.log(this.productcontents)
if(item.desc !=''&& item.desc !=null){
this.productcontents = this.processRichText(item.desc || '')
console.log(this.productcontents)
}
this.showSelect1 = false
},
goprivacy(){
@@ -345,6 +368,33 @@ export default {
this.form.content = e.detail.value.slice(0,this.maxWords)
}
},
sanitize(v) {
v = String(v || '');
v = v.replace(/[^\d.]/g, ''); // 只留数字和点
const i = v.indexOf('.');
if (i !== -1) {
v = v.slice(0, i + 1) + v.slice(i + 1).replace(/\./g, '');
}
return v;
},
onPriceInput(e) {
const v = this.sanitize(e.detail.value);
// 关键:先更新数据,再 nextTick 强制触发视图回写
if (v !== this.form.price) {
this.form.price = v;
this.$nextTick(() => {
// 再写一次,逼迫输入框用受控值覆盖(对合成态更稳)
this.form.price = v;
});
}
},
onPriceBlur(e) {
// 兜底:失焦时彻底清洗,保证最终不会残留中文
const v = this.sanitize(e.detail.value);
if (v !== this.form.price) this.form.price = v;
},
uploadfn(imgUrl){
return new Promise((resolve, reject) => {
uni.uploadFile({
@@ -421,7 +471,7 @@ export default {
this.form.content='';
this.form.media=[];
this.form.price='';
this.form.is_free=1;
this.form.is_free='';
this.productcontents=''
// 同步清理文件选择器内部的文件列表
this.$nextTick(() => {
@@ -460,6 +510,14 @@ export default {
});
return
}
if(this.form.is_free==''){
uni.showToast({
title: '请选择包邮方式',
icon: 'none'
});
return
}
if(!this.form.media || this.form.media.length === 0){
uni.showToast({
title: '请至少上传一张图片',
@@ -503,6 +561,11 @@ export default {
</script>
<style lang="scss">
.prices{
display: flex;
align-items: center;
gap: 10px;
}
.detils{
margin-top: 40rpx;
overflow: hidden;
@@ -747,29 +810,32 @@ export default {
background: #3BC8BE;
margin-top: 20rpx;
}
.select-popup{
position: fixed;
inset: 0;
z-index: 999;
.position{
position: relative;
}
.popup-mask{
.select-popup{
position: absolute;
inset: 0;
background: rgba(0,0,0,0.35);
left: 0;
right: 0;
top: 100%; /* 紧贴选择框下方 */
z-index: 1000;
}
.popup-panel{
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 8rpx; /* 与选择框留一点间距 */
background: #fff;
border-top-left-radius: 20rpx;
border-top-right-radius: 20rpx;
max-height: 40vh; /* 控制整体可视高度 */
border-bottom-left-radius: 20rpx;
border-bottom-right-radius: 20rpx;
max-height: 40vh; /* 控制整体可视高度,下拉列表形式 */
display: flex;
flex-direction: column;
padding: 20rpx;
box-sizing: border-box;
z-index: 1001;
}
.popup-header{
display: flex;
@@ -788,6 +854,11 @@ export default {
margin-right: 12rpx;
box-sizing: border-box;
}
.popup-mask{
position: fixed;
inset: 0;
background: transparent;
}
.popup-title{
font-size: 28rpx;
color: #333;
@@ -816,10 +887,10 @@ export default {
padding: 30rpx 0;
}
.cont-text{
max-width: 350px;
max-height: 450px;
max-width: 300px;
max-height: 480px;
overflow: scroll;
padding: 10px;
padding: 10px 20px;
}
.popupcontent{
background-size: 100% 100%;
@@ -869,6 +940,31 @@ export default {
line-height: 50px;
}
}
.cents{
display: flex;
align-items: center;
justify-content: space-around;
padding: 0px 10px 20px;
.btns1{
background-color: #fff;
border: 1px solid #206ff4;
color: #206ff4;
border-radius: 50px;
width: 46%;
margin: 10px 0px 0px;
height: 40px;
line-height: 40px;
}
.btns{
background-color: #206ff4;
color: white;
border-radius: 50px;
width: 46%;
margin: 10px 0px 0px;
height: 40px;
line-height: 40px;
}
}
.product-card {
background: #fff;
margin-top: 16rpx;