procurementAdd.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <view class="release">
  3. <form>
  4. <view class="uni-form-item uni-column">
  5. <view class="title">商品图片</view>
  6. <view class="uploadComp">
  7. <proUpload @uploadDel="uploadDel" @uploadImg="uploadImg" :imageData="formData.productImage" />
  8. </view>
  9. </view>
  10. <view class="uni-form-item uni-column">
  11. <view class="title">
  12. <span>*</span>
  13. 商品名称
  14. </view>
  15. <view>
  16. <input
  17. class="uni-input"
  18. placeholder="请输入想要采购的商品名称"
  19. v-model="formData.productName"
  20. maxlength="30"
  21. />
  22. <!-- <small>请输入商品名称</small> -->
  23. </view>
  24. </view>
  25. <view class="uni-form-item uni-column">
  26. <view class="title">
  27. <span>*</span>
  28. 期望单价
  29. </view>
  30. <view>
  31. <input
  32. class="uni-input"
  33. placeholder="请输入您对商品的期望单价"
  34. v-model="formData.price"
  35. @input="fpNumInput($event, 'formData', 'price')"
  36. maxlength="10"
  37. />
  38. </view>
  39. </view>
  40. <view class="uni-form-item uni-column">
  41. <view class="title">
  42. <span>*</span>
  43. 采购数量
  44. </view>
  45. <view>
  46. <input
  47. class="uni-input"
  48. type="number"
  49. placeholder="请输入您的采购数量"
  50. v-model="formData.number"
  51. @input="NumberInput($event, 'formData', 'number')"
  52. maxlength="10"
  53. />
  54. </view>
  55. </view>
  56. </form>
  57. <view class="release_btn">
  58. <proBtn
  59. width="600rpx"
  60. v-if="isActive"
  61. @click="handlerSave"
  62. height="90rpx"
  63. background="#F3B574"
  64. color="#FFFFFF"
  65. fontSize="32rpx"
  66. >
  67. 发布
  68. </proBtn>
  69. <proBtn width="600rpx" height="90rpx" v-else background="#E2E2E2" color="#999999" fontSize="32rpx">
  70. 发布
  71. </proBtn>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. import proBtn from './components/procurement-btn.vue'
  77. import proUpload from './components/upload.vue'
  78. import { mapState } from 'vuex'
  79. import procurementMixins from './mixins/procurementMixins.js'
  80. export default {
  81. components: {
  82. proUpload,
  83. proBtn
  84. },
  85. mixins: [procurementMixins],
  86. data() {
  87. return {
  88. // 发布需求
  89. formData: {
  90. userId: 0,
  91. productImage: '',
  92. productName: '',
  93. price: '',
  94. number: '',
  95. userName: ''
  96. },
  97. userInfo: {}, // 用户详情
  98. isActive: false,
  99. currentTab: 0, //上一页tab
  100. detailData: {
  101. id: '',
  102. userId: '',
  103. procurementType: 1
  104. }
  105. }
  106. },
  107. watch: {
  108. 'formData.productName': {
  109. handler() {
  110. this.activeBtn()
  111. },
  112. deep: true
  113. },
  114. 'formData.price': {
  115. handler() {
  116. this.activeBtn()
  117. },
  118. deep: true
  119. },
  120. 'formData.number': {
  121. handler() {
  122. this.activeBtn()
  123. },
  124. deep: true
  125. }
  126. },
  127. onLoad(options) {
  128. this.userInfo = uni.getStorageSync('userInfo')
  129. if (options.id) {
  130. this.detailData.id = options.id
  131. this.handlerDetail()
  132. } else {
  133. this.currentTab = Number(options.currentTab)
  134. }
  135. },
  136. mounted() {
  137. this.userInfo = uni.getStorageSync('userInfo')
  138. this.formData.userId = this.userInfo.userId
  139. this.formData.userName = this.userInfo.name
  140. },
  141. methods: {
  142. // 发布按钮
  143. activeBtn() {
  144. if (this.formData.productName === '' || this.formData.price === '' || this.formData.number === '') {
  145. setTimeout(() => {
  146. this.isActive = false
  147. }, 300)
  148. } else {
  149. setTimeout(() => {
  150. this.isActive = true
  151. }, 200)
  152. }
  153. },
  154. // 图片上传
  155. uploadImg(url) {
  156. if (url !== '' && url !== null) {
  157. this.formData.productImage = url
  158. }
  159. },
  160. // 图片删除
  161. uploadDel(e) {
  162. this.formData.productImage = e
  163. },
  164. // submit 发布
  165. async handlerSave() {
  166. const form = {
  167. userId: this.userInfo.userId,
  168. productImage: this.formData.productImage,
  169. productName: this.formData.productName,
  170. price: this.formData.price,
  171. number: this.formData.number,
  172. userName: this.formData.userName,
  173. }
  174. if (this.detailData.id) {
  175. form.id = this.detailData.id
  176. }
  177. this.isActive = false
  178. try {
  179. const data = await this.ProcurementService.procurementSave(form)
  180. uni.showToast({
  181. title: `${this.detailData.id ? '修改' : '发布'}成功`,
  182. icon: 'success'
  183. })
  184. setTimeout(() => {
  185. uni.navigateBack({
  186. data: 1
  187. })
  188. }, 800)
  189. uni.$emit('refreshAddData', this.detailData.id) // 刷新修改的数据
  190. } catch (error) {
  191. console.log(error)
  192. }
  193. },
  194. // 发布详情
  195. async handlerDetail() {
  196. this.detailData.userId = this.userInfo.userId
  197. try {
  198. const {data} = await this.ProcurementService.procurementEditData(this.detailData)
  199. this.formData = data
  200. if (this.isImageUrl(this.formData.productImage)) {
  201. this.formData.productImage = ''
  202. }
  203. } catch (error) {
  204. console.log(error)
  205. }
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss" scoped>
  211. .release {
  212. padding: 24rpx;
  213. }
  214. span {
  215. color: #f85050;
  216. font-size: 28rpx;
  217. }
  218. .title {
  219. font-size: 28rpx;
  220. color: #666666;
  221. margin-bottom: 24rpx;
  222. }
  223. .uploadComp {
  224. margin-bottom: 40rpx;
  225. }
  226. .uni-input {
  227. height: 90rpx;
  228. border: 1px solid #b2b2b2;
  229. border-radius: 6rpx 6rpx 6rpx 6rpx;
  230. font-size: 28rpx;
  231. padding-left: 47rpx;
  232. margin-bottom: 40rpx;
  233. }
  234. .release_btn {
  235. position: fixed;
  236. left: 0;
  237. bottom: 0;
  238. margin-bottom: 76rpx;
  239. display: flex;
  240. justify-content: center;
  241. align-items: center;
  242. width: 100%;
  243. }
  244. </style>