ruku_new.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. <template>
  2. <view class="ChuKuContainer">
  3. <view class="all">
  4. <view class="btn" @click="toUrlLink('stock/ruku_record')">入库记录</view>
  5. </view>
  6. <view class="goodList">
  7. <view v-for="(item, i) in list" :key="i" class="goodItem">
  8. <view class="top">
  9. <view class="avatar" :style="{ backgroundImage: `url(${item.imgurl})` }"></view>
  10. <view class="info">
  11. <view class="name">
  12. <text class="text">{{ item.name }}</text>
  13. <text class="text spec">(单位:{{ item.unitName }})</text>
  14. </view>
  15. <view class="fixed">一年零一天不满意退钱</view>
  16. </view>
  17. </view>
  18. <view class="skuList">
  19. <view v-for="(btem, bi) in item.skuList" :key="bi" class="skuItem">
  20. <picker mode="selector" :range="sexList" range-key="name"
  21. @change="toChangeSex($event, btem, item)">
  22. <view class="select">
  23. <view class="value">{{ btem.sex === '' ? '款式' : btem.sex ? '男款' : '女款' }}</view>
  24. </view>
  25. </picker>
  26. <template v-if="btem.sex === ''">
  27. <view class="select" @click="selectSizeTip">
  28. <view class="value">{{ btem.size === '' ? '尺码' : btem.size }}</view>
  29. </view>
  30. </template>
  31. <template v-else>
  32. <picker mode="selector" :range="item.pickerSizeList[String(btem.sex)]"
  33. @change="toChangeSize($event, btem, item)">
  34. <view class="select">
  35. <view class="value">{{ btem.size === '' ? '尺码' : btem.size }}</view>
  36. </view>
  37. </picker>
  38. </template>
  39. <view class="countBox">
  40. <count2 :countNum.sync="btem.num" />
  41. </view>
  42. <view class="addIcon" :class="bi ? 'delete' : ''" @click="toAddSku(item, bi)" />
  43. </view>
  44. </view>
  45. <view class="dataAll">
  46. <view class="sex">
  47. 男款:{{ item.skuList.filter(v => Number(v.sex)).reduce((a, b) => a + Number(b.num), 0) }}{{ item.unitName }}
  48. /
  49. 女款:{{ item.skuList.filter(v => !Number(v.sex)).reduce((a, b) => a + Number(b.num), 0) }}{{ item.unitName }}
  50. </view>
  51. <view class="num">
  52. <text>共计:</text>
  53. <text class="spec">
  54. {{ item.skuList.reduce((a, b) => a + Number(b.num), 0) }}{{ item.unitName }}
  55. </text>
  56. </view>
  57. </view>
  58. <view class="dataAll" style="margin-top: 20rpx;">
  59. <view class="unit" v-if="item.unitNum > 1">
  60. 1{{ item.unitName }} = {{ item.unitNum }}套
  61. </view>
  62. <view class="num">
  63. <text>合计:</text>
  64. <text class="spec">
  65. {{ item.skuList.reduce((a, b) => a + Number(b.num), 0) * item.unitNum }}套
  66. </text>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. <view class="reviseFooter">
  72. <view class="footer-right">
  73. <text class="text2">共计:</text>
  74. <text class="text3">
  75. {{ list.reduce((a, b) => a + (b.skuList.reduce((x,y) => x + Number(y.num), 0)), 0) }}
  76. </text>
  77. <text class="text4">件</text>
  78. </view>
  79. <view class="footer-right" style="margin-right: 0;">
  80. <text class="text2">合计:</text>
  81. <text class="text3">
  82. {{ list.reduce((a, b) => a + (b.skuList.reduce((x,y) => x + Number(y.num) * b.unitNum, 0)), 0) }}
  83. </text>
  84. <text class="text4">套</text>
  85. </view>
  86. <view class="footer-btn" @click="$noMultipleClicks(toSubmitRuku)">确认入库</view>
  87. </view>
  88. </view>
  89. </template>
  90. <script>
  91. const skuAllList = [{
  92. size: 'L',
  93. sex: 1,
  94. num: 0,
  95. type: ['hard']
  96. },
  97. {
  98. size: 'XL',
  99. sex: 1,
  100. num: 0,
  101. type: ['hard', 'simple', 'old', 'new_old', 'youth']
  102. },
  103. {
  104. size: '2XL',
  105. sex: 1,
  106. num: 0,
  107. type: ['hard', 'simple', 'old', 'new_old', 'youth']
  108. },
  109. {
  110. size: '3XL',
  111. sex: 1,
  112. num: 0,
  113. type: ['hard', 'simple', 'old', 'new_old', 'youth']
  114. },
  115. {
  116. size: '4XL',
  117. sex: 1,
  118. num: 0,
  119. type: ['hard']
  120. },
  121. {
  122. size: '5XL',
  123. sex: 1,
  124. num: 0,
  125. type: ['hard']
  126. },
  127. {
  128. size: 'M',
  129. sex: 0,
  130. num: 0,
  131. type: ['hard', 'simple', 'youth']
  132. },
  133. {
  134. size: 'L',
  135. sex: 0,
  136. num: 0,
  137. type: ['hard', 'simple', 'old', 'new_old', 'youth']
  138. },
  139. {
  140. size: 'XL',
  141. sex: 0,
  142. num: 0,
  143. type: ['hard', 'simple', 'old', 'new_old', 'youth']
  144. },
  145. {
  146. size: '2XL',
  147. sex: 0,
  148. num: 0,
  149. type: ['hard', 'simple', 'old', 'new_old', 'youth']
  150. },
  151. {
  152. size: '3XL',
  153. sex: 0,
  154. num: 0,
  155. type: ['hard', 'old']
  156. },
  157. {
  158. size: '4XL',
  159. sex: 0,
  160. num: 0,
  161. type: ['hard']
  162. }
  163. ]
  164. import Count2 from "./components/count2.vue"
  165. import {
  166. stockGoods,
  167. publishRuKuNew
  168. } from "@/apis/stock.js"
  169. export default {
  170. components: {
  171. Count2
  172. },
  173. data() {
  174. return {
  175. sexList: [{
  176. name: '男款',
  177. value: 1
  178. },
  179. {
  180. name: '女款',
  181. value: 0
  182. },
  183. ],
  184. list: [],
  185. noClick: true,
  186. }
  187. },
  188. onShow() {
  189. this.getStockGoods()
  190. },
  191. methods: {
  192. selectSizeTip() { // 尺码选择提醒
  193. uni.showModal({
  194. content: "请先选择款式",
  195. showCancel: false
  196. })
  197. },
  198. toSubmitRuku() { // 入库
  199. let arr = {}
  200. let num = 0,
  201. errorNum = 0
  202. this.list.forEach(v => {
  203. arr[v.k] = v.skuList
  204. errorNum += v.skuList.filter(item => (item.sex === '' || item.size === '') && item.num > 0)
  205. .length
  206. num += v.skuList.reduce((a, b) => a + Number(b.num), 0)
  207. })
  208. if (num === 0) {
  209. uni.showModal({
  210. content: '入库最少为1件',
  211. showCancel: false
  212. })
  213. return false
  214. }
  215. if (errorNum > 0) {
  216. uni.showModal({
  217. content: '请选择款式和尺码',
  218. showCancel: false
  219. })
  220. return false
  221. }
  222. let copy_arr = JSON.parse(JSON.stringify(arr))
  223. Object.keys(copy_arr).forEach(k => {
  224. copy_arr[k].forEach((item, i) => {
  225. if (i < copy_arr[k].length - 1) {
  226. if (item.size === copy_arr[k][i + 1].size && item.sex === copy_arr[k][i + 1]
  227. .sex) {
  228. item.num += copy_arr[k][i + 1].num
  229. copy_arr[k][i + 1].num = 0
  230. }
  231. }
  232. })
  233. copy_arr[k] = copy_arr[k].filter(item => Number(item.num) > 0)
  234. })
  235. uni.showLoading()
  236. publishRuKuNew({
  237. put_type: 0,
  238. data: copy_arr
  239. }).then(res => {
  240. uni.hideLoading()
  241. if (res.code === 200) {
  242. uni.showModal({
  243. content: "入库成功",
  244. showCancel: false,
  245. success(res) {
  246. if (res.confirm) {
  247. uni.reLaunch({
  248. url: '../stock/stock'
  249. })
  250. }
  251. }
  252. })
  253. } else {
  254. uni.showModal({
  255. content: typeof res.message === "string" ? res.message : "入库失败",
  256. showCancel: false
  257. })
  258. }
  259. }).catch(() => {
  260. uni.hideLoading()
  261. uni.showModal({
  262. content: "入库失败",
  263. showCancel: false
  264. })
  265. })
  266. },
  267. toAddSku(parent, i) { // 添加尺码
  268. if (i) {
  269. parent.skuList.splice(i, 1)
  270. } else {
  271. parent.skuList.push({
  272. sex: '',
  273. size: '',
  274. num: 0
  275. })
  276. }
  277. },
  278. // 尺码选择
  279. toChangeSize(e, data, parent) {
  280. let i = e.detail.value
  281. data.size = parent.pickerSizeList[String(data.sex)][i]
  282. },
  283. // 男女款选择
  284. toChangeSex(e, data, parent) {
  285. let i = e.detail.value
  286. data.sex = this.sexList[i].value
  287. data.size = ''
  288. },
  289. // 获取图片
  290. getStockGoods() {
  291. const unitMap = new Map([
  292. ['hard', {
  293. name: '套',
  294. num: 1
  295. }],
  296. ['simple', {
  297. name: '件',
  298. num: 4
  299. }],
  300. ['old', {
  301. name: '件',
  302. num: 4
  303. }],
  304. ['new_old', {
  305. name: '件',
  306. num: 6
  307. }],
  308. ['youth', {
  309. name: '件',
  310. num: 4
  311. }]
  312. ])
  313. const _this = this
  314. stockGoods().then(res => {
  315. if (res.code === 200) {
  316. _this.list = Object.keys(res.data).map(k => ({
  317. k: k,
  318. imgurl: res.data[k].imgurl,
  319. name: res.data[k].name,
  320. unitName: unitMap.get(k).name,
  321. unitNum: unitMap.get(k).num,
  322. pickerSizeList: {
  323. '0': skuAllList.filter(stem => stem.type.includes(k) && Number(stem
  324. .sex) === 0).map(xtem => xtem.size),
  325. '1': skuAllList.filter(stem => stem.type.includes(k) && Number(stem
  326. .sex) === 1).map(xtem => xtem.size)
  327. },
  328. skuList: [{
  329. sex: '',
  330. size: '',
  331. num: 0,
  332. }]
  333. }))
  334. }
  335. })
  336. },
  337. toUrlLink(url) {
  338. if (!url) return false
  339. uni.navigateTo({
  340. url: `../${url}`
  341. })
  342. }
  343. }
  344. }
  345. </script>
  346. <style lang="scss" scoped>
  347. page {
  348. display: flex;
  349. flex-direction: column;
  350. }
  351. .ChuKuContainer {
  352. width: 100%;
  353. flex: 1;
  354. background-color: #F9F9FB;
  355. .btn {
  356. width: 140rpx;
  357. height: 56rpx;
  358. border-radius: 8rpx;
  359. background-color: #EA4A41;
  360. color: #FFFFFF;
  361. font-size: 28rpx;
  362. line-height: 56rpx;
  363. text-align: center;
  364. text-align: center;
  365. }
  366. .reviseFooter {
  367. position: fixed;
  368. bottom: 0;
  369. left: 0;
  370. right: 0;
  371. height: 98rpx;
  372. background-color: #ffffff;
  373. border-top: 2rpx solid #EEEEEE;
  374. padding: 0 30rpx;
  375. box-sizing: border-box;
  376. display: flex;
  377. align-items: center;
  378. justify-content: flex-end;
  379. .footer-right {
  380. margin-right: auto;
  381. .text1 {
  382. color: #999999;
  383. font-size: 28rpx;
  384. line-height: 40rpx;
  385. }
  386. .text2 {
  387. color: #333333;
  388. font-size: 28rpx;
  389. line-height: 40rpx;
  390. margin-left: 10rpx;
  391. }
  392. .text3 {
  393. color: #EA4A41;
  394. font-size: 40rpx;
  395. line-height: 56rpx;
  396. }
  397. .text4 {
  398. color: #EA4A41;
  399. font-size: 28rpx;
  400. line-height: 40rpx;
  401. }
  402. }
  403. .footer-text {
  404. color: #999999;
  405. font-size: 28rpx;
  406. line-height: 40rpx;
  407. }
  408. .footer-btn {
  409. width: 192rpx;
  410. height: 68rpx;
  411. border-radius: 68rpx;
  412. text-align: center;
  413. line-height: 68rpx;
  414. background: linear-gradient(141deg, #F97C55 0%, #F44545 100%);
  415. color: #FFFFFF;
  416. font-size: 28rpx;
  417. margin-left: 12rpx;
  418. }
  419. }
  420. .all {
  421. width: 100%;
  422. height: 116rpx;
  423. padding: 0 30rpx;
  424. display: flex;
  425. align-items: center;
  426. justify-content: flex-end;
  427. .num {
  428. color: #333333;
  429. font-size: 36rpx;
  430. line-height: 50rpx;
  431. font-weight: bold;
  432. .spec {
  433. color: #EA4A41 !important;
  434. }
  435. }
  436. }
  437. .goodList {
  438. width: 100%;
  439. padding-bottom: 100rpx;
  440. .goodItem {
  441. width: 100%;
  442. margin-bottom: 30rpx;
  443. padding: 30rpx;
  444. box-sizing: border-box;
  445. background-color: #ffffff;
  446. .top {
  447. width: 100%;
  448. display: flex;
  449. align-items: stretch;
  450. justify-content: space-between;
  451. margin-bottom: 40rpx;
  452. .avatar {
  453. width: 180rpx;
  454. height: 144rpx;
  455. background-color: #eeeeee;
  456. background-position: center;
  457. background-size: cover;
  458. background-repeat: no-repeat;
  459. border-radius: 8rpx;
  460. }
  461. .info {
  462. display: flex;
  463. justify-content: center;
  464. flex-direction: column;
  465. flex: 1;
  466. overflow: hidden;
  467. margin-left: 20rpx;
  468. .name {
  469. .text {
  470. color: #333333;
  471. font-size: 32rpx;
  472. line-height: 44rpx;
  473. font-weight: bold;
  474. &.spec {
  475. color: #3394F8 !important;
  476. }
  477. }
  478. margin-bottom: 20rpx;
  479. }
  480. .fixed {
  481. color: #F76454;
  482. font-size: 28rpx;
  483. height: 40rpx;
  484. line-height: 40rpx;
  485. border: 1px solid #F76454;
  486. box-sizing: border-box;
  487. width: 328rpx;
  488. border-radius: 40rpx;
  489. color: #F76454;
  490. text-align: center;
  491. }
  492. }
  493. }
  494. .goodsAll {
  495. width: 100%;
  496. display: flex;
  497. align-items: center;
  498. justify-content: space-between;
  499. margin-bottom: 30rpx;
  500. padding-bottom: 36rpx;
  501. border-bottom: 1px solid #EEEEEE;
  502. .sex {
  503. color: #333333;
  504. font-size: 28rpx;
  505. line-height: 40rpx;
  506. }
  507. .num {
  508. color: #999999;
  509. font-size: 28rpx;
  510. .spec {
  511. color: #EA4A41 !important;
  512. font-size: 40rpx !important;
  513. font-weight: bold;
  514. }
  515. }
  516. }
  517. .skuList {
  518. width: 100%;
  519. border-top: 1px solid #EEEEEE;
  520. padding: 30rpx 0;
  521. .skuItem {
  522. width: 100%;
  523. display: flex;
  524. align-items: center;
  525. justify-content: space-between;
  526. margin-bottom: 30rpx;
  527. &:nth-last-of-type(1) {
  528. margin-bottom: 0;
  529. }
  530. .select {
  531. height: 72rpx;
  532. width: 156rpx;
  533. padding: 20rpx;
  534. box-sizing: 0 border-box;
  535. border-radius: 8rpx;
  536. background-color: #F5F5F5;
  537. display: flex;
  538. align-items: center;
  539. justify-content: flex-end;
  540. .value {
  541. color: #333333;
  542. font-size: 32rpx;
  543. line-height: 44rpx;
  544. text-align: center;
  545. flex: 1;
  546. overflow: hidden;
  547. }
  548. &::after {
  549. content: "";
  550. display: block;
  551. width: 30rpx;
  552. height: 30rpx;
  553. background-image: url(../../static/new_my/arrow.png);
  554. background-position: center;
  555. background-size: cover;
  556. background-repeat: no-repeat;
  557. margin-left: 10rpx;
  558. transform: rotate(90deg);
  559. }
  560. }
  561. .countBox {
  562. width: 192rpx;
  563. }
  564. .addIcon {
  565. width: 40rpx;
  566. height: 40rpx;
  567. background-image: url(../../static/new_stock/add.png);
  568. background-repeat: no-repeat;
  569. background-size: 100%;
  570. background-position: center;
  571. &.delete {
  572. background-image: url(../../static/new_stock/delete.png) !important;
  573. }
  574. }
  575. }
  576. }
  577. .dataAll {
  578. width: 100%;
  579. display: flex;
  580. align-items: baseline;
  581. justify-content: flex-end;
  582. .sex {
  583. color: #333333;
  584. font-size: 28rpx;
  585. margin-right: 30rpx;
  586. }
  587. .unit {
  588. color: #3394F8;
  589. font-size: 32rpx;
  590. margin-right: 30rpx;
  591. font-weight: bold;
  592. }
  593. .num {
  594. color: #999999;
  595. font-size: 28rpx;
  596. .spec {
  597. color: #EA4A41 !important;
  598. font-size: 40rpx !important;
  599. font-weight: bolder;
  600. }
  601. }
  602. }
  603. }
  604. }
  605. }
  606. </style>