<!-- @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 v-show="flgValid != null && !flgValid" ref="enable" name="enable"></BaseIndexButton>
        <!--    停用    -->
        <BaseIndexButton v-show="flgValid != null &&flgValid" ref="disable" name="disable"></BaseIndexButton>
      </template>
      <template #right>
        <!--   新建     -->
        <BaseIndexButton ref="add" name="add"></BaseIndexButton>
      </template>
    </BaseIndexButtonGroup>

    <!--  查询条件区域  -->
    <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>

    <!--  表格部分  -->
    <div :style="'height: ' + (tableHeight + 30) + 'px'" class="split-div-class">
      <!-- 表格   -->
      <DkTable :data="tableData"
               :page-flag="false"
               :page-total-flag="false"
               :height="tableHeight-20"
               primaryKey="macId"
               :pageFlag="true"
               @pageChange="pageSizeChange"
               :page-total="pageInfo.total"
               :current-page="pageInfo.currentPage"
               @current-change="currentChangeEvent($event)"
               ref="table-select" name="table">
        <DkTableColumn field="macCode"></DkTableColumn>
        <DkTableColumn field="macName"></DkTableColumn>
        <DkTableColumn field="macTypeName"></DkTableColumn>
        <DkTableColumn field="balance"></DkTableColumn>
        <DkTableColumn field="实时余额"></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">
        <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="balance">
          <InputNumberPop v-model="formData.balance"/>
        </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: [],
      // 是否显示启用或停用按钮
      flgValid: null,

      formData: {
        macName: null,
        macType: null,
        balance: null,
        remarks: null
      },
      //查询
      searchContent:
        [
          {
            itemCode: 'macName',
          },
          {
            itemCode: 'macTypeList',
            itemName: self.$t('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 : songy
     * @date   : 2024/3/1 16:33
     */
    getMacType() {
      console.log('11', this.$config.dictCode.macType)
      let params = {
        dictCode: this.$config.dictCode.macType,
      }
      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   : 根据ID查询数据
     * @author : 宋扬
     * @date   : 2024/3/1 15:43
     */
    detail(id) {
      return this.excuteNoParam(this.$service.moneyAccountService, this.$service.moneyAccountService.selectById, [id])
    },

    /**
     * @desc   :分页
     * @author : songy
     * @date   : 2024-02-20 15:52
     */
    pageSizeChange(pageInfo) {
      this.pageInfo = pageInfo
      this.getData() // 查询数据
    },

    /**
     * @desc   : 查询数据
     * @author : songy
     * @date   : 2024-02-20 15:53
     */
    getData(params) {
      return this.excute(this.$service.moneyAccountService, this.$service.moneyAccountService.selectByCond, params)
    },
  /**
   * @desc   : 保存或编辑
   * @author : songy
   * @date   : 2024/3/4 17:12
   */
    saveData() {
      if (this.modalParams.button === this.$config.formMode.edit) {
        return this.excute(this.$service.moneyAccountService, this.$service.moneyAccountService.update, this.params);
      } else {
        return this.excute(this.$service.moneyAccountService, this.$service.moneyAccountService.insert, this.params);
      }
    },
    /**
     * @desc   : 启用按钮
     * @author : songy
     * @date   : 2024/3/4 16:14
     */
    enable() {
      if (this.$refs['table-select'].batchKeys.length >= 1) {
        this.$IBMessage({
            content: this.$t('Q_002', {'param': this.$t('enable')}),
            title: this.$t('systemQuestion')
          },
          {
            ok: () => {
              //获取id
              let id = this.$refs['table-select'].batchKeys
              this.excuteNoParam(this.$service.moneyAccountService, this.$service.moneyAccountService.enable, [id], true, this.$t('enable'), true)
            },
          })
      } else {
        this.$Message.warning(this.$t('W_013'))
      }
    },
    /**
     * @desc   : 停用按钮
     * @author : songy
     * @date   : 2024/3/4 16:16
     */
    disable() {
      if (this.$refs['table-select'].batchKeys.length >= 1) {
        this.$IBMessage({
            content: this.$t('Q_002', {'param': this.$t('disable')}),
            title: this.$t('systemQuestion')
          },
          {
            ok: () => {
              //获取id
              let id = this.$refs['table-select'].batchKeys
              this.excuteNoParam(this.$service.moneyAccountService, this.$service.moneyAccountService.disable, [id], true, this.$t('disable'), true)
            },
          })
      } else {
        this.$Message.warning(this.$t('W_013'))
      }
    },

    /**
     * @desc   : 切换实际赋值flgValid
     * @author : songy
     * @date   : 2024/3/4 17:17
     */
    currentChangeEvent({row}) {
      console.log('tt000', row, row.flgValid)
      if (row != null) {

        this.flgValid = row.flgValid
      }
    }
    ,
  },
  created() {
    this.primaryKey = 'macId'  // 设置主键Id
    this.routeObjName = 'moneyAccount'  // 设置路由名称
  }
}
</script>

