ruku_new2.vue 13 KB

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