info_fill.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <view>
  3. <nav-bar title="填写资料"></nav-bar>
  4. <view style="margin-top: 30rpx; padding: 0 40rpx">
  5. <u-form :model="form" ref="uForm" :error-type="errorType">
  6. <template v-for="(item, index) in listData">
  7. <u-form-item
  8. :key="index"
  9. v-if="item.type === 'input'"
  10. :label="item.label"
  11. :required="item.required"
  12. :label-width="auto"
  13. :prop="item.required ? item.prop : ''"
  14. >
  15. <u-input
  16. v-model="form[item.key]"
  17. :disabled="item.disabled"
  18. :placeholder="`请输入${item.label}`"
  19. />
  20. </u-form-item>
  21. <u-form-item
  22. :key="index"
  23. v-else-if="item.type === 'radio'"
  24. :label="item.label"
  25. :required="item.required"
  26. :label-width="auto"
  27. :prop="item.required ? item.prop : ''"
  28. >
  29. <u-radio-group v-model="form[item.key]">
  30. <u-radio
  31. v-for="(item1, i) in backDictArr(item)"
  32. :key="i"
  33. :name="item1.value"
  34. :disabled="item.disabled"
  35. >
  36. {{ item1.label }}
  37. </u-radio>
  38. </u-radio-group>
  39. </u-form-item>
  40. <u-form-item
  41. :key="index"
  42. v-else-if="item.type === 'select'"
  43. :label="item.label"
  44. :required="item.required"
  45. :label-width="auto"
  46. :prop="item.required ? item.prop : ''"
  47. >
  48. <u-input
  49. @click="open(item)"
  50. v-model="form[item.key]"
  51. type="select"
  52. :placeholder="`请选择${item.label}`"
  53. />
  54. <u-select
  55. v-model="item.show"
  56. :list="backDictArr(item)"
  57. :default-value="defaultValue"
  58. @confirm="
  59. (e) => {
  60. confirm(e, item.key);
  61. }
  62. "
  63. ></u-select>
  64. </u-form-item>
  65. </template>
  66. </u-form>
  67. </view>
  68. <view @click="submitForm" class="submit_btn">提交资料</view>
  69. </view>
  70. </template>
  71. <script>
  72. import { mapGetters, mapActions } from "vuex";
  73. const list = [
  74. {
  75. key: "realname",
  76. type: "input",
  77. label: "姓名",
  78. required: true,
  79. prop: "realname",
  80. },
  81. {
  82. key: "idCard",
  83. type: "input",
  84. label: "身份证号",
  85. required: true,
  86. prop: "idCard",
  87. },
  88. {
  89. key: "companyName",
  90. type: "input",
  91. label: "工作单位",
  92. required: true,
  93. prop: "companyName",
  94. },
  95. {
  96. key: "sex",
  97. type: "radio",
  98. label: "性别",
  99. required: true,
  100. list: [
  101. { label: "男", value: 1 },
  102. { label: "女", value: 2 },
  103. ],
  104. prop: "sex",
  105. },
  106. {
  107. key: "eduLevel",
  108. type: "select",
  109. label: "学历",
  110. dictKey: "edu_level",
  111. show: false,
  112. required: true,
  113. prop: "eduLevel",
  114. },
  115. ];
  116. export default {
  117. name: "SaasMiniprogramInfoFill",
  118. data() {
  119. return {
  120. listData: [],
  121. form: {},
  122. options: {},
  123. errorType: ["message"],
  124. auto: "180rpx",
  125. defaultValue: [0],
  126. isUploading: false,
  127. rules: {
  128. realname: [
  129. {
  130. required: true,
  131. message: "请输入姓名",
  132. trigger: ["change", "blur"],
  133. },
  134. ],
  135. sex: [
  136. {
  137. validator: (rule, value, callback) => {
  138. return !!value;
  139. },
  140. message: "请选择性别",
  141. trigger: "change",
  142. },
  143. ],
  144. idCard: [
  145. {
  146. required: true,
  147. message: "请输入身份证号",
  148. trigger: ["change", "blur"],
  149. },
  150. ],
  151. eduLevel: [
  152. {
  153. required: true,
  154. message: "请选择学历",
  155. trigger: ["change", "blur"],
  156. },
  157. ],
  158. companyName: [
  159. {
  160. required: true,
  161. message: "请输入工作单位",
  162. trigger: ["change", "blur"],
  163. },
  164. ],
  165. },
  166. };
  167. },
  168. async onLoad(options) {
  169. this.options = options;
  170. !this.userInfo && (await this.getUserInfo());
  171. this.init();
  172. },
  173. methods: {
  174. ...mapActions(["getUserInfo"]),
  175. init() {
  176. let { keys } = this.options;
  177. if (!keys) {
  178. return;
  179. }
  180. keys.split(",").forEach((key) => {
  181. let item = list.find((item) => item.key == key);
  182. if (item) {
  183. const value = this.userInfo[key];
  184. this.$set(this.form, key, value);
  185. this.listData.push({ ...item, disabled: !!value });
  186. }
  187. });
  188. },
  189. backDictArr(item) {
  190. let { dictKey, list } = item;
  191. if (dictKey) {
  192. if (!this.dictObj) {
  193. return [];
  194. }
  195. list = this.dictObj[dictKey].map((e, i) => {
  196. return { label: e, value: i };
  197. });
  198. item.list = list;
  199. }
  200. return list;
  201. },
  202. open(item) {
  203. if (item.disabled) {
  204. return;
  205. }
  206. let { key, list } = item;
  207. const option = list.find((e) => e.label === this.form[key]);
  208. this.defaultValue = [option ? option.value : 0];
  209. item.show = true;
  210. },
  211. confirm(e, key) {
  212. this.form[key] = e[0].label;
  213. },
  214. submitForm() {
  215. if (this.isUploading) {
  216. return;
  217. }
  218. this.isUploading = true;
  219. this.$nextTick(() => {
  220. this.$refs.uForm.validate((valid) => {
  221. if (valid) {
  222. this.$api
  223. .appuserInfo(this.form)
  224. .then((res) => {
  225. if (res.data.code === 200) {
  226. uni.showToast({
  227. title: "提交成功",
  228. icon: "none",
  229. });
  230. this.getUserInfo();
  231. setTimeout(() => {
  232. uni.navigateBack();
  233. }, 1500);
  234. } else {
  235. uni.showToast({
  236. title: res.data.msg,
  237. icon: "none",
  238. });
  239. }
  240. })
  241. .finally(() => {
  242. this.isUploading = false;
  243. });
  244. } else {
  245. this.isUploading = false;
  246. console.log(this.form);
  247. console.log("验证失败");
  248. }
  249. });
  250. });
  251. },
  252. },
  253. computed: {
  254. ...mapGetters(["userInfo", "dictObj"]),
  255. },
  256. onReady(res) {
  257. this.$refs.uForm.setRules(this.rules);
  258. },
  259. };
  260. </script>
  261. <style lang="scss" scoped>
  262. .submit_btn {
  263. width: 526rpx;
  264. height: 80rpx;
  265. background: #007aff;
  266. border-radius: 40rpx;
  267. text-align: center;
  268. line-height: 80rpx;
  269. color: #ffffff;
  270. position: absolute;
  271. left: 50%;
  272. margin-left: -263rpx;
  273. bottom: 140rpx;
  274. }
  275. </style>