add.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view>
  3. <view class="cmain">
  4. <view class="form_group">
  5. <view class="lable re">贸易区域</view>
  6. <picker :range="tradeAreaList" @change="pickerTradeArea($event)" range-key="name">
  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 v-if="flag === '新增商品'" :range="goodsList" @change="pickerGoods($event)" range-key="name">
  14. <input placeholder="请选择" v-model="item.goodsName" :disabled="true" />
  15. <view class="icon more">&#xe8f2;</view>
  16. </picker>
  17. <input v-else placeholder="请选择" v-model="item.goodsName" :disabled="true" disabled="true"/>
  18. </view>
  19. <view class="form_group">
  20. <view class="lable re">商品价格</view>
  21. <input type="number" placeholder="请输入" v-model="item.price" />
  22. <view class="ops" v-if="flag === '编辑商品'">{{ item.goodsUnits }}</view>
  23. <view class="ops" v-else>{{ item.unit }}</view>
  24. </view>
  25. <view class="form_group">
  26. <view class="lable re">商品数量</view>
  27. <input type="number" placeholder="请输入" v-model="item.stock" />
  28. </view>
  29. <view class="form_group">
  30. <view class="lable re">净重</view>
  31. <input placeholder="请输入" v-model="item.netWeight" />
  32. <view class="ops" v-if="flag === '编辑商品'">{{ item.goodsUnits }}</view>
  33. <view class="ops" v-else>{{ item.unit }}</view>
  34. </view>
  35. <view class="form_group">
  36. <view class="lable re">毛重</view>
  37. <input placeholder="请输入" v-model="item.grossWeight" />
  38. <view class="ops" v-if="flag === '编辑商品'">{{ item.goodsUnits }}</view>
  39. <view class="ops" v-else>{{ item.unit }}</view>
  40. </view>
  41. <view class="form_group">
  42. <view class="lable re">商品状态</view>
  43. <picker :range="dict.goodsStatus" @change="picker($event, 'goodsStatus')">
  44. <input placeholder="请选择" :value="item.goodsStatus" :disabled="true" />
  45. <view class="icon more">&#xe8f2;</view>
  46. </picker>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. data() {
  54. return {
  55. flag: '新增商品',
  56. item: {tradeAreaName:''},
  57. dict: {
  58. goodsType: ['水果', '药品', '茶叶'],
  59. goodsUnits: ['吨', '个', '柜'],
  60. goodsStatus: ['在售', '下架']
  61. },
  62. goodsList: [],
  63. tradeAreaList: []
  64. };
  65. },
  66. onLoad(e) {
  67. if (e.id) {
  68. this.flag = '编辑商品'
  69. this.http.request({
  70. url: '/level-one-server/app/TbGoodsTransit/getById?id=' + e.id,
  71. success: res => {
  72. this.item = res.data.data;
  73. this.item.goodsStatus = this.item.goodsStatus == 1 ? '在售' : '下架';
  74. uni.setNavigationBarTitle({ title: '编辑商品' });
  75. }
  76. });
  77. };
  78. this.getGoodsList();
  79. this.getTradeAreaList();
  80. },
  81. methods: {
  82. picker(e, tag) {
  83. this.item[tag] = this.dict[tag][e.detail.value];
  84. this.$forceUpdate();
  85. },
  86. pickerGoods(e) {
  87. this.item['goodsName'] = this.goodsList[e.detail.value].name;
  88. this.item['unit'] = this.goodsList[e.detail.value].unit;
  89. this.$forceUpdate();
  90. if(this.flag == '新增商品') {
  91. this.item.id = this.goodsList[e.detail.value].id;
  92. }
  93. },
  94. pickerTradeArea(e) {
  95. this.item['tradeAreaName'] = this.tradeAreaList[e.detail.value].name;
  96. this.$forceUpdate();
  97. this.item.tradeAreaId = this.tradeAreaList[e.detail.value].id;
  98. },
  99. // 获取监管商品列表
  100. getGoodsList() {
  101. this.http.request({
  102. url: '/level-one-server/app/TbGoods/getList',
  103. method: 'POST',
  104. success: res => {
  105. this.goodsList = res.data.data;
  106. console.log("监管商品列表",this.goodsList);
  107. }
  108. });
  109. },
  110. // 获取贸易区域列表
  111. getTradeAreaList() {
  112. this.http.request({
  113. url: '/level-one-server/app/TbTradeArea/getList',
  114. method: 'POST',
  115. success: res => {
  116. this.tradeAreaList = res.data.data;
  117. console.log("贸易区域列表",this.tradeAreaList);
  118. }
  119. });
  120. }
  121. },
  122. onNavigationBarButtonTap() {
  123. let rule = [
  124. { name: 'goodsName', checkType: 'notnull', errorMsg: '请输入商品名称' },
  125. { name: 'goodsStatus', checkType: 'notnull', errorMsg: '请选择状态' }
  126. ];
  127. if (!this.verify.check(this.item, rule)) {
  128. uni.showModal({ content: this.verify.error, showCancel: false });
  129. return false;
  130. }
  131. this.item.goodsStatus = this.item.goodsStatus == '在售' ? 1 : 0;
  132. let url = '';
  133. if(this.flag == '新增商品') {
  134. url = '/level-one-server/app/TbGoodsTransit/transactionGoods';
  135. } else {
  136. url = '/level-one-server/app/TbGoodsTransit/update';
  137. }
  138. delete this.item.createTime;
  139. delete this.item.createBy;
  140. delete this.item.createName;
  141. this.http.request({
  142. url: url,
  143. method: 'POST',
  144. data: this.item,
  145. success: res => {
  146. uni.showToast({ title: '操作成功' });
  147. setTimeout(() => {
  148. uni.$emit('goodsHandle');
  149. uni.navigateBack();
  150. }, 1000);
  151. }
  152. });
  153. }
  154. };
  155. </script>
  156. <style lang="scss"></style>