uniteForm.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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="type!=5?'idCard':''" required v-if="type!=5">
  9. <u-input placeholder="请输入您的身份证号" type="number" maxlength="18" v-model="form.idCard" />
  10. </u-form-item>
  11. <u-form-item label="联系方式" prop="phone" required>
  12. <u-input type="number" maxlength="11" placeholder="请输入您的联系方式" v-model="form.phone" />
  13. <u-button open-type="getPhoneNumber" :custom-style="customBtn" @getphonenumber="getPhone"
  14. slot="right" type="success" hover-class="none" size="mini">获取手机号</u-button>
  15. </u-form-item>
  16. <u-form-item label="联系地址" prop="aera" required>
  17. <u-input placeholder="请输入您的联系地址" v-model="form.aera" />
  18. </u-form-item>
  19. </u-form>
  20. </view>
  21. <view class="u-padding-left-40 u-padding-right-40 u-margin-top-20" style="background: #fff;">
  22. <u-form label-width="130">
  23. <u-form-item label="附件" prop="name" label-position="top">
  24. <u-upload ref="uUpload" :form-data="formData" :before-upload="beforeUpload"
  25. :max-size="5 * 1024 * 1024" max-count="6" :action="action"></u-upload>
  26. </u-form-item>
  27. </u-form>
  28. </view>
  29. <view class="textArea">
  30. <view class="bodystyle">
  31. <textarea placeholder="请填写您的问题" maxlength="500" @input="input"
  32. style="font-size: 28rpx;color: #666666;height: 250rpx;width: 100%;padding-left: 15rpx;" />
  33. <view
  34. style="height: 68rpx;width: 100%;color:#999999;padding: 20rpx 30rpx;font-size: 28rpx;text-align: right;">
  35. <text>{{problem_lenght}}</text>/500
  36. </view>
  37. </view>
  38. </view>
  39. <u-button hover-class="none" @click="submitForm" :custom-style="customStyle">提交</u-button>
  40. <lyg-popup @popupState="popupState" :nodeContent="nodeContent" title="使用须知"></lyg-popup>
  41. </view>
  42. </template>
  43. <script>
  44. import util from '@/common/util.js'
  45. import lyg_popup from '@/components/lyg-popup/lyg-popup.vue';
  46. export default {
  47. components: {
  48. lyg_popup
  49. },
  50. data() {
  51. return {
  52. problem_lenght: '0',
  53. problem: '',
  54. customStyle: {
  55. width: '694rpx',
  56. height: '88rpx',
  57. backgroundColor: '#1721F4',
  58. color: '#fff',
  59. marginTop: '88rpx',
  60. marginBottom: '30rpx'
  61. },
  62. form: {
  63. name: '',
  64. aera: '',
  65. idCard: '',
  66. phone: ''
  67. },
  68. formData: {},
  69. customBtn: {
  70. backgroundColor: '#1721F4',
  71. color: '#fff'
  72. },
  73. rules: {
  74. name: [{
  75. required: true,
  76. message: '请输入您的姓名',
  77. // 可以单个或者同时写两个触发验证方式
  78. trigger: ['change', 'blur'],
  79. }, {
  80. validator: (rule, value, callback) => {
  81. return this.$u.test.chinese(value);
  82. },
  83. message: '请输入汉字',
  84. trigger: ['change', 'blur'],
  85. }],
  86. idCard: [{
  87. required: true,
  88. min: 18,
  89. message: '请输入身份证号',
  90. trigger: ['change', 'blur'],
  91. }, {
  92. validator: (rule, value, callback) => {
  93. return this.$u.test.idCard(value);
  94. },
  95. message: '身份证号码不正确',
  96. trigger: ['change', 'blur'],
  97. }],
  98. phone: [{
  99. required: true,
  100. min: 11,
  101. message: '请输入联系方式',
  102. trigger: ['change', 'blur'],
  103. },
  104. {
  105. validator: (rule, value, callback) => {
  106. return this.$u.test.mobile(value);
  107. },
  108. message: '手机号码不正确',
  109. trigger: ['change', 'blur'],
  110. }
  111. ],
  112. aera: [{
  113. required: true,
  114. message: '请输入住所',
  115. trigger: ['change', 'blur'],
  116. }, {
  117. validator: (rule, value, callback) => {
  118. return this.$u.test.chinese(value);
  119. },
  120. message: '请输入汉字',
  121. trigger: ['change', 'blur'],
  122. }]
  123. },
  124. type: null,
  125. action: 'https://zhengda.oss-cn-chengdu.aliyuncs.com',
  126. imgList: [],
  127. nodeContent: ''
  128. }
  129. },
  130. onReady() {
  131. if (this.type == 5) {
  132. console.log("hahha")
  133. delete this.rules['idCard']
  134. }
  135. this.$refs.uForm.setRules(this.rules);
  136. },
  137. onLoad(op) {
  138. this.type = op.type
  139. if (op.title !== undefined) {
  140. uni.setNavigationBarTitle({
  141. title: op.title
  142. })
  143. }
  144. this.getServiceContent(op.type)
  145. },
  146. methods: {
  147. popupState(value) {
  148. if (!value) {
  149. uni.navigateBack()
  150. return false
  151. }
  152. },
  153. async getServiceContent(type) {
  154. let res = await this.$u.get('/home/xieyi', {
  155. id: type
  156. })
  157. this.nodeContent = res.content
  158. },
  159. getPhone(e) {
  160. uni.login({
  161. success: (res) => {
  162. util.getPhoneData(res.code, e.detail).then(data => {
  163. this.form.phone = data
  164. })
  165. }
  166. })
  167. },
  168. async beforeUpload(index, list) {
  169. let data = await this.$u.get('/upload-config/config')
  170. this.formData = {
  171. 'key': 'danling/' + list[index].url.split('/')[3],
  172. 'policy': data.policy,
  173. 'OSSAccessKeyId': data.OSSAccessKeyId,
  174. 'signature': data.signature,
  175. 'success_action_status': '200',
  176. 'domain': data.domain
  177. }
  178. },
  179. input(e) {
  180. this.problem = e.detail.value
  181. this.problem_lenght = e.detail.value.length
  182. },
  183. submitForm() {
  184. this.imgList = this.$refs.uUpload.lists.filter(val => {
  185. return val.progress == 100;
  186. }).map(item => {
  187. return item.urlImg
  188. })
  189. this.$refs.uForm.validate(valid => {
  190. if (valid) {
  191. // if (this.imgList.length == 0) {
  192. // uni.showToast({
  193. // title: "请先上传附件",
  194. // icon: "none"
  195. // })
  196. // return false
  197. // }
  198. if (this.problem == '') {
  199. uni.showToast({
  200. title: "请填写您的问题",
  201. icon: "none"
  202. })
  203. return false
  204. }
  205. this.getFormUnite()
  206. }
  207. });
  208. },
  209. async getFormUnite() {
  210. let res = await this.$u.post("/form-input/apply", {
  211. name: this.form.name,
  212. idcard: this.form.idCard,
  213. contact: this.form.phone,
  214. address: this.form.aera,
  215. type: this.type,
  216. files: JSON.stringify(this.imgList),
  217. info: this.problem
  218. })
  219. uni.showModal({
  220. title: "温馨提示",
  221. content: '您的留言我们已经收悉,将尽快安排工作人员办理',
  222. showCancel: false,
  223. success: (res) => {
  224. if (res.confirm) {
  225. uni.navigateBack()
  226. }
  227. }
  228. })
  229. }
  230. }
  231. }
  232. </script>
  233. <style lang="scss">
  234. .textArea {
  235. height: auto;
  236. width: 100%;
  237. // padding: 0 30rpx;
  238. // background-color: #FFFFFF;
  239. margin-top: 25rpx;
  240. .bodystyle {
  241. width: 100%;
  242. height: auto;
  243. padding: 35rpx 20rpx;
  244. word-break: break-all;
  245. word-wrap: break-word;
  246. background: #FFFFFF;
  247. border-radius: 10rpx;
  248. }
  249. }
  250. </style>