add.vue 5.3 KB

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