TestMobileForm.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view>
  3. <cu-custom bgColor="bg-blue" backUrl="/pages/test/mobile/TestMobileList" :isBack="true">
  4. <block slot="backText">返回</block>
  5. <block slot="content">{{title}}</block>
  6. </cu-custom>
  7. <form @submit="formSubmit" class="cu-list menu">
  8. <view class="cu-form-group margin-top">
  9. <view class="title">
  10. <text class="red-color ">* </text> 姓名
  11. </view>
  12. <input placeholder='请填写姓名' v-model="inputForm.name"></input>
  13. </view>
  14. <view class="cu-form-group ">
  15. <view class="title">
  16. <text class="red-color ">* </text> 年龄
  17. </view>
  18. <input placeholder='请填写年龄' v-model="inputForm.age"></input>
  19. </view>
  20. <view class="cu-form-group ">
  21. <view class="title">
  22. <text class="red-color ">* </text> 地区
  23. </view>
  24. <jp-area-select v-model="inputForm.area.id"></jp-area-select>
  25. </view>
  26. <view class="cu-form-group ">
  27. <view class="title">
  28. <text class="red-color ">* </text> 公司
  29. </view>
  30. <jp-office-select v-model="inputForm.company.id"></jp-office-select>
  31. </view>
  32. <view class="cu-form-group ">
  33. <view class="title">
  34. <text class="red-color ">* </text> 部门
  35. </view>
  36. <jp-office-select v-model="inputForm.office.id"></jp-office-select>
  37. </view>
  38. <view class="cu-form-group ">
  39. <view class="title">
  40. <text class="red-color ">* </text> 性别
  41. </view>
  42. <jp-picker v-model="inputForm.sex" rangeKey="label" rangeValue="value" :range="$dictUtils.getDictList('sex')">
  43. <view class="picker">
  44. {{$dictUtils.getDictLabel('sex', inputForm.sex ,'请选择')}}
  45. </view>
  46. </jp-picker>
  47. </view>
  48. <view class="cu-form-group ">
  49. <view class="title">
  50. <text class="red-color ">* </text> 头像
  51. </view>
  52. <jp-image-upload2 v-model="inputForm.teImage"></jp-image-upload2>
  53. </view>
  54. <view class="cu-form-group ">
  55. <view class="title">
  56. <text class="red-color ">* </text> 单选框
  57. </view>
  58. <jp-radio-group v-model="inputForm.isSingle">
  59. <label v-for="(option, index) in $dictUtils.getDictList('yes_no')">
  60. <view>
  61. {{option.label}}
  62. <radio class='blue radio' :value="option.value" :class="inputForm.isSingle==option.value?'checked':''" :checked="inputForm.isSingle==option.value?true:false" ></radio>
  63. </view>
  64. </label>
  65. </jp-radio-group>
  66. </view>
  67. <view class="cu-form-group ">
  68. <view class="title">
  69. <text class="red-color ">* </text> 多选框
  70. </view>
  71. <jp-checkbox-group2 v-model="inputForm.cks">
  72. <label v-for="(option, index) in $dictUtils.getDictList('form_style')">
  73. <view>
  74. {{option.label || option.value}}
  75. <checkbox class="blue" :value="option.value" :class="(','+inputForm.cks+',').indexOf(','+option.value+',')>=0?'checked':''" :checked="(','+inputForm.cks+',').indexOf(','+option.value+',')>=0" ></checkbox>
  76. </view>
  77. </label>
  78. </jp-checkbox-group2>
  79. </view>
  80. <view class="cu-form-group ">
  81. <view class="title">
  82. <text class="red-color ">* </text> 多行文本框
  83. </view>
  84. <textarea placeholder='请填写多行文本框' v-model="inputForm.textArea"></textarea>
  85. </view>
  86. <view class="cu-form-group ">
  87. <view class="title">
  88. <text class="red-color ">* </text> 数字输入框
  89. </view>
  90. <input placeholder='请填写数字输入框' type="number" v-model="inputForm.textNumber"></input>
  91. </view>
  92. <view class="cu-form-group ">
  93. <view class="title">
  94. <text class="red-color ">* </text> 日期选择框
  95. </view>
  96. <jp-datetime-picker v-model="inputForm.teDate" placeholder="选择日期时间" mode="date"></jp-datetime-picker>
  97. </view>
  98. <view class="cu-form-group ">
  99. <view class="title">
  100. 邮箱
  101. </view>
  102. <input placeholder='请填写邮箱' v-model="inputForm.email"></input>
  103. </view>
  104. <view class="cu-form-group ">
  105. <view class="title">
  106. 手机号
  107. </view>
  108. <input placeholder='请填写手机号' v-model="inputForm.phone"></input>
  109. </view>
  110. <view class="cu-form-group ">
  111. <view class="title">
  112. 电话
  113. </view>
  114. <input placeholder='请填写电话' v-model="inputForm.tel"></input>
  115. </view>
  116. <view class="padding-xl">
  117. <button form-type="submit" class="cu-btn block bg-blue margin-tb-sm lg" >提交</button>
  118. </view>
  119. </form>
  120. </view>
  121. </template>
  122. <script>
  123. var graceChecker = require("@/common/graceChecker.js");
  124. import testMobileService from '@/api/test/mobile/testMobileService'
  125. export default {
  126. onShow() {
  127. this.$auth.checkLogin()
  128. },
  129. data () {
  130. return {
  131. title: '新建测试移动表单',
  132. inputForm: {
  133. id: '',
  134. name: '',
  135. age: '',
  136. area: {
  137. id: ''
  138. },
  139. company: {
  140. id: ''
  141. },
  142. office: {
  143. id: ''
  144. },
  145. sex: '',
  146. teImage: '',
  147. isSingle: '',
  148. cks: '',
  149. textArea: '',
  150. textNumber: '',
  151. teDate: '',
  152. email: '',
  153. phone: '',
  154. tel: ''
  155. }
  156. }
  157. },
  158. async onLoad(query) {
  159. if(query&&query.id){
  160. this.titile = "修改测试移动表单";
  161. let {data} = await testMobileService.queryById(query.id)
  162. this.inputForm = this.recover(this.inputForm, data)
  163. }
  164. },
  165. methods: {
  166. formSubmit: function(e) {
  167. //定义表单规则
  168. var rule = [
  169. {name:"name", checkType : "notnull", checkRule:"", errorMsg:"姓名不能为空"},
  170. {name:"age", checkType : "notnull", checkRule:"", errorMsg:"年龄不能为空"},
  171. {name:"area.id", checkType : "notnull", checkRule:"", errorMsg:"地区不能为空"},
  172. {name:"company.id", checkType : "notnull", checkRule:"", errorMsg:"公司不能为空"},
  173. {name:"office.id", checkType : "notnull", checkRule:"", errorMsg:"部门不能为空"},
  174. {name:"sex", checkType : "notnull", checkRule:"", errorMsg:"性别不能为空"},
  175. {name:"teImage", checkType : "notnull", checkRule:"", errorMsg:"头像不能为空"},
  176. {name:"isSingle", checkType : "notnull", checkRule:"", errorMsg:"单选框不能为空"},
  177. {name:"cks", checkType : "notnull", checkRule:"", errorMsg:"多选框不能为空"},
  178. {name:"textArea", checkType : "notnull", checkRule:"", errorMsg:"多行文本框不能为空"},
  179. {name:"textNumber", checkType : "notnull", checkRule:"", errorMsg:"数字输入框不能为空"},
  180. {name:"teDate", checkType : "notnull", checkRule:"", errorMsg:"日期选择框不能为空"},
  181. {name:"email", checkType : "isEmail", checkRule:"", errorMsg:""},
  182. {name:"phone", checkType : "isMobile", checkRule:"", errorMsg:""},
  183. {name:"tel", checkType : "isPhone", checkRule:"", errorMsg:""}
  184. ];
  185. //进行表单检查
  186. var formData = this.inputForm;
  187. var checkRes = graceChecker.check(formData, rule);
  188. if(checkRes){
  189. uni.showLoading()
  190. testMobileService.save(this.inputForm).then(({data}) => {
  191. uni.showToast({title:data, icon:"success"});
  192. uni.navigateTo({
  193. url: '/pages/test/mobile/TestMobileList'
  194. })
  195. }).catch((e)=>{
  196. })
  197. }else{
  198. uni.showToast({ title: graceChecker.error, icon: "none" });
  199. }
  200. }
  201. }
  202. }
  203. </script>