<template>
  <div class="aimodeltc-edit">
    <el-dialog
      v-bind="$attrs"
      :title="state.dialogTitle"
      v-model="state.modalVisible"
      :before-close="cancelDialog"
      :append-to-body="true"
      :destroy-on-close="true"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :lock-scroll="false"
      class="aimodel-dialog"
      draggable
    >
      <el-form ref="aimodeltcRef" :model="state.form" :rules="state.rules" label-width="140px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="退费金额" prop="tfjtfprice">
              <el-input v-model="state.form.tfjtfprice" placeholder="退费金额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生效时间" prop="tfjsxsj">
              <el-date-picker
                v-model="state.form.tfjsxsj"
                type="datetime"
                placeholder="请选择生效时间"
              />
            </el-form-item>
          </el-col>

          <!-- <el-col :span="12">
            <el-form-item label="类型" prop="iplibrarylx">
              <el-radio-group v-model="state.form.iplibrarylx" :disabled="state.dialogType === 'up'" @change="onformType">
                <el-radio :value="'1'" :label="'1'">路由器</el-radio>
                <el-radio :value="'2'" :label="'2'">个人</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col> -->
          <el-col :span="24">
            <el-form-item label="备注" prop="tfjbz">
              <el-input v-model="state.form.tfjbz" placeholder="备注" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitDialog">确 定</el-button>
          <el-button @click="cancelDialog">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import allStoreApi from '@store/modules/allStoreApi'
import {filterObject} from '@/utils/index'
import {nextTick} from 'vue'
import UploadFile from '@/components/UploadFile/index.vue'
import {generateip} from '@/api/app'
import { tfjlogAdd } from '@/api/app'

// 接口封装文件
const alleApi = allStoreApi()
// 全局变量
const {proxy} = getCurrentInstance()
// 验证form
const aimodeltcRef = ref(null)

const state = reactive({
  // 弹窗开关
  modalVisible: false,
  // 弹窗标题
  dialogTitle: '',
  // 详情
  editView: {},
  // 表单
  form: {
    tfjtfprice: '10',
    tfjbz: '备注信息',
    tfjsxsj: '',
  },
  // 验证表单
  rules: {
    productradiusxxpj: [{required: true, message: '此项不能为空', trigger: 'blur'}],
    productradiusxxmax: [{required: true, message: '此项不能为空', trigger: 'blur'}],
    productradiussxpj: [{required: true, message: '此项不能为空', trigger: 'blur'}],
    productradiussxmax: [{required: true, message: '此项不能为空', trigger: 'blur'}]
    // username: [{ required: true, message: '姓名/昵称不能为空', trigger: 'blur' }],
    // userworkgroup1: [{ required: true, message: '关联公司不能为空', trigger: 'blur' }],
    // userworkgroup2: [{ required: true, message: '关联部门不能为空', trigger: 'blur' }],
  },
  textTypeData: []
})

const emits = defineEmits(['refresh'])

// 确定弹窗回调
const submitDialog = () => {
  aimodeltcRef.value.validate(async (valid) => {
    if (valid) {
      let params = JSON.parse(JSON.stringify(state.form))
      params.tfjyhid = state.editView.yhinfoid
      // // 宽带帐号
      // params.tfjkdzh = state.editView.yhinfozh
      // // 业务类型
      params.tfjywlx = '销户'
      await tfjlogAdd(params)
      proxy.$modal.msgSuccess('修改成功！')
      state.editView = {}
      aimodeltcRef.value.resetFields()
      emits('refresh')
      state.modalVisible = false
    }
  })
}

// 关闭弹窗
const cancelDialog = () => {
  state.editView = {}
  aimodeltcRef.value.resetFields()
  state.modalVisible = false
}

// 打开弹窗
const openDialog = async (data = {}) => {
  state.editView = data
  console.log(state.editView, 'state.editView')
  state.modalVisible = true
  state.dialogTitle = Object.keys(data).length ? `销户` : `销户`
}

// 申请详情
const getDataView = (data) => {
  nextTick(async () => {
    let params = {
      'iplibraryid.value': data.iplibraryid,
      pagevalue: 341
    }
    const result = await alleApi.view(params)
    state.editView = result
    state.form = filterObject(result, Object.keys(state.form))
    state.modalVisible = true
  })
}

// 拉取产品详情
import productStoreApi from '@store/modules/productStoreApi'
const productManageStore = productStoreApi()
const getDataType = () => {
  nextTick(async () => {
    const {Total, Data} = await productManageStore.list({pageindex: 1, rows: 99})
    state.textTypeData = Data
  })
}

defineExpose({
  openDialog
})
</script>
