<script src="../../api/apis/operationalModule.js"></script>
<template>
  <div class="recordContrast">
    <div class="right">
      <div class="topBox">
        <div class="searchBox">
          公司：
          <el-select
            class="w-100"
            v-model="name"
            filterable
            :clearable="true"
            placeholder="请选择"
            @change="getTableData"
          >
            <el-option
              v-for="(el, index) in nameOptions"
              :key="el.value"
              :label="el.label"
              :value="el.value"
            >
            </el-option>
          </el-select>
        </div>
        <div style="display: flex;align-items: center;justify-content: flex-end;">
          <el-button
            size="small"
            :icon="item.icon"
            @click="clickSave(item)"
            :type="item.type ? item.type : 'primary'"
            v-for="(item, index) in nowBtns"
            :key="index"
          >{{ item.menuName }}
          </el-button>
        </div>
      </div>
      <div class="table">
        <base-table ref="customtable" :showIndex="false" :slotrow="true"
                    tableHeight="calc(100vh - 570px)" :tableData="tableData" :tableColumn="tableColumn"
                    @radioChange="radioChange" id="printMe"
                    :border="true"
        >
          <template #operation="{row}">
            <div style="display: flex;align-content: center;justify-content: center">
              <div style="cursor: pointer;color: #3876ee;margin-right: 10px"
                   @click="comparisonEditHandle(row.row)"
              >
                对照表
              </div>
              <div style="cursor: pointer;color: #3876ee;margin-right: 0px" @click.stop="copyHanlde(row.row)">复制行
              </div>
            </div>
          </template>
        </base-table>
      </div>
      <div class="table2">
        <base-table ref="customtable" :showIndex="true" :slotrow="false"
                    :tableData="masterTableData2" :tableColumn="masterTableColumn2"
                    :sortableSwitch="true"
                    id="printMe"
                    tableHeight="calc(100vh - 570px)"
                    :border="true"
        >
        </base-table>
      </div>
    </div>
    <base-right-dialog
      @handleClose="examineOperateDialog = false"
      @handleConfirmClick="handleConfirmClick"
      :dialogVisible="examineOperateDialog"
      size="900px"
      :appendBody="true"
      :loading="true"
      :footerShow="true"
      :submitShow="true"
      :title="dialogTitle +'会计科目'"
      submitTitle="保存"
    >
      <div class="rightDialogClass_main" style="background-color: #fff;" v-if="examineOperateDialog">
        <base-form
          ref="basicFormRefsName"
          :formRow="basicFormForm"
          :isFunBtn="false"
          :spanWidth="'100px'"
          justifyContent="flex-end"
          :rules="basicFormRulers"
          @onSelect="onSelect"
          :view-status="statusView"
          @elDialogClick="elDialogClick"
        >
        </base-form>

      </div>
    </base-right-dialog>
    <base-dialog
      :dialogVisible.sync="masterDialog"
      :closeModal="false"
      :footerShow="true"
      title="基础档案对照表"
      width="80%"
      top="10vh"
      @handleConfirmClick="masterPickDialog"
    >
      <div class="rightDialogClass_main" style="background-color: #fff;" v-if="masterDialog">
        <div style="display: flex;justify-content: flex-end">
          <el-button size="mini" type="primary" @click="addHandle" style="margin-bottom: 10px">新增</el-button>
        </div>
        <base-table ref="customtable" :showIndex="true" :slotrow="false"
                    :tableData="masterTableData" :tableColumn="masterTableColumn"
                    :sortableSwitch="true"
                    id="printMe"
                    tableHeight="calc(100vh - 570px)"
        >
          <template #factorname1="{row}">
            <div style="background: #fff;cursor: pointer" class="elDialog" @click="elDialogOpen(1,row)">
              <p :style="{ color: row['factorname1'] ? '#000' : '#c0c4cc' }" class="showText">
                {{
                  row['factorname1'] ? row['factorname1'] :
                    '请点击选择'
                }}
              </p>
              <i class="el-icon-more "
                 v-if="!row['factorname1']"
              ></i>
            </div>
          </template>
          <template #factorname2="{row}">
            <div style="background: #fff;cursor: pointer" class="elDialog" @click="elDialogOpen(2,row)">
              <p :style="{ color: row['factorname2'] ? '#000' : '#c0c4cc' }" class="showText">
                {{
                  row['factorname2'] ? row['factorname2'] :
                    '请点击选择'
                }}
              </p>
              <i class="el-icon-more "
                 v-if="!row['factorname2']"
              ></i>
            </div>
          </template>
          <template #factorname3="{row}">
            <div style="background: #fff;cursor: pointer" class="elDialog" @click="elDialogOpen(3,row)">
              <p :style="{ color: row['factorname3'] ? '#000' : '#c0c4cc' }" class="showText">
                {{
                  row['factorname3'] ? row['factorname3'] :
                    '请点击选择'
                }}
              </p>
              <i class="el-icon-more "
                 v-if="!row['factorname3']"
              ></i>
            </div>

          </template>
          <template #factorname4="{row}">
            <div style="background: #fff;cursor: pointer" class="elDialog" @click="elDialogOpen(4,row)">
              <p :style="{ color: row['factorname4'] ? '#000' : '#c0c4cc' }" class="showText">
                {{
                  row['factorname1'] ? row['factorname4'] :
                    '请点击选择'
                }}
              </p>
              <i class="el-icon-more "
                 v-if="!row['factorname4']"
              ></i>
            </div>
          </template>
          <template #factorname5="{row}">
            <div style="background: #fff;cursor: pointer" class="elDialog" @click="elDialogOpen(5,row)">
              <p :style="{ color: row['factorname5'] ? '#000' : '#c0c4cc' }" class="showText">
                {{
                  row['factorname5'] ? row['factorname5'] :
                    '请点击选择'
                }}
              </p>
              <i class="el-icon-more "
                 v-if="!row['factorname5']"
              ></i>
            </div>
          </template>
          <template #factorname6="{row}">
            <div style="background: #fff;cursor: pointer" class="elDialog" @click="elDialogOpen(6,row)">
              <p :style="{ color: row['factorname6'] ? '#000' : '#c0c4cc' }" class="showText">
                {{
                  row['factorname6'] ? row['factorname6'] :
                    '请点击选择'
                }}
              </p>
              <i class="el-icon-more "
                 v-if="!row['factorname6']"
              ></i>
            </div>
          </template>
          <template #factorname7="{row}">
            <div style="background: #fff;cursor: pointer" class="elDialog" @click="elDialogOpen(7,row)">
              <p :style="{ color: row['factorname7'] ? '#000' : '#c0c4cc' }" class="showText">
                {{
                  row['factorname7'] ? row['factorname7'] :
                    '请点击选择'
                }}
              </p>
              <i class="el-icon-more "
                 v-if="!row['factorname7']"
              ></i>
            </div>
          </template>
          <template #factorname8="{row}">
            <div style="background: #fff;cursor: pointer" class="elDialog" @click="elDialogOpen(8,row)">
              <p :style="{ color: row['factorname8'] ? '#000' : '#c0c4cc' }" class="showText">
                {{
                  row['factorname8'] ? row['factorname8'] :
                    '请点击选择'
                }}
              </p>
              <i class="el-icon-more "
                 v-if="!row['factorname8']"
              ></i>
            </div>
          </template>
          <template #factorname9="{row}">
            <div style="background: #fff;cursor: pointer" class="elDialog" @click="elDialogOpen(9,row)">
              <p :style="{ color: row['factorname9'] ? '#000' : '#c0c4cc' }" class="showText">
                {{
                  row['factorname9'] ? row['factorname9'] :
                    '请点击选择'
                }}
              </p>
              <i class="el-icon-more "
                 v-if="!row['factorname9']"
              ></i>
            </div>
          </template>
          <template #desdocvalue="{row}">
            <div style="background: #fff;cursor: pointer" class="elDialog" @click="elDialogOpenTree(9,row)">
              <p :style="{ color: row['desdocvalue'] ? '#000' : '#c0c4cc' }" class="showText">
                {{
                  row['desdocvalue'] ? row['desdocvalue'] :
                    '请点击选择'
                }}
              </p>
              <i class="el-icon-more "
                 v-if="!row['desdocvalue']"
              ></i>
            </div>
          </template>
          <template #operation="{row}">
            <div style="display: flex;align-content: center;justify-content: center">
              <div style="cursor: pointer;color: #3876ee;margin-right: 0px" @click.stop="copymasterHanlde(row)">复制行
              </div>
              <div style="cursor: pointer;color: red;margin-left: 10px"
                   @click.stop="delmasterHandle(row)"
              >
                删除行
              </div>

            </div>
          </template>
        </base-table>
      </div>
    </base-dialog>
    <base-dialog
      :dialogVisible.sync="addDialog"
      :closeModal="false"
      :footerShow="true"
      :title="'选择'+ addTiTle"
      width="80%"
      top="10vh"
      @handleConfirmClick="addPickDialog"
    >
      <div class="rightDialogClass_main" style="background-color: #fff;" v-if="addDialog">
        <baseChoice ref="baseChoice" :tableData="addTableData" :tableColumn="addTableColumn" @onQuery="addonQuery" @getTableList="getAddTableData"
                    :showSearch="true" :placeholder="addTiTle+'搜索'"
        ></baseChoice>
      </div>
    </base-dialog>
    <treePickDialog ref="treePickDialog" :nameClickRow="nameClickRow" @handleNodeClick="handleNodeClick"
    ></treePickDialog>
  </div>
</template>


<script>
import treePickDialog from '@/views/accountingSubject/compoments/treePickDialog.vue'
import basePage from '@/components/base/basePage/index.vue'
import baseChoice from '@/components/base/baseChoice/index.vue'
import baseDialog from '@/components/base/BaseNewDialog/index.vue'
import baseRightDialog from '@/components/base/baseRightDialog'
import baseTable from '@/components/base/baseTable/index.vue'
import baseForm from '@/components/base/baseNewForm'

import {
  businessModuledeleteAPI,
  businessModuleMdmdeleteListAPI,
  businessModuleMdmSaveListAPI,
  businessModuleMdmupdateListAPI,
  businessModulequeryAllAPI,
  businessModuleUpdateAPI,
  queryAllAPI,
  queryByIdAPI,
  queryMdmsByModuleIdAPI
} from '@/api/apis/operationalModule'
import { GetLoginUserButtonsAPI } from '@/api/apis/buttonList'
import {
  queryBdinfoListAPI, queryDataByMapAPI, queryDataPagedByMapAPI,
  queryOrgBookVOAPI, subjectContrastBDelete, subjectContrastdeleteAPI, subjectContrastqueryAll,
  subjectContrastQueryAll,
  subjectContrastSaveAPI, subjectContrastupdateAPI
} from '@/api/apis/accountingSubject'

export default {
  name: 'recordContrast',
  components: { baseDialog, baseChoice, basePage, baseTable, baseRightDialog, baseForm, treePickDialog },
  data() {
    return {
      masterTableData2: [],
      masterTableColumn2: [
        {
          label: '来源组织',
          prop: 'glorgname'
        },
        {
          label: '会计科目',
          prop: 'desdocvalue'
        }
      ],
      nameClickRow: {},
      clickMasterRow: {},
      addTableData: [],
      addTableColumn: [],
      addDialog: false,
      addTiTle: '',
      clickNum: 0,
      clickObj: {},
      clickRow: {},
      nameOptions: [],
      name: '',
      masterTableData: [],
      masterTableColumn: [],
      masterDialog: false,
      basicFormForm: [
        {
          elCol: [
            {
              label: '账簿类型',
              prop: 'accountBookTypeName',
              tag: 'elSelect',
              span: 24,
              placeholder: '点击选择'
            },
            {
              label: '编码',
              prop: 'code',
              tag: 'elInput',
              span: 12
            },
            {
              label: '名称',
              prop: 'name',
              tag: 'elInput',
              span: 12
            },
            {
              label: '来源档案',
              prop: 'sourceIdsArr',
              tag: 'elMultiple',
              span: 24,
              options: [],
              limit: 9
            },
            {
              label: '目标档案',
              prop: 'desdocName',
              tag: 'elInput',
              span: 24,
              disabled: true,
              options: []
            }
          ]
        }
      ],
      basicFormRulers: {
        accountBookTypeId: [
          { required: true, message: '请选择账簿类型', trigger: 'change' }
        ],
        code: [
          { required: true, message: '请输入编码', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ]
      },
      nowBtns: [],
      billTypeName: '',
      billTypeClickID: '',
      billTypeClickName: '',
      billTypeList: [
        {
          name: '人员对照',
          id: 1
        },
        {
          name: '人员对照',
          id: 2
        },
        {
          name: '人员对照',
          id: 3
        },
        {
          name: '人员对照',
          id: 4
        }
      ],
      searchObj: {},
      pageModel: {
        page: 1, //当前页码
        limit: 10 //每页显示多少
      },
      selected: [],

      tableColumn: [
        {
          label: '账簿类型',
          prop: 'accountBookTypeName'
        },
        {
          label: '编码',
          prop: 'code'
        },
        {
          label: '名称',
          prop: 'name'
        },
        {
          label: '来源档案',
          prop: 'sourceNames'
        },
        {
          label: '目标档案类型',
          prop: 'desdocName'
        },
        {
          label: '操作',
          prop: 'operation'
        }
      ],
      tableData: [],
      dialogTitle: '新增',
      examineOperateDialog: false,
      statusView: false,
      passwordDialogShow: false,
      passwordDialogTitle: '新增',
      billTypeADDName: '',
      billTypeADDID: '',
			bdInfoRow:{}
    }
  },
  methods: {
    async getTableAddList(val){
			let params = {
				tablename:this.bdInfoRow.tablename,
				prop7:this.bdInfoRow.codefieldname,
				propValue7:val,
				prop8:this.bdInfoRow.namefieldname,
				propValue8:val,
			}
			let res = await queryDataByMapAPI(params)
			this.addTableData = []
			this.addTableData = res.attribute.list
			
    },
    handleNodeClick(node) {
      console.log(node, '?')
      this.$set(this.clickRow, `pkAccsubj`, node[0].pkAccsubj)
      this.$set(this.clickRow, `desdocvalue`, node[0].dispname)
    },
    elDialogOpenTree(num, row) {
      this.clickNum = num
      this.clickObj = this.masterTableColumn[num - 1]
      this.clickRow = row
      this.$refs.treePickDialog.openDialog()
    },
    delmasterHandle(row) {
      this.$confirm('确认删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        const res = await subjectContrastBDelete({
          id: row.id
        })
        this.$vmNews('删除成功', 'success')
        this.masterTableData.splice(row.index, 1)
        this.getTableData()
      })
    },
    copymasterHanlde(row) {
      this.masterTableData.push(JSON.parse(JSON.stringify(row)))
    },
    addonQuery(res, pageModel) {
      this.pageModel = pageModel
      this.getAddTableData()
    },
    addPickDialog() {
      if (!this.$refs.baseChoice.optionData[this.clickObj.key]) {
        this.$vmNews('请选择一条数据')
        return
      }
      this.$set(this.clickRow, `factorid${this.clickNum}`, this.$refs.baseChoice.optionData[this.clickObj.key])
      this.$set(this.clickRow, `factorname${this.clickNum}`, this.$refs.baseChoice.optionData[this.clickObj.labelKey])
      this.$set(this.clickRow, `factorpk${this.clickNum}`, this.$refs.baseChoice.optionData['id'])
      console.log(this.clickRow, 'this.clickRow')
      this.addDialog = false
    },
    elDialogOpen(num, row) {
      this.clickNum = num
      this.clickObj = this.masterTableColumn[num]
      this.clickRow = row
      this.pageModel.page = 1
      this.pageModel.limit = 10
      this.addTiTle = this.clickObj.label
      this.addTableData = []
      this.addTableColumn = [
        {
          label: '名称',
          prop: this.clickObj.labelKey
        },
        {
          label: '编码',
          prop: this.clickObj.key
        }

      ]
      this.addDialog = true
      this.getAddTableData()
    },
    async getAddTableData(val = false) {
		let params = {
			pageNum: this.pageModel.page,
			pageSize: this.pageModel.limit,
			tablename: this.clickObj.factortable,
			pkentityorg: this.nameClickRow.pkentityorg,
		}
		if(val){
			this.pageModel.page = 1
				  				params.tablename=this.bdInfoRow.tablename
				  				params.prop7=this.bdInfoRow.codefieldname
				  				params.propValue7=val
				  				params.prop8=this.bdInfoRow.namefieldname
				  				params.propValue8=val
		}
      const res = await queryDataPagedByMapAPI(params)

      console.log(res, 'res??')
      this.$refs.baseChoice.pageModel.total = res.attribute.total
      this.addTableData = res.attribute.list
    },
    addHandle() {
      let obj = {
        glorgname: this.nameClickRow.glorgname,
        pkentityorg: this.nameClickRow.pkentityorg
      }
      this.masterTableColumn.forEach((item, index) => {
        let num = index
        obj['factortable' + num] = item.factortable
        obj['factorpk' + num] = item.factorpk
        obj['factorid' + num] = ''
        obj['factorname' + num] = ''

      })
      this.masterTableData.push(obj)
    },
    async comparisonEditHandle(row) {
      this.masterTableColumn = [
        {
          label: '来源组织',
          prop: 'glorgname'
        }
      ]
      for (let i = 0; i < row.sourceIds.split(',').length; i++) {
        let item = row.sourceNames.split(',')[i]
        let id = row.sourceIds.split(',')[i]
        let num = i + 1
        this.openLoading()
        const res = await queryBdinfoListAPI({
          pkBdinfo: id
        })
				this.bdInfoRow = res.attribute[0]
        //转大写
        //value  编码
        let key = res.attribute[0].codefieldname
        //label 名称
        let labelKey = res.attribute[0].namefieldname
        let obj = {
          label: item,
          prop: 'factorname' + num,
          tag: 'elSelect',
          options: [],
          factortable: res.attribute[0].tablename,
          factorpk: res.attribute[0].tablepkname,
          key: key,
          labelKey: labelKey
        }
        this.masterTableData = JSON.parse(JSON.stringify(row.contrastBEntityList))
        this.masterTableColumn.push(obj)

      }
      this.clickMasterRow = row
      this.masterDialog = true
      this.masterTableColumn.push(
        {
          label: '会计科目',
          prop: 'desdocvalue'
        }
      )
      this.masterTableColumn.push(
        {
          label: '操作',
          prop: 'operation'
        }
      )
    },
    copyHanlde(row) {
      this.dialogTitle = '复制'
      this.examineOperateDialog = true
      this.$nextTick(() => {
        this.$refs.basicFormRefsName.ruleForm = {
          ...row,
          sourceIdsArr: row.sourceIds.split(',')
        }
      })
    },
    async getNameOptions() {
      const res = await queryOrgBookVOAPI({})
      res.attribute.forEach(el => {
        el.label = el.glorgname
        el.value = el.pkentityorg
      })
      this.nameOptions = res.attribute
      const res2 = await queryBdinfoListAPI({})
      console.log(res2, '2')
      res2.attribute.forEach(el => {
        el.label = el.bdname
        el.value = el.pkBdinfo
      })
      this.basicFormForm[0].elCol[3].options = res2.attribute
    },
    async masterPickDialog() {
      const res = await subjectContrastupdateAPI(
        {
          ...this.clickMasterRow,
          contrastBEntityList: this.masterTableData
        }
      )
      this.$vmNews('保存成功', 'success')
      this.masterDialog = false
      this.getTableData()
    },
    async elDialogClick(row, index) {
      this.masterDialog = true
      const res = await businessModulequeryAllAPI({})
      this.masterTableData = res.attribute
    },
    delRightTitle(item) {
      this.$confirm('确认删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        const res = await subjectContrastdeleteAPI({
          id: item.id
        })
        if (res.status == 200) {
          this.$vmNews('删除成功', 'success')
          this.billTypeClickName = ''
          this.billTypeClickID = ''
          this.getLeftList()
          this.resetTable()
        }
      })
    },
    editRightTitle(item) {
      this.billTypeADDName = item.name
      this.billTypeADDID = item.id
      this.passwordDialogTitle = '编辑'
      this.passwordDialogShow = true
    },
    rightAddHandle() {
      this.passwordDialogShow = true
      this.passwordDialogTitle = '新增'
      this.billTypeADDName = ''
      this.billTypeADDID = ''
    },
    async passwordChangeHandle() {
      if (!this.billTypeADDName) {
        this.$vmNews('请输入单据类型名称')
        return
      }
      let params = {
        'moduleName': this.billTypeADDName
      }
      if (this.passwordDialogTitle === '编辑') {
        params.id = this.billTypeADDID
        const res = await subjectContrastupdateAPI(params)
        if (res.status == 200) {
          this.$vmNews('保存成功', 'success')
          this.passwordDialogShow = false
          this.getLeftList()
        }
        return
      }
      const res = await queryByIdAPI(params)
      if (res.status == 200) {
        this.$vmNews('保存成功', 'success')
        this.passwordDialogShow = false
        this.getLeftList()
      }
    },
    async getSelect() {
      const res = await GetBillListAPI({
        page: 1,
        limit: 9999
      })
      res.data[1].forEach(item => {
        item.label = item.appName
        item.value = item.appID
      })
      this.basicFormForm[0].elCol[2].options = res.data[1]
      this.basicFormForm[0].elCol[6].options = res.data[1]
    },
    async getLeftList() {
      this.openLoading()
      const res = await queryAllAPI({})
      res.attribute.forEach((el) => {
        el.name = el.moduleName
        el.id = el.id
      })
      this.billTypeList = res.attribute
    },
    onSelect(val, index, indexRow, obj, options, form, row) {
      if (row.prop === 'accountBookTypeName') {
        this.$set(this.$refs.basicFormRefsName.ruleForm, 'accountBookTypeCode', obj.accountBookTypeCode)
        this.$set(this.$refs.basicFormRefsName.ruleForm, 'accountBookTypeName', obj.accountBookTypeName)
        this.$set(this.$refs.basicFormRefsName.ruleForm, 'accountBookTypeId', obj.accountBookTypeId)

      }
      if (row.prop === 'sourceIdsArr') {
        let sourceIds = []
        let sourceNames = []
        val.forEach(item=>{
          options.forEach(el => {
            if (item === el.value) {
              sourceIds.push(el.value)
              sourceNames.push(el.label)
            }

          })

        })
        this.$set(this.$refs.basicFormRefsName.ruleForm, 'sourceIds', sourceIds.join(','))
        this.$set(this.$refs.basicFormRefsName.ruleForm, 'sourceNames', sourceNames.join(','))
      }
    },
    async handleConfirmClick() {
      await this.$refs.basicFormRefsName.$refs.ruleForm.validate()
      let form = this.$refs.basicFormRefsName.ruleForm
      if (this.dialogTitle === '编辑') {
        this.openLoading()
        const res = await subjectContrastupdateAPI(
          {
            ...this.$refs.basicFormRefsName.ruleForm
          }
        )
        if (res.status == 200) {
          this.$vmNews('保存成功', 'success')
          this.examineOperateDialog = false
          this.resetTable()
        }
      } else {
        this.openLoading()
        const res = await subjectContrastSaveAPI(
          {
            desdocId: '',
            desdocCode: '',
            desdocName: '',
            contrastBEntityList: [],
            ...this.$refs.basicFormRefsName.ruleForm

          }
        )
        if (res.status == 200) {
          this.$vmNews('保存成功', 'success')
          this.examineOperateDialog = false
          this.resetTable()
        }
      }

    },
    pageChange(model) {
      this.pageModel.page = model.page
      this.pageModel.limit = model.limit
      this.getTableData()
    },
    async getTableData() {
      const res = await subjectContrastqueryAll({
        ...this.searchObj,
        pkCorp: this.name
      })
      this.tableData = res.attribute
      this.$nextTick(() => {
        this.$refs.customtable.clearRadioIndex()
        this.selected = []
        this.clickMasterRow = {}
      })
      this.nameClickRow = this.nameOptions.find(el => el.value == this.name)
      console.log(this.nameClickRow, 'nameClickRow', this.nameOptions)
    },
    resetTable() {
      this.tableData = []
      this.pageModel.page = 1
      this.selected = []
      this.getTableData()
    },
    // 点击某条数据
    async radioChange(row) {
      console.log(123, '123123')
      this.selected = []
      this.selected.push(row)
      this.masterTableData2 = row.contrastBEntityList
      let arr = [
        {
          label: '来源组织',
          prop: 'glorgname'
        }
      ]

      console.log(row.sourceIds)
      for (let i = 0; i < row.sourceIds.split(',').length; i++) {
        let item = row.sourceNames.split(',')[i]
        let id = row.sourceIds.split(',')[i]
        let num = i + 1
        this.openLoading()
        const res = await queryBdinfoListAPI({
          pkBdinfo: id
        })
        //转大写
        let key = res.attribute[0].codefieldname
        let labelKey = res.attribute[0].namefieldname
        let obj = {
          label: item,
          prop: 'factorname' + num,
          tag: 'elSelect',
          options: [],
          factortable: res.attribute[0].tablename,
          factorpk: res.attribute[0].tablepkname,
          key: key,
          labelKey: labelKey
        }
        arr.push(obj)

      }
      arr.push(
        {
          label: '会计科目',
          prop: 'desdocvalue'
        }
      )
      this.masterTableColumn2 = arr
    },
    // 删除
    delOperate() {
      if (!this.selected.length) {
        this.$vmNews('请至少选择一条数据')
        return
      }
      this.$confirm('确认删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        const res = await subjectContrastdeleteAPI({
          id: this.selected[0].id
        })
        if (res.status == 200) {
          this.$vmNews('删除成功', 'success')
          this.resetTable()
        }
      })
    },
    // 编辑
    editOperate() {
      if (!this.selected.length) {
        this.$vmNews('请至少选择一条数据')
        return
      }
      this.dialogTitle = '编辑'
      this.examineOperateDialog = true
      this.$nextTick(() => {
        this.$refs.basicFormRefsName.ruleForm = {
          ...this.selected[0],
          sourceIdsArr: this.selected[0].sourceIds.split(',')
        }
      })
    },
    //新增
    async Operate() {
      if (!this.name) {
        this.$vmNews('请选择公司')
        return
      }
      const res = await queryOrgBookVOAPI({
        pkentityorg: this.name
      })
      console.log(res, 'res?')
      res.attribute.forEach(el => {
        el.label = el.glbookname
        el.value = el.glbookname
        el.accountBookTypeCode = el.glbookcode
        el.accountBookTypeId = el.pkglbook
        el.accountBookTypeName = el.glbookname
      })
      this.basicFormForm[0].elCol[0].options = res.attribute
      this.dialogTitle = '新增'
      this.examineOperateDialog = true
      this.$nextTick(() => {
        this.$set(this.$refs.basicFormRefsName.ruleForm, 'pkCorp', res.attribute[0].pkentityorg)
        this.$set(this.$refs.basicFormRefsName.ruleForm, 'desdocName', '会计科目')
      })
    },
    refresh() {
      this.searchObj = {}
    },
    //获取按钮（头部）
    async buttonPermissions() {
      let arr = [
        {
          'id': '297c66371d484f5ea163c70b1c3944a7',
          'create_user_id': '1',
          'create_time': '2025-05-30 11:28:56',
          'modify_time': '2025-05-30 11:28:56',
          'modify_user_id': '1',
          'org_id': '0',
          'companyId': '0',
          'sts': 'Y',
          'start': null,
          'limit': null,
          'offset': null,
          'sort': null,
          'order': null,
          'dir': null,
          'rows': null,
          'page': null,
          'dialect_type': null,
          'pageNum': null,
          'pageSize': null,
          'sorts': 1,
          'dataSourceCode': 'master',
          'code': '1',
          'nameCh': '新增',
          'nameEn': 'Operate',
          'menuId': '936df6d1cd7e4f9ba4c972e0f84b5ab4',
          'iconName': 'el-icon-plus',
          'styles': 'primary',
          'btnFunction': 'Operate',
          'remark': null,
          'userId': null,
          'check': false
        },
        {
          'id': 'ad708a5f65fb42d49e203a230096f43e',
          'create_user_id': '1',
          'create_time': '2025-05-30 11:29:22',
          'modify_time': '2025-05-30 11:29:22',
          'modify_user_id': '1',
          'org_id': '0',
          'companyId': '0',
          'sts': 'Y',
          'start': null,
          'limit': null,
          'offset': null,
          'sort': null,
          'order': null,
          'dir': null,
          'rows': null,
          'page': null,
          'dialect_type': null,
          'pageNum': null,
          'pageSize': null,
          'sorts': 2,
          'dataSourceCode': 'master',
          'code': '2',
          'nameCh': '编辑',
          'nameEn': 'editOperate',
          'menuId': '936df6d1cd7e4f9ba4c972e0f84b5ab4',
          'iconName': 'el-icon-edit',
          'styles': 'primary',
          'btnFunction': 'editOperate',
          'remark': null,
          'userId': null,
          'check': false
        },
        {
          'id': 'cca6382b141e4816833581db63c768da',
          'create_user_id': '1',
          'create_time': '2025-05-30 11:29:39',
          'modify_time': '2025-05-30 11:29:39',
          'modify_user_id': '1',
          'org_id': '0',
          'companyId': '0',
          'sts': 'Y',
          'start': null,
          'limit': null,
          'offset': null,
          'sort': null,
          'order': null,
          'dir': null,
          'rows': null,
          'page': null,
          'dialect_type': null,
          'pageNum': null,
          'pageSize': null,
          'sorts': 3,
          'dataSourceCode': 'master',
          'code': '3',
          'nameCh': '删除',
          'nameEn': 'delOperate',
          'menuId': '936df6d1cd7e4f9ba4c972e0f84b5ab4',
          'iconName': 'el-icon-delete',
          'styles': 'danger',
          'btnFunction': 'delOperate',
          'remark': null,
          'userId': null,
          'check': false
        }
      ]
      arr.forEach((el) => {
        el.menuName = el.nameCh
        el.icon = el.icoName
        el.type = el.style
        el.name = el.nameCN
      })
      this.nowBtns = arr
    },
    billTypeClickHandle(id, name) {
      this.billTypeClickID = id
      this.billTypeClickName = name
      this.resetTable()
    },
    //头部按钮统一调用方法
    clickSave(item) {
      this[item.btnFunction]()
    }
  },
  mounted() {
    this.buttonPermissions()
    this.getLeftList()
    this.getNameOptions()
    // this.getTableData()
    // this.getSelect()
  }
}
</script>


<style scoped lang="scss">
.addDialog {
  display: flex;
  align-items: center;

  .nameTitle {
    padding: 10px;
    font-size: 14px;
    color: #333;
    margin-right: 10px;
    width: 180px;
    text-align: right;
  }
}

.recordContrast {
  display: flex;
  overflow: hidden;
  background-color: #f5f5f5;

  .left {
    width: 270px;
    padding: 10px;
    background-color: #fff;
    border-radius: 4px;
    margin-right: 5px;

    .leftTitle {
      color: #333;
      font-size: 18px;
      font-weight: 500;
    }
  }

  .right {
    flex: 1;
    padding: 10px;
    background-color: #fff;
    border-radius: 4px;

    .topBox {
      display: flex;
      align-items: center;
      justify-content: space-between;

      .searchBox {
        display: flex;
        align-items: center;

        > div {
          margin-right: 10px;
        }
      }
    }

    .table {
      margin-top: 10px;
    }
  }
}

.searchBtn {
  display: flex;
  align-items: center;
  justify-content: space-around;
  margin-top: 20px;

  .input {
    flex: 1;
    margin-right: 5px;
  }
}

.showList {
  height: calc(100vh - 200px);
  overflow: auto;
  margin-top: 10px;

  .showItem {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    cursor: pointer;

    .icon {
      display: none;
    }

    &:hover {
      background-color: #ebeced;
      border-radius: 4px;

      .icon {
        display: block !important;
      }
    }

    &.active {
      background-color: #ebeced !important;
    }
  }
}

.elDialog {
  display: flex;
  width: 100%;
  /* width: calc(100% - 14px);1 */
  align-items: center;
  justify-content: space-between;
  border: 1px solid #DCDFE6;
  border-radius: 4px;
  padding: 5px 15px;
  cursor: pointer;


  i {
    color: #c0c4cc
  }
}

.showText {
  /* width: 100%; */
  /* width: calc(100% - 110px); */
  /*让长段文本不换行*/
  white-space: nowrap;
  /*设置文本超出元素宽度部分隐藏*/
  overflow-x: hidden;
  /*设置文本超出部分用省略号显示*/
  text-overflow: ellipsis;

}
</style>
