<template>
  <div>
    <!--    <SearchBox ref="SearchBoxRef" formName="selectTop" :formData="query" @showPop="showPop" @reset="reset"></SearchBox>-->
    <el-card :body-style="cardBodyStyle">
      <el-form :model="query" label-width="auto" label-position="right">
        <el-row style="margin-bottom: 5px;" :gutter="5">
          <!-- <el-col :span="5">
            <el-form-item label="库房名称" prop="storeNm" style="margin-bottom: 0px; ">
              <Popup_sto_config_one ref="PopupRefThree3" v-model="query.storeNm" :level1="true"
                @receive-from-child="retuKf"></Popup_sto_config_one>
            </el-form-item>
          </el-col> -->
          <!-- <el-col :span="5">
            <el-form-item label="区号" prop="areaCd" style="margin-bottom: 0px; ">
              <Popup_sto_config_one ref="PopupRefThree3" v-model="query.areaCd" :level2="true"
                @receive-from-child="retuQh"></Popup_sto_config_one>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="垛位" prop="stackCd" style="margin-bottom: 0px; ">
              <Popup_sto_config_one ref="PopupRefThree3" v-model="query.stackCd" :level3="true"
                @receive-from-child="retuDw"></Popup_sto_config_one>
            </el-form-item>
          </el-col> -->
          <el-col :span="5">
            <el-form-item label="物料名称" prop="itemNm" style="margin-bottom: 0px; ">
              <el-input clearable placeholder="请输入" v-model="query.itemNm">
                <!-- <template #append>
                  <el-button :icon="Search" @click="clickWl" />
                </template> -->
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <ButtonBox @search="handleSearch" @add="shengChanRuKu"></ButtonBox>

    <el-card :body-style="cardBodyStyle">
      <el-table :data="tableData" border highlight-current-row @selection-change="handleSelectionChange">
        <el-table-column type="selection" fixed></el-table-column>
        <el-table-column type="index" label="序号" align="center" width="60">
          <template #default="scope">
            <span>{{ scope.$index + (currentPage - 1) * pageSize + 1 }}</span>
          </template>
        </el-table-column>


        <el-table-column v-if="true" prop="itemCd" label="物料编码" width="180" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="itemNm" label="物料名称" width="180" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="qty" label="库存现有量" width="140" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="itemType" label="物料类型" width="140" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="uom" label="计量单位" width="140" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>

        <el-table-column v-if="true" prop="qtyWet" label="湿基量" width="180" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="lastName" label="最后操作人" width="300" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="lastTime" label="最后操作时间" width="360" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="remarks" label="备注" width="120" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="price" label="物料成本" width="240" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="batchNo" label="批次号" width="180" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="false" prop="compCd" label="公司代码" width="160" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="false" prop="deptCd" label="部门代码" width="160" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="storeCd" label="库房代码" width="160" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="storeNm" label="库房名称" width="200" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="areaCd" label="区号" width="120" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="stackCd" label="垛位号" width="160" header-align="center" align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="storeType" label="库房类型" :formatter="formatter" width="140"
          header-align="center" align="center" show-overflow-tooltip>
        </el-table-column>

        <!-- <el-table-column label="操作" header-align="center" align="center" width="180px" fixed="right">
          <template #default="scope">
            <el-button plain type="primary" @click="handleEdit(scope.row)">查看</el-button> -->
        <!--            <el-button plain type="warning" @click="handleEdit(scope.row)">编辑</el-button>-->
        <!--            <el-button plain type="danger" @click="handleDelete(scope.row )">删除</el-button>-->
        <!-- </template>
        </el-table-column> -->
      </el-table>
    </el-card>
    <el-card :body-style="cardBodyStyle">
      <el-pagination :current-page="currentPage" :page-size="pageSize" :page-sizes="pageSizes" :total="totalRows"
        background="background" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange"
        @current-change="handleCurrentChange">
      </el-pagination>
    </el-card>



    <el-card :body-style="cardBodyStyle">
      <el-tabs type="border-card">
        <el-tab-pane label="入库记录">
          <el-row>
            <el-form :inline="true">
              <el-form-item label="物料名称" style="margin-bottom: 5px;" prop="itemNm">
                <el-input v-model="query.itemNm" placeholder="请输入物料名称" clearable style="width: 200px;">
                </el-input>
              </el-form-item>
            </el-form>
            <el-button type="primary" @click="handleSearchLog">查询</el-button>
          </el-row>
          <el-table :data="tableDataLog" border highlight-current-row style="margin-top:10px;">
            <el-table-column type="index" label="序号" align="center" width="60">
              <template #default="scope">
                <span>{{ scope.$index + (currentPageLog - 1) * pageSizeLog + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column v-if="true" prop="addTime" label="操作时间" width="200" header-align="center" align="center"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="addName" label="操作人" width="120" header-align="center" align="center"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="itemCd" label="物料编码" width="120" header-align="center" align="center"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="itemNm" label="物料名称" width="120" header-align="center" align="center"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="qty" label="入库数量" width="120" header-align="center" align="center"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="uom" label="计量单位" width="120" header-align="center" align="center"
              show-overflow-tooltip>
            </el-table-column>

            <el-table-column label="操作" header-align="center" align="center" width="100px" fixed="right">
              <template #default="scope">
                <el-button plain type="danger" @click="handleDeleteLog(scope.row)">撤销</el-button>
              </template>
            </el-table-column>

          </el-table>

          <el-pagination :current-page="currentPageLog" :page-size="pageSizeLog" :page-sizes="pageSizesLog"
            :total="totalRowsLog" background="background" layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChangeLog" @current-change="handleCurrentChangeLog" style="margin-top:10px;">
          </el-pagination>
        </el-tab-pane>
      </el-tabs>
    </el-card>






    <el-dialog class="diaClass" :close-on-click-modal="false" draggable title="查看" v-model="dialogVisible" width="40%"
      top="5vh" @open="openDialog">
      <el-card>
        <el-form :model="form" label-width="120px" label-position="right" inline ref="ruleFormRef" :rules="rules">
          <el-row>
            <el-col :span="12">
              <el-form-item label="公司代码">
                <el-input v-model="form.compCd" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="库房代码">
                <el-input v-model="form.storeCd" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="库房名称">
                <el-input v-model="form.storeNm" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="区号">
                <el-input v-model="form.areaCd" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="垛位号">
                <el-input v-model="form.stackCd" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="库房类型">
                <el-input v-model="form.storeType" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="物料编码">
                <el-input v-model="form.itemCd" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="物料名称">
                <el-input v-model="form.itemNm" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="物料类型">
                <el-input v-model="form.itemType" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="采购订单号">
                <el-input v-model="form.purOrdNo" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="采购订单行号">
                <el-input v-model="form.purOrdLn" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="物料类型">
                <el-input v-model="form.itemType" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计量单位">
                <el-input v-model="form.uom" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="库存现有量">
                <el-input v-model="form.qty" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="湿基量">
                <el-input v-model="form.qtyWet" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注">
                <el-input readonly v-model="form.remarks" :autosize="{ minRows: 2, maxRows: 4 }" type="textarea"
                  placeholder="" />
              </el-form-item>
            </el-col>

          </el-row>
        </el-form>
      </el-card>
      <template #footer>
        <div class="dialog-footer">
          <!--          <el-button type="success" @click="handleSave(ruleFormRef)">保存</el-button>-->
          <el-button type="danger" plain @click="handleCancelSave">取消</el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog :close-on-click-modal="false" draggable title="投料" v-model="ruKuDialogVisible" width="700px" top="5vh"
      @close="ruKuCloseDialog">

      <el-row>
        <el-col :span="20">
          <el-form-item label="库房名称" prop="storeCdMB">
            <!--                  <el-input v-model="form.storeNmMB" placeholder="" disabled> </el-input>-->
            <Popup_sto_config_kf_bx @receive-from-child="returnKf" :storeType="'CP'"></Popup_sto_config_kf_bx>

          </el-form-item>
        </el-col>
        <el-col :span="20">
          <el-form-item label="区号">
            <Popup_sto_config_Qh :kf-id="form.storeIdMB" :area-cd="form.areaCdMB" @receive-from-child="returnQh">
            </Popup_sto_config_Qh>
          </el-form-item>
        </el-col>
        <el-col :span="20">
          <el-form-item label="垛位号">
            <Popup_sto_config_Dw :qh-id="form.areaIdMB" :stack-cd="form.stackCdMB" @receive-from-child="returnDw">
            </Popup_sto_config_Dw>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row gutter="35">
        <el-col :span="10">
          <el-form-item label="物料编码" prop="itemCd">
            <el-input v-model="form.itemCd" readonly disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="物料名称" prop="itemNm">
            <el-input v-model="form.itemNm" readonly disabled>
              <template #append v-if="searchValue">
                <el-button :icon="Search" @click="itemDialog" />
              </template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row gutter="35">
        <el-col :span="10">
          <el-form-item label="生产日期" prop="prodDt">
            <el-date-picker v-model="form.prodDt" type="date" placeholder="请选择生产日期" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-button type="primary" plain @click="chanLiangQuery">产量查询</el-button>
        </el-col>
      </el-row>
      <el-col :span="8">
        <el-form-item label="入库数量" prop="itemNm">
          <el-input v-model="form.qty" style="width: 240px" placeholder="请输入入库数量" />
        </el-form-item>
      </el-col>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="success" @click="ruku">入库</el-button>
          <el-button type="danger" @click="ruKuCloseDialog">取消</el-button>
        </div>
      </template>
    </el-dialog>

    <Popup_base_wl ref="PopupRefTwo" @receive-from-child="retuWl"></Popup_base_wl>
    <Popup_base_wl ref="PopupRef" @receive-from-child="retu"></Popup_base_wl>
  </div>
</template>

<script setup>
import ButtonBar from '@/components/ButtonBar.vue'

import Popup_sto_config_kf_bx from "@/views/sto/components/Popup_sto_config_kf_bx.vue";
import Popup_sto_config_Qh from "@/views/sto/components/Popup_sto_config_Qh.vue";
import Popup_sto_config_Dw from "@/views/sto/components/Popup_sto_config_Dw.vue";
const PopupRef = ref(null)
const returnQh = (val) => {
  form.value.areaIdMB = val.id
  form.value.areaCdMB = val.areaCd
  console.log(val)

}

const returnDw = (val) => {
  form.value.stackIdMB = val.id
  form.value.stackCdMB = val.stackCd
  console.log(val)

}
const itemDialog = () => {
  PopupRef.value.open()
}
import {
  ref,
  reactive,
  onMounted,
  getCurrentInstance
} from 'vue'

const {
  proxy
} = getCurrentInstance()

const returnKf = (val) => {
  form.value.storeIdMB = val.id
  form.value.storeCdMB = val.storeCd
  form.value.storeNmMB = val.storeNm
  form.value.areaCdMB = ''

  console.log(val)

}

import tools from '@/tools'
import SearchBox from "@/components/SearchBox.vue";
import ButtonBox from "@/components/ButtonBox.vue";
import Popup_sto_config_one from "@/views/sto/components/Popup_sto_config_one.vue";
import Popup_base_wl from "@/views/bas/Popup_base_wl.vue";
import {Search} from '@element-plus/icons-vue'

const cardBodyStyle = ref(tools.style.card)
const inputStyle = ref(tools.style.input)

onMounted(() => {
  handleSearch()
  handleSearchLog()
  dictData()
  updateViewportHeight()
})


const chanLiangQuery = () => {
  var url = 'prd/ProduceOut/chanLiangQuery'
  var param = {
    params: JSON.stringify(form.value)
  }
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      form.value.qty = response.data.data
    } else {
      ElMessage.error('操作失败！' + response.data.msg)
    }
  })
}

const ruKuDialogVisible = ref(false)
const ruKuCloseDialog = () => {
  ruKuDialogVisible.value = false
  form.value = {}
}

const searchValue = ref(true)
const shengChanRuKu = () => {
  if (multipleSelection.value.length == 1) {
    console.log(multipleSelection.value[0])
    form.value.itemCd = multipleSelection.value[0].itemCd
    form.value.itemNm = multipleSelection.value[0].itemNm
    searchValue.value = false
  }else{
    searchValue.value = true
  }
  form.value.prodDt = proxy.$dayjs().subtract(1, 'day').format('YYYY-MM-DD')
  ruKuDialogVisible.value = true
}

const retu = (val) => {
  console.log("val", val)
  form.value.itemCd = val.itemCd
  form.value.itemId = val.id
  form.value.itemNm = val.itemNm
  form.value.itemType = val.itemType
  form.value.uom = val.unit

}
const rukuCanShu = ref ({
  compCd:'',
  deptCd:'',
  itemCd:'',
  itemNm:'',
  qty:'',
  storeCd:'',
  storeNm:'',
  areaCd:'',
  stackCd:'',
  transactionId:'',
  transactionTable:'STO_ONHAND',
  transactionDate:'',
  transactionType:'A3'
})
const ruku = () => {
  rukuCanShu.value.compCd = JSON.parse(localStorage.getItem('deptTree'))[0].deptCode
  rukuCanShu.value.deptCd = JSON.parse(localStorage.getItem('dept'))[0].deptCode
  rukuCanShu.value.itemCd = form.value.itemCd
  rukuCanShu.value.itemNm = form.value.itemNm
  rukuCanShu.value.qty = form.value.qty
  rukuCanShu.value.storeCd = form.value.storeCdMB
  rukuCanShu.value.storeNm = form.value.storeNmMB
  rukuCanShu.value.areaCd = form.value.areaCdMB
  rukuCanShu.value.stackCd = form.value.stackCdMB
  rukuCanShu.value.transactionId = form.value.storeIdMB
  rukuCanShu.value.transactionDate = proxy.$dayjs().format('YYYY-MM-DD HH:mm:ss')
  console.log(rukuCanShu.value)
  var url = 'sto/TransRecord/add'
  var param = {
    json: JSON.stringify(rukuCanShu.value),
  }
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == 0) {
      ElMessage({
        message: '入库成功',
        type: 'success',
      })
      ruKuDialogVisible.value = false
      getTableData()
      getTableDataLog()
    } else {
      // ElMessage.error('操作失败！' + response.data.msg)
      ElMessage({
        message: '操作失败' + response.data.msg,
        type: 'error'
      })
    }
  })
}
/**
 *   查询
 */




const query = ref({
  storeNm : '',
  areaCd : '',
  stackCd : '',
  itemNm : '',
  itemType : '',
  storeType : 'CP',
})
const tableData = ref([])
const handleSearch = () => {
  currentPage.value = 1
  getTableData()
}

const getTableData = () => {
  var url = 'sto/Onhand/query'
  var param = {
    page: currentPage.value,
    rows: pageSize.value,
    params: JSON.stringify(query.value)
  }
  // tableData.value = list
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      tableData.value = response.data.data.records
      totalRows.value = response.data.data.total
    } else {
      ElMessage.error('操作失败！' + response.data.msg)
    }
  })
}
/**
 *   查询
 */




 /**
 *   查询
 */
const tableDataLog = ref([])
const handleSearchLog = () => {
  currentPageLog.value = 1
  getTableDataLog()
}

const getTableDataLog = () => {
  var url = 'sto/TransRecord/queryRuKu'
  var param = {
    page: currentPageLog.value,
    rows: pageSizeLog.value,
    params: JSON.stringify(query.value)
  }
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      tableDataLog.value = response.data.data.records
      totalRowsLog.value = response.data.data.total
    } else {
      ElMessage.error('操作失败！' + response.data.msg)
    }
  })
}
/**
 *   查询
 */

/**
 * 分页
 */
const currentPage = ref(1)
const totalRows = ref(0)
const pageSizes = ref([10, 20, 30, 40])
const pageSize = ref(10)
const handleSizeChange = (val) => {
  pageSize.value = val
  getTableData()
}
const handleCurrentChange = (val) => {
  currentPage.value = val
  getTableData()
}
/**
 * 分页
 */

 /**
 * 分页
 */
const currentPageLog = ref(1)
const totalRowsLog = ref(0)
const pageSizesLog = ref([10, 20, 30, 40])
const pageSizeLog = ref(10)
const handleSizeChangeLog = (val) => {
  pageSizeLog.value = val
  getTableDataLog()
}
const handleCurrentChangeLog = (val) => {
  currentPageLog.value = val
  getTableDataLog()
}
/**
 * 分页
 */


/**
 * 新增
 */
const dialogVisible = ref(false)
const form = ref({})
const ruleFormRef = ref()
const rules = reactive({})

const handleAdd = () => {
  form.value = {}
  dialogVisible.value = true
}
/**
 * 新增
 */


/**
 * 保存、修改、删除
 */

const openDialog = () => {
}

const handleSave = (ruleFormRef) => {
  ruleFormRef.validate((valid, fields) => {
    if (valid) {
      var url = 'sto/Onhand/save'
      var param = {
        json: JSON.stringify(form.value),
      }
      proxy.$axios.post(url, param).then(response => {
        if (response.data.code == 0) {
          form.value = response.data.data
          ElMessage({
            message: '保存成功',
            type: 'success',
          })
          getTableData()
          getTableDataLog()
          dialogVisible.value = false
        } else {
          // ElMessage.error('操作失败！' + response.data.msg)
          ElMessage({
            message: '操作失败' + response.data.msg,
            type: 'error'
          })
        }
      })

    } else {
      console.log('error submit!', fields)
    }
  })
}
const handleCancelSave = () => {
  dialogVisible.value = false
}
const handleEdit = (row) => {

  var url = 'sto/Onhand/queryByPK'
  var param = {
    id: row.id,
  }
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == 0) {
      form.value = response.data.data
      dialogVisible.value = true
    } else {
      // ElMessage.error('操作失败！' + response.data.msg)
      ElMessage({
        message: '操作失败' + response.data.msg,
        type: 'error'
      })
    }
  })
}
const handleDelete = (row) => {
  ElMessageBox.confirm(
      '确定删除本条记录?',
      '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
        draggable: true,
      }
  )
      .then(() => {
        var url = 'sto/Onhand/remove'
        var param = {
          id: row.id
        }
        proxy.$axios.post(url, param).then(response => {
          if (response.data.code == 0) {
            ElMessage({
              type: 'success',
              message: '删除成功',
            })
            getTableData()
          } else {
            ElMessage({
              type: 'error',
              message: '删除失败' + response.data.msg
            });
          }
        });
      })
      .catch(() => {
        ElMessage({
          type: 'info',
          message: '已取消',
        })
      })
}


//撤销

const rukutuihui = ref ({
  compCd:'',
  deptCd:'',
  itemCd:'',
  itemNm:'',
  qty:'',
  storeCd:'',
  storeNm:'',
  areaCd:'',
  stackCd:'',
  transactionId:'',
  transactionTable:'STO_ONHAND',
  transactionDate:'',
  transactionType:'A4'
})
const handleDeleteLog = (row) => {
  ElMessageBox.confirm(
      '确定撤销本条记录?',
      '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
        draggable: true,
      }
  )
      .then(() => {
        console.log(row)
        var url = 'sto/TransRecord/remove'
        var param = {
          id: row.id
        }
        proxy.$axios.post(url, param).then(response => {
          if (response.data.code == 0) {

            rukutuihui.value.compCd = JSON.parse(localStorage.getItem('deptTree'))[0].deptCode
            rukutuihui.value.deptCd = JSON.parse(localStorage.getItem('dept'))[0].deptCode
            rukutuihui.value.itemCd = row.itemCd
            rukutuihui.value.itemNm = row.itemNm
            rukutuihui.value.qty = row.qty
            rukutuihui.value.storeCd = 'D0100002'
            rukutuihui.value.storeNm = '成品库'
            rukutuihui.value.areaCd = row.areaCd
            rukutuihui.value.stackCd = row.stackCd
            rukutuihui.value.transactionId = 'a3c0f95b8d0a55088cc237afe42ab573'
            rukutuihui.value.transactionDate = proxy.$dayjs().format('YYYY-MM-DD HH:mm:ss')
            console.log(rukutuihui.value)
            var url = 'sto/TransRecord/add'
            var param = {
              json: JSON.stringify(rukutuihui.value),
            }
            proxy.$axios.post(url, param).then(response => {
              if (response.data.code == 0) {
                ElMessage({
                  type: 'success',
                  message: '撤销成功',
                })
                getTableDataLog()
                getTableData()
              } else {
                // ElMessage.error('操作失败！' + response.data.msg)
                ElMessage({
                  message: '操作失败' + response.data.msg,
                  type: 'error'
                })
              }
            })
          } else {
            ElMessage({
              type: 'error',
              message: '撤销失败' + response.data.msg
            });
          }
        });
      })
      .catch(() => {
        ElMessage({
          type: 'info',
          message: '已取消',
        })
      })
}

/**
 * 保存、修改、删除
 */

const multipleSelection = ref([])
const handleSelectionChange = (val) => {
  multipleSelection.value = val
}

const handleRemoveBatch = () => {
  console.log('handleRemoveBatch')

  if (multipleSelection.value.length < 1) {
    ElMessage({
      type: 'warning',
      message: '请选择要删除的数据!'
    })
    return
  }

  ElMessageBox.confirm('此操作将删除该数据, 是否继续?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    var ids = []
    multipleSelection.value.forEach((item, index) => {
      ids.push(item.id)
    })
    var url = 'sto/Onhand/removeBatch'
    var param = {
      ids: JSON.stringify(ids)
    }
    proxy.$axios.post(url, param).then(response => {
      if (response.data.code == '0') {
        ElMessage({
          type: 'success',
          message: '操作成功!',
        });
        getTableData()
        dialogVisible.value = false
      } else {
        ElMessage({
          type: 'error',
          message: '操作失败!' + response.data.msg
        });
      }
    })
  }).catch(() => {
    ElMessage({
      type: 'info',
      message: '已取消删除'
    })
  })
}

const handleEditBatch = () => {
  console.log('handleEditBatch')
  if (multipleSelection.value.length != 1) {
    ElMessage({
      type: 'warning',
      message: '请选择一条数据编辑!'
    })
    return
  }
  handleEdit(multipleSelection.value[0])
}

const handleUpload = () => {
  console.log('handleUpload')
}

const handleDownload = () => {
  console.log('handleDownload')
}

const handleImport = () => {
  console.log('handleImport')
}

const handleExport = () => {
  console.log('handleExport')
}

const retuKf = (val) => {
  console.log('val', val)
  query.value.storeNm = val
}
const retuQh = (val) => {
  console.log('val', val)
  query.value.areaCd = val
}
const retuDw = (val) => {
  console.log('val', val)
  query.value.stackCd = val
}
const retuWl = (val) => {
  console.log('val', val)
  query.value.itemNm = val.itemNm
}
const PopupRefTwo = ref(null)
const clickWl = () => {
  PopupRefTwo.value.open()
}

const height = ref(600)
const updateViewportHeight = () => {
  height.value = window.innerHeight * 0.65
  console.log( window.innerHeight);
};

const formatter = (row, column, cellValue, index) => {
  if (!cellValue || cellValue == null || cellValue == '') {
    return cellValue
  }
  switch (column.property) {
    case 'storeType':
      cellValue = dictList.value && Array.isArray(dictList.value.STORE_TYPE)
          ? dictList.value.STORE_TYPE.find(item => item.dicCode == cellValue)?.dicName
          : undefined
      break
  }
  return cellValue
}
const dictList = ref({})
const dictData = () => {
  var url = 'framework/Common/querySelectorList'
  var param = {
    type: JSON.stringify(['STORE_TYPE'  ])
  }
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      dictList.value = response.data.data
    } else {
      ElMessage.error('操作失败！' + response.data.msg)
    }
  })
}


</script>

<style scoped>

::v-deep .diaClass .el-form-item {
  width: 100%
}
::v-deep .el-autocomplete{
  width: 100%;
}
::v-deep .el-dialog__body {
  background-color: #F2F6FC;
}
</style>
