release.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <view class="content">
  3. <view class="box">
  4. <view class="title">需求说明</view>
  5. <u--textarea v-model="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">
  8. <image src="@/static/images/index/upload_img.png" mode="" style="width: 200rpx;height: 200rpx"></image>
  9. </u-upload>
  10. </view>
  11. <view class="box">
  12. <view class="title">上传图片以及资质证件照片</view>
  13. <u-upload :fileList="fileList2" @afterRead="afterRead" @delete="deletePic" name="2" multiple :maxCount="9" width="200rpx" height="200rpx">
  14. <image src="@/static/images/index/upload_img.png" mode="" style="width: 200rpx;height: 200rpx"></image>
  15. </u-upload>
  16. </view>
  17. <view class="box" style="margin-bottom: 186rpx;">
  18. <view class="hflex acenter jbetween">
  19. <view class="title">是否隐藏需求</view>
  20. <u-switch v-model="hidden" @change="changeHide1" inactiveColor="rgb(230, 230, 230)"></u-switch>
  21. </view>
  22. <view class="text">
  23. 说明:灰色开关为显示需求,蓝色开关为隐藏需求,默认为显示需求
  24. </view>
  25. </view>
  26. <view class="bottom">
  27. <view class="bottom_btn" @click="open" v-if="!purchase">立即发布</view>
  28. <view class="bottom_btn" @click="open" v-if="purchase">立即修改</view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import $api from '@/static/js/api.js'
  34. var that = ''
  35. export default {
  36. data() {
  37. return {
  38. hidden: false,
  39. description: '',
  40. purchase: {
  41. },
  42. fileList1: [],
  43. fileList2: []
  44. }
  45. },
  46. onLoad() {
  47. that = this
  48. that.getData()
  49. },
  50. methods: {
  51. getData() {
  52. $api.req({
  53. url: '/data/api.auth.Center/myneed',
  54. method: 'POST',
  55. data: {
  56. type: 1
  57. }
  58. }, function(res) {
  59. if(res.code == 1) {
  60. that.purchase = res.data
  61. if(!that.purchase) {
  62. return
  63. }
  64. that.description = res.data.description
  65. if(res.data.hidden == 2) {
  66. that.hidden = true
  67. } else {
  68. that.hidden = false
  69. }
  70. that.fileList1 = []
  71. that.fileList1.push({
  72. url:res.data.business_img
  73. })
  74. var imgs = res.data.imgs
  75. let obj = {}
  76. for(let key in imgs) {
  77. obj[key] = imgs[key]
  78. }
  79. var fileList2 = Object.keys(obj).map(item => ({
  80. url: obj[item]
  81. }))
  82. that.fileList2 = fileList2
  83. }
  84. })
  85. },
  86. // 删除图片
  87. deletePic(event) {
  88. this[`fileList${event.name}`].splice(event.index, 1)
  89. },
  90. // 新增图片
  91. async afterRead(event) {
  92. uni.showLoading({
  93. title: '上传中',
  94. mask: true
  95. })
  96. let lists = [].concat(event.file)
  97. let fileListLen = this[`fileList${event.name}`].length
  98. lists.map((item) => {
  99. this[`fileList${event.name}`].push({
  100. ...item,
  101. status: 'uploading',
  102. message: '上传中'
  103. })
  104. })
  105. for (let i = 0; i < lists.length; i++) {
  106. const result = await this.uploadFilePromise(lists[i].url)
  107. let item = this[`fileList${event.name}`][fileListLen]
  108. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  109. status: 'success',
  110. message: '',
  111. url: result.url
  112. }))
  113. fileListLen++
  114. if(lists.length - 1 == i) {
  115. uni.hideLoading()
  116. }
  117. }
  118. },
  119. uploadFilePromise(url) {
  120. return new Promise((resolve, reject) => {
  121. let a = uni.uploadFile({
  122. url: $api.config.baseUrl + '/data/api.auth.Center/upload',
  123. filePath: url,
  124. name: 'file',
  125. header: {
  126. 'content-type': 'application/x-www-form-urlencoded',
  127. 'api-token': uni.getStorageSync('token').token?uni.getStorageSync('token').token:'',
  128. 'api-name': 'wxapp'
  129. },
  130. formData: {
  131. user: 'test'
  132. },
  133. success: (res) => {
  134. setTimeout(() => {
  135. var data = JSON.parse(res.data)
  136. resolve(data.data)
  137. }, 1000)
  138. }
  139. });
  140. })
  141. },
  142. // 立即发布
  143. open() {
  144. if(that.description == '') {
  145. $api.info('请先输入需求说明')
  146. return
  147. }
  148. if(that.fileList1 == '') {
  149. $api.info('请先上传营业执照或者身份证照')
  150. return
  151. }
  152. if(that.fileList2 == '') {
  153. $api.info('请先上传图片以及资质证书照片')
  154. return
  155. }
  156. var imgs = ''
  157. if(that.fileList2.length == 1) {
  158. imgs = that.fileList2[0].url
  159. } else if (that.fileList2.length > 1) {
  160. for(var i=0;i<that.fileList2.length;i++) {
  161. if(i == that.fileList2.length - 1) {
  162. imgs += that.fileList2[i].url
  163. } else {
  164. imgs += that.fileList2[i].url + ','
  165. }
  166. }
  167. }
  168. $api.req({
  169. url: '/data/api.auth.Center/subpurchaseacceptance',
  170. method: 'POST',
  171. data: {
  172. description : that.description,
  173. business_img: that.fileList1[0].url,
  174. imgs: imgs,
  175. hidden: that.hidden ? 2 : 1,
  176. province: uni.getStorageSync('location').province ?uni.getStorageSync('location').province : null ,
  177. city: uni.getStorageSync('location').city ?uni.getStorageSync('location').city : null,
  178. area: uni.getStorageSync('location').district ?uni.getStorageSync('location').district : null,
  179. id: that.purchase?that.purchase.id:''
  180. }
  181. }, function(res) {
  182. if(res.code == 1) {
  183. $api.info(res.info)
  184. $api.jump(-1)
  185. }
  186. })
  187. },
  188. changeHide1(e) {
  189. console.log(e);
  190. },
  191. },
  192. }
  193. </script>
  194. <style lang="scss" scoped>
  195. .content::v-deep {
  196. background: #F5F5F5;
  197. .box {
  198. width: 690rpx;
  199. margin: 20rpx 30rpx 0;
  200. background: #FFFFFF;
  201. border-radius: 20rpx;
  202. box-sizing: border-box;
  203. padding: 12rpx 20rpx;
  204. .title {
  205. font-size: 28rpx;
  206. font-weight: 400;
  207. color: #222222;
  208. margin: 20rpx 0;
  209. position: relative;
  210. padding-left: 10rpx;
  211. }
  212. .title::before{
  213. content: '*';
  214. position: absolute;
  215. top: 20%;
  216. left: -10rpx;
  217. color: #ff0000;
  218. }
  219. .u-textarea {
  220. background: #F5F5F5;
  221. }
  222. .text {
  223. font-size: 24rpx;
  224. font-weight: 400;
  225. color: #d75a59;
  226. margin: 16rpx 0;
  227. }
  228. }
  229. .bottom {
  230. width: 100%;
  231. z-index: 9;
  232. position: fixed;
  233. bottom: 0;
  234. height: 166rpx;
  235. background: #FFFFFF;
  236. box-sizing: border-box;
  237. padding: 8rpx 40rpx 74rpx;
  238. .bottom_btn {
  239. width: 100%;
  240. height: 84rpx;
  241. background: #506DFF;
  242. border-radius: 42rpx;
  243. font-size: 36rpx;
  244. font-weight: 500;
  245. color: #FFFFFF;
  246. text-align: center;
  247. line-height: 84rpx;
  248. }
  249. }
  250. }
  251. </style>