<!--
 * @Author: zwq
 * @Date: 2024-04-15 16:52:38
 * @LastEditors: zwq
 * @LastEditTime: 2024-09-11 15:30:41
 * @Description:
-->
<template>
	<div class="app-container">
		<!-- 列表 -->
		<base-table
			v-loading="dataListLoading"
			:table-props="tableProps"
			:page="listQuery.pageNo"
			:limit="listQuery.pageSize"
			:max-height="tableH"
			:table-data="tableData">
			<method-btn
				v-if="tableBtn.length"
				slot="handleBtn"
				:width="80"
				label="操作"
				:method-list="tableBtn"
				@clickBtn="handleClick" />
		</base-table>
		<pagination
			:limit.sync="listQuery.pageSize"
			:page.sync="listQuery.pageNo"
			:total="listQuery.total"
			@pagination="getDataList" />

		<!-- 对话框(添加 / 修改) -->
		<base-dialog
			:dialogTitle="addOrEditTitle"
			:dialogVisible="addOrUpdateVisible"
			@cancel="handleCancel"
			@confirm="handleConfirm"
			:before-close="handleCancel"
			width="40%">
			<add-or-update
				ref="addOrUpdate"
				@refreshDataList="successSubmit"></add-or-update>
		</base-dialog>
	</div>
</template>

<script>
import AddOrUpdate from './add-or-updata';
import basicPage from '@/mixins/basic-page';
import typeRule from './typeRule';
import {
	getRawOthercostRulePage,
} from '@/api/cost/deepOthercostRule';
import tableHeightMixin from '@/mixins/lb/tableHeightMixin';

const tableProps = [
	{
		prop: 'label',
		label: '成本名称',
	},
	{
		prop: 'type',
		label: '自动计算方式',
		subcomponent: typeRule,
	},
	{
		prop: 'remark',
		label: '备注',
	},
];

export default {
	mixins: [basicPage,tableHeightMixin],
	data() {
		return {
			urlOptions: {
				getDataListURL: getRawOthercostRulePage,
			},
			tableProps,
			tableBtn: [{
							type: 'edit',
							btnName: '编辑',
					  }
			].filter((v) => v),
			tableData: [],
		};
	},
	components: {
		AddOrUpdate,
	},
	created() {
	},
	methods: {
    //tableBtn点击
    handleClick(val) {
      if (val.type === "edit") {
        this.addOrUpdateVisible = true;
        this.addOrEditTitle = "编辑";
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(val.data);
        });
      }
    },
	},
};
</script>
