add.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view>
  3. <view class="address" @click="address()">
  4. <view class="con" v-if="item.addressName">
  5. <view class="title omit">{{ item.addressName }}</view>
  6. <view class="desc">
  7. <text>{{ item.name }}</text>
  8. <text>{{ item.phone }}</text>
  9. </view>
  10. </view>
  11. <view class="con" v-else>
  12. <view class="title omit">你还没添加收货地址</view>
  13. <view class="desc">点击添加地址</view>
  14. </view>
  15. <view class="icon">&#xe8f2;</view>
  16. </view>
  17. <view class="forms">
  18. <view class="form_group">
  19. <view class="lable re">互市区</view>
  20. <picker @click="selectArea()" :disabled="true">
  21. <input placeholder="请选择" v-model="item.tradeAreaName" :disabled="true" />
  22. <view class="icon more">&#xe8f2;</view>
  23. </picker>
  24. </view>
  25. <view class="form_group">
  26. <view class="lable re">收购商品</view>
  27. <picker @click="selectGoods()" :disabled="true">
  28. <input placeholder="请选择" v-model="item.goodsName" :disabled="true" />
  29. <view class="icon more">&#xe8f2;</view>
  30. </picker>
  31. </view>
  32. <view class="form_group">
  33. <view class="lable">商品编号</view>
  34. <input placeholder="请输入" v-model="item.goodsNo" :disabled="true" />
  35. </view>
  36. <view class="form_group">
  37. <view class="lable re">计价单位</view>
  38. <input placeholder="请输入" v-model="item.goodsUnit" :disabled="true" />
  39. </view>
  40. <view class="form_group">
  41. <view class="lable re">数量</view>
  42. <input type="number" placeholder="请输入" v-model="item.goodsQuantity" />
  43. </view>
  44. <view class="form_group">
  45. <view class="lable re">到货日期</view>
  46. <picker mode="date" @change="picker($event, 'arrivalTime')">
  47. <input placeholder="请选择" v-model="item.arrivalTime" :disabled="true" />
  48. <view class="icon more">&#xe8f2;</view>
  49. </picker>
  50. </view>
  51. </view>
  52. <view class="mfooter">
  53. <view class="flex">
  54. <view class="f">
  55. <button class="save btn" @click="save(0)">取消发布</button>
  56. </view>
  57. <view class="f">
  58. <button class="btn" @click="save(1)">一键发布</button>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. export default {
  66. data() {
  67. return {
  68. item: {},
  69. tradeAreaList: []
  70. };
  71. },
  72. onLoad(e) {
  73. if (e.id) {
  74. this.http.request({
  75. url: '/level-two-server/app/TbGoodsDemand/getById?id=' + e.id,
  76. success: res => {
  77. this.item = res.data.data;
  78. uni.setNavigationBarTitle({ title: '编辑求购信息' });
  79. }
  80. });
  81. }
  82. //选择互市回显
  83. uni.$on('area', res => {
  84. this.item.tradeAreaName = res.name;
  85. this.item.tradeAreaId = res.id;
  86. this.$forceUpdate();
  87. });
  88. //选择地址回显
  89. uni.$on('selectAddress', res => {
  90. this.item.addressName = res.province + ' ' + res.city + ' ' + res.area + ' ' + res.street;
  91. this.item.name = res.name;
  92. this.item.phone = res.phone;
  93. this.$forceUpdate();
  94. });
  95. //选择商品回显
  96. uni.$on('selects', res => {
  97. this.item.goodsName = res.name;
  98. this.item.levelOneGoodsId = res.id;
  99. this.item.goodsImg = res.avatar;
  100. this.item.goodsNo = res.code;
  101. this.item.goodsUnit = res.unit;
  102. this.$forceUpdate();
  103. });
  104. },
  105. methods: {
  106. //选择地址
  107. address() {
  108. uni.navigateTo({ url: '/pages/market/two/purchaser/address/list?select=true' });
  109. },
  110. //选择互市区
  111. selectArea() {
  112. uni.navigateTo({ url: '/pages/market/one/merchant/goods/area' });
  113. },
  114. //选择商品
  115. selectGoods() {
  116. if (this.item.tradeAreaId) {
  117. uni.navigateTo({ url: '/pages/market/one/merchant/goods/selects?tradeAreaId=' + this.item.tradeAreaId + '&tradeAreaName=' + this.item.tradeAreaName });
  118. } else {
  119. uni.showModal({ content: '请先选择互市区', showCancel: false });
  120. return;
  121. }
  122. },
  123. picker(e, tag) {
  124. if (tag == 'arrivalTime') {
  125. this.item[tag] = e.detail.value;
  126. }
  127. if (tag == 'tradeAreaName') {
  128. this.item.tradeAreaName = this.tradeAreaList[e.detail.value].name;
  129. this.item.tradeAreaId = this.tradeAreaList[e.detail.value].id;
  130. }
  131. this.$forceUpdate();
  132. },
  133. //保存或发布
  134. save(isRelease) {
  135. let rule = [
  136. { name: 'addressName', checkType: 'notnull', errorMsg: '请选择一个收货地址' },
  137. { name: 'tradeAreaName', checkType: 'notnull', errorMsg: '请选择互市区' },
  138. { name: 'goodsName', checkType: 'notnull', errorMsg: '请选择商品' },
  139. { name: 'goodsQuantity', checkType: 'notnull', errorMsg: '请输入数量' },
  140. { name: 'arrivalTime', checkType: 'notnull', errorMsg: '请选择到货日期' }
  141. ];
  142. if (!this.verify.check(this.item, rule)) {
  143. uni.showModal({ content: this.verify.error, showCancel: false });
  144. return false;
  145. }
  146. this.item.isRelease = isRelease;
  147. delete this.item.createTime;
  148. delete this.item.updateTime;
  149. let action = this.item.id ? 'update' : 'add';
  150. this.http.request({
  151. url: '/level-two-server/app/TbGoodsDemand/' + action,
  152. method: 'POST',
  153. data: this.item,
  154. success: res => {
  155. uni.showToast({ title: '操作成功' });
  156. setTimeout(() => {
  157. uni.$emit('purchaser_buy_list');
  158. uni.navigateBack();
  159. }, 1000);
  160. }
  161. });
  162. }
  163. }
  164. };
  165. </script>
  166. <style lang="scss">
  167. .cmain {
  168. padding-bottom: 90px;
  169. }
  170. .address {
  171. border-bottom: 1px solid $line;
  172. }
  173. .btn {
  174. width: 100%;
  175. border-radius: 5px;
  176. }
  177. </style>