procurementAdd.vue 7.1 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. focus
  19. placeholder="请输入想要采购的商品名称"
  20. v-model="formData.productName"
  21. maxlength="30"
  22. />
  23. <!-- <small>请输入商品名称</small> -->
  24. </view>
  25. </view>
  26. <view class="uni-form-item uni-column">
  27. <view class="title">
  28. <span>*</span>
  29. 期望单价
  30. </view>
  31. <view>
  32. <input
  33. class="uni-input"
  34. type="number"
  35. focus
  36. placeholder="请输入您对商品的期望单价"
  37. v-model="formData.price"
  38. @input="fpNumInput($event, 'formData')"
  39. maxlength="10"
  40. />
  41. </view>
  42. </view>
  43. <view class="uni-form-item uni-column">
  44. <view class="title">
  45. <span>*</span>
  46. 采购数量
  47. </view>
  48. <view>
  49. <input
  50. class="uni-input"
  51. type="number"
  52. focus
  53. placeholder="请输入您的采购数量"
  54. v-model="formData.number"
  55. @input="NumberInput($event, 'formData')"
  56. maxlength="10"
  57. />
  58. </view>
  59. </view>
  60. </form>
  61. <view class="release_btn">
  62. <proBtn
  63. width="600rpx"
  64. v-if="isActive"
  65. @click="handlerSave"
  66. height="90rpx"
  67. background="#F3B574"
  68. color="#FFFFFF"
  69. fontSize="32rpx"
  70. >
  71. 发布
  72. </proBtn>
  73. <proBtn width="600rpx" height="90rpx" v-else background="#E2E2E2" color="#999999" fontSize="32rpx">
  74. 发布
  75. </proBtn>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. import proBtn from './components/procurement-btn.vue'
  81. import proUpload from './components/upload.vue'
  82. import { mapState } from 'vuex'
  83. import procurementMixins from './mixins/procurementMixins.js'
  84. export default {
  85. components: {
  86. proUpload,
  87. proBtn
  88. },
  89. mixins: [procurementMixins],
  90. data() {
  91. return {
  92. // 发布需求
  93. formData: {
  94. userId: 0,
  95. productImage: '',
  96. productName: '',
  97. price: '',
  98. number: '',
  99. userName: ''
  100. },
  101. userInfo: {}, // 用户详情
  102. isActive: false,
  103. currentTab: 0, //上一页tab
  104. detailData: {
  105. id: '',
  106. userId: '',
  107. procurementType: 1
  108. }
  109. }
  110. },
  111. watch: {
  112. 'formData.productName': {
  113. handler() {
  114. this.activeBtn()
  115. },
  116. deep: true
  117. },
  118. 'formData.price': {
  119. handler() {
  120. this.activeBtn()
  121. },
  122. deep: true
  123. },
  124. 'formData.number': {
  125. handler() {
  126. this.activeBtn()
  127. },
  128. deep: true
  129. }
  130. },
  131. onLoad(options) {
  132. this.userInfo = uni.getStorageSync('userInfo')
  133. if (options.id) {
  134. this.detailData.id = options.id
  135. this.handlerDetail()
  136. } else {
  137. this.currentTab = Number(options.currentTab)
  138. }
  139. },
  140. mounted() {
  141. this.userInfo = uni.getStorageSync('userInfo')
  142. this.formData.userId = this.userInfo.userId
  143. this.formData.userName = this.userInfo.userName
  144. },
  145. methods: {
  146. // 发布按钮
  147. activeBtn() {
  148. if (this.formData.productName === '' || this.formData.price === '' || this.formData.number === '') {
  149. setTimeout(() => {
  150. this.isActive = false
  151. }, 300)
  152. } else {
  153. setTimeout(() => {
  154. this.isActive = true
  155. }, 200)
  156. }
  157. },
  158. // 图片上传
  159. uploadImg(url) {
  160. if (url !== '' && url !== null) {
  161. this.formData.productImage = url
  162. }
  163. },
  164. // 图片删除
  165. uploadDel(e) {
  166. this.formData.productImage = e
  167. },
  168. // submit 发布
  169. async handlerSave() {
  170. const form = {
  171. userId: this.userInfo.userId,
  172. productImage: this.formData.productImage,
  173. productName: this.formData.productName,
  174. price: this.formData.price,
  175. number: this.formData.number,
  176. userName: this.formData.userName,
  177. }
  178. if (this.detailData.id) {
  179. form.id = this.detailData.id
  180. }
  181. try {
  182. const data = await this.ProcurementService.procurementSave(form)
  183. uni.showToast({
  184. title: `${this.detailData.id ? '修改' : '发布'}成功`,
  185. icon: 'success'
  186. })
  187. setTimeout(() => {
  188. uni.navigateBack({
  189. data: 1
  190. })
  191. }, 800)
  192. uni.$emit('refreshAddData', this.detailData.id) // 刷新修改的数据
  193. } catch (error) {
  194. console.log(error)
  195. }
  196. },
  197. // 发布详情
  198. async handlerDetail() {
  199. this.detailData.userId = this.userInfo.userId
  200. try {
  201. const data = await this.ProcurementService.procurementEditData(this.detailData)
  202. this.formData = data.data
  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>