<!-- @desc:资金账户  @auth:常皓宁  @time:2024-2-1 13:47 -->
<template>
  <div class="main-div" ref="mainDiv">
    <loading :loading="loading" v-if="!modalVisible"></loading>
    <BaseIndexButtonGroup ref="BaseIndexButtonGroup" id="BaseIndexButtonGroup">
      <template #left>
        <BaseIndexButton ref="search" name="search"></BaseIndexButton>
        <BaseIndexButton ref="clear" name="clear"></BaseIndexButton>
        <BaseIndexButton ref="edit" name="edit"></BaseIndexButton>
        <BaseIndexButton ref="enable" name="enable"></BaseIndexButton>
        <BaseIndexButton ref="disable" name="disable"></BaseIndexButton>
      </template>
      <template #right>
        <BaseIndexButton ref="add" name="add"></BaseIndexButton>
      </template>
    </BaseIndexButtonGroup>

    <!--  卡片区  -->
    <div class="index-card">
      <!--  查询条件区域  -->
      <div id="search-cond-div" ref="search-cond-div" class="search-cond-class">
        <SearchCond ref="searchCond" v-model="searchCond"
                    @collapse-change="collapseChange" :setFlag="false"
                    :searchContent="searchContent"
        ></SearchCond>
      </div>
      <!-- 表格   -->
      <DkTable ref="table-select" name="table" :data="tableData" primaryKey="macId"
               @pageChange="pageSizeChange"
               :page-total="pageInfo.total"
               :page-size="pageInfo.pageSize"
               :page-size-opts="pageSizeOpts"
               :current-page="pageInfo.currentPage"
               :choose-flag="false"
               :height="tableHeight-30" showFooter>
        <DkTableColumn field="macCode"></DkTableColumn>
        <DkTableColumn field="macName"></DkTableColumn>
        <DkTableColumn field="macTypeName"></DkTableColumn>
        <DkTableColumn field="balance" data-type="number" :digits="2" sum></DkTableColumn>
        <DkTableColumn field="initBalance" data-type="number" :digits="2" sum></DkTableColumn>
        <DkTableColumn field="accDate" :title="$t('initDate')" :dataType="$config.columnType.date"></DkTableColumn>
        <DkTableColumn field="flgNegative" type="switch"></DkTableColumn>
        <DkTableColumn field="flgValid" type="switch"></DkTableColumn>
        <DkTableColumn field="remarks"></DkTableColumn>
      </DkTable>
    </div>

    <!--新建编辑-->
    <DkModal :loading="loading"
             v-model="editAddModal"
             ref="modal_editAdd"
             @on-visible-change="handleVisibleModal"
             @modalOk="save"
             :saveFlag="true"
             :title="modalTitle">
      <DkForm ref="formInline" v-model="formData" :col-count="1" :label-max-words="8">
        <DkFormItem prop="macName" :required="true">
          <InputPop v-model="formData.macName"/>
        </DkFormItem>
        <DkFormItem prop="macType" :required="true">
          <SelectPop v-model="formData.macType" ref="macType" :options="macTypeList" :multiple="false"
                     labelKey="dataValue" valueKey="dataId">
          </SelectPop>
        </DkFormItem>
        <DkFormItem prop="initBalance">
          <InputNumberPop v-model="formData.initBalance"/>
        </DkFormItem>
        <!--开户日期-->
        <DkFormItem prop="accDate" :label="$t('initDate')" :data-type="$config.dataType.date">
          <DatePickerPop v-model="formData.accDate" :short-cut-flag="true"/>
        </DkFormItem>
        <DkFormItem prop="flgNegative">
          <DkSwitch v-model="formData.flgNegative"/>
        </DkFormItem>
        <DkFormItem prop="remarks">
          <InputPop v-model="formData.remarks" textareaFlag/>
        </DkFormItem>
      </DkForm>
    </DkModal>
  </div>
</template>

<script>
import {indexMixin} from '@/mixins'

export default {
  name: 'money-account',
  mixins: [indexMixin],
  data() {
    let self = this
    return {
      // 资金类别
      macTypeList: [],
      formData: {
        macName: null,
        macType: null,
        initBalance: null,
        balance: null,
        flgNegative: true,
        remarks: null,
        accDate: new Date(),
        orgId: self.$store.state.user.orgId,
        staffId: self.$store.state.user.id,
        makeStaff: self.$store.state.user.id,
      },
      //查询
      searchContent: [
        {
          itemCode: 'macName',
          valueFormat: {code: 'macName'},
          valueKind: 'STR'
        },
        {
          itemCode: 'macTypeName',
          valueFormat: {
            code: 'macTypeList',
            data: [],
            valueKey: 'dataId',
            labelKey: 'dataValue',
          },
          valueKind: 'M-CHOICE'
        },
        self.$config.flgValidSearch
      ],
    }
  },
  methods: {
    /**
     * @desc   : 加载数据
     * @author : 宋扬
     * @date   : 2024/3/1 11:16
     */
    initData() {
      // 获取账户类别
      this.getMacType();
    },
    /**
     * @desc   : 获取资金账号数据
     * @author : 宋扬
     * @date   : 2024/3/1 16:33
     */
    getMacType() {
      let params = {
        dictCode: this.$config.kindCode.basicMacType,
      }
      this.excute(this.$service.commonService, this.$service.commonService.getDictionaryData, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          let list = this.searchContent.filter(it => it.valueFormat.code == 'macTypeList')
          if (list.length > 0) {
            list[0].valueFormat.data = res.data
          }
          this.macTypeList = res.data;
        }
      })
    },
    /**
     * @desc   : 查询数据
     * @author : 宋扬
     * @date   : 2024-02-20 15:53
     */
    getData(params) {
      return this.excute(this.$service.moneyAccountService, this.$service.moneyAccountService.selectByCond, params)
    },
    /**
     * @desc   : 根据ID查询数据
     * @author : 宋扬
     * @date   : 2024/3/1 15:43
     */
    detail(id) {
      return this.excuteNoParam(this.$service.moneyAccountService, this.$service.moneyAccountService.selectById, [id], false)
    },
    /**
     * @desc   : 保存或编辑
     * @author : 宋扬
     * @date   : 2024/3/4 17:12
     */
    saveData() {
      this.params.accDate = new Date(this.params.accDate).toDateStr();
      if (this.modalParams.button === this.$config.formMode.add) {
        return this.excute(this.$service.moneyAccountService, this.$service.moneyAccountService.insert, this.params);
      } else {
        return this.excute(this.$service.moneyAccountService, this.$service.moneyAccountService.update, this.params);
      }
    },
  },

  created() {
    this.primaryKey = 'macId'  // 设置主键Id
    this.routeObjName = 'moneyAccount'  // 设置路由名称
    this.comHandleEnableFlag = true; // 开启启用停用功能
  }
}
</script>

