service.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <view class="container">
  3. <uni-card v-if="isdy == 0">
  4. <uni-section title="您还不能签到" type="line">
  5. <text class="msg">您需要进行党员或下沉干部报到后,才能进行签到。</text>
  6. </uni-section>
  7. </uni-card>
  8. <uni-forms v-else 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 == 'upload' && !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. <image class="uploadVideo" v-if="item.type == 'upload' && formData[item.name]" :mode="item.mode" :src="filesUrl + formData[item.name]"></image>
  18. <!-- <video controls v-if="item.type == 'video' && formData[item.name]" class="uploadVideo" :src="filesUrl + formData[item.name]"></video> -->
  19. </uni-forms-item>
  20. </uni-forms>
  21. <button v-if="isdy != 0" :disabled="formData && formData.userId" class="btn" type="primary" @click="submitForm">{{ btnText }}</button>
  22. </view>
  23. </template>
  24. <script>
  25. import request from '../../api/report.js';
  26. import { BASE_URL } from '../../env.js';
  27. export default {
  28. data() {
  29. return {
  30. pickerList: [],
  31. pickerValue: '',
  32. pickerName: '',
  33. indicatorStyle: `height: 50px`,
  34. visible: false,
  35. btnText: '签到',
  36. baseUrl: BASE_URL.url,
  37. filesUrl: BASE_URL.fileUrl,
  38. formData: {},
  39. fileds: [
  40. { name: 'deptId', title: '报到社区', type: 'picker' },
  41. { name: 'description', title: '报到内容' },
  42. { name: 'photo', title: '上传照片', type: 'upload' },
  43. ],
  44. rules: {
  45. photo: {
  46. rules:[{ required: true, errorMessage: '请上传照片' }]
  47. },
  48. description: {
  49. rules:[{ required: true, errorMessage: '请填写报到内容' }]
  50. },
  51. deptId: {
  52. rules:[{ required: true, errorMessage: '请选择报到社区' }]
  53. },
  54. },
  55. isdy: 1
  56. }
  57. },
  58. async mounted() {
  59. const isdy = await request.getisdy();
  60. this.isdy = isdy.data;
  61. if (isdy && isdy.data == 0) {
  62. return;
  63. }
  64. const getCommunity = await request.getCommunity();
  65. this.pickerList = getCommunity.rows;
  66. await this.setDict();
  67. const is_status = await request.getqdstatus();
  68. if (is_status.data) {
  69. this.formData = is_status.data;
  70. this.btnText = '已签到'
  71. }
  72. },
  73. onShow() {},
  74. methods: {
  75. // 社区选择改变
  76. bindChange(e) {
  77. console.log(e, '社区选择改变')
  78. },
  79. // 选择社区
  80. pickerClick() {
  81. console.log('选择社区')
  82. this.visible = true;
  83. },
  84. async setDict() {
  85. this.fileds = await Promise.all(this.fileds.map(async e => {
  86. if (e.name == 'deptId') e.dict = this.pickerList.map(e => ({ ...e, text: e.deptName, value: e.deptId }));
  87. if (e.formatter && e.formatter.includes('dict')) {
  88. const dictType = e.formatter.split(':')[1];
  89. const res = await request.getDict(dictType);
  90. if (res.code == 200) e.dict = res.data.map(l => ({ ...l, value: l.dictValue, text: l.dictLabel }));
  91. }
  92. return e;
  93. }));
  94. },
  95. async upVideo() {
  96. const _this = this;
  97. const token = uni.getStorageSync('token');
  98. uni.chooseImage({
  99. count: 1,
  100. success: async (chooseImageRes) => {
  101. wx.showLoading({
  102. title: '上传中'
  103. })
  104. const tempFilePaths = chooseImageRes.tempFilePaths;
  105. uni.uploadFile({
  106. url: BASE_URL.url + '/activity/photo',
  107. name: 'file',
  108. header: {
  109. 'Authorization': `Bearer ${token}`
  110. },
  111. filePath: tempFilePaths[0],
  112. success: (uploadFileRes) => {
  113. const obj = JSON.parse(uploadFileRes.data);
  114. _this.$set(_this.formData, 'photo', obj.imgUrl);
  115. },
  116. fail(e) {
  117. console.log(e)
  118. wx.showToast({
  119. title: '上传失败'
  120. })
  121. },
  122. complete() {
  123. wx.hideLoading();
  124. }
  125. });
  126. }
  127. });
  128. },
  129. submitForm() {
  130. this.$refs.baseForm.validate().then(async valid=>{
  131. const res = await request.clockin(this.formData);
  132. if (res.code == 200) {
  133. uni.showToast({
  134. title: '签到成功',
  135. icon: 'success',
  136. duration: 2000,
  137. });
  138. setTimeout(() => {
  139. uni.navigateBack();
  140. }, 1000)
  141. }
  142. }).catch(err =>{
  143. console.log('表单错误信息:', err);
  144. })
  145. }
  146. },
  147. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  148. onReachBottom() {}
  149. }
  150. </script>
  151. <style>
  152. .uni-forms {
  153. width: 90%;
  154. margin: 10px auto;
  155. }
  156. .btn {
  157. width: 90%;
  158. margin: 0 auto;
  159. }
  160. .upVideo {
  161. width: 100px;
  162. height: 100px;
  163. border: 1px solid #cacaca;
  164. border-radius: 12px;
  165. }
  166. .videoIcon {
  167. display: block;
  168. text-align: center;
  169. line-height: 100px;
  170. }
  171. .uploadVideo {
  172. width: 100px;
  173. height: 100px;
  174. }
  175. .pickerItem {
  176. text-indent: 0.5em;
  177. border: 1px solid #e8e8e8;
  178. line-height: 2.5em;
  179. }
  180. .msg {
  181. color: red;
  182. font-size: 12px;
  183. }
  184. </style>