public_welfare.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <view class="main">
  3. <view class="u-padding-left-40 u-padding-right-40" style="background: #fff;">
  4. <u-form :model="form" ref="uForm" label-width="130">
  5. <u-form-item label="姓名" prop="name" required>
  6. <u-input placeholder="请输入您的姓名" v-model="form.name" />
  7. </u-form-item>
  8. <u-form-item label="联系方式" prop="phone" required>
  9. <u-input type="number" maxlength="11" placeholder="请输入您的联系方式" v-model="form.phone" />
  10. <u-button open-type="getPhoneNumber" :custom-style="customBtn" @getphonenumber="getPhone"
  11. slot="right" type="success" hover-class="none" size="mini">获取手机号</u-button>
  12. </u-form-item>
  13. <u-form-item label="举报类型" required label-position="top">
  14. <dataCheckbox mode="tag" selectedColor="#1721F4" v-model="value" :localdata="range"
  15. @change="changeRadio"></dataCheckbox>
  16. </u-form-item>
  17. </u-form>
  18. </view>
  19. <view class="textArea">
  20. <view class="bodystyle">
  21. <textarea placeholder="请填写您的问题" maxlength="500" @input="input"
  22. style="font-size: 28rpx;color: #666666;height: 250rpx;width: 100%;padding-left: 15rpx;" />
  23. <view
  24. style="height: 68rpx;width: 100%;color:#999999;padding: 20rpx 30rpx;font-size: 28rpx;text-align: right;">
  25. <text>{{problem_lenght}}</text>/500
  26. </view>
  27. </view>
  28. </view>
  29. <view class="u-padding-left-40 u-padding-right-40 u-margin-top-25" style="background: #fff;">
  30. <u-form :model="formLocation" label-width="130">
  31. <u-form-item label="现场位置" required>
  32. <u-input @click="selectLocation" :disabled="true" placeholder="请选择现场位置"
  33. v-model="formLocation.location" />
  34. <u-icon slot="right" name="map-fill" color="#1721F4" size="40"></u-icon>
  35. </u-form-item>
  36. <u-form-item label="照片" required label-position="top">
  37. <u-upload :form-data="formData" :before-upload="beforeUpload" ref="uUpload"
  38. :max-size="5 * 1024 * 1024" max-count="6" :action="action"></u-upload>
  39. </u-form-item>
  40. </u-form>
  41. </view>
  42. <u-button hover-class="none" @click="submitForm" :custom-style="customStyle">提交</u-button>
  43. <lyg-popup @popupState="popupState" :nodeContent="nodeContent" title="使用须知"></lyg-popup>
  44. </view>
  45. </template>
  46. <script>
  47. import util from '@/common/util.js'
  48. import dataCheckbox from '@/components/uni-data-checkbox/uni-data-checkbox.vue'
  49. import lyg_popup from '@/components/lyg-popup/lyg-popup.vue';
  50. export default {
  51. components: {
  52. dataCheckbox,
  53. lyg_popup
  54. },
  55. data() {
  56. return {
  57. formData: {},
  58. imgList: [],
  59. action: 'https://zhengda.oss-cn-chengdu.aliyuncs.com',
  60. problem_lenght: '0',
  61. problem: '',
  62. value: 0,
  63. range: [{
  64. "value": 0,
  65. "text": "生态环境资源保护"
  66. }, {
  67. "value": 1,
  68. "text": "食品药品安全"
  69. }, {
  70. "value": 2,
  71. "text": "国有土地使用权"
  72. },
  73. {
  74. "value": 3,
  75. "text": "国有财产保护"
  76. },
  77. {
  78. "value": 4,
  79. "text": "英烈保护"
  80. },
  81. {
  82. "value": 5,
  83. "text": "其他公益举报"
  84. }
  85. ],
  86. customBtn: {
  87. backgroundColor: '#1721F4',
  88. color: '#fff'
  89. },
  90. customStyle: {
  91. width: '694rpx',
  92. height: '88rpx',
  93. backgroundColor: '#1721F4',
  94. color: '#fff',
  95. marginTop: '88rpx',
  96. marginBottom: '30rpx'
  97. },
  98. form: {
  99. name: '',
  100. phone: ''
  101. },
  102. formLocation: {
  103. location: ''
  104. },
  105. rules: {
  106. name: [{
  107. required: true,
  108. message: '请输入您的姓名',
  109. // 可以单个或者同时写两个触发验证方式
  110. trigger: ['change', 'blur'],
  111. }, {
  112. validator: (rule, value, callback) => {
  113. return this.$u.test.chinese(value);
  114. },
  115. message: '请输入汉字',
  116. trigger: ['change', 'blur'],
  117. }],
  118. phone: [{
  119. required: true,
  120. min: 11,
  121. message: '请输入联系方式',
  122. trigger: ['change', 'blur'],
  123. },
  124. {
  125. validator: (rule, value, callback) => {
  126. return this.$u.test.mobile(value);
  127. },
  128. message: '手机号码不正确',
  129. trigger: ['change', 'blur'],
  130. }
  131. ],
  132. },
  133. latitude: null,
  134. longitude: null,
  135. kind: '生态环境资源保护',
  136. nodeContent: ''
  137. }
  138. },
  139. onReady() {
  140. this.$refs.uForm.setRules(this.rules);
  141. },
  142. onLoad() {
  143. uni.getLocation({
  144. type: 'gcj02',
  145. isHighAccuracy: true,
  146. success: (res) => {
  147. this.longitude = res.longitude
  148. this.latitude = res.latitude
  149. }
  150. })
  151. this.getServiceContent()
  152. },
  153. methods: {
  154. popupState(value) {
  155. if (!value) {
  156. uni.navigateBack()
  157. return false
  158. }
  159. },
  160. async getServiceContent() {
  161. let res = await this.$u.get('/home/xieyi', {
  162. id: 7
  163. })
  164. this.nodeContent = res.content
  165. },
  166. async beforeUpload(index, list) {
  167. let data = await this.$u.get('/upload-config/config')
  168. this.formData = {
  169. 'key': 'danling/' + list[index].url.split('/')[3],
  170. 'policy': data.policy,
  171. 'OSSAccessKeyId': data.OSSAccessKeyId,
  172. 'signature': data.signature,
  173. 'success_action_status': '200',
  174. 'domain': data.domain
  175. }
  176. },
  177. getPhone(e) {
  178. uni.login({
  179. success: (res) => {
  180. util.getPhoneData(res.code, e.detail).then(data => {
  181. this.form.phone = data
  182. })
  183. }
  184. })
  185. },
  186. changeRadio(e) {
  187. this.kind = e.detail.data.text
  188. },
  189. input(e) {
  190. this.problem = e.detail.value
  191. this.problem_lenght = e.detail.value.length
  192. },
  193. selectLocation() {
  194. uni.chooseLocation({
  195. latitude: this.latitude,
  196. longitude: this.longitude,
  197. success: (res) => {
  198. this.formLocation.location = res.address
  199. },
  200. fail: (err) => {
  201. uni.getSetting({
  202. success: (res) => {
  203. if (!res.authSetting['scope.userLocation']) {
  204. //打开提示框,提示前往设置页面
  205. uni.showModal({
  206. title: "温馨提示",
  207. content: "获取定位失败,请前往设置打开定位权限",
  208. showCancel: false,
  209. success: (data) => {
  210. if (data.confirm) {
  211. uni.openSetting()
  212. }
  213. }
  214. })
  215. }
  216. }
  217. })
  218. }
  219. })
  220. },
  221. submitForm() {
  222. this.imgList = this.$refs.uUpload.lists.filter(val => {
  223. return val.progress == 100;
  224. }).map(item => {
  225. return item.urlImg
  226. })
  227. this.$refs.uForm.validate(valid => {
  228. if (valid) {
  229. if (this.problem == '') {
  230. uni.showToast({
  231. title: "请填写您的问题",
  232. icon: "none"
  233. })
  234. return false
  235. }
  236. if (this.formLocation.location == '') {
  237. uni.showToast({
  238. title: "请选择现场位置",
  239. icon: "none"
  240. })
  241. return false
  242. }
  243. if (this.imgList.length == 0) {
  244. uni.showToast({
  245. title: "请上传照片",
  246. icon: "none"
  247. })
  248. return false
  249. }
  250. this.submitLawForm()
  251. }
  252. });
  253. },
  254. async submitLawForm() {
  255. let res = await this.$u.post("/form-input/pai", {
  256. name: this.form.name,
  257. contact: this.form.phone,
  258. content: this.problem,
  259. kind: this.kind,
  260. address: this.formLocation.location,
  261. files: JSON.stringify(this.imgList)
  262. })
  263. uni.showModal({
  264. title: "温馨提示",
  265. content: "您的举报内容我们已经收悉,将尽快安排工作人员办理",
  266. showCancel: false,
  267. success: (res) => {
  268. if (res.confirm) {
  269. uni.navigateBack()
  270. }
  271. }
  272. })
  273. }
  274. }
  275. }
  276. </script>
  277. <style lang="scss">
  278. .textArea {
  279. height: auto;
  280. width: 100%;
  281. // padding: 0 30rpx;
  282. // background-color: #FFFFFF;
  283. margin-top: 25rpx;
  284. .bodystyle {
  285. width: 100%;
  286. height: auto;
  287. padding: 35rpx 20rpx;
  288. word-break: break-all;
  289. word-wrap: break-word;
  290. background: #FFFFFF;
  291. border-radius: 10rpx;
  292. }
  293. }
  294. </style>