<template>
  <div class="main-div" ref="mainDiv">
    <!--加载中-->
    <loading :loading="loading" v-if="!modalVisible"></loading>
    <!--按钮区-->
    <BaseIndexButtonGroup id="BaseIndexButtonGroup">
      <template #left>
        <!--    查询    -->
        <BaseIndexButton right-button="printLayout-select" ref="search" name="search"></BaseIndexButton>
        <!--    清空条件    -->
        <BaseIndexButton right-button="printLayout-clear" ref="clear" name="clear"></BaseIndexButton>
        <!--    编辑    -->
        <BaseIndexButton right-button="printLayout-edit" ref="edit" name="edit"></BaseIndexButton>
        <!--    模板设置    -->
        <BaseIndexButton ref="layoutSetting" name="layoutSetting" @click="open($config.routeUrl.printLayout.layoutSetting)"/>
        <!--    操作日志    -->
        <BaseIndexButton right-button="role-log" ref="log" name="log"></BaseIndexButton>
      </template>
      <template #right>
        <!--   新建     -->
        <BaseIndexButton right-button="printLayout-add" 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" :set-flag="false"
                    :search-content="searchContent"></SearchCond>
      </div>

      <!-- 列表部分   -->
      <div :style="'height: ' + tableHeight + 'px'" class="split-div-class">
        <DkTable :id="'table-'+$options.name" primary-key="layoutId" ref="table-select" :pageSize="pageInfo.pageSize" :pageSizeOpts="pageSizeOpts" :data="tableData"
                 :height="tableHeight-30"
                 :choose-flag="false" :multiple="false" :pageFlag="true" :page-total="pageInfo.total"
                 :current-page="pageInfo.currentPage" @pageChange="pageSizeChange">
          <DkTableColumn field="layoutName" type="link" @on-link="handleLink(Object.assign($event, { button: 'edit' }))"/>
          <DkTableColumn field="docName"></DkTableColumn>
          <DkTableColumn field="displayNo"></DkTableColumn>
          <DkTableColumn field="flgValid" type="switch" @on-switch-change="onSwitchChange" :switch-disabled="false"/>
          <DkTableColumn field="remarks" width="auto"></DkTableColumn>
        </DkTable>
      </div>

    </div>

    <!--新建编辑-->
    <DkModal :loading="loading" v-model="editAddModal" ref="modal_editAdd" @on-visible-change="handleVisibleModal"
             @modalOk="save" @modalCancel="clear" @on-cancel="clear" :saveFlag="true" :title=modalTitle>
      <DkForm ref="formInline" v-model="formData" :col-count="1">
        <!--    模板名称    -->
        <DkFormItem prop="layoutName" :required="true">
          <InputPop v-model="formData.layoutName" ref="layoutName"/>
        </DkFormItem>
        <!--打印模板分类 -->
        <DkFormItem prop="docName" :required="true">
          <SelectPop v-model="formData.docName" ref="printType" :multiple="false" :disabled="formData?.layoutId!==undefined" :options="doc" labelKey="docName" valueKey="docName">
          </SelectPop>
        </DkFormItem>
        <!--    备注    -->
        <DkFormItem prop="remarks">
          <InputPop v-model="formData.remarks" textareaFlag/>
        </DkFormItem>
      </DkForm>
    </DkModal>

  </div>
</template>

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

export default {
  name: "print-layout",
  mixins: [indexMixin],
  // components: {
  //   Setting
  // },
  data() {
    let self = this
    return {
      editAddModal: false,
      modalTitle: '',//新建编辑弹窗名称
      titleItem: '',
      submitType: '',//新建编辑提交类型
      formData: {
        layoutId: undefined,
        layoutData: {},
        layoutName: '',
        docName: '',
        remarks: ''
      },
      doc: [],
      searchContent: [
        {
          itemCode: 'layoutName',
        },
        self.$config.flgValidSearch,// 有效标识
      ],
      showSetTemplate: false,
    }
  },
  methods:{
    /**
     * @desc   : 停用启用
     * @author : 周兴
     * @date   : 2024/4/23 13:27
     */
    onSwitchChange(param) {
      if (param.flgValid) {
        this.excuteNoParam(this.$service.printLayoutService, this.$service.printLayoutService.enable, [param.layoutId])
      } else {
        this.excuteNoParam(this.$service.printLayoutService, this.$service.printLayoutService.disable, [param.layoutId])
      }
    },
    /**
     * @desc   : 查询数据
     * @author : 周兴
     * @date   : 2024/4/23 13:27
     */
    getData(params) {
      return this.excute(this.$service.printLayoutService, this.$service.printLayoutService.selectByCond, params);
    },
    searchSet() {
      this.showSetTemplate = true
    },
    /**
     * @desc   : 清空
     * @author : 周兴
     * @date   : 2024/4/23 13:27
     */
    clear() {
      this.formData = {
        layoutId:undefined,
        layoutName: '',
        docName: '',
        layoutData: {},
        remarks: ''
      }
    },
    /**
     * @desc   : 保存数据
     * @author : 周兴
     * @date   : 2024/4/23 13:27
     */
    saveData() {
      return this.modalParams.button === this.$config.formMode.add
        ? this.excute(this.$service.printLayoutService, this.$service.printLayoutService.insert, this.params)
        : this.excute(this.$service.printLayoutService, this.$service.printLayoutService.update, this.params)
    },
    /**
     * @desc   : 查询明细
     * @author : 周兴
     * @date   : 2024/4/23 13:27
     */
    detail(id) {
      return this.excuteNoParam(this.$service.printLayoutService, this.$service.printLayoutService.selectById,
        [id], false)
    },
    /**
     * @desc   : 加载初始数据
     * @author : 周兴
     * @date   : 2024/4/23 13:29
     */
    initData(){
      this.getDoc();
    },
    /**
     * @desc   : 查询单据类型
     * @author : 周兴
     * @date   : 2024/4/23 13:29
     */
    getDoc(){
      this.excute(this.$service.commonService, this.$service.commonService.getDoc, {flgPrint:true}).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.doc = res.data
        }
      })
    }
  },
  created() {
    this.primaryKey = 'layoutId'  // 设置主键Id
    this.routeObjName = 'printLayout'  // 设置路由名称
  }
}
</script>

<style scoped>

</style>
