answer-form.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <view>
  3. <form v-if="data_list_loding_status == 0" @submit="formSubmit" class="form-container">
  4. <view class="padding-main oh">
  5. <view class="form-gorup">
  6. <view class="form-gorup-title">联系人<text class="form-group-tips-must">*</text></view>
  7. <input type="text" class="cr-base" name="name" maxlength="30" placeholder="联系人格式 1~30 个字符之间" placeholder-class="cr-grey">
  8. </view>
  9. <view class="form-gorup">
  10. <view class="form-gorup-title">联系电话<text class="form-group-tips-must">*</text></view>
  11. <input type="text" class="cr-base" name="tel" maxlength="30" placeholder-class="cr-grey" placeholder="座机 或 手机">
  12. </view>
  13. <view class="form-gorup">
  14. <view class="form-gorup-title">描述<text class="form-group-tips-must">*</text></view>
  15. <textarea class="cr-base" name="content" maxlength="160" :auto-height="true" placeholder-class="cr-grey" placeholder="请详细描述问题,我们将尽快为您解答!"></textarea>
  16. </view>
  17. <view class="form-gorup form-gorup-submit">
  18. <button class="bg-main br-main cr-white round text-size" type="default" form-type="submit" hover-class="none" :loading="form_submit_loading" :disabled="form_submit_loading">提交</button>
  19. </view>
  20. </view>
  21. </form>
  22. <view v-else>
  23. <!-- 提示信息 -->
  24. <component-no-data :propStatus="data_list_loding_status"></component-no-data>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. const app = getApp();
  30. import componentNoData from "../../components/no-data/no-data";
  31. export default {
  32. data() {
  33. return {
  34. data_list_loding_status: 1,
  35. data_list_loding_msg: '处理错误',
  36. form_submit_loading: false
  37. };
  38. },
  39. components: {
  40. componentNoData
  41. },
  42. props: {},
  43. onLoad() {},
  44. onShow() {
  45. this.init();
  46. // 分享菜单处理
  47. app.globalData.page_share_handle();
  48. },
  49. methods: {
  50. // 初始化
  51. init() {
  52. var user = app.globalData.get_user_info(this, "init");
  53. if (user != false) {
  54. // 用户未绑定用户则转到登录页面
  55. if (app.globalData.user_is_need_login(user)) {
  56. uni.redirectTo({
  57. url: "/pages/login/login?event_callback=init"
  58. });
  59. return false;
  60. }
  61. // 开启表单
  62. this.setData({
  63. data_list_loding_status: 0
  64. });
  65. } else {
  66. // 提示错误
  67. this.setData({
  68. data_list_loding_status: 2,
  69. data_list_loding_msg: '用户未登录'
  70. });
  71. }
  72. },
  73. /**
  74. * 表单提交
  75. */
  76. formSubmit(e) {
  77. // 数据验证
  78. var validation = [
  79. {fields: 'name', msg: '请填写联系人'},
  80. {fields: 'tel', msg: '请填写联系电话'},
  81. {fields: 'content', msg: '请填写内容'}
  82. ];
  83. if (app.globalData.fields_check(e.detail.value, validation)) {
  84. uni.showLoading({
  85. title: '提交中...'
  86. });
  87. this.setData({
  88. form_submit_loading: true
  89. });
  90. // 网络请求
  91. uni.request({
  92. url: app.globalData.get_request_url('add', 'answer'),
  93. method: 'POST',
  94. data: e.detail.value,
  95. dataType: 'json',
  96. success: res => {
  97. uni.hideLoading();
  98. if (res.data.code == 0) {
  99. app.globalData.showToast(res.data.msg, 'success');
  100. setTimeout(function() {
  101. uni.redirectTo({
  102. url: "/pages/user-answer-list/user-answer-list"
  103. });
  104. }, 2000);
  105. } else {
  106. this.setData({
  107. form_submit_loading: false
  108. });
  109. if (app.globalData.is_login_check(res.data)) {
  110. app.globalData.showToast(res.data.msg);
  111. } else {
  112. app.globalData.showToast('提交失败,请重试!');
  113. }
  114. }
  115. },
  116. fail: () => {
  117. uni.hideLoading();
  118. this.setData({
  119. form_submit_loading: false
  120. });
  121. app.globalData.showToast('服务器请求出错');
  122. }
  123. });
  124. }
  125. }
  126. }
  127. };
  128. </script>
  129. <style>
  130. </style>