AskingQuestions.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <view class="bg">
  3. <!-- 提问 -->
  4. <view class="commodity">
  5. <view class="rateBox">
  6. 描述问题
  7. </view>
  8. <view class="pjBox">
  9. <u--textarea v-model="value1" placeholder="输入你想提问的问题..."
  10. count maxlength="200" ></u--textarea>
  11. </view>
  12. <view class="upload">
  13. <u-upload
  14. :fileList="fileList1"
  15. @afterRead="afterRead"
  16. @delete="deletePic"
  17. name="1"
  18. multiple
  19. :maxCount="3"
  20. ></u-upload>
  21. </view>
  22. </view>
  23. <view style="height: 200rpx;"></view>
  24. <view class="btnBox">
  25. <view class="btn" @click="submit">
  26. 提交
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import env from "@/http/config/config.js"
  33. import { toastFunc } from "@/pages/util/util";
  34. import {createQuestion} from '@/http/api/common.js'
  35. export default {
  36. components: {
  37. },
  38. data() {
  39. return {
  40. fileList1:[],
  41. value1:'',
  42. }
  43. },
  44. onLoad() {
  45. },
  46. methods: {
  47. linktoPublishComments(){
  48. uni.navigateTo({
  49. url: '/pages/market/PublishComments'
  50. });
  51. },
  52. // 删除图片
  53. deletePic(event) {
  54. this[`fileList${event.name}`].splice(event.index, 1)
  55. },
  56. // 新增图片
  57. async afterRead(event) {
  58. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  59. let lists = [].concat(event.file)
  60. let fileListLen = this[`fileList${event.name}`].length
  61. lists.map((item) => {
  62. this[`fileList${event.name}`].push({
  63. ...item,
  64. status: 'uploading',
  65. message: '上传中'
  66. })
  67. })
  68. for (let i = 0; i < lists.length; i++) {
  69. const result = await this.uploadFilePromise(lists[i].url)
  70. console.log('1111',result);
  71. let item = this[`fileList${event.name}`][fileListLen]
  72. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  73. status: 'success',
  74. message: '',
  75. url: result
  76. }))
  77. fileListLen++
  78. }
  79. },
  80. uploadFilePromise(url) {
  81. return new Promise((resolve, reject) => {
  82. let a = uni.uploadFile({
  83. url: env.BASEURL + '/open/upload/uploadFile',
  84. filePath: url,
  85. name: 'file',
  86. formData: {
  87. user: 'test'
  88. },
  89. success: (res) => {
  90. const fileData = JSON.parse(res.data)
  91. if (fileData.code == 500) {
  92. resolve('')
  93. }else{
  94. const fileData = JSON.parse(res.data)
  95. resolve(fileData.data)
  96. }
  97. }
  98. });
  99. })
  100. },
  101. async submit(){
  102. if (this.value1 == '') {
  103. toastFunc('请填写问题')
  104. return
  105. }
  106. let uploadList = this.fileList1.map(item=>{
  107. return item.url
  108. })
  109. let res = await createQuestion({
  110. content:this.value1,
  111. uploadList:uploadList
  112. })
  113. if (res.data.code == 200) {
  114. toastFunc('提问成功',()=>{
  115. uni.navigateBack({
  116. delta: 1
  117. });
  118. })
  119. }
  120. },
  121. }
  122. }
  123. </script>
  124. <style>
  125. .bg{
  126. width: 750rpx;
  127. height: auto;
  128. min-height: calc(100vh - 100rpx) ;
  129. background: #F1F1F1;
  130. border-radius: 0rpx 0rpx 0rpx 0rpx;
  131. display: flex;
  132. flex-direction: column;
  133. align-items: center;
  134. }
  135. .commodity{
  136. width: 702rpx;
  137. height: auto;
  138. /* min-height: 954rpx; */
  139. background: #FFFFFF;
  140. border-radius: 16rpx 16rpx 16rpx 16rpx;
  141. opacity: 1;
  142. margin-top: 24rpx;
  143. /* padding-bottom: 100rpx; */
  144. }
  145. .commodity_title{
  146. width: 650rpx;
  147. height: 40rpx;
  148. font-size: 28rpx;
  149. font-weight: 500;
  150. color: #999;
  151. line-height: 40rpx;
  152. padding: 24rpx 0 0 24rpx;
  153. display: flex;
  154. justify-content: space-between;
  155. align-items: center;
  156. }
  157. .mc_item{
  158. width: 702rpx;
  159. height: 244rpx;
  160. background: #FFFFFF;
  161. border-radius: 16rpx 16rpx 16rpx 16rpx;
  162. opacity: 1;
  163. margin-top: 24rpx;
  164. }
  165. .item_swipe{
  166. width: 678rpx;
  167. height: 244rpx;
  168. background: #FFFFFF;
  169. border-radius: 16rpx 16rpx 16rpx 16rpx;
  170. opacity: 1;
  171. display: flex;
  172. align-items: center;
  173. flex-direction: row;
  174. padding-left: 24rpx;
  175. }
  176. .box_img{
  177. width: 180rpx;
  178. height: 180rpx;
  179. background-color: #999999;
  180. }
  181. .box_text{
  182. width: 392rpx;
  183. height: 200rpx;
  184. margin-left: 20rpx;
  185. display: flex;
  186. flex-direction: column;
  187. justify-content: space-between;
  188. }
  189. .box_title{
  190. width: 392rpx;
  191. height: 40rpx;
  192. font-size: 28rpx;
  193. font-weight: bold;
  194. color: #333333;
  195. line-height: 40rpx;
  196. display: -webkit-box;
  197. word-break: break-all;
  198. text-overflow: ellipsis;
  199. overflow: hidden;
  200. -webkit-box-orient: vertical;
  201. -webkit-line-clamp:1;
  202. }
  203. .box_type{
  204. width: 410rpx;
  205. height: 48rpx;
  206. background: #EEEEEE;
  207. border-radius: 8rpx 8rpx 8rpx 8rpx;
  208. opacity: 1;
  209. font-size: 28rpx;
  210. font-weight: 500;
  211. color: #999999;
  212. padding-left: 24rpx;
  213. line-height: 48rpx;
  214. display: -webkit-box;
  215. word-break: break-all;
  216. text-overflow: ellipsis;
  217. overflow: hidden;
  218. -webkit-box-orient: vertical;
  219. -webkit-line-clamp:1;
  220. }
  221. .box_num{
  222. width: 410rpx;
  223. display: flex;
  224. justify-content: space-between;
  225. align-items: center;
  226. }
  227. .rateBox{
  228. display: flex;
  229. margin: 24rpx;
  230. }
  231. .pjBox{
  232. margin-left: 24rpx;
  233. width: 654rpx;
  234. /* height: 320rpx; */
  235. background: #F1F1F1;
  236. border-radius: 16rpx 16rpx 16rpx 16rpx;
  237. opacity: 1;
  238. }
  239. .btnBox{
  240. width: 750rpx;
  241. height: 100rpx;
  242. background: #FFFFFF;
  243. border-radius: 0rpx 0rpx 0rpx 0rpx;
  244. opacity: 1;
  245. display: flex;
  246. flex-direction: row;
  247. justify-content: center;
  248. align-items: center;
  249. position: fixed;
  250. bottom: 0;
  251. }
  252. .btn{
  253. width: 702rpx;
  254. height: 80rpx;
  255. background: #46A6FF;
  256. border-radius: 64rpx 64rpx 64rpx 64rpx;
  257. opacity: 1;
  258. font-weight: 500;
  259. color: #FFFFFF;
  260. line-height: 80rpx;
  261. text-align: center;
  262. }
  263. .upload{
  264. width: 702rpx;
  265. margin: 48rpx 0 48rpx 24rpx;
  266. }
  267. </style>