edit.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view class="edit-page">
  3. <!-- 项目摘要 -->
  4. <view class="summary">
  5. <view class="cover"></view>
  6. <view class="summary-info">
  7. <text class="title">{{ detail.title }}</text>
  8. <text class="billing">{{ detail.billingType }}</text>
  9. </view>
  10. </view>
  11. <!-- 只读信息行 -->
  12. <view class="info-section">
  13. <view class="info-row">
  14. <text class="label">服务分类</text>
  15. <text class="value">{{ detail.categoryName }} &gt;</text>
  16. </view>
  17. <view class="info-row">
  18. <text class="label">价格</text>
  19. <text class="value">¥{{ detail.platformPrice }} &gt;</text>
  20. </view>
  21. <view class="info-row">
  22. <text class="label">价格区间</text>
  23. <text class="value">{{ priceRangeText }}</text>
  24. </view>
  25. </view>
  26. <!-- 我的售价 -->
  27. <view class="price-section">
  28. <text class="section-label">我的售价</text>
  29. <input
  30. class="price-input"
  31. v-model="myPrice"
  32. type="digit"
  33. placeholder="请输入"
  34. />
  35. <text class="price-tip">
  36. 设置您的服务价格,请参照价格区间的最高价和最低价,不允许高于最高价或者低于最低价
  37. </text>
  38. </view>
  39. <view class="footer-bar">
  40. <view class="submit-btn" :class="{ active: canSubmit }" @click="onSubmit">提交</view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import { formatPriceRange } from './mock.js'
  46. export default {
  47. data() {
  48. return {
  49. detail: {
  50. id: '',
  51. title: '',
  52. categoryName: '',
  53. billingType: '',
  54. platformPrice: '',
  55. priceRangeMin: '',
  56. priceRangeMax: '',
  57. },
  58. myPrice: '',
  59. }
  60. },
  61. computed: {
  62. priceRangeText() {
  63. const { priceRangeMin, priceRangeMax } = this.detail
  64. if (priceRangeMin && priceRangeMax) {
  65. return formatPriceRange(priceRangeMin, priceRangeMax)
  66. }
  67. return '-'
  68. },
  69. canSubmit() {
  70. return this.myPrice !== '' && this.validatePrice()
  71. },
  72. },
  73. onLoad(query) {
  74. this.detail = {
  75. id: query.id || '',
  76. title: query.title || '中式推拿-培元疏通',
  77. categoryName: query.categoryName || '上门按摩',
  78. billingType: query.billingType || '按分钟计费',
  79. platformPrice: query.platformPrice || '368.00',
  80. priceRangeMin: Number(query.priceRangeMin) || 288,
  81. priceRangeMax: Number(query.priceRangeMax) || 368,
  82. }
  83. this.myPrice = query.myPrice || ''
  84. },
  85. methods: {
  86. validatePrice() {
  87. const val = Number(this.myPrice)
  88. if (isNaN(val)) return false
  89. return val >= this.detail.priceRangeMin && val <= this.detail.priceRangeMax
  90. },
  91. onSubmit() {
  92. if (!this.myPrice) {
  93. uni.showToast({ title: '请输入售价', icon: 'none' })
  94. return
  95. }
  96. if (!this.validatePrice()) {
  97. uni.showToast({
  98. title: `价格需在${this.detail.priceRangeMin}-${this.detail.priceRangeMax}之间`,
  99. icon: 'none',
  100. })
  101. return
  102. }
  103. uni.showToast({ title: '修改完成', icon: 'none' })
  104. setTimeout(() => uni.navigateBack(), 1000)
  105. },
  106. },
  107. }
  108. </script>
  109. <style lang="scss" scoped>
  110. .edit-page {
  111. min-height: 100vh;
  112. background: #f5f5f5;
  113. padding-bottom: 140rpx;
  114. }
  115. .summary {
  116. display: flex;
  117. align-items: center;
  118. background: #fff;
  119. padding: 32rpx;
  120. margin-bottom: 16rpx;
  121. }
  122. .cover {
  123. width: 120rpx;
  124. height: 120rpx;
  125. background: #eee;
  126. border-radius: 8rpx;
  127. flex-shrink: 0;
  128. }
  129. .summary-info {
  130. margin-left: 24rpx;
  131. }
  132. .title {
  133. display: block;
  134. font-size: 30rpx;
  135. color: #333;
  136. font-weight: 500;
  137. margin-bottom: 8rpx;
  138. }
  139. .billing {
  140. font-size: 24rpx;
  141. color: #999;
  142. }
  143. .info-section {
  144. background: #fff;
  145. margin-bottom: 16rpx;
  146. }
  147. .info-row {
  148. display: flex;
  149. align-items: center;
  150. justify-content: space-between;
  151. padding: 28rpx 32rpx;
  152. border-bottom: 1rpx solid #eee;
  153. font-size: 28rpx;
  154. &:last-child {
  155. border-bottom: none;
  156. }
  157. }
  158. .label {
  159. color: #333;
  160. }
  161. .value {
  162. color: #666;
  163. }
  164. .price-section {
  165. background: #fff;
  166. padding: 32rpx;
  167. }
  168. .section-label {
  169. display: block;
  170. font-size: 28rpx;
  171. color: #333;
  172. margin-bottom: 20rpx;
  173. }
  174. .price-input {
  175. width: 100%;
  176. height: 80rpx;
  177. border-bottom: 1rpx solid #eee;
  178. font-size: 30rpx;
  179. color: #333;
  180. margin-bottom: 20rpx;
  181. }
  182. .price-tip {
  183. font-size: 24rpx;
  184. color: #999;
  185. line-height: 1.6;
  186. }
  187. .footer-bar {
  188. position: fixed;
  189. left: 0;
  190. right: 0;
  191. bottom: 0;
  192. padding: 20rpx 32rpx;
  193. padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx);
  194. background: #fff;
  195. border-top: 1rpx solid #eee;
  196. }
  197. .submit-btn {
  198. height: 88rpx;
  199. line-height: 88rpx;
  200. text-align: center;
  201. border-radius: 12rpx;
  202. font-size: 32rpx;
  203. color: #999;
  204. background: #f0f0f0;
  205. &.active {
  206. color: #fff;
  207. background: #333;
  208. }
  209. }
  210. </style>