123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <template>
- <uni-section title="提交前请仔细核对信息,提交后不可修改!" type="line">
- <view class="example">
- <!-- 自定义表单校验 -->
- <uni-forms ref="customForm" :rules="rules" :modelValue="customFormData" label-align="center">
- <uni-forms-item label="名 称" required name="name" label-width="125" label-align="center" >
- <uni-easyinput v-model="customFormData.name" placeholder="请输入供销社名称" />
- </uni-forms-item>
- <uni-forms-item label="地 址" required name="address" label-width="95" label-align="center" >
- <uni-easyinput v-model="customFormData.address" placeholder="请输入供销社地址" />
- </uni-forms-item>
- <uni-forms-item label="电 话" required name="chargePhone" label-width="95" label-align="center" >
- <uni-easyinput v-model="customFormData.chargePhone" placeholder="请输入负责人电话" />
- </uni-forms-item>
- <uni-forms-item label="负责人" required name="chargePeople" label-width="95" label-align="center" >
- <uni-easyinput v-model="customFormData.chargePeople" placeholder="请输入负责人姓名" />
- </uni-forms-item>
- <uni-forms-item label="图 片" required name="url" label-width="95">
- <upload :imgArr="imageList" :fileSize="1" :limit="3" @updateImg="updateImg"/>
- </uni-forms-item>
- </uni-forms>
- <button type="primary" @click="submit('customForm')">提交</button>
- </view>
- </uni-section>
- </template>
- <script>
- import { addCooperative } from "@/api/cooperative/cooperative";
- import upload from '../../components/upload/index.vue'
- export default {
- components: {
- upload
- },
- data() {
- return {
- // 基础表单数据
- baseFormData: {
- name: '',
- address:'',
- chargePeople:'',
- chargePhone:'',
- imgUrl:'',
- },
- // 校验规则
- rules: {
- name: {
- rules: [{
- required: true,
- errorMessage: '供销社名称不能为空'
- }]
- },
- address: {
- rules: [{
- required: true,
- errorMessage: '供销社地址不能为空'
- }]
- },
- chargePeople: {
- rules: [{
- required: true,
- errorMessage: '负责人姓名不能为空'
- }]
- },
- chargePhone: {
- rules: [
- {
- required: true,
- errorMessage: '负责人电话不能为空'
- },
- {
- pattern:'^1[3456789]\\d{9}$',
- errorMessage: '负责人电话不合法'
- }
- ]
- },
- imgUrlList: {
- rules: [{
- required: true,
- errorMessage: '图片不能为空'
- }]
- },
- },
- imageList: [],
- customFormData:{}
- }
- },
- onLoad() {},
- onReady() {
- // 设置自定义表单校验规则,必须在节点渲染完毕后执行
- this.$refs.customForm.setRules(this.rules)
- },
- created() {
- },
- methods: {
- //转换为下拉选列表
- formatOptions(data) {
- return data.map(item => ({
- value: item.id,
- text: item.productName,
- children: item.children ? this.formatOptions(item.children) : null,
- }));
- },
- submit(ref) {
- this.$refs[ref].validate().then(res => {
- if (res) {
- this.customFormData.imgUrl = this.imageList.join(',')
- addCooperative(this.customFormData).then(response => {
- this.$modal.msgSuccess('提交成功');
- this.customFormData = {...this.baseFormData};
- uni.navigateTo({
- url: '../cooperative/cooperative'
- });
- }).catch(err => {
- console.log('err', err);
- })
- }
- })
- },
- updateImg(imgList) {
- this.imageList = imgList;
- }
- }
- }
- </script>
- <style lang="scss">
- .example {
- padding: 15px;
- background-color: #fff;
- }
- .segmented-control {
- margin-bottom: 15px;
- }
- .button-group {
- margin-top: 15px;
- display: flex;
- justify-content: space-around;
- }
- .form-item {
- display: flex;
- align-items: center;
- }
- .button {
- display: flex;
- align-items: center;
- height: 35px;
- margin-left: 10px;
- }
- </style>
|