<!-- @desc:供应商一览  @auth:宋扬  @time:2024年1月31日11:01:32 -->
<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="changeDisplayNo" name="changeDisplayNo"></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"
                  :search-content="searchContent"></SearchCond>
    </div>

    <!--  表格部分  -->
    <div>
      <DkTable :data="tableData"
               :page-flag="false"
               :page-total-flag="false"
               :height="tableHeight-20"
               primaryKey="supId"
               :pageFlag="true"
               @pageChange="pageSizeChange"
               :page-total="pageInfo.total"
               :current-page="pageInfo.currentPage"
               @current-change="currentChangeEvent($event)"
               ref="table-select" name="table">
        <DkTableColumn field="supCode"></DkTableColumn>
        <DkTableColumn field="supName"></DkTableColumn>
        <DkTableColumn field="contactPhone"></DkTableColumn>
        <DkTableColumn field="contactName"></DkTableColumn>
        <DkTableColumn field="supTypeName"></DkTableColumn>
        <DkTableColumn field="serviceCategoriesName"></DkTableColumn>
        <DkTableColumn field="staffName"></DkTableColumn>
        <DkTableColumn field="orgCode"></DkTableColumn>
        <DkTableColumn field="orgName"></DkTableColumn>
        <DkTableColumn field="flgValid" type="switch" ></DkTableColumn>
        <DkTableColumn field="remarks" width="auto"></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="supCode" :required="true">
          <InputPop v-model="formData.supCode" />
        </DkFormItem>
        <!--  供应商名称  -->
        <DkFormItem prop="supName" :required="true">
          <InputPop v-model="formData.supName" />
        </DkFormItem>
        <!--业务部门-->
<!--        <DkFormItem prop="orgId" :label="$t('orgId')" :required="true">-->
<!--          <SelectMagnifier v-model="formData.orgId" :display-text="formData.staffName"-->
<!--                           :type="this.$config.MagnifierType.staff"-->
<!--                           @ok="orgOk"-->
<!--                           :initSearchFlag="true"-->
<!--                           :multiple="false"/>-->
<!--        </DkFormItem>-->
        <!--业务员-->
        <DkFormItem prop="staffId" :label="$t('staffId')" :required="true">
          <SelectMagnifier v-model="formData.organization" :display-text="formData.staffName"
                           :type="this.$config.MagnifierType.staff"
                           @ok="staffOk"
                           :initSearchFlag="true"
                           :readonly="checkColumnIsEdit('staffId')"
                           :multiple="false"/>
        </DkFormItem>
        <!--业务员-->
        <DkFormItem prop="staffId" :label="$t('staffId')" :required="true">
          <SelectMagnifier v-model="formData.staffId" :display-text="formData.staffName"
                           :type="this.$config.MagnifierType.staff"
                           @ok="staffOk"
                           :initSearchFlag="true"
                           :readonly="checkColumnIsEdit('staffId')"
                           :multiple="false"/>
        </DkFormItem>
        <!--  联系人  -->
        <DkFormItem prop="contactName" >
          <InputPop v-model="formData.contactName" />
        </DkFormItem>
        <!--  联系电话  -->
        <DkFormItem prop="contactPhone" >
          <InputPop v-model="formData.contactPhone" />
        </DkFormItem>
        <!--  供应商类别  -->
        <DkFormItem prop="supType" :required="true">
          <SelectPop v-model="formData.supType" ref="macType" :options="supTypeList" :multiple="false"
                     labelKey="dataValue" valueKey="dataId">
          </SelectPop>
        </DkFormItem>
        <!--  服务类别  -->
        <DkFormItem prop="serviceCategories" :required="true">
          <SelectPop v-model="formData.serviceCategories" ref="macType" :options="serviceCategoriesList" :multiple="false"
                     labelKey="dataValue" valueKey="dataId">
          </SelectPop>
        </DkFormItem>
        <!--   备注     -->
        <DkFormItem prop="remarks">
          <InputPop v-model="formData.remarks" textareaFlag/>
        </DkFormItem>

      </DkForm>
    </DkModal>
  </div>
</template>

<script>
import {indexMixin} from "@/mixins";

export default {
  name: "supplier",
  mixins: [indexMixin],

  data() {
    let self = this
    return {
      orgList:[],
      staffList:[],
      supTypeList:[],
      serviceCategoriesList:[],
      formData: {
        supCode: null,
        supName: null,
        contactPhone: null,
        contactName: null,
        staff:null,
        organization:null,
        supType: null,
        serviceCategories:null,
        remarks: null
      },
      // 查询条件
      searchContent: [
        {
          itemCode: 'supName',
        },
        self.$config.flgValidSearch // 有效标识
      ],
    }
  },
  methods:{
    orgOk(val) {
      if (val && val.length > 0) {
        this.formData.orgId = val[0].orgId
        this.formData.orgCode = val[0].orgCode
        this.formData.orgName = val[0].orgName
      }
    },
    /**
     * @desc   : 加载数据
     * @author : 宋扬
     * @date   : 2024/3/4 11:16
     */
    initData() {
      // 获取供应商类别
      this.getSupType();
      // 获取服务类别
      this.getserviceCategories();
    },

    /**
     * @desc   : 获取供应商类别
     * @author : songy
     * @date   : 2024/3/4 16:33
     */
    getSupType(){
      let params = {
        dictCode: this.$config.kindType.supType,
      }
      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 == 'SupTypeLise')
          if (list.length > 0) {
            list[0].valueFormat.data = res.data
          }
          this.SupTypeLise = res.data;
        }
      })
    },

    /**
     * @desc   : 获取服务类别
     * @author : songy
     * @date   : 2024/3/4 16:33
     */
    getserviceCategories(){
      let params = {
        dictCode: this.$config.kindType.serviceCategories,
      }
      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 == 'serviceCategoriesList')
          if (list.length > 0) {
            list[0].valueFormat.data = res.data
          }
          this.serviceCategoriesList = res.data;
        }
      })
    },

    /**
     * @desc   : 根据ID查询数据
     * @author : 宋扬
     * @date   : 2024/3/4 15:43
     */
    detail(id){
      return this.excuteNoParam(this.$service.suppliersService, this.$service.suppliersService.selectById, [id])
    },

    /**
     * @desc   :分页
     * @author : songy
     * @date   : 2024/3/4 15:43
     */
    pageSizeChange(pageInfo) {
      this.pageInfo = pageInfo
      this.getData() // 查询数据
    },

    /**
     * @desc   : 查询数据
     * @author : songy
     * @date   : 2024/3/4 15:43
     */
    getData(params) {
      return this.excute(this.$service.suppliersService, this.$service.suppliersService.selectByCond, params)
    },
  /**
   * @desc   : 保存数据
   * @author : songy
   * @date   : 2024/3/4 14:47
   */
    saveData(){
      console.log('tt1',this.params,this.modalParams.button)
      if(this.modalParams.button === this.$config.formMode.edit){
        return this.excute(this.$service.suppliersService, this.$service.suppliersService.update, this.params);
      }else{
        return this.excute(this.$service.suppliersService, this.$service.suppliersService.insert, this.params);
      }
    },
  },
  /**
   * @desc   : 切换实际赋值flgValid
   * @author : songy
   * @date   : 2024/3/5 10:19
   */
  currentChangeEvent({row}) {
    if (row != null) {
      this.flgValid = row.flgValid
    }
  },
  /**
   * @desc   : 启用按钮
   * @author : songy
   * @date   : 2024/3/5 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.suppliersService, this.$service.suppliersService.enable, [id], true, this.$t('enable'), true)
          },
        })
    } else {
      this.$Message.warning(this.$t('W_013'))
    }
  },
  /**
   * @desc   : 停用按钮
   * @author : songy
   * @date   : 2024/3/5 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.suppliersService, this.$service.suppliersService.disable, [id], true, this.$t('disable'), true)
          },
        })
    } else {
      this.$Message.warning(this.$t('W_013'))
    }
  },
  created() {
    this.primaryKey = 'supId'  // 设置主键Id
    this.routeObjName = 'suppliers'  // 设置路由名称
  }
}
</script>

<style scoped>

</style>

