feedbackMixin.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // feedbackMixin.js - 可复用的反馈表单逻辑
  2. export default {
  3. data() {
  4. return {
  5. scanCode: '',
  6. filterStatus: '2',
  7. filterOptions: [{
  8. label: '意见反馈',
  9. value: '1'
  10. },
  11. {
  12. label: '留言评价',
  13. value: '2'
  14. }
  15. ],
  16. model1: {
  17. userInfo: {
  18. qrCode: '',
  19. type: '',
  20. liuyan: '',
  21. tel: '',
  22. mail: '',
  23. name: ''
  24. },
  25. },
  26. rules: {
  27. 'userInfo.name': {
  28. type: 'string',
  29. required: true,
  30. message: '请填写姓名',
  31. trigger: ['blur', 'change']
  32. },
  33. 'userInfo.tel': [{
  34. required: true,
  35. message: '请输入手机号',
  36. trigger: ['change', 'blur'],
  37. },
  38. {
  39. // 自定义验证函数,见上说明
  40. validator: (rule, value, callback) => {
  41. console.log(value);
  42. // 上面有说,返回true表示校验通过,返回false表示不通过
  43. // uni.$u.test.mobile()就是返回true或者false的
  44. return uni.$u.test.mobile(value);
  45. },
  46. message: '手机号码不正确',
  47. // 触发器可以同时用blur和change
  48. trigger: ['change', 'blur'],
  49. }
  50. ],
  51. },
  52. }
  53. },
  54. onReady() { // 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
  55. this.$refs.uForm.setRules(this.rules)
  56. },
  57. onLoad() {
  58. this.scanCode = uni.getStorageSync('scanCode');
  59. this.model1.userInfo.qrCode = this.scanCode;
  60. },
  61. methods: {
  62. baseOpenDetail(url) {
  63. uni.navigateTo({
  64. url: '/pages/'+url+'/index/rules'
  65. });
  66. },
  67. baseGoBack() {
  68. uni.navigateBack();
  69. },
  70. baseOnFilterChange(val) {
  71. if (this.filterStatus !== val) {
  72. this.filterStatus = val;
  73. }
  74. },
  75. baseSaveData(apiFunction, successCallback) {
  76. let that = this;
  77. this.model1.userInfo.type = this.filterStatus;
  78. this.$refs.uForm.validate().then(res => {
  79. apiFunction(that.model1.userInfo).then(data => {
  80. this.model1.userInfo.liuyan = '';
  81. this.model1.userInfo.tel = '';
  82. this.model1.userInfo.mail = '';
  83. this.model1.userInfo.name = '';
  84. let params = {
  85. type: "success",
  86. title: "成功主题(带图标)",
  87. message: "提交成功",
  88. iconUrl: "https://uviewui.com/demo/toast/success.png",
  89. }
  90. this.$refs.uToast.show({
  91. ...params
  92. });
  93. if (successCallback && typeof successCallback === 'function') {
  94. successCallback(data);
  95. }
  96. })
  97. }).catch(errors => {
  98. })
  99. }
  100. }
  101. }