stock-manage.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <view class="stock">
  3. <view class="goods_box" v-for="(item,goodsIdx) in goodsList" :key="item.id">
  4. <view class="goods_con flexB" @click="cur(goodsIdx)">
  5. <view class="flexS">
  6. <image :src="item.img" class="goods_img"></image>
  7. <view>
  8. <view style="font-size:30rpx;font-weight: bold;">{{item.name}}</view>
  9. <view class="one_year" style="width:120rpx;">3条装</view>
  10. </view>
  11. </view>
  12. <text class="store_icon iconjiantou4" v-if="item.toggle"></text>
  13. <text class="store_icon iconjiantou2" v-else></text>
  14. </view>
  15. <view class="goods_detail" v-if="item.toggle">
  16. <view class="title flexS">
  17. <text>规格</text>
  18. <text>尺码</text>
  19. <text>库存</text>
  20. <text class="pedometer">修改</text>
  21. </view>
  22. <view>
  23. <view class="stock_opear flexS" v-for="(temp,skuIdx) in item.sku" :key="temp.id">
  24. <view>{{temp.type}}</view>
  25. <view>{{temp.size}}</view>
  26. <view>{{temp.num}}</view>
  27. <view class="pedometer flexC">
  28. <image src="../../static/imgs/shop/minus.png" class="symbol_icon"
  29. @click="minus(goodsIdx,skuIdx,temp.num)"></image>
  30. <input type="number" v-model="temp.num" @input="getVal($event, goodsIdx, skuIdx)"
  31. maxlength="5">
  32. <image src="../../static/imgs/shop/add.png" class="symbol_icon"
  33. @click="add(goodsIdx,skuIdx)"></image>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="dataAll">
  39. <view class="sex">
  40. 男款:{{ item.sku|man }}套
  41. /
  42. 女款:{{ item.sku|female }}套
  43. </view>
  44. <view class="num">
  45. <text>
  46. 合计:
  47. </text>
  48. <text class="spec">
  49. {{ item.sku.reduce((sum, e) => sum + Number(e.num || 0), 0) }}套
  50. </text>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="sub_btn_box flexC">
  55. <view class="sub_btn" @click="submit">立即提交</view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import {
  61. getSku,
  62. setStock
  63. } from '../../apis/shop.js'
  64. export default {
  65. data() {
  66. return {
  67. goodsList: []
  68. }
  69. },
  70. onShow() {
  71. this.getlist()
  72. },
  73. filters: {
  74. man(data) {
  75. let num = 0;
  76. if (data) {
  77. data.map(i => {
  78. if (i.type == '男款') {
  79. num += i.num
  80. }
  81. })
  82. }
  83. return num;
  84. },
  85. female(data) {
  86. let num = 0;
  87. if (data) {
  88. data.map(i => {
  89. if (i.type == '女款') {
  90. num += i.num
  91. }
  92. })
  93. }
  94. return num;
  95. }
  96. },
  97. methods: {
  98. //展开关闭列表
  99. cur(idx) {
  100. this.goodsList[idx].toggle = !this.goodsList[idx].toggle
  101. },
  102. //添加数量
  103. add(goodsIdx, skuIdx) {
  104. this.goodsList[goodsIdx].sku[skuIdx].num++;
  105. },
  106. //获取添加的数量
  107. getVal(e, goodsIdx, skuIdx) {
  108. this.goodsList[goodsIdx].sku[skuIdx].num = Number(e.detail.value);
  109. },
  110. //减少数量
  111. minus(goodsIdx, skuIdx, num) {
  112. if (num == 0) {
  113. uni.showToast({
  114. title: '没有啦~',
  115. icon: 'none'
  116. })
  117. return false;
  118. }
  119. this.goodsList[goodsIdx].sku[skuIdx].num--;
  120. },
  121. getlist() {
  122. getSku().then(res => {
  123. if (res.code == 200) {
  124. let list = res.data;
  125. list.map((i, idx) => {
  126. this.$set(i, 'sku', [])
  127. if (idx == 0) {
  128. this.$set(i, 'toggle', true)
  129. } else {
  130. this.$set(i, 'toggle', false)
  131. }
  132. let size = i.size;
  133. for (let k in size) {
  134. size[k].map(j => {
  135. i.sku.push(j)
  136. })
  137. }
  138. })
  139. this.goodsList = list;
  140. }
  141. })
  142. },
  143. //立即提交
  144. submit() {
  145. let list = this.goodsList;
  146. let data = [];
  147. let k = 0;
  148. list.map(i => {
  149. let sku = i.sku;
  150. for (let j in sku) {
  151. if (sku[j].num > 0) {
  152. data[k] = [sku[j].id, sku[j].num]
  153. k++;
  154. }
  155. }
  156. })
  157. setStock({
  158. data
  159. }).then(res => {
  160. if (res.code == 200) {
  161. uni.showModal({
  162. content: '设置成功',
  163. showCancel: false,
  164. success: res => {
  165. uni.navigateBack({})
  166. }
  167. })
  168. } else {
  169. uni.showModal({
  170. content: res.data || '设置失败',
  171. showCancel: false
  172. })
  173. }
  174. })
  175. },
  176. }
  177. }
  178. </script>
  179. <style>
  180. page {
  181. width: 100%;
  182. min-height: 100%;
  183. background: #F9F9FB;
  184. }
  185. </style>
  186. <style lang="scss">
  187. .stock {
  188. position: relative;
  189. padding-bottom: 140rpx;
  190. }
  191. .goods_box {
  192. padding: 30rpx;
  193. box-sizing: border-box;
  194. margin-top: 20rpx;
  195. background: #fff;
  196. .goods_con {
  197. .store_icon {
  198. font-size: 40rpx;
  199. color: #333;
  200. }
  201. .goods_img {
  202. width: 180rpx;
  203. height: 144rpx;
  204. border-radius: 16rpx;
  205. flex-shrink: 0;
  206. margin-right: 20rpx;
  207. }
  208. }
  209. .goods_detail {
  210. .title,
  211. .stock_opear {
  212. text,
  213. >view {
  214. width: 20%;
  215. text-align: center;
  216. font-size: 30rpx;
  217. }
  218. .pedometer {
  219. width: 40%;
  220. text-align: center;
  221. .symbol_icon {
  222. width: 60rpx;
  223. height: 60rpx;
  224. }
  225. input {
  226. width: 130rpx;
  227. }
  228. }
  229. }
  230. .title {
  231. padding: 20rpx 0;
  232. border-bottom: 2rpx solid #eee;
  233. text {
  234. color: #999;
  235. }
  236. }
  237. .stock_opear {
  238. height: 104rpx;
  239. border-bottom: 2rpx solid #eee;
  240. >view {
  241. font-weight: bold;
  242. }
  243. }
  244. .stock_opear:last-child {
  245. border-bottom: none;
  246. }
  247. }
  248. .dataAll {
  249. width: 100%;
  250. margin-top: 15rpx;
  251. display: flex;
  252. align-items: center;
  253. justify-content: space-between;
  254. border-top: 2rpx solid #eee;
  255. padding-top: 15rpx;
  256. .sex {
  257. color: #333333;
  258. font-size: 28rpx;
  259. }
  260. .num {
  261. color: #999999;
  262. font-size: 28rpx;
  263. .spec {
  264. color: $base-color;
  265. font-size: 40rpx;
  266. font-weight: bolder;
  267. }
  268. }
  269. }
  270. }
  271. .sub_btn_box {
  272. width: 100%;
  273. height: 100rpx;
  274. position: fixed;
  275. bottom: 0;
  276. left: 0;
  277. background: #fff;
  278. z-index: 9999;
  279. .sub_btn {
  280. width: 690rpx;
  281. }
  282. }
  283. </style>