procurementAdd.vue 6.7 KB

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