index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view class="container">
  3. <!-- #ifdef H5 -->
  4. <view style="color: #fff;">
  5. <tn-nav-bar backgroundColor="#26B3A0" :bottomShadow="false">上传完成凭证
  6. <!-- <template slot="right">
  7. 课程购买记录
  8. </template> -->
  9. </tn-nav-bar>
  10. <view :style="{ height: tobheight + 'px' }"></view>
  11. </view>
  12. <!-- #endif -->
  13. <view class="detailBox">
  14. <view class="label1">
  15. 上传文案
  16. </view>
  17. <view class="textArea">
  18. <textarea placeholder="请输入完成说明" maxlength="200" class="textarea" v-model="textAreaValue"></textarea>
  19. </view>
  20. <view class="line">
  21. <view class="lineCon">
  22. </view>
  23. </view>
  24. <view class="label2">
  25. 图片
  26. </view>
  27. <!-- 选择要上传的图片区域 -->
  28. <view class="chooscontainer">
  29. <view class="addpicall" v-for="(item,index) in pic_url" :key="index">
  30. <image style="width: 184rpx;height:186rpx;border-radius: 14rpx;" @click="previewImg(item)"
  31. :src="item" mode="aspectFill"></image>
  32. <view @click="delectImg(index)" class="del_btn">×</view>
  33. </view>
  34. <view class="addpic" @click="addquesPic" v-show="pic_url.length<9">
  35. <view class="addPicBox">
  36. <image src="/static/add.png"></image>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="line">
  41. <view class="lineCon">
  42. </view>
  43. </view>
  44. <view class="label2">
  45. 视频
  46. </view>
  47. <view class="chooscontainer" style="margin-left: 15rpx;">
  48. <xfx-image-upload mediaType="video" :max="6" :chooseNum="6" v-model="video_url"
  49. @uploadSuccess="ceshiUploadSuccess" @chooseSuccess="chooseMobile" @uploadFail="errorUpload"
  50. @imgDelete="delMobile" name="file" :action="upUrl"></xfx-image-upload>
  51. </view>
  52. <view class="line">
  53. <view class="lineCon">
  54. </view>
  55. </view>
  56. <view class="label2">
  57. PDF文件
  58. </view>
  59. <view class="chooscontainer" style="margin-left: 10rpx;flex-direction: column;">
  60. <view class="addpic" @click="uploadFile" v-if="!pdfFileName">
  61. <view class="addPicBox">
  62. <image src="/static/add.png"></image>
  63. </view>
  64. </view>
  65. <!-- <view class="" v-else> -->
  66. <view class="">
  67. {{pdfFileName}}<text v-if="pdfFileName" style="color: #26B3A0;margin-left: 20rpx;"
  68. @click="pdfFileName='',fileUrl=''">删除</text>
  69. </view>
  70. </view>
  71. <view class="kefuAndBtn">
  72. <view class="btn" @click="upload">
  73. 上传
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. import {
  81. postTicket
  82. } from '@/api/tusk/index.js'
  83. import uploadUrl from '@/common/config.js'
  84. export default {
  85. components: {},
  86. data() {
  87. return {
  88. upUrl: uploadUrl.baseUrl,
  89. pdfFileName: '',
  90. tobheight: 45,
  91. pic_url: [],
  92. textAreaValue: '',
  93. video_url: [],
  94. urlConfig: "", //上传的地址,
  95. mobileData: [], //上传成功的数组
  96. task_order_id: 0,
  97. fileUrl: ''
  98. };
  99. },
  100. computed: {
  101. },
  102. watch: {
  103. },
  104. onLoad(o) {
  105. this.task_order_id = o.id
  106. },
  107. onReady() {
  108. },
  109. onShow() {
  110. },
  111. onUnload() {
  112. },
  113. methods: {
  114. async upload() {
  115. // console.log('用户填写的上传完成凭证内容', {
  116. // textAreaValue: this.textAreaValue,
  117. // pic_url: this.pic_url,
  118. // video_url: this.video_url,
  119. // fileUrl: this.fileUrl
  120. // });
  121. console.log('上传完成凭证参数', {
  122. task_order_id: this.task_order_id,
  123. perform: this.textAreaValue,
  124. perform_image: this.pic_url,
  125. perform_video: this.video_url,
  126. perform_file: [this.fileUrl]
  127. });
  128. //return
  129. let res = await postTicket({
  130. task_order_id: this.task_order_id,
  131. perform: this.textAreaValue,
  132. perform_image: this.pic_url,
  133. perform_video: this.video_url,
  134. perform_file: [this.fileUrl]
  135. })
  136. if (res.code == 0) {
  137. // this.detail = res.data
  138. uni.showToast({
  139. title: '上传凭证成功',
  140. icon: 'success'
  141. })
  142. setTimeout(() => {
  143. uni.navigateBack()
  144. }, 1500)
  145. } else {
  146. uni.showToast({
  147. icon: 'none',
  148. title: res.msg
  149. })
  150. }
  151. console.log('上传完成凭证返回值', res);
  152. },
  153. //上传成功
  154. ceshiUploadSuccess(res) {
  155. console.log(res);
  156. /****************
  157. 因为上传接口返回的结构不一致,所以以下代码需要根据实际的接口返回结构开发,在此只是展示如果给数组里添加的过程,仅供参考
  158. ***************/
  159. var _res = JSON.parse(res.data);
  160. if (_res.code == 0) {
  161. console.log('文件上传成功返回值', _res);
  162. this.video_url.push(_res.data.url);
  163. }
  164. },
  165. // 未配置地址
  166. chooseMobile(res) {
  167. console.log(res);
  168. },
  169. //删除
  170. delMobile(del, tempFilePaths) {
  171. this.mobileData = del.tempFilePaths;
  172. console.log(this.mobileData);
  173. },
  174. // 上传失败
  175. errorUpload(res) {},
  176. handlePlay(index1) {
  177. this.video_url.forEach((item, index) => {
  178. let refId = `myVideo${index}`
  179. if (index != index1) {
  180. uni.createVideoContext(refId, this).pause()
  181. }
  182. })
  183. },
  184. //删除图片
  185. delectImg(i) {
  186. this.pic_url.splice(i, 1)
  187. },
  188. //点击预览图片
  189. previewImg(item) {
  190. uni.previewImage({
  191. current: item,
  192. urls: this.pic_url, //存放图片的数组
  193. loop: true,
  194. indicator: 'default'
  195. })
  196. },
  197. uploadFile() {
  198. console.log('1221321');
  199. let that = this
  200. uni.chooseFile({
  201. count: 1, //默认100
  202. // extension:['.zip','.doc'],
  203. success: function(res) {
  204. console.log(res.tempFilePaths[0]);
  205. // console.log(res.tempFiles[0].name);
  206. uni.uploadFile({
  207. url: that.upUrl, //仅为示例,非真实的接口地址
  208. filePath: res.tempFilePaths[0],
  209. name: 'file',
  210. formData: {
  211. 'user': 'test'
  212. },
  213. success: (uploadFileRes) => {
  214. console.log(JSON.parse(uploadFileRes.data).data.url);
  215. that.fileUrl = JSON.parse(uploadFileRes.data).data.url
  216. that.pdfFileName = res.tempFiles[0].name
  217. console.log(that.fileUrl, that.pdfFileName);
  218. }
  219. });
  220. }
  221. });
  222. },
  223. // 新增图片
  224. addquesPic() {
  225. let _this = this
  226. let imgList = []
  227. uni.chooseImage({
  228. count: 9 - _this.pic_url.length, //默认9
  229. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  230. sourceType: ['album'], //从相册选择
  231. success: function(res) {
  232. if (_this.pic_url.length >= 9) {
  233. _this.$toast("只能选择9张照片")
  234. return
  235. }
  236. if (res.tempFilePaths.length > 0) {
  237. console.log('res.tempFilePaths', res);
  238. imgList = res.tempFilePaths
  239. imgList.forEach(async (item, index) => {
  240. uni.uploadFile({
  241. //后端接口地址
  242. url: _this.upUrl,
  243. filePath: imgList[index],
  244. name: 'file',
  245. //上传文件类型
  246. formData: {
  247. tag: 'avatar',
  248. // Authorization: uni.getStorageSync('token') || ''
  249. },
  250. // 请求头一定要加,否则 iOS 图片上传会失败
  251. header: {
  252. //'content-type': 'multipart/form-data',
  253. 'Authorization': uni.getStorageSync('token') || ''
  254. },
  255. success: (res) => {
  256. console.log('上传图片返回值', res);
  257. //后端返回的图片名称
  258. let data = JSON.parse(res.data)
  259. _this.pic_url = _this.pic_url
  260. .concat(data.data.url)
  261. },
  262. })
  263. })
  264. }
  265. }
  266. })
  267. },
  268. }
  269. };
  270. </script>
  271. <style lang="scss" scoped>
  272. @import './index.scss';
  273. </style>