• 子组件跳转父组件


    描述:父组件Form.vue 点击关联,弹出子组件importForm.vue 选中一条数据之后,点击确定按钮,关闭子组件importForm.vue,将子组件的内容显示在父组件Form.vue中

    选中第一条数据,点击确定

                                                    父组件对应的工作内容就有了

     父组件

    父组件跳转子组件

     this.$refs.子组件.子组件中的方法的方法名(父组件给子组件方法传的参数)

    1. "dataForm.LineAppFormId" placeholder="请点击输入框进行关联" clearable
    2. :style='{ "width": "100%" }' readonly @click.native="openAppForm()">
    1. /**
    2. * 弹出线路申请单关联界面
    3. */
    4. openAppForm() {
    5. // this.dataForm.LineAppFormId='';
    6. this.appFormVisible = true;
    7. this.$nextTick(() => {
    8. this.$refs.APPForm.sendParam(this.dataForm.LineAppFormId)
    9. })
    10. },
    1. <APP-Form v-if="appFormVisible" ref="APPForm" @assignMent="assignMent" @func="hiddenAppForm"/>
    2. import APPForm from './appForm'
    3. export default {
    4. components: { APPForm, },
    5. }
    6. /**
    7. * 勾选中的数据进行表单赋值
    8. */
    9. assignMent(param) {
    10. console.log('关联线路申请单关闭',param)
    11. this.appFormVisible = false;
    12. //线路申请单id
    13. this.dataForm.LineAppFormId = param.id;
    14. //工作内容
    15. this.dataForm.workContent = param.workContent;
    16. },
    17. hiddenAppForm(){
    18. this.appFormVisible = false;
    19. },

    子组件

    子组件给父组件

    this.$emit('父组件中方法的方法名', 子组件给父组件传的参数);
    1. sendParam(id) {
    2. if (id != null && id != '') {
    3. this.checkedId = id;
    4. }
    5. },
    6. /**
    7. * 列表复选框选中change事件
    8. * @author fuzibo
    9. * @date 2023-03-08
    10. * @copyright 上海柒志科技有限公司
    11. */
    12. handleSelectionChange(val) {
    13. this.recordData = '';
    14. this.recordLenth = val.length;
    15. if (val.length > 1) {
    16. this.$message({
    17. message: '只能关联一条申请单数据',
    18. type: "error",
    19. duration: 1000,
    20. });
    21. return;
    22. }
    23. //记录勾选的数据
    24. this.recordData = val[0];
    25. console.log('勾选的数据为>>>', val)
    26. },
    27. //确定关联线路申请单
    28. dataFormSubmit() {
    29. if (this.recordLenth > 1 || this.recordLenth == '') {
    30. this.$message({
    31. message: '请关联一条申请单数据',
    32. type: "error",
    33. duration: 1000,
    34. });
    35. return;
    36. }
    37. this.visible = false;
    38. let data = this.recordData;
    39. //调用父组件进行传值
    40. this.$emit('assignMent', data);
    41. },
    1. <script>
    2. //业务后台接口api方法,js文件存放的api目录由开发人员进行调整
    3. import { listStation, listEquip, listWeeklyPlan } from "@/api/qizCust/information/common/common"
    4. export default {
    5. components: {},
    6. data() {
    7. return {
    8. visible: true,
    9. recordLenth: '',
    10. recordData: '',
    11. detailVisible: false,
    12. query: {
    13. stationId: undefined,
    14. equipName: undefined,
    15. equipId: undefined,
    16. workSTime: undefined,
    17. },
    18. treeProps: {
    19. children: 'children',
    20. label: 'fullName',
    21. value: 'id'
    22. },
    23. list: [],
    24. listLoading: true,
    25. total: 0,
    26. listQuery: {
    27. currentPage: 1,
    28. pageSize: 20,
    29. sort: "desc",
    30. sidx: "",
    31. },
    32. formVisible: false,
    33. exportBoxVisible: false,
    34. columnList: [
    35. { prop: 'voltageName', label: '电压等级' },
    36. { prop: 'stationId', label: '变电站' },
    37. { prop: 'equipId', label: '回路名称' },
    38. // { prop: 'months', label: '计划停电月份' },
    39. { prop: 'workSTime', label: '开始日期' },
    40. { prop: 'workETime', label: '结束日期' },
    41. { prop: 'operateState', label: '停电状态' },
    42. { prop: 'workContent', label: '主要工作内容' },
    43. ],
    44. stationIdOptions: [],
    45. stationIdProps: { "label": "fullName", "value": "id" },
    46. equipIdOptions: [],
    47. equipIdProps: { "label": "fullName", "value": "id" },
    48. checkedId: '',
    49. }
    50. },
    51. /**
    52. * 开启watch列表数据监听,自动勾选已选中的行数据
    53. */
    54. watch: {
    55. listLoading: {
    56. handler(val) {
    57. if (!val) {
    58. this.$nextTick(() => {
    59. this.list.forEach(row => {
    60. if (this.checkedId === row.id) {
    61. this.$refs.multipleTable.$refs.JNPFTable.toggleRowSelection(row, true)
    62. }
    63. })
    64. })
    65. }
    66. },
    67. deep: true
    68. }
    69. },
    70. computed: {
    71. menuId() {
    72. return this.$route.meta.modelId || ''
    73. }
    74. },
    75. created() {
    76. //初始化列表数据
    77. this.initData()
    78. },
    79. methods: {
    80. sendParam(id) {
    81. console.log('关联表id',id)
    82. if (id != null && id != '') {
    83. this.checkedId = id;
    84. }
    85. },
    86. /**
    87. * 列表复选框选中change事件
    88. */
    89. handleSelectionChange(val) {
    90. this.recordData = '';
    91. this.recordLenth = val.length;
    92. if (val.length > 1) {
    93. this.$message({
    94. message: '只能关联一条申请单数据',
    95. type: "error",
    96. duration: 1000,
    97. });
    98. return;
    99. }
    100. //记录勾选的数据
    101. this.recordData = val[0];
    102. console.log('勾选的数据为>>>', val)
    103. },
    104. //关闭线路申请单弹出框
    105. closeDialog() {
    106. this.visible = false;
    107. this.$emit('func', true);
    108. },
    109. //确定关联线路申请单
    110. dataFormSubmit() {
    111. if (this.recordLenth > 1 || this.recordLenth == '') {
    112. this.$message({
    113. message: '请关联一条申请单数据',
    114. type: "error",
    115. duration: 1000,
    116. });
    117. return;
    118. }
    119. this.visible = false;
    120. let data = this.recordData;
    121. //调用父组件进行传值
    122. this.$emit('assignMent', data);
    123. },
    124. /**
    125. * 打开详情表单页面
    126. */
    127. goDetail(id) {
    128. this.detailVisible = true
    129. this.$nextTick(() => {
    130. this.$refs.Detail.init(id)
    131. })
    132. },
    133. /**
    134. * 列表字段排序
    135. */
    136. sortChange({ column, prop, order }) {
    137. this.listQuery.sort = order == 'ascending' ? 'asc' : 'desc'
    138. this.listQuery.sidx = !order ? '' : prop
    139. this.initData()
    140. },
    141. /**
    142. * 初始化加载列表数据
    143. */
    144. initData() {
    145. this.listLoading = true;
    146. let _query = {
    147. ...this.listQuery,
    148. ...this.query,
    149. menuId: this.menuId
    150. };
    151. console.log('输入参数',_query)
    152. listWeeklyPlan(_query).then(res => {
    153. var _list = [];
    154. for (let i = 0; i < res.data.list.length; i++) {
    155. let _data = res.data.list[i];
    156. _list.push(_data)
    157. }
    158. this.list = _list
    159. this.total = res.data.pagination.total
    160. this.listLoading = false
    161. })
    162. },
    163. /**
    164. * 执行查询
    165. */
    166. search() {
    167. this.listQuery = {
    168. currentPage: 1,
    169. pageSize: 20,
    170. sort: "desc",
    171. sidx: "",
    172. }
    173. this.initData()
    174. },
    175. /**
    176. * 刷新列表数据
    177. */
    178. refresh(isrRefresh) {
    179. this.formVisible = false
    180. if (isrRefresh) this.reset()
    181. },
    182. /**
    183. * 重置查询条件
    184. */
    185. reset() {
    186. for (let key in this.query) {
    187. this.query[key] = undefined
    188. }
    189. this.search()
    190. }
    191. }
    192. }
    193. script>

  • 相关阅读:
    网络安全--安全认证、IPSEC技术
    谷歌宣布:今年将Android 12L系统交付于三星、联想和微软
    2分钟彻底搞懂JS的版本演进
    【本地运行chatgpt-web】启动前端项目和service服务端项目,也是使用nodejs进行开发的。两个都运行成功才可以使用!
    JOSEF约瑟 闭锁继电器 LB-7 YDB-100 100V 50HZ 控制断路器的合闸或跳闸
    初识OpenGL (4)链接着色器
    【Flink入门修炼】2-2 Flink State 状态
    自认为最好的rule_of_five
    【第十四届蓝桥杯单片机组】个人笔记汇总
    嵌入式C 语言中的三块技术难点
  • 原文地址:https://blog.csdn.net/xy58451921/article/details/133684016