123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <template>
- <!-- <BasicTable @register="registerTable" /> -->
- <div class="wrap">
- <div class="content">
- <Input
- :class="placeholder === '交易名称' ? 'input-width' : ''"
- :placeholder="placeholder"
- disabled
- v-model:value="value"
- />
- <a-button
- class="mr-2 add-btn"
- color="success"
- :disabled="disabled"
- @click="openAddPop(placeholder, type)"
- >
- 添加
- </a-button>
- <Checkbox
- class="checkbox"
- v-if="placeholder === '交易名称'"
- v-model:checked="checked"
- @change="onCheckChange"
- :disabled="ck_disabled"
- >会费</Checkbox
- >
- </div>
- <Popup @register="register" @select="select" />
- </div>
- </template>
- <script lang="ts">
- import { defineComponent, onUpdated, reactive, nextTick, toRefs } from 'vue';
- import { Input } from 'ant-design-vue';
- import { Checkbox } from 'ant-design-vue';
- import Popup from './popup.vue';
- import { useModal } from '/@/components/Modal';
- const props = {
- value: { type: Object, default: '' },
- placeholder: { type: String, default: '' },
- type: { type: Number, default: 1 },
- };
- interface State {
- value: object | string;
- placeholder: string;
- disabled: boolean;
- type: number;
- }
- export default defineComponent({
- name: 'CustomInput',
- components: { Input, Checkbox, Popup },
- props,
- emits: ['change'],
- setup(props, { emit }) {
- console.log('---------------set---up----------------');
- const state = reactive<State>({
- value: '',
- placeholder: props.placeholder,
- disabled: false,
- type: 1,
- });
- const checkbox = reactive({
- checked: false,
- ck_disabled: false,
- });
- const [register, { openModal: openPopup }] = useModal();
- // 初始化
- function init() {
- nextTick(() => {
- state.type = props.type;
- if (props.value.name) {
- state.value = props.value.name;
- } else if (props.value.url) {
- state.value = props.value.url;
- } else {
- state.value = props.value;
- if (props.value === '会费') {
- checkbox.checked = true;
- } else {
- checkbox.checked = false;
- }
- }
- });
- }
- onUpdated(() => {
- init();
- if (state.value !== '会费' || !state.disabled) {
- if (
- state.value !== '' &&
- (typeof props.value === 'string' || typeof props.value === 'number')
- ) {
- state.disabled = true;
- checkbox.ck_disabled = true;
- } else {
- state.disabled = false;
- checkbox.ck_disabled = false;
- if (state.value === '会费') {
- checkbox.checked = true;
- state.disabled = true;
- }
- }
- }
- if (props.value == '' && state.disabled) {
- checkbox.checked = false;
- state.disabled = false;
- state.value = '';
- } else if (props.value === '会费' && state.disabled) {
- // checkbox.checked = true;
- checkbox.ck_disabled = true;
- }
- });
- function onCheckChange(evt) {
- console.log(`evt`, evt);
- console.log(`evt.target.checked`, evt.target.checked);
- const checked = evt.target.checked;
- if (checked) {
- state.disabled = true;
- emit('change', { id: 0, name: '会费' });
- } else {
- state.disabled = false;
- emit('change', '');
- }
- }
- function openAddPop(title, type) {
- openPopup(true, { title, type });
- }
- function select(data) {
- emit('change', data);
- }
- return {
- openAddPop,
- onCheckChange,
- select,
- openPopup,
- register,
- ...toRefs(state),
- ...toRefs(checkbox),
- };
- },
- });
- </script>
- <style scoped>
- .content {
- display: flex;
- }
- .add-btn {
- margin-left: 2px;
- }
- .input-width {
- width: 70%;
- }
- .checkbox {
- height: 30px;
- }
- @media screen and (max-width: 450px) {
- .input-width {
- width: 39%;
- }
- }
- @media screen and (max-width: 380px) {
- .input-width {
- width: 35%;
- }
- }
- @media screen and (max-width: 330px) {
- .input-width {
- width: 23%;
- }
- }
- </style>
|