add.vue 5.2 KB

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