Jeecg-boot 一对多 Table 学习使用笔记

目录

1.  效果图:

1. 创建一对多表:

2.  创建页面

主页面:

主表编辑页面:

子表页面

子表编辑页面

3.  踩过的坑:

1.  如何将表头复选框变为单选框:

2.  不支持POST请求方法,支持一下put

 3.  加载不出子表数据


参考官方的的 一对多Table 示例,主要记录自己踩过的坑。

1.  效果图:

1. 创建一对多表:

使用在线表单开发创建一对多表单,创建主表与附表,关于创建主附表可参考官方文档:http://doc.jeecg.com/2044058

注: 创建表的相关,创建表过程遇到的问题可参考我的另外一篇文章https://blog.csdn.net/qq_41722795/article/details/108881930

并在线 生成代码将其放在相应的位置。

2.  创建页面

主页面:

<template>
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="24">

            <a-col :md="6" :sm="24">
              <a-form-item label="名称">
                <a-input placeholder="请名称" ></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="归属">
                <a-select placeholder="请选择归属" >
                  <a-select-option value="1">归肺经</a-select-option>
                  <a-select-option value="2">归胃经</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :md="6" :sm="24" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary"  icon="search">查询</a-button>
              <a-button type="primary"  icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
            </a-col>

          </a-row>
        </a-form>
      </div>

      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
        <a-button type="primary" icon="download" @click="handleExportXls('一对多示例')">导出</a-button>
        <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
          <a-button type="primary" icon="import">导入</a-button>
        </a-upload>

        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
        </a-dropdown>
      </div>

      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <!-- rowSelection type 设置 选择方式  可设置为复选框或单选框 -->
        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          filterMultiple="filterMultiple"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type:type}"
          @change="handleTableChange"
          :customRow="clickThenCheck"
        >

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

        </a-table>
      </div>
      <!-- table区域-end -->

      <!-- 下方卡片信息 -->
      <a-tabs defaultActiveKey="1">
        <a-tab-pane tab="配方信息" key="1">
          <research-sub-one-to-more-table-list ref="ResearchSubOneToMoreTableList"></research-sub-one-to-more-table-list>
        </a-tab-pane>
        <a-tab-pane tab="备注信息">
          <!--todo -->

        </a-tab-pane>

      </a-tabs>

    <!--表单区域-->
      <!--      点击编辑 弹窗内容-->
      <research-one-to-more-table-modal ref="modalForm" @ok="modalFormOk"></research-one-to-more-table-modal>

    </a-card>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ResearchOneToMoreTableModal from './form/ResearchOneToMoreTableModal'
  import ResearchSubOneToMoreTableList from "./ResearchSubOneToMoreTableList";
  import {deleteAction} from '@/api/manage'

    export default {
        name: "ResearchOneToMoreTable",
      mixins: [JeecgListMixin],
      components:{
        ResearchOneToMoreTableModal,
        ResearchSubOneToMoreTableList
      },
      data(){
          return{
            importExcelUrl:`${window._CONFIG['domianURL']}/test/jeecgOrderMain/importExcel`,
            type: "radio",//将选择列设置为单选,即type设置为radio
            /* 分页参数 */
            ipagination:{
              current: 1,
              pageSize: 5,
              pageSizeOptions: ['5', '10', '20'],
              showTotal: (total, range) => {
                return range[0] + "-" + range[1] + " 共" + total + "条"
              },
              showQuickJumper: true,
              showSizeChanger: true,
              total: 0
            },


            // 表头
            columns: [
              {
                title: '#',
                dataIndex: '',
                key:'rowIndex',
                width:60,
                align:"center",
                customRender:function (t,r,index) {
                  return parseInt(index)+1;
                }
              },
              {
                title:'编号',
                align:"center",
                dataIndex: 'orderCode'
              },
              {
                title:'名称',
                align:"center",
                dataIndex: 'name'
              },
              {
                title:'头像',
                align:"center",
                dataIndex: 'headSculpture'
              },
              {
                title:'别名',
                align:"center",
                dataIndex: 'byname'
              },
              {
                title:'功效',
                align:"center",
                dataIndex: 'efficiency'
              },
              {
                title:'产地',
                align:"center",
                dataIndex: 'localityOfGrowth'
              },
              {
                title:'形态特征',
                align:"center",
                dataIndex: 'morphologicalCharacter'
              },
              {
                title:'图像',
                align:"center",
                dataIndex: 'picture'
              },
              {
                title:'主治',
                align:"center",
                dataIndex: 'functionOfDrug'
              },
              {
                title:'归属',
                align:"center",
                dataIndex: 'parentCode',
                customRender: (text, record, index) => {
                  let re = "";
                  if (text === '1') {
                    re = "归肺";
                  } else if (text === '2') {
                    re = "归肾";
                  }
                  return re;
                }
              },
              {
                title:'相关配伍',
                align:"center",
                dataIndex: 'relatedCompatibility'
              },
              {
                title:'备注',
                align:"center",
                dataIndex: 'remark'
              },
              {
                title: '操作',
                dataIndex: 'action',
                align:"center",
                scopedSlots: { customRender: 'action' },
              }
            ],
            url: {
              list: "/zhzy/zgTraditionalMedicines/list",
              delete: "/zhzy/zgTraditionalMedicines/delete",
              deleteBatch: "/zhzy/zgTraditionalMedicines/deleteBatch",
              exportXlsUrl: "/zhzy/zgTraditionalMedicines/exportXls",
              importExcelUrl: "zhzy/zgTraditionalMedicines/importExcel",
              // queryZgTraditionalMedicinesPrescriptionByMainId: "zhzy/zgTraditionalMedicines/queryZgTraditionalMedicinesPrescriptionByMainId",
              // queryZgTraditionalMedicinesPrescriptionListByMainOrderOrderCode: "zhzy/zgTraditionalMedicines/queryZgTraditionalMedicinesPrescriptionListByMainOrderOrderCode"
            },

          }
      },
      methods:{
        clickThenCheck(record) {
          return {
            on: {
              click: () => {
                this.onSelectChange(record.id.split(","), [record]);
              }
            }
          };
        },
        onSelectChange(selectedRowKeys, selectionRows) {
          this.selectedRowKeys = selectedRowKeys;
          this.selectionRows = selectionRows;
          debugger;
          this.$refs.ResearchSubOneToMoreTableList.getOrderMain(this.selectionRows[0]);
          // this.$refs.JeecgOrderTicketList.getOrderMain(this.selectedRowKeys[0]);
        },
        onClearSelected() {
          this.selectedRowKeys = [];
          this.selectionRows = [];
          this.$refs.ResearchSubOneToMoreTableList.queryParam.mainId = null;

          this.$refs.ResearchSubOneToMoreTableList.loadData();

          this.$refs.ResearchSubOneToMoreTableList.selectedRowKeys = [];
          this.$refs.ResearchSubOneToMoreTableList.selectionRows = [];

        },

        handleDelete: function (id) {
          var that = this;
          deleteAction(that.url.delete, {id: id}).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.loadData();
              this.$refs.JeecgOrderCustomerList.loadData();
              this.$refs.JeecgOrderTicketList.loadData();
            } else {
              that.$message.warning(res.message);
            }
          });
        },
        searchQuery:function(){
          this.selectedRowKeys = [];
          this.selectionRows = [];
          this.$refs.ResearchSubOneToMoreTableList.queryParam.mainId = null;

          this.$refs.ResearchSubOneToMoreTableList.loadData();

          this.$refs.ResearchSubOneToMoreTableList.queryParam.mainId = null;

          this.$refs.ResearchSubOneToMoreTableList.loadData();

          this.$refs.ResearchSubOneToMoreTableList.selectedRowKeys = [];
          this.$refs.ResearchSubOneToMoreTableList.selectionRows = [];
          this.loadData();
        }
      }
    }
</script>

<style scoped>
  .ant-btn {
    padding: 0 10px;
    margin-left: 3px;
  }

  .ant-form-item-control {
    line-height: 0px;
  }

  /** 主表单行间距 */
  .ant-form .ant-form-item {
    margin-bottom: 10px;
  }

  /** Tab页面行间距 */
  .ant-tabs-content .ant-form-item {
    margin-bottom: 0px;
  }

</style>

注意:

主表编辑页面:

<template>
  <a-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <!-- 主表单区域 -->
        <a-row>

          <a-col :xs="24" :sm="12">
            <a-form-item label="编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['orderCode', validatorRules.orderCode]" placeholder="请输入编号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['name', validatorRules.name]" placeholder="请输入名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="头像" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['headSculpture']" placeholder="请输入头像"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="别名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['byname']" placeholder="请输入别名"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="功效" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['efficiency']" placeholder="请输入功效"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="产地" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['localityOfGrowth']" placeholder="请输入产地"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="形态特征" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['morphologicalCharacter']" placeholder="请输入形态特征"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="图像" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['picture']" placeholder="请输入图像"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="主治" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['functionOfDrug']" placeholder="请输入主治"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="归属" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['parentCode']" placeholder="请输入归属"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="相关配伍" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['relatedCompatibility']" placeholder="请输入相关配伍"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['remark']" placeholder="请输入备注"></a-input>
            </a-form-item>
          </a-col>

        </a-row>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction,getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment";

    export default {
        name: "ResearchOneToMoreTableModal",

      data(){
          return{
            title:"操作",
            visible: false,
            confirmLoading: false,
            orderMainModel: {jeecgOrderCustomerList: [{}]},
            form: this.$form.createForm(this),
            labelCol: {
              xs: { span: 24 },
              sm: { span: 5 },
            },
            wrapperCol: {
              xs: { span: 24 },
              sm: { span: 16 },
            },
            validatorRules:{
              orderCode: {
                rules: [
                  { required: true, message: '请输入编号!'},
                ]
              },
              name: {
                rules: [
                  { required: true, message: '请输入名称!'},
                ]
              },
            },
            url: {
              add: "/zhzy/zgTraditionalMedicines/add",
              edit: "/zhzy/zgTraditionalMedicines/edit",
              orderCustomerList: '/zhzy/zgTraditionalMedicines/queryZgTraditionalMedicinesPrescriptionByMainId',
              zgTraditionalMedicinesPrescription: {
                list: '/zhzy/zgTraditionalMedicines/queryZgTraditionalMedicinesPrescriptionByMainId'
              },
            }
          }
      },
      created () {
      },
      methods:{
        add () {
          this.edit({});
        },
        edit (record) {
          this.form.resetFields();
          this.orderMainModel = Object.assign({}, record);
          this.orderMainModel.jeecgOrderCustomerList = [{}];
          this.orderMainModel.jeecgOrderTicketList = [{}];
          //--------------------------------------------------------
          //初始化明细表数据
          console.log(this.orderMainModel.id)
          if(this.orderMainModel.id){
            let params = {id:this.orderMainModel.id}
            //初始化订单机票列表
            getAction(this.url.orderCustomerList,params).then((res)=>{
              if(res.success){
                this.orderMainModel.jeecgOrderCustomerList = res.result;
                this.$forceUpdate()
              }
            })

          }
          //--------------------------------------------------------
          this.visible = true;
          this.$nextTick(() => {
            this.form.setFieldsValue(pick(this.orderMainModel,'orderCode','name','headSculpture','byname','efficiency','localityOfGrowth','morphologicalCharacter','picture','functionOfDrug','parentCode','relatedCompatibility','remark'))
            this.form.setFieldsValue({orderDate:this.orderMainModel.orderDate?moment(this.orderMainModel.orderDate):null}) //时间格式化
          });
          console.log(this.orderMainModel)

        },
        close () {
          this.$emit('close');
          this.visible = false;
        },
        handleOk () {

        },
        handleCancel () {
          this.close()
        },
        addRowCustom () {

        },
        delRowCustom (index) {

        },
        addRowTicket () {

        },
        delRowTicket (index) {

        },
      }
    }
</script>

<style scoped>
  .ant-btn {
    padding: 0 10px;
    margin-left: 3px;
  }
  .ant-form-item-control {
    line-height: 0px;
  }
  /** 主表单行间距 */
  .ant-form .ant-form-item {
    margin-bottom: 10px;
  }
  /** Tab页面行间距 */
  .ant-tabs-content .ant-form-item {
    margin-bottom: 0px;
  }

</style>

子表页面

<template>
  <a-card :bordered="false">
    <!-- 操作按钮区域 -->
    <div class="table-operator" :md="24" :sm="24" style="margin: -25px 0px 10px 0px">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>

      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:;" @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <!-- 编辑弹窗 -->
    <research-sub-one-to-more-table-modal ref="modalForm" @ok="modalFormOk"></research-sub-one-to-more-table-modal>


  </a-card>
    
</template>

<script>
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import {getAction} from '@/api/manage'
  import ResearchSubOneToMoreTableModal from "./form/ResearchSubOneToMoreTableModal";

    export default {
        name: "ResearchSubOneToMoreTableList",
      mixins: [JeecgListMixin],
      components:{
        ResearchSubOneToMoreTableModal
      },
      data(){
          return{
            //表头
            columns:[
              {
                title: '名称',
                align: "center",
                width: 100,
                dataIndex: 'name',
                key: 'name'
              },
              {
                title: '别名',
                align: "center",
                width: 100,
                dataIndex: 'byname',
              },
              {
                title: '药方',
                align: "center",
                width: 100,
                dataIndex: 'prescription',
              },
              {
                title: '功效',
                align: "center",
                width: 100,
                dataIndex: 'efficiency',
              },
              {
                title: '操作',
                dataIndex: 'action',
                align:"center",
                width: 130,
                scopedSlots: { customRender: 'action' }
              }
            ],
            url: {
              list: "zhzy/zgTraditionalMedicines/queryZgTraditionalMedicinesPrescriptionByMainIdV2"
            }

          }
      },
      methods:{
        loadData(arg) {
          if (arg === 1) {
            this.ipagination.current = 1;
          }
          //update-begin--Author:kangxiaolin  Date:20190905 for:[442]主子表分开维护,生成的代码子表的分页改为真实的分页--------------------
          var params = this.getQueryParams();
          debugger;
          getAction(this.url.list, {orderId: params.orderId, pageNo : this.ipagination.current,
            pageSize :this.ipagination.pageSize}).then((res) => {
            if (res.success) {
              this.dataSource = res.result.records;
              this.ipagination.total = res.result.total;
            } else {
              this.dataSource = null;
            }
          })
          //update-end--Author:kangxiaolin  Date:20190905 for:[442]主子表分开维护,生成的代码子表的分页改为真实的分页--------------------

        },
        getOrderMain(row) {
          if(row == undefined)
          {
            this.queryParam.orderId = undefined;
            this.loadData(1);
          }else
          {
            this.queryParam.orderId = row.orderCode; //orderId 为外键
            this.loadData(1);
          }

        },
        handleAdd: function () {
          // 新增需要需要编辑弹窗
          this.$refs.modalForm.add(this.queryParam.orderId);
          this.$refs.modalForm.title = "添加客户信息";
        },

      }

    }
</script>

<style scoped>

</style>

子表编辑页面

<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :okButtonProps="{ props: {disabled: disableSubmit} }"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <!-- 编辑 -->
    <a-spin :spinning="confirmLoading" v-if="editStatus">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="名称"
          hasFeedback>
          <a-input placeholder="请输入药物名称" v-decorator="['name', {rules: [{ required: true, message: '请输入药物名称!' }]}]"
                   :readOnly="disableSubmit"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="别名"
          hasFeedback>
          <a-input placeholder="请输入药物别名" v-decorator="['byname', {rules: [{ required: false, message: '请输入药物别名!' }]}]"
                   :readOnly="disableSubmit"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="药方"
          hasFeedback>
          <a-input placeholder="请输入药方" v-decorator="['prescription', {rules: [{ required: true, message: '请输入药方!' }]}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="功效"
          hasFeedback>
          <a-input placeholder="请输入功效" v-decorator="['efficiency', {rules: [{ required: true, message: '请输入功效!' }]}]"/>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>

</template>

<script>
  import {httpAction} from '@/api/manage'
  import pick from 'lodash.pick'
  import Vue from 'vue'
  import {ACCESS_TOKEN} from "@/store/mutation-types"


    export default {
        name: "ResearchSubOneToMoreTableModal",
      data() {
        return {
          title: "操作",
          visible: false,
          model: {},
          labelCol: {
            xs: {span: 24},
            sm: {span: 5},
          },
          wrapperCol: {
            xs: {span: 24},
            sm: {span: 16},
          },
          fileList: [],
          disableSubmit: false,
          selectedRowKeys: [],
          orderId: "",
          hiding: false,
          headers: {},
          picUrl: "",
          picArray:[],
          previewVisible: false,
          previewImage: '',
          addStatus: false,
          editStatus: false,
          confirmLoading: false,
          form: this.$form.createForm(this),
          url: {
            add: "zhzy/zgTraditionalMedicines/addZgTraditionalMedicinesPrescription",
            edit: "zhzy/zgTraditionalMedicines/editZgTraditionalMedicinesPrescription",
            getOrderCustomerList: "/test/order/listOrderCustomerByMainId",
          },
          validatorRules: {

          },
        }
      },
      computed: {

      },
      created() {
        const token = Vue.ls.get(ACCESS_TOKEN);
        this.headers = {"X-Access-Token": token}
      },
      methods: {
        add(orderId) {
          this.hiding = true;
          if (orderId) {
            this.orderId = orderId;
            this.edit({orderId}, '');
          } else {
            this.$message.warning("请选择一种药物");
          }
        },
        detail(record) {
          this.edit(record, 'd');
        },
        edit(record, v) {
          if (v == 'e') {
            this.hiding = false;
            this.disableSubmit = false;
          } else if (v == 'd') {
            this.hiding = false;
            this.disableSubmit = true;
          } else {
            this.hiding = true;
            this.disableSubmit = false;
          }

          this.form.resetFields();
          this.orderId = record.orderId;
          this.model = Object.assign({}, record);
          if (record.id) {
            this.hiding = false;
            this.addStatus = false;
            this.editStatus = true;
            this.$nextTick(() => {
              this.form.setFieldsValue(pick(this.model, 'name', 'byname', 'prescription','efficiency'))
            });
            setTimeout(() => {
              this.fileList = record.idcardPic
            }, 5)
          } else {
            this.addStatus = false;
            this.editStatus = true;
          }
          this.visible = true;
        },
        close() {
          this.$emit('close');
          this.visible = false;
          this.picUrl = "";
          this.fileList=[];
        },
        handleOk() {
          const that = this;
          // 触发表单验证
          this.form.validateFields((err, values) => {
            if (!err) {
              that.confirmLoading = true;
              let httpurl = '';
              let method = '';
              if (!this.model.id) {
                httpurl += this.url.add;
                method = 'post';
              } else {
                httpurl += this.url.edit;
                method = 'put';
              }
              let formData = Object.assign(this.model, values);
              console.log(formData);
              formData.orderId = this.orderId;
              if(this.fileList != '') {
                formData.idcardPic = this.fileList;
              }else{
                formData.idcardPic = '';
              }
              httpAction(httpurl, formData, method).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.$emit('ok');
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.confirmLoading = false;
                that.close();
              })
            }
          })
        },
        handleCancel() {
          this.close();
        },
      
      }
    }
</script>

<style scoped>

</style>

3.  踩过的坑:

1.  如何将表头复选框变为单选框:

设置 rowSelection 的 type 属性,设置为 "radio";

2.  不支持POST请求方法,支持一下put

 

 后台:

根据自己需要,将前后的的方法修改一致:我将后台修改为PostMapping

 3.  加载不出子表数据

查看后台查询代码:并修改代码

/**
	 * 通过id查询及分页公共查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "配方通过主表ID查询")
	@ApiOperation(value = "配方主表ID查询", notes = "配方-通主表ID查询")
	@GetMapping(value = "/queryZgTraditionalMedicinesPrescriptionByMainIdV2")
	public Result<?> queryZgTraditionalMedicinesPrescriptionListByMainIdV2(
			ZgTraditionalMedicinesPrescription zgTraditionalMedicinesPrescription,
			@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
			@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
//		List<ZgTraditionalMedicinesPrescription> zgTraditionalMedicinesPrescriptionList = zgTraditionalMedicinesPrescriptionService
//				.selectByMainId(id);
//		return Result.ok(zgTraditionalMedicinesPrescriptionList);
		QueryWrapper<ZgTraditionalMedicinesPrescription> queryWrapper = QueryGenerator
				.initQueryWrapper(zgTraditionalMedicinesPrescription, req.getParameterMap());
		Page<ZgTraditionalMedicinesPrescription> page = new Page<ZgTraditionalMedicinesPrescription>(pageNo, pageSize);
		IPage<ZgTraditionalMedicinesPrescription> pageList = zgTraditionalMedicinesPrescriptionService.page(page,
				queryWrapper);
		return Result.ok(pageList);
	}

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值