output.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view class="container">
  3. <view class="sku-list">
  4. <view class="item-wrap" v-for="(item, index) in outputList" :key="index">
  5. <view class="form-wrap">
  6. <text class="label">规格</text>
  7. <text class="value">{{ item.sku_name }}</text>
  8. </view>
  9. <view class="form-wrap">
  10. <text class="label">销售价</text>
  11. <text class="value">{{ item.price }}</text>
  12. <text class="unit">元</text>
  13. </view>
  14. <view class="form-wrap">
  15. <view class="label">
  16. <text class="required color-base-text">*</text>
  17. <text>库存</text>
  18. </view>
  19. <input class="uni-input" v-model="item.stock" type="number" placeholder="0" />
  20. <text class="unit">件</text>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="footer-wrap"><button type="primary" @click="save()">保存</button></view>
  25. <loading-cover ref="loadingCover"></loading-cover>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. return {
  32. goodsId: 0,
  33. outputList: []
  34. };
  35. },
  36. onLoad(option) {
  37. this.goodsId = option.goods_id || 0;
  38. this.getOutputList();
  39. },
  40. onShow() {},
  41. methods: {
  42. getOutputList() {
  43. this.$api.sendRequest({
  44. url: '/shopapi/goods/getOutputList',
  45. data: { goods_id: this.goodsId },
  46. success: res => {
  47. if (res.data) {
  48. this.outputList = res.data;
  49. if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
  50. }
  51. }
  52. });
  53. },
  54. verify() {
  55. var flag = true;
  56. for (var i = 0; i < this.outputList.length; i++) {
  57. var item = this.outputList[i];
  58. if (item.stock.length == 0) {
  59. this.$util.showToast({ title: `请输入[第${i + 1}个规格]的库存` });
  60. flag = false;
  61. break;
  62. }
  63. if (isNaN(item.stock) || !this.$util.data().regExp.number.test(item.stock)) {
  64. this.$util.showToast({ title: `[第${i + 1}个规格的库存]格式输入错误` });
  65. flag = false;
  66. break;
  67. }
  68. }
  69. return flag;
  70. },
  71. save() {
  72. if (!this.verify()) return;
  73. this.$api.sendRequest({
  74. url: '/shopapi/goods/editGoodsStock',
  75. data: { sku_list: JSON.stringify(this.outputList) },
  76. success: res => {
  77. this.$util.showToast({
  78. title: res.message
  79. });
  80. if (res.code == 0) {
  81. setTimeout(() => {
  82. this.$util.redirectTo('/pages/goods/list', {}, 'redirectTo');
  83. }, 1000);
  84. }
  85. }
  86. });
  87. }
  88. }
  89. };
  90. </script>
  91. <style lang="scss">
  92. @import './css/edit.scss';
  93. .sku-list {
  94. margin-bottom: 160rpx;
  95. .item-wrap {
  96. background: #fff;
  97. margin: $margin-updown $margin-both;
  98. .form-wrap {
  99. .value {
  100. vertical-align: middle;
  101. display: inline-block;
  102. flex: 1;
  103. text-align: right;
  104. overflow: hidden;
  105. text-overflow: ellipsis;
  106. white-space: pre;
  107. }
  108. }
  109. }
  110. }
  111. </style>