financingManagement.vue 14.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516


  <script lang="ts" setup name="financingManagement" >
  import { ref,onBeforeMount } from 'vue';
  import { ElMessage, ElMessageBox } from "element-plus"
  import { useRoute } from "vue-router"
  import useUserStore from "@/store/modules/user";
  import TableTools from "@/components/Tools/table_tools.vue";
  import Table from "./components/Table/index.vue"
  import {
    getFinancingList,
    deleteFinancingAll,
    createFinancing,
    financingUpdate,
    getDocumentList
  } from "@/api/modules/dataTransaction";
const route = useRoute()
const userStore = useUserStore();
const searchItemList = ref([
    {
      type: "input",
      label: "",
      field: "daName",
      default: "",
      placeholder: "资产名称",
      clearable: true,
    },
  ]);
  const page = ref({
    limit: 50,
    rows:0,
    curr: 1,
    sizes: [
      { label: "10", value: 10 },
      { label: "50", value: 50 },
      { label: "100", value: 100 },
      { label: "150", value: 150 },
      { label: "200", value: 200 },
    ],
    daName: '',
  });
  const BASE_ID = "BASE_ID"
  const { proxy } = getCurrentInstance() as any;
  const tableRef = ref()
  const tableInfo = ref({
    id: 'entry-asset-table',
    loading:false,
    isEdit:false,
    currentId:"0",
    flag:"create",
    data:[] as any,
  })
const companyOption = ref<any>([])
const assetsOption = ref<any>([])
const NUMBER_MAX=999999999999
  const colums = [
  {
    type:"index",
    label:"序号",
    align:"center",
    width:"56"
  },
  {
    prop:"companyName",
    label:"公司名称",
    width:"220",
    componentType:"select",
    selectKey:"tenantName",
    selectOption:() => companyOption.value
  },
  {
    prop:"daName",
    label:"资产名称",
    width:"180",
    componentType:"select",
    selectOption:() => assetsOption.value ,
    selectKey:"daName",
  },
  {
    prop:"daCode",
    label:"资产编号",
    width:"180"
  },
  {
    prop:"registerTime",
    label:"登记时间",
    width:"130",
    componentType:"dateTime",
  },
  {
    prop:"effectiveDate",
    label:"有效期",
    width:"130",
    componentType:"dateTime",
  },
  {
    prop:"issuingEntityName",
    label:"发证主体",
    width:"250"
  },
  {
    prop:"creditGrantingTime",
    label:"授信时间",
    width:"130",
    componentType:"dateTime",
    componentDisabled:false
  },
  {
    prop:"creditGrantingGenerality",
    label:"授信主体",
    width:"180",
    componentDisabled:false
  },
  {
    prop:"creditGrantingMoney",
    label:"授信金额(万元)",
    width:"200",
    componentType:"number",
    placeholder:"0.00",
    componentDisabled:false,
    config:{
      controls:false
    },
    toFixed:true,
    align:"right",
    input:(value,key,info)=>{
     tableRef.value.columnInfo[key] = tableRef.value.columnInfo[key].toString().replace(/[^\d.]/g,"")
     tableRef.value.columnInfo[key] = tableRef.value.columnInfo[key].toString().replace(/\.{2,}/g,".")
     tableRef.value.columnInfo[key] = tableRef.value.columnInfo[key].toString().replace(".","$#$").replace(/\./g,"").replace("$#$",".")
     tableRef.value.columnInfo[key] = tableRef.value.columnInfo[key].toString().replace(/^(\-)*(\d+)\.(\d\d\d\d\d\d).*$/,"$1$2.$3")
     tableRef.value.columnInfo[key] = tableRef.value.columnInfo[key].toString().replace(/^\D*(\d{0,12}(?:\.\d{0,6})?).*$/g,"$1")
    },
    change:(value,key,info) => {
      let strArr = value.split(".")
      if(strArr.length>1) {
        let right = strArr[1]
        if(right==='' || right.length<2) {
          tableRef.value.columnInfo[key] = parseFloat(tableRef.value.columnInfo[key]||0).toFixed(2)
        }
      } else {
        tableRef.value.columnInfo[key] = parseFloat(tableRef.value.columnInfo[key]||0).toFixed(2)
      }
    }
  },
  {
    prop:"creditGrantingTerm",
    label:"授信期限(月)",
    width:"180",
    componentType:"number",
    placeholder:"0",
    config:{
      controls:false,
    },
    align:"right",
    componentDisabled:false,
    toFixed:false,
    input:(value,key,info)=>{
      //tableRef.value.columnInfo[key] = tableRef.value.columnInfo[key].toString().replace(/[^\d]/g,"")
     tableRef.value.columnInfo[key] = tableRef.value.columnInfo[key].toString().replace(/\./g,"")
     //tableRef.value.columnInfo[key] = tableRef.value.columnInfo[key].toString().replace(".","$#$").replace(/\./g,"").replace("$#$",".")
     //tableRef.value.columnInfo[key] = tableRef.value.columnInfo[key].toString().replace(/^(\-)*(\d+)\.(\d\d).*$/,"$1$2.$3")
     tableRef.value.columnInfo[key] = tableRef.value.columnInfo[key].toString().replace(/^\D*(\d{0,12}(?:\.\d{0})?).*$/g,"$1")
    }
  },
]
  const columnInfo = ref({
    guid:"",
    companyGuid: "",
    registerGuid: "",
    daName: "",
    companyName:"",
    registerTime: "",
    issuingEntityName:"",
    daCode: "",
    effectiveDate: "",
    issuingEntityGuid: "",
    creditGrantingTime: "",
    creditGrantingGenerality: "",
    creditGrantingMoney: 0,
    creditGrantingTerm: 0
  })
  const tableSelectInfo = ref({
  selectValue:"",
  companyGuid:""
})
  const toSearch = (val: any, clear: boolean = false) => {
    page.value.curr = 1;
    if (clear) {
      searchItemList.value.map((item) => (item.default = ""));
      page.value.daName = '';
    } else {
      page.value.daName = val.daName;
    }
    getTableData();
  };
  // 查资产
const getAssetsList = async ()  => {
  const res = await  getDocumentList({
    daName:tableSelectInfo.value.selectValue,
    companyGuid:tableSelectInfo.value.companyGuid,
    type:3})
    assetsOption.value =res.data || []
    return Promise.resolve()
}
  const documentList = async () => {
    const res:any = await  getDocumentList({
      daName:tableSelectInfo.value.selectValue,
      isCompany: true,
      type:3})
      if(res?.code === proxy.$passCode) {
        companyOption.value = res.data || []
      } 
  }
  const getTableData = () => {
    tableInfo.value.loading = true;
    getFinancingList({
      pageSize: page.value.limit,
      pageIndex: page.value.curr,
      daName: page.value.daName,
    }).then((res: any) => {
      tableInfo.value.loading = false;
      if (res?.code == proxy.$passCode) {
        const data = res.data || {};
        tableInfo.value.data = data.records || [];
        page.value.curr = data.pageIndex;
        page.value.rows = data.totalRows || 0;
      } 
    })
  }
  
  const createOneData = async () => {
    
    if(companyOption.value.length>0) {
      findTab(true)
      assetsOption.value = []
      tableInfo.value.flag = "create"
      tableInfo.value.data.unshift({
        guid:BASE_ID,
        companyGuid: "",
        registerGuid: "",
        daName: "",
        issuingEntityName:"",
        registerTime: "",
        daCode: "",
        effectiveDate: "",
        issuingEntityGuid: "",
        creditGrantingTime: "",
        creditGrantingGenerality: "",
        creditGrantingMoney: 0,
        creditGrantingTerm: 0
    })
    tableInfo.value.currentId = BASE_ID
    tableInfo.value.isEdit = true
    }else {
    ElMessage.warning("没有可添加的数据!")
  }
  }
  
  const columnDel =async (row) => {
    ElMessageBox.confirm(
    '是否确定删除所选数据?',
    '提示',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
      const guids = [row.guid]
      deleteFinancingAll(row.guid).then((res:any)=>{
        if(res?.code===proxy.$passCode){
        ElMessage.success("删除成功")
        getTableData()
        documentList()
        columnCancel()
        findTab(false)
        tableRef.value.columnInfo = {}
      } else {
        ElMessage.error(res?.msg)
      }
      })
    }).catch(()=>{
      tableRef.value.columnInfo = {}
    })
  }
  const columnSave = async (row) => {
    if(!row.companyName) {
      ElMessage.warning("公司名称不能为空")
      return
    } else if(!row.daName) {
      ElMessage.warning("资产名称不能为空")
      return
    } else if(!row.creditGrantingTime) {
      ElMessage.warning("授信时间不能为空")
      return
    } else if(!row.creditGrantingGenerality) {
      ElMessage.warning("授信主体不能为空")
      return
    } else if(!row.creditGrantingMoney || row.creditGrantingMoney<=0) {
      ElMessage.warning("授信金额不能小于0")
      return
    } else if(!row.creditGrantingTerm || row.creditGrantingTerm<1) {
      ElMessage.warning("授信期限不能小于1")
      return
    }
    let res:any
    switch(tableInfo.value.flag) {
      case "create":res = await createFinancing(row);break
      case "edit":res = await financingUpdate(row);break
    }
     if(res?.code===proxy.$passCode) {
      ElMessage.success(`${tableInfo.value.flag==='create' ? '新增' : '修改'}成功`);
      getTableData()
      columnInfoReset()
      documentList()
      findTab(false)
      assetsOption.value = []
      tableRef.value.columnInfo = {}
     }else {
      ElMessage.error(res.msg);
      //columnCancel()
     }
    
     //columnInfoReset()
  }
  const columnInfoReset = () => {
    tableInfo.value.currentId = "0"
    tableInfo.value.isEdit = false
    columnInfo.value = {
      guid:BASE_ID,
      companyGuid: "",
      companyName:"",
      issuingEntityName:"",
      registerGuid: "",
      daName: "",
      registerTime: "",
      daCode: "",
      effectiveDate: "",
      issuingEntityGuid: "",
      creditGrantingTime: "",
      creditGrantingGenerality: "",
      creditGrantingMoney: 0,
      creditGrantingTerm: 0
    }
  }
  const columnEdit = (row) => {
    tableInfo.value.currentId = row.guid
    tableInfo.value.isEdit = true
    tableInfo.value.flag = "edit"
    columnInfo.value = {...row}
    findTab(true)
    tableSelectInfo.value.companyGuid = row.companyGuid
    addAssetsOption(null,row,true)
    addCompanyOption(row)
    tableRef.value.columnInfo.creditGrantingMoney = tableRef.value.columnInfo.creditGrantingMoney.toFixed(2)
    assetsOption.value = []
  
  }
  const columnCancel = () => {
    tableInfo.value.isEdit = false
    if(tableInfo.value.flag==="edit") {
      tableInfo.value.currentId = "0"
    } else {
      tableInfo.value.data.shift()
      columnInfoReset()
    }
    findTab(false)
  }
  const pageChange = (info) => {
    page.value.curr = info.curr
    page.value.limit = info.limit
    getTableData()
  }
  const handelSelect = (row,key,row1) => {
    if(key==="companyName"){
      tableSelectInfo.value.companyGuid = row.tenantGuid
      addAssetsOption(row,row1)
      columnInfo.value.companyName = row.tenantName
      tableRef.value.columnInfo.companyName = row.tenantName
      if(row.tenantGuid!==row1.companyGuid) {
        tableRef.value.columnInfo.daName = ""
        tableRef.value.columnInfo.daCode = ""
        tableRef.value.columnInfo.issuingEntityName = ""
        tableRef.value.columnInfo.issuingEntityGuid = ""
        tableRef.value.columnInfo.registerGuid = ""
        tableRef.value.columnInfo.registerTime = ""
        tableRef.value.columnInfo.effectiveDate = ""
      }
      
    } else {
      if(tableInfo.value.flag==="create") {
        columnInfo.value = {
        guid:row.guid,
        companyName:row.tenantName,
        daName:row.daName,
        registerTime:row.registerTime,
        daCode:row.daCode,
        effectiveDate:row.effectiveDate,
        issuingEntityName:row.issuingEntityName,
        issuingEntityGuid:row.issuingEntityGuid,
        companyGuid:row.tenantGuid,
        registerGuid:row.registerGuid,
        creditGrantingTime: "",
        creditGrantingGenerality:"",
        creditGrantingMoney: 0,
        creditGrantingTerm: 0
      }
      // 新增不用传guid 所以删掉,但是往输入框添加数据 通过guid判断
      const {guid,...obj} = columnInfo.value
      tableRef.value.columnInfo = obj
      } else {
      columnInfo.value.daName = row.daName
      columnInfo.value.daCode = row.daCode
      columnInfo.value.registerTime = row.registerTime
      columnInfo.value.effectiveDate = row.effectiveDate
      columnInfo.value.issuingEntityName = row.issuingEntityName;
      columnInfo.value.registerGuid = row.registerGuid;
      tableRef.value.columnInfo = {...columnInfo.value}
      }
      
    }
   
  }
const findTab = (flag) => {
const tab:any = userStore.tabbar.find((tab:any)=>tab.fullPath===route.path)
tab.meta.editPage = flag
}
const addAssetsOption = (values,row,flag=false) => {
  getAssetsList().then(()=>{
    const obj = {
    costAccessmentGuid:null,
    daCode:row.daCode,
    daName: row.daName,
    documentFile: null,
    documentType: 1,
    effectiveDate: row.effectiveDate,
    guid:row.guid,
    issuingEntityGuid:row.issuingEntityGuid ,
    issuingEntityName:row.issuingEntityName,
    qualityEvaluationGuid: null,
    registerGuid:row.registerGuid,
    registerTime:row.registerTime,
    state: row.state,
    tenantGuid: row.companyGuid,
    tenantName:row.companyName,
  }
  const arr = assetsOption.value
  if(values&&values.tenantGuid===row.companyGuid) {
    arr.unshift(obj)
    assetsOption.value = arr
  }else if(flag) {
    arr.unshift(obj)
    assetsOption.value = arr
  }
 
  })
}
const addCompanyOption = (row) => {
  let flag = true
  documentList().then(()=>{
    const obj = {
      tenantName:row.companyName,
      tenantGuid:row.companyGuid
  }
  const arr = companyOption.value
  arr.forEach((item)=>{
       if(item.tenantGuid===row.companyGuid){
           flag = false
       }
  })
  if(flag) {
    arr.unshift(obj)
    companyOption.value = arr
  }
  })
}
onBeforeMount(()=> {
    //getTableData()
    documentList()
  })
  </script>
  
  <template>
    <div class="container_wrap">
      <div class="table_tool_wrap">
        <TableTools :searchItems="searchItemList" :searchId="'entry-data-search'" @search="toSearch" />
        <div class="tools_btns">
          <el-button type="primary" @click="createOneData" :disabled="tableInfo.isEdit">新建</el-button>
        </div>
      </div>
      <div class="table_panel_wrap">
        <Table 
          ref="tableRef"
          :tableInfo="tableInfo"
          :page="page"
          :colums="colums"
          v-model="columnInfo"
          @pageChange="pageChange"
          @columnSave="columnSave"
          @columnDel="columnDel"
          @columnEdit="columnEdit"
          @columnCancel="columnCancel"
          @handelSelect="handelSelect"
        ></Table>
      </div>
    </div>
  </template>
  
  
  <style scoped lang="scss">
  .container_wrap {
    padding: 0 16px;
  }
  
  </style>