procurementAdd.vue 7.5 KB

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