add.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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" />
  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" />
  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>
  22. <view class="form_group">
  23. <view class="lable re">商品单位</view>
  24. <picker @change="selectUnits($event)" :value="index" :range="unitList" range-key="units">
  25. <input placeholder="请选择" v-model="item.goodsUnits"/>
  26. <view class="icon more">&#xe8f2;</view>
  27. </picker>
  28. </view>
  29. <view class="form_group">
  30. <view class="lable re">发售数量</view>
  31. <input type="number" placeholder="请输入" v-model="item.stock" />
  32. </view>
  33. <view class="form_group">
  34. <view class="lable re">净重</view>
  35. <input placeholder="请输入" v-model="item.netWeight" />
  36. </view>
  37. <view class="form_group">
  38. <view class="lable re">毛重</view>
  39. <input placeholder="请输入" v-model="item.grossWeight" />
  40. </view>
  41. </view>
  42. <view class="mfooter">
  43. <view class="flex">
  44. <view class="f">
  45. <button class="save btn" @click="save(0)">下架</button>
  46. </view>
  47. <view class="f">
  48. <button class="btn" @click="save(1)">一键发售</button>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. export default {
  56. data() {
  57. return {
  58. index: 0,
  59. flag: '新增商品',
  60. item: {},
  61. unitList: [],
  62. };
  63. },
  64. onLoad(e) {
  65. if (e.id) {
  66. this.flag = '编辑商品';
  67. this.http.request({
  68. url: '/level-one-server/app/TbGoodsTransit/getById?id=' + e.id,
  69. success: res => {
  70. this.item = res.data.data;
  71. uni.setNavigationBarTitle({ title: this.item.goodsStatus == 1 ? '编辑商品(在售)' : '编辑商品(下架)' });
  72. }
  73. });
  74. }
  75. //查询单位列表
  76. this.http.request({
  77. url: '/level-one-server/app/TbGoodsUnits/getList',
  78. loading: 'false',
  79. success: res => {
  80. this.unitList = res.data.data;
  81. }
  82. });
  83. //选择互市回显
  84. uni.$on('area', res => {
  85. this.item.tradeAreaName = res.name;
  86. this.item.tradeAreaId = res.id;
  87. this.$forceUpdate();
  88. });
  89. //选择商品回显
  90. uni.$on('selects', res => {
  91. this.item.goodsName = res.name;
  92. this.item.goodsUnits = res.unit;
  93. if (this.flag == '新增商品') {
  94. this.item.id = res.id;
  95. }
  96. this.$forceUpdate();
  97. });
  98. },
  99. methods: {
  100. //选择互市区
  101. selectArea() {
  102. uni.navigateTo({ url: '/pages/market/one/merchant/goods/area' });
  103. },
  104. //选择商品
  105. selectGoods() {
  106. if (this.item.tradeAreaId) {
  107. uni.navigateTo({ url: '/pages/market/one/merchant/goods/selects?tradeAreaId=' + this.item.tradeAreaId + '&tradeAreaName=' + this.item.tradeAreaName });
  108. } else {
  109. uni.showModal({ content: '请先选择互市区', showCancel: false });
  110. return;
  111. }
  112. },
  113. //选择单位
  114. selectUnits(e) {
  115. if (this.item.goodsName) {
  116. this.index = e.detail.value;
  117. this.item.goodsUnits = this.unitList[this.index].units;
  118. } else {
  119. uni.showModal({ content: '请先选择商品', showCancel: false });
  120. return;
  121. }
  122. },
  123. save(goodsStatus) {
  124. let rule = [
  125. { name: 'tradeAreaName', checkType: 'notnull', errorMsg: '请选择互市区' },
  126. { name: 'goodsName', checkType: 'notnull', errorMsg: '请选择商品' },
  127. { name: 'price', checkType: 'notnull', errorMsg: '请输入商品单价' },
  128. { name: 'goodsUnits', checkType: 'notnull', errorMsg: '请选择商品单位' },
  129. { name: 'stock', checkType: 'notnull', errorMsg: '请输入发售数量' },
  130. { name: 'netWeight', checkType: 'notnull', errorMsg: '请输入净重' },
  131. { name: 'grossWeight', checkType: 'notnull', errorMsg: '请输入毛重' }
  132. ];
  133. if (!this.verify.check(this.item, rule)) {
  134. uni.showModal({ content: this.verify.error, showCancel: false });
  135. return false;
  136. }
  137. let action = this.flag == '新增商品' ? 'add' : 'update';
  138. this.item.goodsStatus = goodsStatus;
  139. delete this.item.createTime;
  140. delete this.item.createBy;
  141. delete this.item.createName;
  142. this.http.request({
  143. url: '/level-one-server/app/TbGoodsTransit/' + action,
  144. method: 'POST',
  145. data: this.item,
  146. success: res => {
  147. uni.showToast({ title: '操作成功' });
  148. setTimeout(() => {
  149. uni.$emit('goodsHandle');
  150. uni.navigateBack();
  151. }, 1000);
  152. }
  153. });
  154. }
  155. }
  156. };
  157. </script>
  158. <style lang="scss">
  159. .cmain {
  160. padding-bottom: 90px;
  161. }
  162. .btn {
  163. width: 100%;
  164. border-radius: 5px;
  165. }
  166. </style>