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