double.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <view class="container">
  3. <uni-forms ref="baseForm" :modelValue="formData" :label-width="100">
  4. <uni-forms-item v-for="item in fileds" :label="item.title" :name="item.name" :key="item.name">
  5. <uni-easyinput v-if="!item.formatter && !item.type" type="text" v-model="formData[item.name]" :placeholder="`请输入${item.title}`" />
  6. <uni-data-checkbox v-model="formData[item.name]" v-if="item.formatter && item.type == 'checkbox'" :multiple="item.multiple || false" :localdata="item.dict" />
  7. <uni-data-select v-model="formData[item.name]" v-if="item.formatter && item.type == 'select'" :localdata="item.dict"></uni-data-select>
  8. <view class="upVideo" v-if="item.type == 'video' && !formData[item.name]" @click="upVideo">
  9. <uni-icons color="#cacaca" class="videoIcon" type="videocam" size="30"></uni-icons>
  10. </view>
  11. <video controls v-if="item.type == 'video' && formData[item.name]" class="uploadVideo" :src="filesUrl + formData[item.name]"></video>
  12. </uni-forms-item>
  13. </uni-forms>
  14. <button :disabled="btnText == '已报道'" class="btn" type="primary" @click="submitForm">{{ btnText }}</button>
  15. </view>
  16. </template>
  17. <script>
  18. import request from '../../api/report.js';
  19. import { BASE_URL } from '../../env.js';
  20. export default {
  21. data() {
  22. return {
  23. btnText: '提交',
  24. baseUrl: BASE_URL.url,
  25. filesUrl: BASE_URL.fileUrl,
  26. formData: {},
  27. fileds: [
  28. { name: 'name', title: '姓名' },
  29. { name: 'sex', title: '性别', formatter: 'dict:user_sex_type', type: 'checkbox' },
  30. { name: 'phone', title: '联系电话' },
  31. { name: 'workUnit', title: '工作单位' },
  32. { name: 'reportLocation', title: '报道位置' },
  33. { name: 'reportType', title: '报道类别', formatter: 'dict:baodao_type', type: 'select' },
  34. { name: 'residence', title: '居住地' },
  35. { name: 'content', title: '报道内容' },
  36. { name: 'videoPath', title: '影片', type: 'video' },
  37. ]
  38. }
  39. },
  40. async mounted() {
  41. const res = await request.getDyStatus();
  42. if (res.data) {
  43. this.formData = { ...res.data, sex: String(res.data.sex), reportType: String(res.data.reportType) };;
  44. this.btnText = '已报道';
  45. }
  46. await this.setDict();
  47. },
  48. onShow() {},
  49. methods: {
  50. async setDict() {
  51. this.fileds = await Promise.all(this.fileds.map(async e => {
  52. if (e.formatter && e.formatter.includes('dict')) {
  53. const dictType = e.formatter.split(':')[1];
  54. const res = await request.getDict(dictType);
  55. if (res.code == 200) e.dict = res.data.map(l => ({ ...l, value: l.dictValue, text: l.dictLabel }));
  56. }
  57. return e;
  58. }));
  59. },
  60. async upVideo() {
  61. const _this = this;
  62. wx.chooseMedia({
  63. count: 1, //上传视频的个数
  64. mediaType:['video'], //限制上传的类型为video
  65. sourceType:['album', 'camera'], //视频选择来源
  66. maxDuration: 30, //拍摄限制时间
  67. camera: 'back', //采用后置摄像头
  68. success:function(res){
  69. const token = uni.getStorageSync('token');
  70. //获取临时存放的视频资源
  71. let tempFilePath=res.tempFiles[0].tempFilePath
  72. // 上传视频
  73. uni.uploadFile({
  74. url: _this.baseUrl + '/api/activity/photo',
  75. name: 'file',
  76. header: {
  77. 'Authorization': `Bearer ${token}`
  78. },
  79. filePath: tempFilePath,
  80. success: (uploadFileRes) => {
  81. const obj = JSON.parse(uploadFileRes.data);
  82. _this.$set(_this.formData, 'videoPath', obj.imgUrl);
  83. },
  84. fail() {
  85. wx.showToast({
  86. title: '上传失败'
  87. })
  88. },
  89. complete() {
  90. wx.hideLoading();
  91. }
  92. });
  93. },
  94. })
  95. },
  96. async submitForm() {
  97. const res = await request.submitdy(this.formData);
  98. if (res.code == 200) {
  99. uni.showToast({
  100. title: '提交成功',
  101. icon: 'success',
  102. duration: 2000,
  103. });
  104. setTimeout(() => {
  105. uni.navigateBack();
  106. }, 1000)
  107. }
  108. }
  109. },
  110. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  111. onReachBottom() {}
  112. }
  113. </script>
  114. <style>
  115. .uni-forms {
  116. width: 90%;
  117. margin: 10px auto;
  118. }
  119. .btn {
  120. width: 90%;
  121. margin: 0 auto;
  122. }
  123. .upVideo {
  124. width: 100px;
  125. height: 100px;
  126. border: 1px solid #cacaca;
  127. border-radius: 12px;
  128. }
  129. .videoIcon {
  130. display: block;
  131. text-align: center;
  132. line-height: 100px;
  133. }
  134. .uploadVideo {
  135. width: 100px;
  136. height: 100px;
  137. }
  138. </style>