<template>
<el-card class="hl-card">
  <template #header>
    <span>库存单价管理</span>
  </template>
    <ContentWrap class="borderxx">
    <!-- 搜索工作栏 -->
    <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true" label-width="108px">
      <el-form-item label="物料编码" prop="matCode">
        <el-input v-model="queryParams.matCode" placeholder="物料编码" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="物料名称" prop="matName">
        <el-input v-model="queryParams.matName" placeholder="物料名称" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="物料类型" prop="matType">
        <el-select v-model="queryParams.matType" placeholder="下拉选择" clearable class="!w-240px">
          <el-option v-for="dict in getIntDictOptions(DICT_TYPE.HELI_MATERIAL_TYPE)" :key="dict.label" :label="dict.label"
            :value="dict.label" />
        </el-select>
      </el-form-item>

      <el-form-item style="margin-left:15px">
        <el-button @click="handleQuery" type="primary">
          <Icon icon="ep:search" class="mr-5px" /> 搜索
        </el-button>
        <el-button @click="resetQuery">
          <Icon icon="ep:refresh" class="mr-5px" /> 重置
        </el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" class="hl-table">
        <el-table-column type="index" width="100" fixed label="序号" align="center" />
      <el-table-column label="物料名称" align="center" prop="matName" fixed min-width="120"/>
      <el-table-column label="物料编码" align="center" prop="matCode" fixed min-width="120" />
      <el-table-column label="物料类型" align="center" prop="matType" min-width="120"/>
      <el-table-column label="库存数量" align="center" prop="storageOkQtys" min-width="120"/>
      <el-table-column label="库存单位" align="center" prop="matUnit" min-width="120"/>
	    <el-table-column label="库存金额(元)" align="center" prop="price" min-width="120">
        <template #default="scope">
        <el-input-number v-model="scope.row.price" type="number" :precision="2"  />


        </template>
    </el-table-column>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button
            type="primary"
            link
            @click="updatePrice(scope.row)"
          >
            修改金额
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination :total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
      @pagination="getList" />
  </ContentWrap>
</el-card>
</template>

<script setup lang="ts">
import download from '@/utils/download'
import * as StorageLogApi from '@/api/heli/storagelog'

import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'

import * as WarehouseApi from '@/api/heli/warehouse'
import * as RgApi from '@/api/heli/rg'
import * as PnApi from '@/api/heli/pn'
import {getStorageNowPage, getStorageNowPricePage} from "@/api/heli/storagelog";
import * as ModelApi from "@/api/bpm/model";
defineOptions({ name: 'StorageLog' })

const whList = ref([])

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  matCode: undefined,
  matName: undefined,
  matType: undefined,
  lotNo: undefined,
  whId: undefined,
  rgId:undefined,
  pnId: undefined,
  headerNo: undefined,
})
const queryFormRef = ref() // 搜索的表单
const emit = defineEmits(['success'])
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await StorageLogApi.getStorageNowPricePage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}
const updatePrice = async (row) => {
  try {
    await message.confirm("是否修改当前物料"+row.matName+"库存金额？")
    await StorageLogApi.updatePrice(row);
    message.success(t('修改成功'))
    await getList()
  }catch {}
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}


/** 初始化 **/
onMounted(async () => {
    await getList()
})
</script>
