1
This commit is contained in:
@@ -112,9 +112,32 @@
|
||||
<el-input type="textarea" :rows="3" v-model="form.channelPvJson" placeholder='示例: [{"property_id":"p","property_name":"颜色","value_id":"v","value_name":"红"}]' />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-alert
|
||||
v-if="createdProduct"
|
||||
:title="`商品ID:${createdProduct.productId || '-'}`"
|
||||
type="success"
|
||||
:closable="false"
|
||||
show-icon
|
||||
style="margin: 10px 0;"
|
||||
>
|
||||
<template slot="description">
|
||||
<div style="display:flex; align-items:center; flex-wrap:wrap; gap:12px;">
|
||||
<span>状态:{{ createdProduct.productStatus || '-' }}</span>
|
||||
<span>商家编码:{{ createdProduct.outerId || '-' }}</span>
|
||||
<el-button type="text" size="mini" @click="copyText(String(createdProduct.productId || ''))">复制ID</el-button>
|
||||
<el-button type="text" size="mini" @click="copyText(String(createdProduct.outerId || ''))">复制商家编码</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-alert>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button @click="closeDialog">取 消</el-button>
|
||||
<el-button type="primary" :loading="loading" @click="submitPublish">确 认</el-button>
|
||||
<el-button
|
||||
type="warning"
|
||||
v-if="createdProduct && createdProduct.productId"
|
||||
:loading="publishLoading"
|
||||
@click="publishNow"
|
||||
>上 架</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
@@ -132,6 +155,8 @@ export default {
|
||||
return {
|
||||
internalVisible: false,
|
||||
loading: false,
|
||||
publishLoading: false,
|
||||
createdProduct: null,
|
||||
wenanOptions: [],
|
||||
productImages: [],
|
||||
form: {
|
||||
@@ -236,6 +261,22 @@ export default {
|
||||
'form.channelCatId'(val) { this.loadProperties(); }
|
||||
},
|
||||
methods: {
|
||||
copyText(text) {
|
||||
const val = String(text || '').trim();
|
||||
if (!val) { this.$modal.msgWarning('无可复制的内容'); return; }
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
navigator.clipboard.writeText(val).then(() => { this.$modal.msgSuccess('复制成功'); }).catch(() => { this.fallbackCopy(val); });
|
||||
} else {
|
||||
this.fallbackCopy(val);
|
||||
}
|
||||
},
|
||||
fallbackCopy(text) {
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = text; ta.style.position = 'fixed'; ta.style.left = '-9999px';
|
||||
document.body.appendChild(ta); ta.focus(); ta.select();
|
||||
try { document.execCommand('copy'); this.$modal.msgSuccess('复制成功'); } catch(e){ this.$modal.msgError('复制失败'); }
|
||||
document.body.removeChild(ta);
|
||||
},
|
||||
async bootstrap() {
|
||||
// 初始化表单与文案/图片
|
||||
const d = this.initialData || {};
|
||||
@@ -349,25 +390,32 @@ export default {
|
||||
const outerId = res.data && (res.data.outerId || (res.data.data && res.data.data.outerId));
|
||||
if (outerId) this.$modal.msgSuccess(`发品成功,商家编码:${outerId}`); else this.$modal.msgSuccess('发品提交成功');
|
||||
} catch(e){ this.$modal.msgSuccess('发品提交成功'); }
|
||||
// 自动上架(需要返回的 productId 与 userName)
|
||||
try {
|
||||
const productId = this.extractProductId(res.data);
|
||||
if (productId && this.form.userName) {
|
||||
const pubRes = await publishProduct({ productId, userName: this.form.userName, appid: this.form.appid });
|
||||
if (pubRes && pubRes.code === 200) {
|
||||
const code = (pubRes.data && pubRes.data.code) ?? pubRes.code;
|
||||
if (code === 0 || code === 200) this.$modal.msgSuccess('上架成功'); else this.$modal.msgWarning('上架已提交或状态未知');
|
||||
} else {
|
||||
this.$modal.msgError((pubRes && pubRes.msg) || '上架失败');
|
||||
}
|
||||
}
|
||||
} catch (e) { /* 忽略上架异常,仅提示 */ }
|
||||
// 记录创建成功的商品,保留弹窗供手动“上架”
|
||||
const productId = this.extractProductId(res.data) || (res.data && (res.data.product_id || (res.data.data && res.data.data.product_id)));
|
||||
const productStatus = res.data && (res.data.product_status || (res.data.data && res.data.data.product_status));
|
||||
const outerId2 = res.data && (res.data.outerId || res.data.outer_id || (res.data.data && (res.data.data.outerId || res.data.data.outer_id)));
|
||||
this.createdProduct = { productId, productStatus, outerId: outerId2 };
|
||||
this.$emit('success', res);
|
||||
this.closeDialog();
|
||||
} else { this.$modal.msgError(res.msg || '发品失败'); }
|
||||
}).catch(err => { this.loading = false; console.error('发品失败', err); this.$modal.msgError('发品失败,请稍后重试'); });
|
||||
});
|
||||
},
|
||||
async publishNow() {
|
||||
if (!this.createdProduct || !this.createdProduct.productId) return;
|
||||
this.publishLoading = true;
|
||||
try {
|
||||
const pubRes = await publishProduct({ productId: this.createdProduct.productId, userName: this.form.userName, appid: this.form.appid });
|
||||
if (pubRes && pubRes.code === 200) {
|
||||
const code = (pubRes.data && pubRes.data.code) ?? pubRes.code;
|
||||
if (code === 0 || code === 200) this.$modal.msgSuccess('上架成功'); else this.$modal.msgWarning('上架已提交或状态未知');
|
||||
} else {
|
||||
this.$modal.msgError((pubRes && pubRes.msg) || '上架失败');
|
||||
}
|
||||
} catch(e) {
|
||||
this.$modal.msgError('上架失败');
|
||||
}
|
||||
this.publishLoading = false;
|
||||
},
|
||||
extractProductId(resp) {
|
||||
try {
|
||||
if (!resp) return null;
|
||||
|
||||
Reference in New Issue
Block a user