double.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view class="container">
  3. <uni-card v-if="formData && formData.status == 1">
  4. <uni-section title="驳回原因" type="line">
  5. <text class="msg">{{ formData.rejectReason }}</text>
  6. </uni-section>
  7. </uni-card>
  8. <uni-forms ref="baseForm" :modelValue="formData" :rules="rules" :label-width="80">
  9. <uni-forms-item v-for="item in fileds" :label="item.title" :name="item.name" :key="item.name" required>
  10. <uni-easyinput v-if="!item.formatter && !item.type" type="text" v-model="formData[item.name]" :placeholder="`请输入${item.title}`" />
  11. <uni-data-checkbox v-model="formData[item.name]" v-if="item.formatter && item.type == 'checkbox'" :multiple="item.multiple || false" :localdata="item.dict" />
  12. <uni-data-select v-model="formData[item.name]" v-if="item.formatter && item.type == 'select'" :localdata="item.dict"></uni-data-select>
  13. <view class="upVideo" v-if="item.type == 'video' && !formData[item.name]" @click="upVideo">
  14. <uni-icons color="#cacaca" class="videoIcon" type="videocam" size="30"></uni-icons>
  15. </view>
  16. <uni-data-select v-model="formData[item.name]" v-if="item.type == 'picker'" :localdata="item.dict" placeholder="请选择社区"></uni-data-select>
  17. <video controls v-if="item.type == 'video' && formData[item.name]" class="uploadVideo" :src="filesUrl + formData[item.name]"></video>
  18. </uni-forms-item>
  19. </uni-forms>
  20. <button :disabled="formData.status == 0 || formData.status == 2" class="btn" type="primary" @click="submitForm">{{ btnText }}</button>
  21. </view>
  22. </template>
  23. <script>
  24. import request from '../../api/report.js';
  25. import { BASE_URL } from '../../env.js';
  26. export default {
  27. data() {
  28. return {
  29. pickerList: [],
  30. pickerValue: '',
  31. pickerName: '',
  32. indicatorStyle: `height: 50px`,
  33. visible: false,
  34. btnText: '提交',
  35. baseUrl: BASE_URL.url,
  36. filesUrl: BASE_URL.fileUrl,
  37. formData: {},
  38. fileds: [
  39. { name: 'name', title: '姓名' },
  40. { name: 'sex', title: '性别', formatter: 'dict:user_sex_type', type: 'checkbox' },
  41. { name: 'phone', title: '联系电话' },
  42. { name: 'workUnit', title: '工作单位' },
  43. { name: 'deptId', title: '报到社区', type: 'picker' },
  44. { name: 'reportLocation', title: '报到位置' },
  45. { name: 'reportType', title: '报到类别', formatter: 'dict:baodao_type', type: 'select' },
  46. { name: 'residence', title: '居住地' },
  47. { name: 'content', title: '报到内容' },
  48. ],
  49. rules: {
  50. name: {
  51. rules:[{ required: true, errorMessage: '请填写姓名' }]
  52. },
  53. sex: {
  54. rules:[{ required: true, errorMessage: '请选择性别' }]
  55. },
  56. phone: {
  57. rules:[{ required: true, errorMessage: '请填写联系电话' }]
  58. },
  59. workUnit: {
  60. rules:[{ required: true, errorMessage: '请填写工作单位' }]
  61. },
  62. reportLocation: {
  63. rules:[{ required: true, errorMessage: '请填写报到位置' }]
  64. },
  65. reportType: {
  66. rules:[{ required: true, errorMessage: '请选择报到类别' }]
  67. },
  68. residence: {
  69. rules:[{ required: true, errorMessage: '请填写居住地' }]
  70. },
  71. content: {
  72. rules:[{ required: true, errorMessage: '请填写报到内容' }]
  73. },
  74. deptId: {
  75. rules:[{ required: true, errorMessage: '请选择报到社区' }]
  76. },
  77. // videoPath: {
  78. // rules:[{ required: true, errorMessage: '请上传影片' }]
  79. // }
  80. }
  81. }
  82. },
  83. async mounted() {
  84. const getCommunity = await request.getCommunity();
  85. this.pickerList = getCommunity.rows;
  86. const res = await request.getDyStatus();
  87. if (res.data) {
  88. this.formData = { ...res.data, sex: String(res.data.sex), reportType: String(res.data.reportType) };;
  89. if (res.data.status == 0) this.btnText = '审核中';
  90. // if (res.data.status == 1) this.btnText = '已驳回';
  91. if (res.data.status == 2) this.btnText = '已报到';
  92. }
  93. await this.setDict();
  94. },
  95. onShow() {},
  96. methods: {
  97. // 社区选择改变
  98. bindChange(e) {
  99. console.log(e, '社区选择改变')
  100. },
  101. // 选择社区
  102. pickerClick() {
  103. console.log('选择社区')
  104. this.visible = true;
  105. },
  106. async setDict() {
  107. this.fileds = await Promise.all(this.fileds.map(async e => {
  108. if (e.name == 'deptId') e.dict = this.pickerList.map(e => ({ ...e, text: e.deptName, value: e.deptId }));
  109. if (e.formatter && e.formatter.includes('dict')) {
  110. const dictType = e.formatter.split(':')[1];
  111. const res = await request.getDict(dictType);
  112. if (res.code == 200) e.dict = res.data.map(l => ({ ...l, value: l.dictValue, text: l.dictLabel }));
  113. }
  114. return e;
  115. }));
  116. },
  117. async upVideo() {
  118. const _this = this;
  119. wx.chooseMedia({
  120. count: 1, //上传视频的个数
  121. mediaType:['video'], //限制上传的类型为video
  122. sourceType:['album', 'camera'], //视频选择来源
  123. maxDuration: 30, //拍摄限制时间
  124. camera: 'back', //采用后置摄像头
  125. success:function(res){
  126. const token = uni.getStorageSync('token');
  127. //获取临时存放的视频资源
  128. let tempFilePath=res.tempFiles[0].tempFilePath
  129. // 上传视频
  130. uni.uploadFile({
  131. url: _this.baseUrl + '/activity/photo',
  132. name: 'file',
  133. header: {
  134. 'Authorization': `Bearer ${token}`
  135. },
  136. filePath: tempFilePath,
  137. success: (uploadFileRes) => {
  138. const obj = JSON.parse(uploadFileRes.data);
  139. _this.$set(_this.formData, 'videoPath', obj.imgUrl);
  140. },
  141. fail() {
  142. wx.showToast({
  143. title: '上传失败'
  144. })
  145. },
  146. complete() {
  147. wx.hideLoading();
  148. }
  149. });
  150. },
  151. })
  152. },
  153. submitForm() {
  154. this.$refs.baseForm.validate().then(async valid=>{
  155. let res;
  156. if (this.formData.dangyuanId) {
  157. res = await request.updatedy(this.formData);
  158. } else {
  159. res = await request.submitdy(this.formData);
  160. }
  161. if (res.code == 200) {
  162. uni.showToast({
  163. title: '提交成功',
  164. icon: 'success',
  165. duration: 2000,
  166. });
  167. setTimeout(() => {
  168. uni.navigateBack();
  169. }, 1000)
  170. }
  171. }).catch(err =>{
  172. console.log('表单错误信息:', err);
  173. })
  174. }
  175. },
  176. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  177. onReachBottom() {}
  178. }
  179. </script>
  180. <style>
  181. .uni-forms {
  182. width: 90%;
  183. margin: 10px auto;
  184. }
  185. .btn {
  186. width: 90%;
  187. margin: 0 auto;
  188. }
  189. .upVideo {
  190. width: 100px;
  191. height: 100px;
  192. border: 1px solid #cacaca;
  193. border-radius: 12px;
  194. }
  195. .videoIcon {
  196. display: block;
  197. text-align: center;
  198. line-height: 100px;
  199. }
  200. .uploadVideo {
  201. width: 100px;
  202. height: 100px;
  203. }
  204. .pickerItem {
  205. text-indent: 0.5em;
  206. border: 1px solid #e8e8e8;
  207. line-height: 2.5em;
  208. }
  209. .msg {
  210. color: red;
  211. font-size: 12px;
  212. }
  213. </style>