lawForm.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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="住所" prop="area" required>
  14. <u-input placeholder="请输入您的住所" v-model="form.area" />
  15. </u-form-item>
  16. </u-form>
  17. </view>
  18. <view class="textArea">
  19. <view class="bodystyle">
  20. <textarea placeholder="请填写您的问题" maxlength="500" @input="input"
  21. style="font-size: 28rpx;color: #666666;height: 400rpx;width: 100%;padding-left: 15rpx;" />
  22. <view
  23. style="height: 68rpx;width: 100%;color:#999999;padding: 20rpx 30rpx;font-size: 28rpx;text-align: right;">
  24. <text>{{problem_lenght}}</text>/500
  25. </view>
  26. </view>
  27. </view>
  28. <u-button hover-class="none" @click="submitForm" :custom-style="customStyle">提交</u-button>
  29. <lyg-popup @popupState="popupState" :nodeContent="nodeContent" title="使用须知"></lyg-popup>
  30. </view>
  31. </template>
  32. <script>
  33. import util from '@/common/util.js'
  34. import lyg_popup from '@/components/lyg-popup/lyg-popup.vue';
  35. export default {
  36. components: {
  37. lyg_popup
  38. },
  39. data() {
  40. return {
  41. customStyle: {
  42. width: '694rpx',
  43. height: '88rpx',
  44. backgroundColor: '#1721F4',
  45. color: '#fff',
  46. marginTop: '190rpx'
  47. },
  48. customBtn: {
  49. backgroundColor: '#1721F4',
  50. color: '#fff'
  51. },
  52. submitType: '',
  53. form: {
  54. name: '',
  55. phone: '',
  56. area: ''
  57. },
  58. rules: {
  59. name: [{
  60. required: true,
  61. message: '请输入您的姓名',
  62. // 可以单个或者同时写两个触发验证方式
  63. trigger: ['change', 'blur'],
  64. }, {
  65. validator: (rule, value, callback) => {
  66. return this.$u.test.chinese(value);
  67. },
  68. message: '请输入汉字',
  69. trigger: ['change', 'blur'],
  70. }],
  71. phone: [{
  72. required: true,
  73. min: 11,
  74. message: '请输入联系方式',
  75. trigger: ['change', 'blur'],
  76. },
  77. {
  78. validator: (rule, value, callback) => {
  79. return this.$u.test.mobile(value);
  80. },
  81. message: '手机号码不正确',
  82. trigger: ['change', 'blur'],
  83. }
  84. ],
  85. area: [{
  86. required: true,
  87. message: '请输入住所',
  88. trigger: 'change',
  89. }, {
  90. validator: (rule, value, callback) => {
  91. return this.$u.test.chinese(value);
  92. },
  93. message: '请输入汉字',
  94. trigger: ['change', 'blur'],
  95. }]
  96. },
  97. problem_lenght: '0',
  98. problem: '',
  99. type: null,
  100. nodeContent:""
  101. }
  102. },
  103. onReady() {
  104. this.$refs.uForm.setRules(this.rules);
  105. },
  106. onLoad(op) {
  107. this.type = op.type
  108. uni.setNavigationBarTitle({
  109. title: op.title
  110. })
  111. this.submitType = op.type
  112. this.getServiceContent()
  113. },
  114. methods: {
  115. popupState(value) {
  116. if (!value) {
  117. uni.navigateBack()
  118. return false
  119. }
  120. },
  121. async getServiceContent() {
  122. let res = await this.$u.get('/home/xieyi', {
  123. id: this.submitType == 1 ? 10 : 11
  124. })
  125. this.nodeContent = res.content
  126. },
  127. getPhone(e) {
  128. uni.login({
  129. success: (res) => {
  130. util.getPhoneData(res.code, e.detail).then(data => {
  131. this.form.phone = data
  132. })
  133. }
  134. })
  135. },
  136. input(e) {
  137. this.problem = e.detail.value
  138. this.problem_lenght = e.detail.value.length
  139. },
  140. submitForm() {
  141. this.$refs.uForm.validate(valid => {
  142. if (valid) {
  143. if (this.problem == '') {
  144. uni.showToast({
  145. title: "请填写您的问题",
  146. icon: "none"
  147. })
  148. return false
  149. }
  150. this.submitLawForm()
  151. }
  152. });
  153. },
  154. async submitLawForm() {
  155. let res = await this.$u.post('/form-input/consult', {
  156. name: this.form.name,
  157. contact: this.form.phone,
  158. content: this.problem,
  159. type: this.type,
  160. area: this.form.area
  161. })
  162. uni.showModal({
  163. title: "温馨提示",
  164. content: "您的留言我们已经收悉,将尽快安排工作人员办理",
  165. showCancel: false,
  166. success: (res) => {
  167. if (res.confirm) {
  168. uni.navigateBack()
  169. }
  170. }
  171. })
  172. }
  173. }
  174. }
  175. </script>
  176. <style lang="scss">
  177. .textArea {
  178. height: auto;
  179. width: 100%;
  180. // padding: 0 30rpx;
  181. // background-color: #FFFFFF;
  182. margin-top: 25rpx;
  183. .bodystyle {
  184. width: 100%;
  185. height: auto;
  186. padding: 35rpx 20rpx;
  187. word-break: break-all;
  188. word-wrap: break-word;
  189. background: #FFFFFF;
  190. border-radius: 10rpx;
  191. }
  192. }
  193. </style>