form-step1.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view class="page-container">
  3. <u-navbar title="新建团餐" :autoBack="true" :placeholder="true"></u-navbar>
  4. <view class="form-card">
  5. <view class="section-title">基础信息</view>
  6. <u-form :model="form" ref="uForm" :rules="rules"
  7. labelPosition="left" labelWidth="auto"
  8. :error-type="['toast', 'border-bottom']"
  9. >
  10. <u-form-item prop="category" label="商品分类" required borderBottom>
  11. <u-input v-model="form.category" placeholder="去设置" height="41" inputAlign="right" @click="show = true"></u-input>
  12. <u-icon slot="right" name="arrow-right" color="#C7C6CA"></u-icon>
  13. </u-form-item>
  14. <u-form-item prop="name" label="商品名称" required borderBottom>
  15. <u-input v-model="form.name" placeholder="输入商品名称" height="41" inputAlign="right"></u-input>
  16. </u-form-item>
  17. <u-form-item prop="coverImages" label="商品封面图" required labelPosition="top">
  18. <view class="upload-content">
  19. <view class="upload-tip">支持jpg、png格式,建议尺寸为300px*300px,上传1-4张</view>
  20. <u-upload
  21. name="cover"
  22. width="140"
  23. height="140"
  24. multiple
  25. :maxCount="4"
  26. :fileList="fileList.cover"
  27. :previewFullImage="true"
  28. @afterRead="afterRead($event, 'cover')"
  29. @delete="deletePic($event, 'cover')"
  30. ></u-upload>
  31. </view>
  32. </u-form-item>
  33. <u-form-item prop="detailImages" label="商品详情图" required borderBottom labelPosition="top">
  34. <view class="upload-content">
  35. <view class="upload-tip">支持jpg、png格式,建议尺寸为300px*300px,最多20张</view>
  36. <u-upload
  37. name="detail"
  38. width="140"
  39. height="140"
  40. multiple
  41. :maxCount="20"
  42. :fileList="fileList.detail"
  43. :previewFullImage="true"
  44. @afterRead="afterRead($event, 'detail')"
  45. @delete="deletePic($event, 'detail')"
  46. ></u-upload>
  47. </view>
  48. </u-form-item>
  49. <u-form-item prop="groupPrice" label="团餐价" required borderBottom>
  50. <u-input v-model="form.groupPrice" type="digit" height="41" :clearable="false" placeholder="请输入团餐价" inputAlign="right"></u-input>
  51. <text slot="right" class="input-suffix">元</text>
  52. </u-form-item>
  53. <u-form-item prop="salePrice" label="售价" required :borderBottom="false">
  54. <u-input v-model="form.salePrice" type="digit" height="41" :clearable="false" placeholder="商品售价" inputAlign="right"></u-input>
  55. <text slot="right" class="input-suffix">元</text>
  56. </u-form-item>
  57. </u-form>
  58. </view>
  59. <view class="footer-bar">
  60. <u-button type="primary" @click="goNextStep">下一步</u-button>
  61. </view>
  62. <!-- 商品分类选择 -->
  63. <u-action-sheet :list="actionSheetList" v-model="show" @click="actionSheetCallback"></u-action-sheet>
  64. </view>
  65. </template>
  66. <script>
  67. export default {
  68. data() {
  69. return {
  70. show: false,
  71. form: {
  72. name: '',
  73. category: '',
  74. coverImages: [],
  75. detailImages: [],
  76. groupPrice: '',
  77. salePrice: '',
  78. },
  79. fileList: {
  80. cover: [],
  81. detail: [],
  82. },
  83. actionSheetList: [
  84. {
  85. text: '早餐'
  86. },
  87. {
  88. text: '午餐'
  89. },
  90. {
  91. text: '晚餐'
  92. }
  93. ],
  94. rules: {
  95. name: [
  96. {
  97. required: true,
  98. message: '请输入名称',
  99. trigger: ['blur', 'change']
  100. }
  101. ],
  102. category: [
  103. {
  104. required: true,
  105. message: '请选择分类',
  106. trigger: ['blur', 'change']
  107. }
  108. ]
  109. }
  110. };
  111. },
  112. onReady() {
  113. this.$refs.uForm.setRules(this.rules);
  114. },
  115. methods: {
  116. // 分类选择,打开弹窗
  117. actionSheetCallback(index) {
  118. this.form.category = this.actionSheetList[index].text;
  119. },
  120. // 图片上传处理
  121. async afterRead(event, type) {
  122. let lists = [].concat(event.file);
  123. this.fileList[type].push(...lists);
  124. // 上传逻辑
  125. this.form[type === 'cover' ? 'coverImages' : 'detailImages'] = this.fileList[type].map(f => f.url);
  126. },
  127. deletePic(event, type) {
  128. this.fileList[type].splice(event.index, 1);
  129. this.form[type === 'cover' ? 'coverImages' : 'detailImages'] = this.fileList[type].map(f => f.url);
  130. },
  131. goNextStep() {
  132. // 表单校验
  133. this.$refs.uForm.validate(valid => {
  134. if (valid) {
  135. console.log('Form Data:', this.form);
  136. uni.navigateTo({
  137. url: '/pages/groupMeal/goods/form-step2'
  138. });
  139. } else {
  140. console.log('验证失败');
  141. }
  142. });
  143. }
  144. }
  145. };
  146. </script>
  147. <style lang="scss" scoped>
  148. $uni-text-color: #303133;
  149. $uni-color-primary: #2979ff;
  150. .page-container {
  151. min-height: 100vh;
  152. background-color: #f5f5f5;
  153. .section-title {
  154. font-weight: 500;
  155. font-size: 30rpx;
  156. color: #333333;
  157. }
  158. }
  159. .form-card {
  160. margin: 24rpx;
  161. padding: 20rpx 24rpx;
  162. background-color: #fff;
  163. border-radius: 16rpx;
  164. ::v-deep .u-form-item {
  165. padding: 16rpx 0;
  166. line-height: 1;
  167. .u-form-item--left__content {
  168. flex: none;
  169. .u-form-item--left__content--required {
  170. color: #fa3534;
  171. left: auto;
  172. right: 0;
  173. }
  174. }
  175. }
  176. .input-suffix {
  177. color: #232832;
  178. font-size: 26rpx;
  179. margin-left: 10rpx;
  180. }
  181. .upload-content {
  182. width: 100%;
  183. .upload-tip {
  184. font-weight: 400;
  185. font-size: 20rpx;
  186. color: #999999;
  187. margin-bottom: 20rpx;
  188. }
  189. ::v-deep .u-add-tips {
  190. margin-top: 10rpx;
  191. }
  192. }
  193. }
  194. // 底部按钮
  195. .footer-bar {
  196. ::v-deep .u-btn {
  197. width: 100%;
  198. height: 76rpx;
  199. font-weight: 400;
  200. font-size: 28rpx;
  201. color: #449AFF;
  202. border-radius: 54rpx;
  203. border: 1rpx solid #449AFF;
  204. background: #FFFFFF;
  205. }
  206. }
  207. // 分类选择弹窗样式
  208. .category-popup {
  209. padding: 30rpx;
  210. .popup-title {
  211. text-align: center;
  212. font-size: 34rpx;
  213. font-weight: bold;
  214. color: $uni-text-color;
  215. margin-bottom: 30rpx;
  216. }
  217. .category-list {
  218. max-height: 600rpx; // 限制高度,可滚动
  219. }
  220. .category-item {
  221. padding: 20rpx 0;
  222. font-size: 30rpx;
  223. color: $uni-text-color;
  224. border-bottom: 1rpx solid #eee;
  225. display: flex;
  226. justify-content: space-between;
  227. align-items: center;
  228. &:last-child {
  229. border-bottom: none;
  230. }
  231. &.selected {
  232. color: $uni-color-primary;
  233. font-weight: bold;
  234. }
  235. }
  236. .popup-footer {
  237. padding-top: 30rpx;
  238. }
  239. }
  240. </style>