| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <template>
- <view class="container">
- <view class="form">
- <view class="form-item">
- <text class="label">套餐名称</text>
- <input class="input" v-model="form.name" placeholder="如:21天养成学习习惯" />
- </view>
- <view class="form-item">
- <text class="label">详细介绍</text>
- <textarea class="textarea" v-model="form.description" placeholder="描述套餐的内容和目标" />
- </view>
- <view class="form-item">
- <text class="label">周期天数</text>
- <input class="input" type="number" v-model="form.cycleDays" placeholder="如:21" />
- </view>
- <view class="form-item">
- <text class="label">分类</text>
- <picker :range="categories" @change="onCategoryChange">
- <view class="picker">
- {{ form.category || '请选择分类' }}
- </view>
- </picker>
- </view>
- <view class="form-item">
- <text class="label">价格 (元)</text>
- <input class="input" type="digit" v-model="form.price" placeholder="0 表示免费" />
- </view>
- <view class="form-item">
- <text class="label">封面图</text>
- <view class="cover-upload" @click="chooseImage">
- <image v-if="form.coverImage" :src="form.coverImage" mode="aspectFill" class="cover-image"></image>
- <text v-else class="upload-icon">+</text>
- </view>
- </view>
- <view class="form-item">
- <text class="label">是否公开</text>
- <switch v-model="form.isPublic" :checked="form.isPublic" @change="onPublicChange" />
- <text class="switch-label">{{ form.isPublic ? '公开到市场' : '仅分享链接' }}</text>
- </view>
- <button class="btn-submit" @click="submit">保存</button>
- </view>
- </view>
- </template>
- <script>
- import { createPackage } from '@/utils/api.js'
- export default {
- data() {
- return {
- form: {
- name: '',
- description: '',
- cycleDays: 21,
- category: '',
- price: 0,
- isPublic: false,
- coverImage: ''
- },
- categories: ['学习', '习惯', '健康', '情绪', '其他']
- }
- },
- methods: {
- onCategoryChange(e) {
- this.form.category = this.categories[e.detail.value]
- },
- onPublicChange(e) {
- this.form.isPublic = e.detail.value
- },
- chooseImage() {
- uni.chooseImage({
- count: 1,
- success: (res) => {
- this.form.coverImage = res.tempFilePaths[0]
- }
- })
- },
- async submit() {
- if (!this.form.name) {
- uni.showToast({ title: '请输入套餐名称', icon: 'none' })
- return
- }
- if (!this.form.cycleDays) {
- uni.showToast({ title: '请输入周期天数', icon: 'none' })
- return
- }
- uni.showLoading({ title: '保存中...' })
- try {
- await createPackage({
- ...this.form,
- isPublic: this.form.isPublic ? 1 : 0
- })
- uni.showToast({ title: '创建成功' })
- setTimeout(() => {
- uni.navigateBack()
- }, 1500)
- } catch (e) {
- uni.showToast({ title: '创建失败', icon: 'none' })
- } finally {
- uni.hideLoading()
- }
- }
- }
- }
- </script>
- <style scoped>
- .container {
- min-height: 100vh;
- background: #f5f5f5;
- padding: 30rpx;
- }
- .form {
- background: #fff;
- border-radius: 16rpx;
- padding: 30rpx;
- }
- .form-item {
- margin-bottom: 30rpx;
- }
- .label {
- display: block;
- font-size: 28rpx;
- color: #333;
- margin-bottom: 16rpx;
- }
- .input, .textarea {
- width: 100%;
- padding: 20rpx;
- background: #f5f5f5;
- border-radius: 12rpx;
- font-size: 28rpx;
- }
- .textarea {
- height: 160rpx;
- }
- .picker {
- padding: 20rpx;
- background: #f5f5f5;
- border-radius: 12rpx;
- font-size: 28rpx;
- color: #333;
- }
- .cover-upload {
- width: 200rpx;
- height: 200rpx;
- background: #f5f5f5;
- border-radius: 12rpx;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .upload-icon {
- font-size: 60rpx;
- color: #ccc;
- }
- .cover-image {
- width: 200rpx;
- height: 200rpx;
- border-radius: 12rpx;
- }
- .switch-label {
- margin-left: 20rpx;
- font-size: 26rpx;
- color: #666;
- }
- .btn-submit {
- background: #4CAF50;
- color: #fff;
- border-radius: 40rpx;
- margin-top: 40rpx;
- }
- </style>
|