panku.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <template>
  2. <view class="PanKuContainer">
  3. <view class="all">
  4. <view class="num">
  5. <text>库存:总共</text>
  6. <text class="spec">
  7. {{ stockList.reduce((a, b) => a + (b.children.reduce((x, y) => x + Number(y.reviseNum), 0)), 0) }}
  8. </text>
  9. <text>套</text>
  10. </view>
  11. <view class="btn" @click="toUrlLink('stock/panku_record')">盘库记录</view>
  12. </view>
  13. <view class="goodList">
  14. <view
  15. v-for="(item, i) in stockList"
  16. :key="i"
  17. class="goodItem"
  18. >
  19. <view class="top">
  20. <view
  21. class="avatar"
  22. :style="{ backgroundImage: `url(${item.imgurl})` }"
  23. />
  24. <view class="info">
  25. <view class="name">{{ item.name }}</view>
  26. <view class="fixed">一年零一天不满意退钱</view>
  27. </view>
  28. </view>
  29. <view class="skuList">
  30. <view
  31. class="skuHeader"
  32. :class="item.toggle ? 'open' : ''"
  33. @click="item.toggle = !item.toggle"
  34. >
  35. <view class="type">规格</view>
  36. <view class="size">尺码</view>
  37. <view class="num">数量</view>
  38. <view class="reviseNum">
  39. <view class="reviseNum-title">修改数量</view>
  40. </view>
  41. </view>
  42. <template v-if="item.toggle">
  43. <view
  44. v-for="(btem, bi) in item.children"
  45. :key="bi"
  46. class="skuItem"
  47. >
  48. <view class="type">{{ +btem.sex ? '男款' : '女款' }}</view>
  49. <view class="size">{{ btem.size }}</view>
  50. <view class="num">{{ btem.num }}</view>
  51. <view class="reviseNum">
  52. <count
  53. :countNum.sync="btem.reviseNum"
  54. @update:inputCountNum="toShowInputDialog(btem)"
  55. />
  56. <!-- :min="-Number(btem.num)" -->
  57. </view>
  58. </view>
  59. </template>
  60. </view>
  61. <view class="dataAll">
  62. <view class="sex">
  63. 男款:{{ item.children.filter(v => Number(v.sex)).reduce((a, b) => a + Number(b.reviseNum), 0) }}套
  64. /
  65. 女款:{{ item.children.filter(v => !Number(v.sex)).reduce((a, b) => a + Number(b.reviseNum), 0) }}套
  66. </view>
  67. <view class="num">
  68. <text>
  69. 合计:
  70. </text>
  71. <text class="spec">
  72. <!-- {{ item.total + item.children.reduce((a, b) => a + Number(b.reviseNum), 0) }}套 -->
  73. {{ item.children.reduce((a, b) => a + Number(b.reviseNum), 0) }}套
  74. </text>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. <view class="reviseBtn" @click="toSubmitRevise">确认修改</view>
  80. <!-- 输入弹窗 -->
  81. <toast
  82. :is-show="dialogInput.show"
  83. :is-close="false"
  84. >
  85. <view class="dialogInput">
  86. <view class="title">请输入要修改的数量</view>
  87. <input
  88. v-model="dialogInput.num"
  89. type="text"
  90. class="input"
  91. :placeholder="`修改数量范围为: ${dialogInput.min}-${dialogInput.max}`"
  92. />
  93. <view class="btns">
  94. <view class="btn cancel" @click="cancelInput">取消</view>
  95. <view class="btn" @click="toPublishInput">修改</view>
  96. </view>
  97. </view>
  98. </toast>
  99. </view>
  100. </template>
  101. <script>
  102. import Count from "./components/count.vue"
  103. import Toast from "@/components/toast.vue"
  104. import { getPanKuStock, stockGoods, morePanKuRevise } from "@/apis/stock.js"
  105. export default {
  106. components: {
  107. Count,
  108. Toast
  109. },
  110. data() {
  111. return {
  112. stockList: [],
  113. inputNum: 0,
  114. dialogInput: {
  115. show: false,
  116. num: '',
  117. min: 0,
  118. max: 999,
  119. info: new Map()
  120. }
  121. }
  122. },
  123. onShow() {
  124. this.init()
  125. },
  126. methods: {
  127. // 提交修改
  128. toSubmitRevise() {
  129. const _this = this
  130. uni.showModal({
  131. content: "确认提交修改吗?",
  132. cancelText: '取消',
  133. confirmText: '修改',
  134. success(res){
  135. if(res.confirm) {
  136. let arr = {}
  137. _this.stockList.forEach(item => {
  138. arr[item.k] = item.children.map(v => {
  139. let _d = {}
  140. // _d.num = Number(v.num) + Number(v.reviseNum)
  141. _d.num = Number(v.reviseNum)
  142. _d.sex = v.sex
  143. _d.size = v.size
  144. return _d
  145. })
  146. })
  147. uni.showLoading()
  148. morePanKuRevise(arr).then(res => {
  149. uni.hideLoading()
  150. if(res.code === 200) {
  151. uni.showModal({
  152. content: "修改盘库成功",
  153. showCancel: false,
  154. success(res) {
  155. if(res.confirm) {
  156. uni.reLaunch({
  157. url: '../stock/stock'
  158. })
  159. }
  160. }
  161. })
  162. } else {
  163. uni.showModal({
  164. content: res.message || "修改库存失败",
  165. showCancel: false
  166. })
  167. }
  168. }).catch(() => {
  169. uni.hideLoading()
  170. uni.showModal({
  171. content: "修改库存失败",
  172. showCancel: false
  173. })
  174. })
  175. }
  176. }
  177. })
  178. },
  179. // 确定弹窗输入
  180. toPublishInput() {
  181. // /^[-]?[0-9]+$/
  182. if(!(/^[0-9]+$/.test(this.dialogInput.num))) {
  183. uni.showModal({
  184. content: "修改数量不合法,请重新输入",
  185. showCancel: false
  186. })
  187. return false
  188. }
  189. if(Number(this.dialogInput.num) < this.dialogInput.min) {
  190. uni.showModal({
  191. content: `修改数量最小为:${this.dialogInput.min}`,
  192. showCancel: false
  193. })
  194. return false
  195. }
  196. if(Number(this.dialogInput.num) > this.dialogInput.max) {
  197. uni.showModal({
  198. content: `修改数量最大为:${this.dialogInput.max}`,
  199. showCancel: false
  200. })
  201. return false
  202. }
  203. this.dialogInput.info.get('data').reviseNum = Number(this.dialogInput.num)
  204. this.cancelInput()
  205. },
  206. // 取消弹窗输入
  207. cancelInput() {
  208. this.dialogInput.show = false
  209. this.dialogInput.num = ''
  210. this.dialogInput.min = 0
  211. this.dialogInput.max = 999
  212. this.dialogInput.info.clear()
  213. },
  214. // 输入弹窗
  215. toShowInputDialog(data) {
  216. // this.dialogInput.min = -Number(data.num)
  217. this.dialogInput.min = 0
  218. this.dialogInput.show = true
  219. this.dialogInput.info.set('data', data)
  220. },
  221. // 初始化
  222. init() {
  223. uni.showLoading()
  224. const _this = this
  225. Promise.all([this.getStockGoods(), this.getPanKuStock()]).then(res => {
  226. uni.hideLoading()
  227. let goodsList = res[0]
  228. let stockList = res[1]
  229. _this.stockList = Object.keys(stockList).map(k => ({
  230. k: k,
  231. children: stockList[k].map(v => {
  232. v.reviseNum = v.num
  233. return v
  234. }),
  235. imgurl: goodsList[k].imgurl,
  236. name: goodsList[k].name,
  237. total: stockList[k].reduce((a, b) => a + Number(b.num), 0),
  238. toggle: false
  239. }))
  240. }).catch(() => {
  241. uni.hideLoading()
  242. uni.showModal({
  243. content: "获取盘库信息失败",
  244. showCancel: false
  245. })
  246. })
  247. },
  248. // 获取图片
  249. getStockGoods() {
  250. return new Promise(resolve => {
  251. stockGoods().then(res => {
  252. if(res.code === 200) {
  253. resolve(res.data)
  254. }
  255. })
  256. })
  257. },
  258. // 获取盘库历史
  259. getPanKuStock() {
  260. return new Promise(resolve => {
  261. getPanKuStock().then(res => {
  262. if(res.code === 200) {
  263. resolve(res.data)
  264. }
  265. })
  266. })
  267. },
  268. toUrlLink(url) {
  269. if(!url) return false
  270. uni.navigateTo({
  271. url: `../${url}`
  272. })
  273. }
  274. }
  275. }
  276. </script>
  277. <style lang="scss" scoped>
  278. /deep/ .uni-input-placeholder {
  279. color: #cccaca !important;
  280. }
  281. page{
  282. display: flex;
  283. flex-direction: column;
  284. }
  285. .PanKuContainer {
  286. width: 100%;
  287. flex: 1;
  288. background-color: #F9F9FB;
  289. .btn {
  290. width: 140rpx;
  291. height: 56rpx;
  292. border-radius: 8rpx;
  293. background-color: #EA4A41;
  294. color: #FFFFFF;
  295. font-size: 28rpx;
  296. line-height: 56rpx;
  297. text-align: center;
  298. text-align: center;
  299. }
  300. .reviseBtn {
  301. position: fixed;
  302. bottom: 0;
  303. left: 0;
  304. right: 0;
  305. height: 100rpx;
  306. text-align: center;
  307. line-height: 100rpx;
  308. background: linear-gradient(to right, #F97C55, #F44545);
  309. color: #FFFFFF;
  310. font-size: 32rpx;
  311. }
  312. .all {
  313. width: 100%;
  314. height: 116rpx;
  315. padding: 0 30rpx;
  316. display: flex;
  317. align-items: center;
  318. justify-content: space-between;
  319. .num {
  320. color: #333333;
  321. font-size: 36rpx;
  322. line-height: 50rpx;
  323. font-weight: bold;
  324. .spec {
  325. color: #EA4A41 !important;
  326. }
  327. }
  328. }
  329. .goodList {
  330. width: 100%;
  331. padding-bottom: 100rpx;
  332. .goodItem {
  333. width: 100%;
  334. margin-bottom: 30rpx;
  335. padding: 30rpx;
  336. box-sizing: border-box;
  337. background-color: #ffffff;
  338. .top {
  339. width: 100%;
  340. display: flex;
  341. align-items: stretch;
  342. justify-content: space-between;
  343. margin-bottom: 40rpx;
  344. .avatar {
  345. width: 180rpx;
  346. height: 144rpx;
  347. background-color: #eeeeee;
  348. background-position: center;
  349. background-size: cover;
  350. background-repeat: no-repeat;
  351. border-radius: 8rpx;
  352. }
  353. .info {
  354. display: flex;
  355. justify-content: center;
  356. flex-direction: column;
  357. flex: 1;
  358. overflow: hidden;
  359. margin-left: 20rpx;
  360. .name {
  361. color: #333333;
  362. font-size: 32rpx;
  363. line-height: 44rpx;
  364. margin-bottom: 20rpx;
  365. }
  366. .fixed {
  367. color: #F76454;
  368. font-size: 28rpx;
  369. height: 40rpx;
  370. line-height: 40rpx;
  371. border: 1px solid #F76454;
  372. box-sizing: border-box;
  373. width: 328rpx;
  374. border-radius: 40rpx;
  375. color: #F76454;
  376. text-align: center;
  377. }
  378. }
  379. }
  380. .skuList{
  381. width: 100%;
  382. margin-bottom: 30rpx;
  383. .skuHeader, .skuItem {
  384. width: 100%;
  385. height: 100rpx;
  386. display: flex;
  387. align-items: center;
  388. justify-content: space-between;
  389. border-bottom: 1px solid #EEEEEE;
  390. .type, .size, .num, .reviseNum {
  391. flex: 1;
  392. overflow: hidden;
  393. display: flex;
  394. align-items: center;
  395. justify-content: center;
  396. }
  397. .type {
  398. justify-content: flex-start;
  399. flex: none;
  400. width: 18%;
  401. }
  402. .reviseNum {
  403. justify-content: flex-end;
  404. }
  405. }
  406. .skuHeader {
  407. color: #999999;
  408. font-size: 28rpx;
  409. line-height: 40rpx;
  410. border-top: 1px solid #EEEEEE;
  411. .reviseNum {
  412. &::after {
  413. display: block;
  414. content: "";
  415. margin-left: 10rpx;
  416. width: 30rpx;
  417. height: 30rpx;
  418. background-image: url(../../static/new_my/arrow.png);
  419. background-size: cover;
  420. background-position: center;
  421. background-repeat: no-repeat;
  422. }
  423. .reviseNum-title {
  424. width: 152rpx;
  425. height: 56rpx;
  426. border-radius: 56rpx;
  427. text-align: center;
  428. line-height: 56rpx;
  429. background: linear-gradient(141deg, #F97C55 0%, #F44545 100%);
  430. color: #FFFFFF;
  431. font-size: 28rpx;
  432. }
  433. }
  434. &.open {
  435. .reviseNum {
  436. &::after {
  437. transform: rotate(90deg) !important;
  438. }
  439. }
  440. }
  441. }
  442. }
  443. .dataAll {
  444. width: 100%;
  445. display: flex;
  446. align-items: center;
  447. justify-content: space-between;
  448. .sex {
  449. color: #333333;
  450. font-size: 28rpx;
  451. }
  452. .num {
  453. color: #999999;
  454. font-size: 28rpx;
  455. .spec {
  456. color: #EA4A41 !important;
  457. font-size: 40rpx !important;
  458. font-weight: bolder;
  459. }
  460. }
  461. }
  462. }
  463. }
  464. .dialogInput {
  465. width: 80%;
  466. max-width: 600rpx;
  467. padding: 50rpx 30rpx;
  468. background-color: #ffffff;
  469. box-sizing: border-box;
  470. margin: 0 auto;
  471. border-radius: 24rpx;
  472. .title {
  473. font-size: 40rpx;
  474. color: #333333;
  475. line-height: 60rpx;
  476. text-align: center;
  477. margin-bottom: 40rpx;
  478. }
  479. .input {
  480. width: 100%;
  481. border: 1px solid #c1c1c1;
  482. height: 80rpx;
  483. font-size: 40rpx;
  484. line-height: 80rpx;
  485. padding: 0 20rpx;
  486. box-sizing: border-box;
  487. text-align: center;
  488. margin-bottom: 40rpx;
  489. border-radius: 8rpx;
  490. }
  491. .btns {
  492. width: 100%;
  493. display: flex;
  494. align-items: center;
  495. justify-content: center;
  496. .btn {
  497. margin: 0 20rpx;
  498. height: 70rpx;
  499. line-height: 70rpx;
  500. padding: 0 20rpx;
  501. &.cancel {
  502. background: #ffffff !important;
  503. color: #EA4A41 !important;
  504. border: 1px solid #EA4A41 !important;
  505. box-sizing: border-box;
  506. }
  507. }
  508. }
  509. }
  510. }
  511. </style>