spec-detail.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <view class="page">
  3. <u-navbar title="规格明细" :autoBack="true" :placeholder="true">
  4. <view slot="right" class="nav-right" @click="toggleBatch">{{ batchMode ? '取消' : '批量操作' }}</view>
  5. </u-navbar>
  6. <scroll-view scroll-y class="list" :style="{ paddingBottom: batchMode ? '140rpx' : '160rpx' }">
  7. <view class="card" v-for="(item, index) in combos" :key="index" @click="toggleSelect(index)">
  8. <view class="check" v-if="batchMode">
  9. <view :class="['dot', selected.includes(index) ? 'on' : '']"></view>
  10. </view>
  11. <view class="body">
  12. <view class="title">{{ item.label }}</view>
  13. <view class="row">
  14. <text class="label required">售价 (元)</text>
  15. <input v-model="item.price" type="digit" placeholder="请输入" :disabled="batchMode" />
  16. </view>
  17. <view class="row">
  18. <text class="label required">原价 (元)</text>
  19. <input v-model="item.sellingPrice" type="digit" placeholder="请输入" :disabled="batchMode" />
  20. </view>
  21. <view class="row">
  22. <text class="label required">每日库存</text>
  23. <input v-model="item.stock" type="number" placeholder="请输入" :disabled="batchMode" />
  24. </view>
  25. <view class="row">
  26. <text class="label">成本价 (元)</text>
  27. <input v-model="item.costPrice" type="digit" placeholder="选填" :disabled="batchMode" />
  28. </view>
  29. </view>
  30. </view>
  31. </scroll-view>
  32. <view class="footer" v-if="!batchMode">
  33. <u-button type="primary" shape="circle" :disabled="!canNext" @click="goNext">下一步</u-button>
  34. </view>
  35. <view class="batch-footer" v-else>
  36. <view class="all" @click="toggleAll">
  37. <view :class="['dot', isAll ? 'on' : '']"></view>
  38. 全选
  39. </view>
  40. <view class="b-btn" @click="openBatchEdit">批量修改</view>
  41. </view>
  42. <u-popup v-model="batchShow" mode="bottom" border-radius="24">
  43. <view class="batch-sheet">
  44. <view class="bs-title">批量设置</view>
  45. <view class="row">
  46. <text class="label required">售价 (元)</text>
  47. <input v-model="batchForm.price" type="digit" placeholder="请输入" />
  48. </view>
  49. <view class="row">
  50. <text class="label required">原价 (元)</text>
  51. <input v-model="batchForm.sellingPrice" type="digit" placeholder="请输入" />
  52. </view>
  53. <view class="row">
  54. <text class="label required">每日库存</text>
  55. <input v-model="batchForm.stock" type="number" placeholder="请输入" />
  56. </view>
  57. <view class="row">
  58. <text class="label">成本价 (元)</text>
  59. <input v-model="batchForm.costPrice" type="digit" placeholder="选填" />
  60. </view>
  61. <view class="bs-btn" @click="applyBatch">确定</view>
  62. </view>
  63. </u-popup>
  64. </view>
  65. </template>
  66. <script>
  67. import session from '../session.js';
  68. export default {
  69. data() {
  70. return {
  71. combos: [],
  72. batchMode: false,
  73. selected: [],
  74. batchShow: false,
  75. batchForm: { price: '', sellingPrice: '', stock: '', costPrice: '' }
  76. };
  77. },
  78. computed: {
  79. isAll() {
  80. return this.combos.length > 0 && this.selected.length === this.combos.length;
  81. },
  82. canNext() {
  83. return this.combos.every((i) => i.price !== '' && i.sellingPrice !== '' && i.stock !== '');
  84. }
  85. },
  86. onLoad() {
  87. const draft = session.getDishDraft() || {};
  88. this.combos = (draft.combos || []).map((i) => ({
  89. ...i,
  90. sellingPrice: i.sellingPrice != null && i.sellingPrice !== '' ? i.sellingPrice : i.originPrice || ''
  91. }));
  92. if (!this.combos.length) {
  93. uni.showToast({ title: '请先选择规格', icon: 'none' });
  94. setTimeout(() => uni.navigateBack(), 500);
  95. }
  96. },
  97. methods: {
  98. toggleBatch() {
  99. this.batchMode = !this.batchMode;
  100. this.selected = [];
  101. },
  102. toggleSelect(index) {
  103. if (!this.batchMode) return;
  104. const i = this.selected.indexOf(index);
  105. if (i >= 0) this.selected.splice(i, 1);
  106. else this.selected.push(index);
  107. },
  108. toggleAll() {
  109. if (this.isAll) this.selected = [];
  110. else this.selected = this.combos.map((_, i) => i);
  111. },
  112. openBatchEdit() {
  113. if (!this.selected.length) {
  114. uni.showToast({ title: '请先选择规格', icon: 'none' });
  115. return;
  116. }
  117. this.batchForm = { price: '', sellingPrice: '', stock: '', costPrice: '' };
  118. this.batchShow = true;
  119. },
  120. applyBatch() {
  121. const { price, sellingPrice, stock, costPrice } = this.batchForm;
  122. if (price === '' || sellingPrice === '' || stock === '') {
  123. uni.showToast({ title: '请完善必填项', icon: 'none' });
  124. return;
  125. }
  126. this.selected.forEach((i) => {
  127. this.combos[i].price = price;
  128. this.combos[i].sellingPrice = sellingPrice;
  129. this.combos[i].stock = stock;
  130. this.combos[i].costPrice = costPrice;
  131. });
  132. this.batchShow = false;
  133. this.batchMode = false;
  134. this.selected = [];
  135. },
  136. goNext() {
  137. if (!this.canNext) {
  138. uni.showToast({ title: '请完善规格价格库存', icon: 'none' });
  139. return;
  140. }
  141. const draft = session.getDishDraft() || {};
  142. draft.combos = this.combos;
  143. session.setDishDraft(draft);
  144. uni.navigateTo({ url: '/pages/merchantDish/dish/sale-time?from=multi' });
  145. }
  146. }
  147. };
  148. </script>
  149. <style lang="scss" scoped>
  150. .page {
  151. min-height: 100vh;
  152. background: #f7f8fc;
  153. }
  154. .nav-right {
  155. padding-right: 24rpx;
  156. font-size: 28rpx;
  157. color: #333;
  158. }
  159. .list {
  160. height: calc(100vh - 100rpx);
  161. padding: 16rpx 24rpx;
  162. box-sizing: border-box;
  163. }
  164. .card {
  165. display: flex;
  166. background: #fff;
  167. border-radius: 16rpx;
  168. padding: 20rpx;
  169. margin-bottom: 16rpx;
  170. .check {
  171. display: flex;
  172. align-items: center;
  173. margin-right: 16rpx;
  174. }
  175. .dot {
  176. width: 36rpx;
  177. height: 36rpx;
  178. border-radius: 50%;
  179. border: 2rpx solid #ccc;
  180. &.on {
  181. background: #449aff;
  182. border-color: #449aff;
  183. }
  184. }
  185. .body {
  186. flex: 1;
  187. }
  188. .title {
  189. font-size: 28rpx;
  190. font-weight: 500;
  191. margin-bottom: 8rpx;
  192. }
  193. .row {
  194. display: flex;
  195. align-items: center;
  196. min-height: 72rpx;
  197. .label {
  198. width: 180rpx;
  199. font-size: 26rpx;
  200. &.required::before {
  201. content: '*';
  202. color: #ff4d4f;
  203. }
  204. }
  205. input {
  206. flex: 1;
  207. text-align: right;
  208. font-size: 26rpx;
  209. }
  210. }
  211. }
  212. .footer {
  213. position: fixed;
  214. left: 0;
  215. right: 0;
  216. bottom: 0;
  217. padding: 20rpx 40rpx calc(20rpx + env(safe-area-inset-bottom));
  218. background: #fff;
  219. }
  220. .batch-footer {
  221. position: fixed;
  222. left: 0;
  223. right: 0;
  224. bottom: 0;
  225. display: flex;
  226. align-items: center;
  227. padding: 16rpx 24rpx calc(16rpx + env(safe-area-inset-bottom));
  228. background: #fff;
  229. .all {
  230. display: flex;
  231. align-items: center;
  232. font-size: 26rpx;
  233. margin-right: 20rpx;
  234. .dot {
  235. width: 36rpx;
  236. height: 36rpx;
  237. border-radius: 50%;
  238. border: 2rpx solid #ccc;
  239. margin-right: 10rpx;
  240. &.on {
  241. background: #449aff;
  242. border-color: #449aff;
  243. }
  244. }
  245. }
  246. .b-btn {
  247. flex: 1;
  248. text-align: center;
  249. height: 72rpx;
  250. line-height: 72rpx;
  251. border-radius: 36rpx;
  252. background: linear-gradient( 89deg, #10ABFE 0%, #2260F6 100%);
  253. color: #fff;
  254. font-size: 28rpx;
  255. }
  256. }
  257. .batch-sheet {
  258. padding: 30rpx 40rpx calc(30rpx + env(safe-area-inset-bottom));
  259. .bs-title {
  260. text-align: center;
  261. font-size: 32rpx;
  262. font-weight: 600;
  263. margin-bottom: 20rpx;
  264. }
  265. .row {
  266. display: flex;
  267. align-items: center;
  268. min-height: 88rpx;
  269. border-bottom: 1rpx solid #f0f0f0;
  270. .label {
  271. width: 180rpx;
  272. &.required::before {
  273. content: '*';
  274. color: #ff4d4f;
  275. }
  276. }
  277. input {
  278. flex: 1;
  279. text-align: right;
  280. }
  281. }
  282. .bs-btn {
  283. margin-top: 30rpx;
  284. height: 80rpx;
  285. line-height: 80rpx;
  286. text-align: center;
  287. background: #449aff;
  288. color: #fff;
  289. border-radius: 40rpx;
  290. }
  291. }
  292. </style>