123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <template>
- <view>
- <nav-bar title="填写资料"></nav-bar>
- <view style="margin-top: 30rpx; padding: 0 40rpx">
- <u-form :model="form" ref="uForm" :error-type="errorType">
- <template v-for="(item, index) in listData">
- <u-form-item
- :key="index"
- v-if="item.type === 'input'"
- :label="item.label"
- :required="item.required"
- :label-width="auto"
- :prop="item.required ? item.prop : ''"
- >
- <u-input
- v-model="form[item.key]"
- :disabled="item.disabled"
- :placeholder="`请输入${item.label}`"
- />
- </u-form-item>
- <u-form-item
- :key="index"
- v-else-if="item.type === 'radio'"
- :label="item.label"
- :required="item.required"
- :label-width="auto"
- :prop="item.required ? item.prop : ''"
- >
- <u-radio-group v-model="form[item.key]">
- <u-radio
- v-for="(item1, i) in backDictArr(item)"
- :key="i"
- :name="item1.value"
- :disabled="item.disabled"
- >
- {{ item1.label }}
- </u-radio>
- </u-radio-group>
- </u-form-item>
- <u-form-item
- :key="index"
- v-else-if="item.type === 'select'"
- :label="item.label"
- :required="item.required"
- :label-width="auto"
- :prop="item.required ? item.prop : ''"
- >
- <u-input
- @click="open(item)"
- v-model="form[item.key]"
- type="select"
- :placeholder="`请选择${item.label}`"
- />
- <u-select
- v-model="item.show"
- :list="backDictArr(item)"
- :default-value="defaultValue"
- @confirm="
- (e) => {
- confirm(e, item.key);
- }
- "
- ></u-select>
- </u-form-item>
- </template>
- </u-form>
- </view>
- <view @click="submitForm" class="submit_btn">提交资料</view>
- </view>
- </template>
- <script>
- import { mapGetters, mapActions } from "vuex";
- const list = [
- {
- key: "realname",
- type: "input",
- label: "姓名",
- required: true,
- prop: "realname",
- },
- {
- key: "idCard",
- type: "input",
- label: "身份证号",
- required: true,
- prop: "idCard",
- },
- {
- key: "companyName",
- type: "input",
- label: "工作单位",
- required: true,
- prop: "companyName",
- },
- {
- key: "sex",
- type: "radio",
- label: "性别",
- required: true,
- list: [
- { label: "男", value: 1 },
- { label: "女", value: 2 },
- ],
- prop: "sex",
- },
- {
- key: "eduLevel",
- type: "select",
- label: "学历",
- dictKey: "edu_level",
- show: false,
- required: true,
- prop: "eduLevel",
- },
- ];
- export default {
- name: "SaasMiniprogramInfoFill",
- data() {
- return {
- listData: [],
- form: {},
- options: {},
- errorType: ["message"],
- auto: "180rpx",
- defaultValue: [0],
- isUploading: false,
- rules: {
- realname: [
- {
- required: true,
- message: "请输入姓名",
- trigger: ["change", "blur"],
- },
- ],
- sex: [
- {
- validator: (rule, value, callback) => {
- return !!value;
- },
- message: "请选择性别",
- trigger: "change",
- },
- ],
- idCard: [
- {
- required: true,
- message: "请输入身份证号",
- trigger: ["change", "blur"],
- },
- ],
- eduLevel: [
- {
- required: true,
- message: "请选择学历",
- trigger: ["change", "blur"],
- },
- ],
- companyName: [
- {
- required: true,
- message: "请输入工作单位",
- trigger: ["change", "blur"],
- },
- ],
- },
- };
- },
- async onLoad(options) {
- this.options = options;
- !this.userInfo && (await this.getUserInfo());
- this.init();
- },
- methods: {
- ...mapActions(["getUserInfo"]),
- init() {
- let { keys } = this.options;
- if (!keys) {
- return;
- }
- keys.split(",").forEach((key) => {
- let item = list.find((item) => item.key == key);
- if (item) {
- const value = this.userInfo[key];
- this.$set(this.form, key, value);
- this.listData.push({ ...item, disabled: !!value });
- }
- });
- },
- backDictArr(item) {
- let { dictKey, list } = item;
- if (dictKey) {
- if (!this.dictObj) {
- return [];
- }
- list = this.dictObj[dictKey].map((e, i) => {
- return { label: e, value: i };
- });
- item.list = list;
- }
- return list;
- },
- open(item) {
- if (item.disabled) {
- return;
- }
- let { key, list } = item;
- const option = list.find((e) => e.label === this.form[key]);
- this.defaultValue = [option ? option.value : 0];
- item.show = true;
- },
- confirm(e, key) {
- this.form[key] = e[0].label;
- },
- submitForm() {
- if (this.isUploading) {
- return;
- }
- this.isUploading = true;
- this.$nextTick(() => {
- this.$refs.uForm.validate((valid) => {
- if (valid) {
- this.$api
- .appuserInfo(this.form)
- .then((res) => {
- if (res.data.code === 200) {
- uni.showToast({
- title: "提交成功",
- icon: "none",
- });
- this.getUserInfo();
- setTimeout(() => {
- uni.navigateBack();
- }, 1500);
- } else {
- uni.showToast({
- title: res.data.msg,
- icon: "none",
- });
- }
- })
- .finally(() => {
- this.isUploading = false;
- });
- } else {
- this.isUploading = false;
- console.log(this.form);
- console.log("验证失败");
- }
- });
- });
- },
- },
- computed: {
- ...mapGetters(["userInfo", "dictObj"]),
- },
- onReady(res) {
- this.$refs.uForm.setRules(this.rules);
- },
- };
- </script>
- <style lang="scss" scoped>
- .submit_btn {
- width: 526rpx;
- height: 80rpx;
- background: #007aff;
- border-radius: 40rpx;
- text-align: center;
- line-height: 80rpx;
- color: #ffffff;
- position: absolute;
- left: 50%;
- margin-left: -263rpx;
- bottom: 140rpx;
- }
- </style>
|