release.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="content">
  3. <view class="box">
  4. <view class="title">需求说明</view>
  5. <u--textarea v-model="purchase.description" placeholder="请详细描述你的采购需求" border="none"></u--textarea>
  6. <view class="title">上传营业执照或者身份证件照</view>
  7. <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="1" width="200rpx" height="200rpx"></u-upload>
  8. </view>
  9. <view class="box" style="margin-bottom: 186rpx;">
  10. <view class="title">上传图片以及资质证件照片</view>
  11. <u-upload :fileList="fileList2" @afterRead="afterRead" @delete="deletePic" name="2" multiple :maxCount="9" width="200rpx" height="200rpx"></u-upload>
  12. </view>
  13. <view class="bottom">
  14. <view class="bottom_btn" @click="open">立即发布</view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import $api from '@/static/js/api.js'
  20. var that = ''
  21. export default {
  22. data() {
  23. return {
  24. purchase: {
  25. },
  26. fileList1: [],
  27. fileList2: []
  28. }
  29. },
  30. onLoad() {
  31. that = this
  32. },
  33. methods: {
  34. // 删除图片
  35. deletePic(event) {
  36. this[`fileList${event.name}`].splice(event.index, 1)
  37. },
  38. // 新增图片
  39. async afterRead(event) {
  40. uni.showLoading({
  41. title: '上传中',
  42. mask: true
  43. })
  44. let lists = [].concat(event.file)
  45. let fileListLen = this[`fileList${event.name}`].length
  46. lists.map((item) => {
  47. this[`fileList${event.name}`].push({
  48. ...item,
  49. status: 'uploading',
  50. message: '上传中'
  51. })
  52. })
  53. for (let i = 0; i < lists.length; i++) {
  54. const result = await this.uploadFilePromise(lists[i].url)
  55. let item = this[`fileList${event.name}`][fileListLen]
  56. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  57. status: 'success',
  58. message: '',
  59. url: result.url
  60. }))
  61. fileListLen++
  62. if(lists.length - 1 == i) {
  63. uni.hideLoading()
  64. }
  65. }
  66. },
  67. uploadFilePromise(url) {
  68. return new Promise((resolve, reject) => {
  69. let a = uni.uploadFile({
  70. url: $api.config.baseUrl + '/data/api.auth.Center/upload',
  71. filePath: url,
  72. name: 'file',
  73. header: {
  74. 'content-type': 'application/x-www-form-urlencoded',
  75. 'api-token': uni.getStorageSync('token').token?uni.getStorageSync('token').token:'',
  76. 'api-name': 'wxapp'
  77. },
  78. formData: {
  79. user: 'test'
  80. },
  81. success: (res) => {
  82. setTimeout(() => {
  83. var data = JSON.parse(res.data)
  84. resolve(data.data)
  85. }, 1000)
  86. }
  87. });
  88. })
  89. },
  90. // 立即发布
  91. open() {
  92. var imgs = ''
  93. if(that.fileList2.length == 1) {
  94. imgs = that.fileList2[0].url
  95. } else if (that.fileList2.length > 1) {
  96. for(var i=0;i<that.fileList2.length;i++) {
  97. if(i == that.fileList2.length - 1) {
  98. imgs += that.fileList2[i].url
  99. } else {
  100. imgs += that.fileList2[i].url + ','
  101. }
  102. }
  103. }
  104. $api.req({
  105. url: '/data/api.auth.Center/subpurchaseacceptance',
  106. method: 'POST',
  107. data: {
  108. description : that.purchase.description,
  109. business_img: that.fileList1[0].url,
  110. imgs: imgs,
  111. province: uni.getStorageSync('location').province,
  112. city: uni.getStorageSync('location').city,
  113. area: uni.getStorageSync('location').district,
  114. id: that.purchase.id?that.purchase.id:''
  115. }
  116. }, function(res) {
  117. if(res.code == 1) {
  118. $api.info(res.info)
  119. $api.jump(-1)
  120. }
  121. })
  122. },
  123. },
  124. }
  125. </script>
  126. <style lang="scss" scoped>
  127. .content::v-deep {
  128. background: #F5F5F5;
  129. .box {
  130. width: 690rpx;
  131. margin: 20rpx 30rpx 0;
  132. background: #FFFFFF;
  133. border-radius: 20rpx;
  134. box-sizing: border-box;
  135. padding: 12rpx 20rpx;
  136. .title {
  137. font-size: 28rpx;
  138. font-weight: 400;
  139. color: #222222;
  140. margin: 20rpx 0;
  141. }
  142. .u-textarea {
  143. background: #F5F5F5;
  144. }
  145. }
  146. .bottom {
  147. width: 100%;
  148. z-index: 9;
  149. position: fixed;
  150. bottom: 0;
  151. height: 166rpx;
  152. background: #FFFFFF;
  153. box-sizing: border-box;
  154. padding: 8rpx 40rpx 74rpx;
  155. .bottom_btn {
  156. width: 100%;
  157. height: 84rpx;
  158. background: #506DFF;
  159. border-radius: 42rpx;
  160. font-size: 36rpx;
  161. font-weight: 500;
  162. color: #FFFFFF;
  163. text-align: center;
  164. line-height: 84rpx;
  165. }
  166. }
  167. }
  168. </style>