index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <page title="发布商品" ref="pageRef" light nav-color="transparent" custom-class="padding-nav">
  3. <view class="paddingX14 paddingY9">
  4. <view
  5. v-for="item in tableData"
  6. :key="item.data.key"
  7. class="marginY6 padding15 cell flex-align"
  8. >
  9. <image :src="item.data.spu.cover" class="image flex-shrink0" mode="aspectFit" />
  10. <view
  11. class="flex1 self-stretch paddingY3 flex-column-between paddingL12 color-white"
  12. >
  13. <view class="flex-align">
  14. <view class="font4 line-ellipsis flex1 bold" style="width: 0">
  15. {{ item.data.spu.name }}
  16. </view>
  17. </view>
  18. <view class="flex-align-between font4">
  19. <image
  20. style="width: 110rpx; height: 32rpx"
  21. :src="LEVEL_MAP[item.data.level].titleText"
  22. />
  23. <view class="color-white font3">x{{ item.total }}</view>
  24. </view>
  25. <view class="input-wrapper flex-align" :class="[item.data.price && 'active']">
  26. <input
  27. v-model.trim="item.data.price"
  28. type="number"
  29. placeholder="请输入商品单价"
  30. placeholder-class="placeholder-class"
  31. class="input flex1"
  32. maxlength="15"
  33. />
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="bottom-wrapper flex-align-center">
  39. <image :src="resource.sell_btn_create" webp class="btn-create" @click="preSubmit" />
  40. </view>
  41. </page>
  42. </template>
  43. <script>
  44. import resource from '@/utils/resource'
  45. import { LEVEL_MAP } from '@/utils/config'
  46. import { throttle } from '@/utils'
  47. export default {
  48. data() {
  49. return {
  50. resource,
  51. LEVEL_MAP,
  52. price: '',
  53. goods: null,
  54. tableData: null
  55. }
  56. },
  57. onLoad() {
  58. this.goods = this.$cache.get(this.$cache.key.STORE_SELL)
  59. this.handleGoods()
  60. },
  61. methods: {
  62. handleGoods() {
  63. let goodsMap = {}
  64. this.goods.forEach((item) => {
  65. let key = item.spuId + '_' + item.level
  66. let obj = goodsMap[key]
  67. if (obj) {
  68. goodsMap[key] = {
  69. total: obj.total + 1,
  70. data: obj.data
  71. }
  72. } else {
  73. goodsMap[key] = {
  74. total: 1,
  75. data: { ...item, key }
  76. }
  77. }
  78. })
  79. this.tableData = Object.values(goodsMap)
  80. },
  81. preSubmit() {
  82. throttle.call(this.submit)
  83. },
  84. submit() {
  85. let flag = this.tableData.every((item) => !!item.data.price)
  86. if (!flag) {
  87. this.$message.warn('请把价格填写完')
  88. return
  89. }
  90. let map = {}
  91. this.tableData.forEach((item) => {
  92. map[item.data.key] = item.data.price
  93. })
  94. this.goods.forEach((item) => {
  95. let key = item.spuId + '_' + item.level
  96. item.price = map[key]
  97. })
  98. this.$message.confirm('确定要发布商品吗?', () => {
  99. this.realSubmit()
  100. })
  101. },
  102. async realSubmit() {
  103. const array = this.goods.map((item) => ({
  104. inventoryId: item.id,
  105. price: item.price
  106. }))
  107. const res = await this.$service.sell.publish(array)
  108. if (res) {
  109. this.$event.emit(this.$event.key.STORE_REFRESH)
  110. this.$router.replace('sell_record')
  111. }
  112. }
  113. }
  114. }
  115. </script>
  116. <style>
  117. </style>
  118. <style lang="scss" scoped>
  119. .bg {
  120. position: fixed;
  121. z-index: -1;
  122. left: 0;
  123. right: 0;
  124. top: 0;
  125. width: 100%;
  126. height: 100%;
  127. opacity: 0.3;
  128. }
  129. .cell {
  130. background: rgba(0, 0, 0, 0.4);
  131. box-shadow: 0px 0px 5px 0px rgba(167, 110, 244, 0.5);
  132. border-radius: 8px;
  133. border: 1px solid rgba(255, 255, 255, 0.2);
  134. .image {
  135. box-shadow: 0px 0px 5px 0px rgba(167, 110, 244, 0.5);
  136. border-radius: 8px;
  137. width: 180rpx;
  138. height: 180rpx;
  139. }
  140. .input-wrapper {
  141. height: 62rpx;
  142. box-shadow: 0px 0px 4px 2px rgba(147, 67, 255, 0.3);
  143. border-radius: 4px;
  144. border: 1px solid rgba(174, 231, 255, 0.5);
  145. &.active {
  146. background: linear-gradient(315deg, #6c6fff 0%, #a948ff 100%);
  147. border: 0;
  148. }
  149. .input {
  150. color: white;
  151. text-align: center;
  152. font-size: 14px;
  153. }
  154. }
  155. }
  156. .bottom-wrapper {
  157. background: #222335;
  158. padding-bottom: 48rpx;
  159. position: fixed;
  160. bottom: 0;
  161. left: 0;
  162. right: 0;
  163. }
  164. .btn-create {
  165. width: 616rpx;
  166. height: 128rpx;
  167. }
  168. .padding-nav {
  169. padding-bottom: 176rpx;
  170. }
  171. .placeholder-class {
  172. color: #f0e6ff;
  173. }
  174. </style>