|
@@ -1,40 +1,38 @@
|
|
|
<template>
|
|
<template>
|
|
|
<view class="page">
|
|
<view class="page">
|
|
|
- <u-navbar :title="isEdit ? '编辑餐盒' : '新增餐盒'" :autoBack="true" :placeholder="true"></u-navbar>
|
|
|
|
|
- <view class="card">
|
|
|
|
|
|
|
+ <u-navbar :title="isEdit ? '编辑餐盒' : '新建餐盒'" :autoBack="true" :placeholder="true" :border-bottom="true"></u-navbar>
|
|
|
|
|
+
|
|
|
|
|
+ <view class="section-head">规格1</view>
|
|
|
|
|
+ <view class="form">
|
|
|
<view class="row">
|
|
<view class="row">
|
|
|
<text class="label">餐盒名称</text>
|
|
<text class="label">餐盒名称</text>
|
|
|
- <input v-model="form.name" placeholder="请输入" />
|
|
|
|
|
|
|
+ <input class="input" v-model="form.name" placeholder="请输入" placeholder-class="ph" />
|
|
|
</view>
|
|
</view>
|
|
|
<view class="row">
|
|
<view class="row">
|
|
|
<text class="label">餐盒价格</text>
|
|
<text class="label">餐盒价格</text>
|
|
|
- <input v-model="form.price" type="digit" placeholder="默认0" />
|
|
|
|
|
|
|
+ <input class="input" v-model="form.price" type="digit" placeholder="请输入金额 元" placeholder-class="ph" />
|
|
|
</view>
|
|
</view>
|
|
|
- <view class="row" @click="goBind">
|
|
|
|
|
- <text class="label">绑定商品</text>
|
|
|
|
|
- <text class="value">{{ form.bindCount ? `已绑${form.bindCount}个` : '去绑定' }}</text>
|
|
|
|
|
- <u-icon name="arrow-right" color="#C7C6CA"></u-icon>
|
|
|
|
|
|
|
+ <view class="row link" @click="goBind">
|
|
|
|
|
+ <text class="label">已绑商品</text>
|
|
|
|
|
+ <view class="right">
|
|
|
|
|
+ <text class="action">{{ form.bindCount ? `已绑${form.bindCount}个` : '去绑定' }}</text>
|
|
|
|
|
+ <u-icon name="arrow-right" color="#C7C6CA" size="24"></u-icon>
|
|
|
|
|
+ </view>
|
|
|
</view>
|
|
</view>
|
|
|
- <view class="upload-row">
|
|
|
|
|
|
|
+ <view class="row link last" @click="pickImage">
|
|
|
<text class="label">餐盒图片</text>
|
|
<text class="label">餐盒图片</text>
|
|
|
- <u-upload
|
|
|
|
|
- :action="uploadAction"
|
|
|
|
|
- :file-list="fileList"
|
|
|
|
|
- :form-data="uploadFormData"
|
|
|
|
|
- :max-count="1"
|
|
|
|
|
- :deletable="true"
|
|
|
|
|
- del-bg-color="#fa3534"
|
|
|
|
|
- upload-text="上传"
|
|
|
|
|
- width="160"
|
|
|
|
|
- height="160"
|
|
|
|
|
- preview-full-image
|
|
|
|
|
- @on-success="onUploadSuccess"
|
|
|
|
|
- @on-remove="onUploadRemove"
|
|
|
|
|
- />
|
|
|
|
|
|
|
+ <view class="right">
|
|
|
|
|
+ <image v-if="form.image" class="thumb" :src="form.image" mode="aspectFill" @click.stop="previewImage"></image>
|
|
|
|
|
+ <template v-else>
|
|
|
|
|
+ <text class="action">去上传</text>
|
|
|
|
|
+ <u-icon name="arrow-right" color="#C7C6CA" size="24"></u-icon>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
+
|
|
|
<view class="footer">
|
|
<view class="footer">
|
|
|
- <u-button type="primary" shape="circle" :loading="saving" @click="onSave">保存</u-button>
|
|
|
|
|
|
|
+ <view :class="['primary-btn', saving ? 'disabled' : '']" @click="onSave">{{ saving ? '保存中...' : '保存' }}</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</template>
|
|
</template>
|
|
@@ -50,12 +48,10 @@ export default {
|
|
|
saving: false,
|
|
saving: false,
|
|
|
uploadAction: configService.apiUrl + '/sys/common/upload',
|
|
uploadAction: configService.apiUrl + '/sys/common/upload',
|
|
|
imageHttp: configService.apiUrl + '/',
|
|
imageHttp: configService.apiUrl + '/',
|
|
|
- uploadFormData: { biz: 'temp' },
|
|
|
|
|
- fileList: [],
|
|
|
|
|
form: {
|
|
form: {
|
|
|
id: null,
|
|
id: null,
|
|
|
name: '',
|
|
name: '',
|
|
|
- price: '0',
|
|
|
|
|
|
|
+ price: '',
|
|
|
image: '',
|
|
image: '',
|
|
|
bindIds: [],
|
|
bindIds: [],
|
|
|
bindCount: 0,
|
|
bindCount: 0,
|
|
@@ -90,12 +86,11 @@ export default {
|
|
|
...this.form,
|
|
...this.form,
|
|
|
id: item.id,
|
|
id: item.id,
|
|
|
name: item.name || '',
|
|
name: item.name || '',
|
|
|
- price: String(item.price != null ? item.price : 0),
|
|
|
|
|
|
|
+ price: item.price != null && item.price !== '' ? String(item.price) : '',
|
|
|
image: item.image || '',
|
|
image: item.image || '',
|
|
|
status: item.status != null ? item.status : 1,
|
|
status: item.status != null ? item.status : 1,
|
|
|
sort: item.sort || 0
|
|
sort: item.sort || 0
|
|
|
};
|
|
};
|
|
|
- this.fileList = item.image ? [{ url: item.image }] : [];
|
|
|
|
|
}
|
|
}
|
|
|
if (pkgRes.data.code === 200) {
|
|
if (pkgRes.data.code === 200) {
|
|
|
const pkgs = pkgRes.data.result || [];
|
|
const pkgs = pkgRes.data.result || [];
|
|
@@ -105,19 +100,45 @@ export default {
|
|
|
})
|
|
})
|
|
|
.finally(() => uni.hideLoading());
|
|
.finally(() => uni.hideLoading());
|
|
|
},
|
|
},
|
|
|
- onUploadSuccess(res, index, lists) {
|
|
|
|
|
- this.fileList = lists;
|
|
|
|
|
- const urls = lists
|
|
|
|
|
- .map((item) => {
|
|
|
|
|
- if (item.response && item.response.message) return this.imageHttp + item.response.message;
|
|
|
|
|
- return item.url || '';
|
|
|
|
|
- })
|
|
|
|
|
- .filter(Boolean);
|
|
|
|
|
- this.form.image = urls[0] || '';
|
|
|
|
|
|
|
+ pickImage() {
|
|
|
|
|
+ uni.chooseImage({
|
|
|
|
|
+ count: 1,
|
|
|
|
|
+ sizeType: ['compressed'],
|
|
|
|
|
+ sourceType: ['album', 'camera'],
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ const filePath = (res.tempFilePaths || [])[0];
|
|
|
|
|
+ if (!filePath) return;
|
|
|
|
|
+ uni.showLoading({ title: '上传中' });
|
|
|
|
|
+ uni.uploadFile({
|
|
|
|
|
+ url: this.uploadAction,
|
|
|
|
|
+ filePath,
|
|
|
|
|
+ name: 'file',
|
|
|
|
|
+ formData: { biz: 'temp' },
|
|
|
|
|
+ success: (uploadRes) => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const data = typeof uploadRes.data === 'string' ? JSON.parse(uploadRes.data) : uploadRes.data;
|
|
|
|
|
+ if (data && data.success !== false && data.message) {
|
|
|
|
|
+ this.form.image = this.imageHttp + data.message;
|
|
|
|
|
+ } else if (data && data.url) {
|
|
|
|
|
+ this.form.image = data.url;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.$tip.toast((data && data.message) || '上传失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ this.$tip.toast('上传失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: () => {
|
|
|
|
|
+ this.$tip.toast('上传失败');
|
|
|
|
|
+ },
|
|
|
|
|
+ complete: () => uni.hideLoading()
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
},
|
|
},
|
|
|
- onUploadRemove(index, lists) {
|
|
|
|
|
- this.fileList = lists;
|
|
|
|
|
- this.form.image = '';
|
|
|
|
|
|
|
+ previewImage() {
|
|
|
|
|
+ if (!this.form.image) return;
|
|
|
|
|
+ uni.previewImage({ urls: [this.form.image] });
|
|
|
},
|
|
},
|
|
|
goBind() {
|
|
goBind() {
|
|
|
const boxId = this.form.id || 'new';
|
|
const boxId = this.form.id || 'new';
|
|
@@ -187,50 +208,83 @@ export default {
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|
|
|
.page {
|
|
.page {
|
|
|
min-height: 100vh;
|
|
min-height: 100vh;
|
|
|
- background: #f7f8fc;
|
|
|
|
|
|
|
+ background: #f7f8fa;
|
|
|
padding-bottom: 160rpx;
|
|
padding-bottom: 160rpx;
|
|
|
}
|
|
}
|
|
|
-.card {
|
|
|
|
|
- margin: 24rpx;
|
|
|
|
|
|
|
+.section-head {
|
|
|
|
|
+ padding: 20rpx 24rpx;
|
|
|
|
|
+ font-size: 30rpx;
|
|
|
|
|
+ font-weight: 600;
|
|
|
|
|
+ color: #333;
|
|
|
|
|
+ background: #eef3f8;
|
|
|
|
|
+}
|
|
|
|
|
+.form {
|
|
|
background: #fff;
|
|
background: #fff;
|
|
|
- border-radius: 16rpx;
|
|
|
|
|
- padding: 8rpx 24rpx;
|
|
|
|
|
}
|
|
}
|
|
|
.row {
|
|
.row {
|
|
|
display: flex;
|
|
display: flex;
|
|
|
align-items: center;
|
|
align-items: center;
|
|
|
min-height: 96rpx;
|
|
min-height: 96rpx;
|
|
|
|
|
+ padding: 0 24rpx;
|
|
|
border-bottom: 1rpx solid #f0f0f0;
|
|
border-bottom: 1rpx solid #f0f0f0;
|
|
|
|
|
+ &.last {
|
|
|
|
|
+ border-bottom: none;
|
|
|
|
|
+ }
|
|
|
|
|
+ &.link:active {
|
|
|
|
|
+ background: #fafafa;
|
|
|
|
|
+ }
|
|
|
.label {
|
|
.label {
|
|
|
width: 180rpx;
|
|
width: 180rpx;
|
|
|
font-size: 28rpx;
|
|
font-size: 28rpx;
|
|
|
|
|
+ color: #333;
|
|
|
|
|
+ flex-shrink: 0;
|
|
|
}
|
|
}
|
|
|
- input {
|
|
|
|
|
|
|
+ .input {
|
|
|
flex: 1;
|
|
flex: 1;
|
|
|
text-align: right;
|
|
text-align: right;
|
|
|
font-size: 28rpx;
|
|
font-size: 28rpx;
|
|
|
|
|
+ color: #333;
|
|
|
}
|
|
}
|
|
|
- .value {
|
|
|
|
|
|
|
+ .right {
|
|
|
flex: 1;
|
|
flex: 1;
|
|
|
- text-align: right;
|
|
|
|
|
- color: #449aff;
|
|
|
|
|
- font-size: 28rpx;
|
|
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ justify-content: flex-end;
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
-.upload-row {
|
|
|
|
|
- padding: 24rpx 0;
|
|
|
|
|
- .label {
|
|
|
|
|
|
|
+ .action {
|
|
|
font-size: 28rpx;
|
|
font-size: 28rpx;
|
|
|
- display: block;
|
|
|
|
|
- margin-bottom: 16rpx;
|
|
|
|
|
|
|
+ color: #999;
|
|
|
|
|
+ margin-right: 4rpx;
|
|
|
}
|
|
}
|
|
|
|
|
+ .thumb {
|
|
|
|
|
+ width: 72rpx;
|
|
|
|
|
+ height: 72rpx;
|
|
|
|
|
+ border-radius: 8rpx;
|
|
|
|
|
+ background: #eee;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+.ph {
|
|
|
|
|
+ color: #c0c4cc;
|
|
|
}
|
|
}
|
|
|
.footer {
|
|
.footer {
|
|
|
position: fixed;
|
|
position: fixed;
|
|
|
left: 0;
|
|
left: 0;
|
|
|
right: 0;
|
|
right: 0;
|
|
|
bottom: 0;
|
|
bottom: 0;
|
|
|
|
|
+ z-index: 20;
|
|
|
padding: 20rpx 40rpx calc(20rpx + env(safe-area-inset-bottom));
|
|
padding: 20rpx 40rpx calc(20rpx + env(safe-area-inset-bottom));
|
|
|
background: #fff;
|
|
background: #fff;
|
|
|
}
|
|
}
|
|
|
|
|
+.primary-btn {
|
|
|
|
|
+ height: 88rpx;
|
|
|
|
|
+ line-height: 88rpx;
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+ color: #fff;
|
|
|
|
|
+ font-size: 32rpx;
|
|
|
|
|
+ border-radius: 44rpx;
|
|
|
|
|
+ background: linear-gradient(90deg, #77b6ff 0%, #449aff 100%);
|
|
|
|
|
+ &.disabled {
|
|
|
|
|
+ opacity: 0.6;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
</style>
|
|
</style>
|