add.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <view>
  3. <view class="cmain animated fadeInDown">
  4. <view class="form_group">
  5. <view class="lable re">贸易区域</view>
  6. <picker @click="selectArea()" :disabled="true">
  7. <input placeholder="请选择" v-model="item.tradeAreaName" :disabled="true" />
  8. <view class="icon more">&#xe8f2;</view>
  9. </picker>
  10. </view>
  11. <view class="form_group">
  12. <view class="lable re">商品名称</view>
  13. <picker @click="selectGoods()" :disabled="true">
  14. <input placeholder="请选择" v-model="item.goodsName" :disabled="true" />
  15. <view class="icon more">&#xe8f2;</view>
  16. </picker>
  17. </view>
  18. <view class="form_group">
  19. <view class="lable re">商品价格</view>
  20. <input type="number" placeholder="请输入" v-model="item.price" />
  21. <view class="ops" v-if="flag === '编辑商品'">{{ item.goodsUnits }}</view>
  22. <view class="ops" v-else>{{ item.unit }}</view>
  23. </view>
  24. <view class="form_group">
  25. <view class="lable re">商品数量</view>
  26. <input type="number" placeholder="请输入" v-model="item.stock" />
  27. </view>
  28. <view class="form_group">
  29. <view class="lable re">净重</view>
  30. <input placeholder="请输入" v-model="item.netWeight" />
  31. <view class="ops" v-if="flag === '编辑商品'">{{ item.goodsUnits }}</view>
  32. <view class="ops" v-else>{{ item.unit }}</view>
  33. </view>
  34. <view class="form_group">
  35. <view class="lable re">毛重</view>
  36. <input placeholder="请输入" v-model="item.grossWeight" />
  37. <view class="ops" v-if="flag === '编辑商品'">{{ item.goodsUnits }}</view>
  38. <view class="ops" v-else>{{ item.unit }}</view>
  39. </view>
  40. </view>
  41. <view class="mfooter">
  42. <view class="flex">
  43. <view class="f">
  44. <button class="save btn" @click="save(0)">下架</button>
  45. </view>
  46. <view class="f">
  47. <button class="btn" @click="save(1)">一键发售</button>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. export default {
  55. data() {
  56. return {
  57. flag: '新增商品',
  58. item: {}
  59. };
  60. },
  61. onLoad(e) {
  62. if (e.id) {
  63. this.flag = '编辑商品';
  64. this.http.request({
  65. url: '/level-one-server/app/TbGoodsTransit/getById?id=' + e.id,
  66. success: res => {
  67. this.item = res.data.data;
  68. uni.setNavigationBarTitle({ title: this.item.goodsStatus == 1 ? '编辑商品(在售)' : '编辑商品(下架)' });
  69. }
  70. });
  71. }
  72. //选择互市回显
  73. uni.$on('area', res => {
  74. this.item.tradeAreaName = res.name;
  75. this.item.tradeAreaId = res.id;
  76. this.$forceUpdate();
  77. });
  78. //选择商品回显
  79. uni.$on('selects', res => {
  80. this.item.goodsName = res.name;
  81. this.item.unit = res.unit;
  82. if (this.flag == '新增商品') {
  83. this.item.id = res.id;
  84. }
  85. this.$forceUpdate();
  86. });
  87. },
  88. methods: {
  89. //选择互市区
  90. selectArea() {
  91. uni.navigateTo({ url: '/pages/market/one/merchant/goods/area' });
  92. },
  93. //选择商品
  94. selectGoods() {
  95. if (this.item.tradeAreaId) {
  96. uni.navigateTo({ url: '/pages/market/one/merchant/goods/selects?tradeAreaId=' + this.item.tradeAreaId + '&tradeAreaName=' + this.item.tradeAreaName });
  97. } else {
  98. uni.showModal({ content: '请先选择互市区', showCancel: false });
  99. return;
  100. }
  101. },
  102. save(goodsStatus) {
  103. let rule = [
  104. { name: 'tradeAreaName', checkType: 'notnull', errorMsg: '请选择互市区' },
  105. { name: 'goodsName', checkType: 'notnull', errorMsg: '请选择商品' },
  106. { name: 'price', checkType: 'notnull', errorMsg: '请输入商品价格' },
  107. { name: 'stock', checkType: 'notnull', errorMsg: '请输入商品数量' },
  108. { name: 'netWeight', checkType: 'notnull', errorMsg: '请输入净重' },
  109. { name: 'grossWeight', checkType: 'notnull', errorMsg: '请输入毛重' }
  110. ];
  111. if (!this.verify.check(this.item, rule)) {
  112. uni.showModal({ content: this.verify.error, showCancel: false });
  113. return false;
  114. }
  115. let action = this.flag == '新增商品' ? 'add' : 'update';
  116. this.item.goodsStatus = goodsStatus;
  117. delete this.item.createTime;
  118. delete this.item.createBy;
  119. delete this.item.createName;
  120. this.http.request({
  121. url: '/level-one-server/app/TbGoodsTransit/' + action,
  122. method: 'POST',
  123. data: this.item,
  124. success: res => {
  125. uni.showToast({ title: '操作成功' });
  126. setTimeout(() => {
  127. uni.$emit('goodsHandle');
  128. uni.navigateBack();
  129. }, 1000);
  130. }
  131. });
  132. }
  133. }
  134. };
  135. </script>
  136. <style lang="scss">
  137. .btn {
  138. width: 100%;
  139. border-radius: 5px;
  140. }
  141. </style>