Update a single/multiple Row(s) | 更新单/多行

本文介绍了如何在SQL中更新数据库行,包括单行更新、使用DEFAULT值、计算更新、ROUND函数处理精度问题,以及多行更新和基于特定条件的客户积分调整。

Update a single row

更新表中的某一行

案例一

这里以更新发票表为例
这里我们更新invoice表中id为1的行

代码
UPDATE invoices 
SET payment_total =10, payment_date = '2019-03-01'
WHERE invoice_id = 1
更新前:

在这里插入图片描述

更新后:

在这里插入图片描述

案例二

现在再把数据更新回去

UPDATE invoices
SET payment_total = 0, payment_date = NULL
WHERE invoice_id = 1-- 通过这个条件来识别记录或需要被更新的记录

注意
SET语句中在设置的时候可以是多样的
1- 使用DEFAULT

SET payment_total = DEFAULT


2- 计算

SET 
    payment_total = invoice_total * 0.5,
    payment_date = due_date

换invoice=3 的进行更新,使得payment_total = invoice_total*0.5 .  payment_date = due_date

UPDATE invoices
SET 
	payment_total = invoice_total * 0.5,
	payment_date = due_date
WHERE invoice_id = 3

这里产生了报错 ,报错原因如下。 payment_total = invoice_total*0.5 ,invoice 为147.99,它*0.5后又三位小数,而这里只能接受2位小数。

更改错误,使用ROUND函数

UPDATE invoices 
SET payment_total = ROUND(invoice_total * 0.5,2), payment_date = due_date
WHERE invoice_id = 3

Update multiple rows

写一段语句来更新同一客户下的多个发票
例如这样的顾客
在这里插入图片描述
 

UPDATE invoices
SET 
	payment_total = invoice_total * 0.5,
	payment_date = due_date
WHERE client_id = 3 

此外代码中的where条件句在这里可以有多种表示

-- 首先where可以在这里有其它样式,例如:
-- WHERE client_id in (3,4)
-- 其次Where在这里是可选的
-- 因此当你想在一张表中更新所有数据,可以忽略where

练习

-- Write a SQL statement to
-- 		give any customers born before 1990
-- 		50 extra points	

写一段查询获取所有在1990年以前出生的客户增加50点积分

UPDATE customers 
SET 
	points = points + 50
WHERE birth_date < '1990-01-01'

<template> <div> <div v-if="hasData"> <div> <a-card :bordered="false" style="margin-bottom: 10px;"> <!-- 条件搜索 --> <div class="table-page-search-wrapper"> <!-- <a-form :labelCol="labelCol" :wrapperCol="wrapperCol" ref="queryForm">--> <!-- <a-row :gutter="32">--> <!-- <a-col :span="6" >--> <!-- <a-form-item label="物品名称">--> <!-- <a-input v-model="queryParam.itemName" placeholder="请输入物品名称" allow-clear @keyup.enter.native="handleQuery"/>--> <!-- </a-form-item>--> <!-- </a-col>--> <!-- <a-col :span="6" >--> <!-- <a-form-item label="规格型号">--> <!-- <a-input v-model="queryParam.description" placeholder="请输入规格型号" allow-clear @keyup.enter.native="handleQuery"/>--> <!-- </a-form-item>--> <!-- </a-col>--> <!-- <a-col :span="6" >--> <!-- <a-form-item label="当前库存数量">--> <!-- <a-input-number v-model="queryParam.quantity" :min="0" style="width: 100%"/>--> <!-- </a-form-item>--> <!-- </a-col>--> <!-- <a-col :span="6" v-if="advanced">--> <!-- <a-form-item label="物品入库日期">--> <!-- <a-date-picker--> <!-- v-model="queryParam.beginIndate"--> <!-- valueFormat="YYYY-MM-DD"--> <!-- :show-today="true"--> <!-- placeholder="选择日期"--> <!-- style="width: 100%"--> <!-- />--> <!-- </a-form-item>--> <!-- </a-col>--> <!-- <a-col>--> <!-- <span class="table-page-search-submitButtons" style="float: right;">--> <!-- <a-button type="primary" @click="handleQuery"><a-icon type="search" />查询</a-button>--> <!-- <a-button style="margin-left: 8px" @click="resetQuery"><a-icon type="redo" />重置</a-button>--> <!-- <a @click="toggleAdvanced" style="margin-left: 8px">--> <!-- {{ advanced ? '收起' : '展开' }}--> <!-- <a-icon :type="advanced ? 'up' : 'down'"/>--> <!-- </a>--> <!-- </span>--> <!-- </a-col>--> <!-- </a-row>--> <!-- </a-form>--> </div> </a-card> <a-card :bordered="false" > <!-- 增加 --> <bt-inventory-add-form v-if="showAddModal" ref="btInventoryAddForm" :contractId="contractId" @ok="getList" @close="showAddModal = false" /> <!-- 编辑 --> <bt-inventory-edit-form v-if="showEditModal" ref="btInventoryEditForm" :contractId="contractId" @ok="getList" @close="showEditModal = false" /> <div class="table-operations"> <!-- <a-button type="primary" @click="handleAdd" v-hasPermi="['bt:btMaterials:add']">--> <!-- <a-icon type="plus" />新增--> <!-- </a-button>--> <!-- <a-button type="danger" v-if="!multiple" :disabled="multiple" @click="handleDelete" v-hasPermi="['bt:btMaterials:remove']">--> <!-- <a-icon type="delete" />删除--> <!-- </a-button>--> <!-- <a-button type="" @click="handleExport" v-hasPermi="['bt:btMaterials:export']">--> <!-- <a-icon type="download" />导出--> <!-- </a-button>--> <a-tooltip title="刷新"> <a-icon @click="getList" class="action" :type="loading ? 'loading' : 'reload'" /> </a-tooltip> </div> <a-table :loading="loading" rowKey="id" size="middle" @change="handleTableChange" @refresh="getList" :columns="columns" :data-source="btInventoryList" :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" :pagination="false" > <!-- <span slot="operation" slot-scope="text, record"> --> <!-- <a @click="handleUpdate(record)" v-hasPermi="['bt:btMaterials:edit']"> 修改 </a> --> <!-- <a-divider type="vertical" v-hasPermi="['bt:btMaterials:remove']"/> <a @click="handleDelete(record)" v-hasPermi="['bt:btMaterials:remove']"> 删除 </a> --> <!-- </span> --> </a-table> </a-card> </div> </div> <div v-else> <h1 style="text-align: center; font-weight: bold; color: blue;">暂无相关库存数据 <a-tag v-if="isOutbound" color="green" style="margin-left:8px;">已出库</a-tag> </h1> </div> </div> </template> <script> import { listBtInventory, delBtInventory, exportBtInventory } from '@/api/tt/Inventory' import AdvanceTable from '@/components/pt/table/AdvanceTable' import BtInventoryAddForm from '@/views/bt/btoutbound/modules/BtInventoryAddForm' import BtInventoryEditForm from '@/views/bt/btoutbound/modules/BtInventoryEditForm' export default { name: 'BtInventory', props: { isOutbound: { type: Boolean, default: false, // 默认不显示“已出库” }, contractId: { type: String, required: true }, title: { type: String, default: '子表' } },watch: { hasData: { immediate: true, handler(newVal) { if (!newVal && !this.isOutbound) { this.$emit('outbound-status', true); this.isOutbound = true; } } } }, components: { AdvanceTable, BtInventoryAddForm, BtInventoryEditForm }, data () { return { hasData:false, showAddModal: false, showEditModal: false, // 遮罩层 loading: true, // 选中数组 ids: [], // 选中的主键集合 selectedRowKeys: [], // 选中的数据集合 selectedRows: [], // 高级搜索 展开/关闭 advanced: false, // 非个禁用 single: true, // 非多个禁用 multiple: true, // 总条数 total: 0, // label的百分比 labelCol: { span: 6 }, // 内容区域的百分比 wrapperCol: { span: 18 }, // 合同管理表格数据 btInventoryList: [], // 查询参数 queryParam: { pageNum: 1, pageSize: 1000, itemName: undefined, description: undefined, quantity: undefined, beginIndate: undefined }, columns: [ { title: '物资名称', dataIndex: 'itemName', ellipsis: true, align: 'left', width: '12.8%' }, { title: '规格型号', dataIndex: 'description', ellipsis: true, align: 'left', width: '12.8%' }, { title: '总库存', dataIndex: 'fulfilledQuantity', align: 'right', width: '12.8%' }, { title: '当前库存数量', dataIndex: 'quantity', align: 'right', width: '12.8%' }, { title: '入库日期', dataIndex: 'indate', align: 'center', width: '12.8%' }, // { // title: '操作', // dataIndex: 'operation', // align: 'center', // width: '10%', // scopedSlots: { customRender: 'operation' } // } ] } }, created () { this.getList() }, methods: { /** 查询合同管理列表 */ getList () { this.loading = true this.queryParam.contractId = this.contractId listBtInventory(this.queryParam).then(response => { this.btInventoryList = response.data.list this.total = response.data.total this.loading = false if(this.btInventoryList.length > 0){ this.hasData = true }else{ this.hasData = false } }) }, /** 搜索按钮操作 */ handleQuery () { this.queryParam.pageNum = 1 this.getList() }, /** 重置按钮操作 */ resetQuery () { this.queryParam = { pageNum: 1, pageSize: 1000, itemName: undefined, description: undefined, quantity: undefined, beginIndate: undefined } this.handleQuery() }, /** 翻页操作 */ onShowSizeChange (current, pageSize) { this.queryParam.pageSize = pageSize this.getList() }, /** 翻页操作 */ onSizeChange (current, size) { this.queryParam.pageNum = 1 this.queryParam.pageSize = size this.getList() }, /** 翻页操作 */ changeSize (current, pageSize) { this.queryParam.pageNum = current this.queryParam.pageSize = pageSize this.getList() }, /** 翻页操作 */ onSelectChange (selectedRowKeys, selectedRows) { this.selectedRowKeys = selectedRowKeys this.selectedRows = selectedRows this.ids = this.selectedRows.map(item => item.id) this.single = selectedRowKeys.length !== 1 this.multiple = !selectedRowKeys.length }, /** 查询折叠和展开操作 */ toggleAdvanced () { this.advanced = !this.advanced }, handleAdd () { this.showAddModal = true this.$nextTick(() => ( this.$refs.btInventoryAddForm.handleAdd() )) }, handleUpdate (record, ids) { this.showEditModal = true this.$nextTick(() => ( this.$refs.btInventoryEditForm.handleUpdate(record, ids) )) }, /** 删除按钮操作 */ handleDelete (row) { var that = this const btInventoryIds = row.id || this.ids this.$confirm({ title: '确认删除所选中数据?', onOk () { return delBtInventory(btInventoryIds) .then(() => { that.onSelectChange([], []) that.getList() that.$message.success( '删除成功', 3 ) }) }, onCancel () {} }) }, /** 导出按钮操作 */ handleExport () { var that = this this.$confirm({ title: '是否确认导出?', content: '此操作将导出当前条件下所有数据而非选中数据', onOk () { return exportBtInventory(that.queryParam) .then(response => { that.download(response.msg) that.$message.success( '导出成功', 3 ) }) }, onCancel () {} }) }, handleTableChange (pagination, filters, sorter) { if (sorter.field !== undefined && sorter.field !== null && sorter.field !== '') { this.queryParam.orderByColumn = 'a.' + sorter.field this.queryParam.isAsc = sorter.order } this.getList() } } } </script> <style scoped> .empty-container { padding: 20px; text-align: center; background: #fff; border-radius: 4px; } .action { font-size: 16px; cursor: pointer; margin-left: 8px; } .action:hover { color: #1890ff; } </style><template> <div> <a-card :bordered="false" style="margin-bottom: 10px;"> <!-- 条件搜索 --> <div class="table-page-search-wrapper"> <a-form :labelCol="labelCol" :wrapperCol="wrapperCol" ref="queryForm"> <a-row :gutter="32"> <a-col :span="6" > <a-form-item label="合同名称"> <a-input v-model="queryParam.contractName" placeholder="请输入合同名称" allow-clear @keyup.enter.native="handleQuery"/> </a-form-item> </a-col> <a-col :span="6" > <a-form-item label="合同正式编号"> <a-input v-model="queryParam.contractId" placeholder="请输入合同正式编号" allow-clear @keyup.enter.native="handleQuery"/> </a-form-item> </a-col> <a-col :span="6" > <a-form-item label="对方签约位"> <a-input v-model="queryParam.counterpartContractUnit" placeholder="请输入对方签约位" allow-clear @keyup.enter.native="handleQuery"/> </a-form-item> </a-col> <!-- <a-col :span="6" v-if="advanced">--> <!-- <a-form-item label="主办位">--> <!-- <a-input v-model="queryParam.organizer" placeholder="请输入主办位" allow-clear @keyup.enter.native="handleQuery"/>--> <!-- </a-form-item>--> <!-- </a-col>--> <a-col> <span class="table-page-search-submitButtons" style="float: right;"> <a-button type="primary" @click="handleQuery"><a-icon type="search" />查询</a-button> <a-button style="margin-left: 8px" @click="resetQuery"><a-icon type="redo" />重置</a-button> <a @click="toggleAdvanced" style="margin-left: 8px"> {{ advanced ? '收起' : '展开' }} <a-icon :type="advanced ? 'up' : 'down'"/> </a> </span> </a-col> </a-row> </a-form> </div> </a-card> <a-card :bordered="false" class="table-card"> <!-- 增加 --> <bt-contracts-detailed-add-form v-if="showAddModal" ref="contractmanageAddForm" :firstContractTypeOptions="firstContractTypeOptions" :secondContractTypeOptions="secondContractTypeOptions" :sealTypeOptions="sealTypeOptions" :signTypeOptions="signTypeOptions" @ok="getList" @close="showAddModal = false" /> <!-- 编辑 --> <bt-contracts-detailed-edit-form v-if="showEditModal" ref="contractmanageEditForm" :firstContractTypeOptions="firstContractTypeOptions" :secondContractTypeOptions="secondContractTypeOptions" :sealTypeOptions="sealTypeOptions" :signTypeOptions="signTypeOptions" @ok="getList" @close="showEditModal = false" /> <!-- 编辑 --> <BtLiveEidt v-if="showLiveModal" ref="liveEidt" :firstContractTypeOptions="firstContractTypeOptions" :secondContractTypeOptions="secondContractTypeOptions" :sealTypeOptions="sealTypeOptions" :signTypeOptions="signTypeOptions" @ok="getList" @close="showLiveModal = false" /> <outBound v-if="visible" ref="outBoundref" @close="onClose" /> <!-- <a-drawer title="出库记录" placement="right" :closable="false" :visible="visible" width="980" :after-visible-change="afterVisibleChange" @close="onClose" > <outBound :id="outBoundId"></outBound> </a-drawer> --> <advance-table title="出库管理" :pagination="{ current: queryParam.pageNum, pageSize: queryParam.pageSize, total: total, showSizeChanger: true, showLessItems: true, showQuickJumper: true, showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条,总计 ${total} 条`, onChange: changeSize, onShowSizeChange: onShowSizeChange }" tableKey="base-contractmanage-index-table" @change="handleTableChange" rowKey="id" size="middle" @refresh="getList" :columns="columns" :data-source="contractmanageList" :loading="loading" :format-conditions="true" :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" > <!-- <div class="table-operations" slot="button">--> <!-- <a-button type="primary" @click="handleAdd" v-hasPermi="['bt:btOutbound:add']">--> <!-- <a-icon type="plus" />新增--> <!-- </a-button>--> <!-- <a-button type="danger" v-if="!multiple" :disabled="multiple" @click="handleDelete" v-hasPermi="['bt:btOutbound:remove']">--> <!-- <a-icon type="delete" />删除--> <!-- </a-button>--> <!-- <a-button type="" @click="handleExport" v-hasPermi="['bt:btOutbound:export']">--> <!-- <a-icon type="download" />导出--> <!-- </a-button>--> <!-- </div>--> <span slot="expandedRowRender" slot-scope="{ record}" > <bt-inventory-index ref="BtInventoryIndex" title="子表" :contractId="record.id" @outbound-status="(status) => handleOutboundStatus(record, status)" /> </span> <span slot="firstContractType" slot-scope="{record}"> {{ firstContractTypeFormat(record) }} </span> <span slot="secondContractType" slot-scope="{record}"> {{ secondContractTypeFormat(record) }} </span> <span slot="sealType" slot-scope="{record}"> {{ sealTypeFormat(record) }} </span> <span slot="signType" slot-scope="{record}"> {{ signTypeFormat(record) }} </span> <span slot="operation" slot-scope="{text, record}"> <!-- <a @click="handleUpdate(record)" v-hasPermi="['bt:btOutbound:edit']">--> <!-- 出库--> <!-- </a>--> <a-radio-group default-value="a" size="small"> <a-button type="primary" @click="handleUpdate1(record)" v-hasPermi="['bt:btOutbound:edit']" :size="size" ghost> <a-icon type="upload" />生活出库 </a-button> | <a-button type="primary" @click="handleUpdate(record)" v-hasPermi="['bt:btOutbound:edit']" :size="size" > <a-icon type="upload" />生产出库 </a-button> | <a-button type="dashed" @click="showDrawer(record)" v-hasPermi="['bt:btOutbound:list']" :size="size"> <a-icon type="table" />出库记录 </a-button> <a-button v-if="record.hasOutbound" type="danger" @click="resetOutboundStatus(record)" :size="size" > <a-icon type="undo" />重置为未出库 </a-button> </a-radio-group> <!-- <a-divider type="vertical" v-hasPermi="['bt:btOutbound:remove']"/>--> <!-- <a @click="handleDelete(record)" v-hasPermi="['bt:btOutbound:remove']">--> <!-- 删除--> <!-- </a>--> </span> <span slot="outboundStatus" slot-scope="{text, record}"> <a-tag v-if="record.hasOutbound" color="green">已出库</a-tag> <a-tag v-else color="orange">未出库</a-tag> </span> </advance-table> </a-card> </div> </template> <script> import { listBtContractsDetailed, delBtContractsDetailed, exportBtContractsDetailed, getInitData } from '@/api/tt/ContractsDetailed' import AdvanceTable from '@/components/pt/table/AdvanceTable' import BtContractsDetailedAddForm from '@/views/bt/btoutbound/modules/BtContractsDetailedAddForm' import BtContractsDetailedEditForm from '@/views/bt/btoutbound/modules/BtContractsDetailedEditForm' import BtInventoryIndex from '@/views/bt/btoutbound/BtInventoryIndex' import outBound from '@/views/bt/btoutbound/outbound/index.vue' import BtLiveEidt from './modules/BtLiveEidt.vue' export default { name: 'BtoutBound', components: { AdvanceTable, BtInventoryIndex, outBound, BtContractsDetailedAddForm, BtContractsDetailedEditForm, BtLiveEidt }, data () { return { size:'small', visible: false, showAddModal: false, showEditModal: false, showLiveModal: false, // 遮罩层 loading: true, // 选中数组 ids: [], // 选中的主键集合 selectedRowKeys: [], // 选中的数据集合 selectedRows: [], // 高级搜索 展开/关闭 advanced: false, // 非个禁用 single: true, // 非多个禁用 multiple: true, // 总条数 total: 0, // label的百分比 labelCol: { span: 6 }, // 内容区域的百分比 wrapperCol: { span: 18 }, // 合同管理表格数据 contractmanageList: [], // 一级合同类型字典 firstContractTypeOptions: [], // 二级合同类型字典 secondContractTypeOptions: [], // 用章类别字典 sealTypeOptions: [], // 签署类型字典 signTypeOptions: [], outBoundId: 0, // 查询参数 queryParam: { pageNum: 1, pageSize: 10, contractName: undefined, contractId: undefined, organizer: undefined, counterpartContractUnit: undefined }, columns: [ { title: '合同分类', dataIndex: 'contractClassification', ellipsis: true, align: 'left', width: '12.8%' }, { title: '合同名称', dataIndex: 'contractName', ellipsis: true, align: 'left', width: '12.8%' }, { title: '合同正式编号', dataIndex: 'contractId', ellipsis: true, align: 'left', width: '12.8%' }, { title: '采购方式', dataIndex: 'procurementMethod', ellipsis: true, align: 'left', width: '12.8%' }, { title: '对方签约位', dataIndex: 'counterpartContractUnit', ellipsis: true, align: 'left', width: '12.8%' }, { title: '我方签订日期', dataIndex: 'ourSignDate', ellipsis: true, align: 'left', width: '12.8%' }, { title: '合同总金额', dataIndex: 'totalContractAmount', ellipsis: true, align: 'left', width: '12.8%' }, { title: '删除作废', dataIndex: 'deletedOrVoided', ellipsis: true, align: 'left', width: '12.8%' }, { title: '出库状态', dataIndex: 'hasOutbound', align: 'center', width: '10%', customRender: (text, record) => { return record.hasOutbound ? <a-tag color="green">已出库</a-tag> : <a-tag color="orange">未出库</a-tag>; } }, { title: '操作', dataIndex: 'operation', align: 'center', width: '60%', scopedSlots: { customRender: 'operation' } } ] } }, created () { this.getList() getInitData('contract_type_level1,contract_type_level2,sys_oper_type,sys_oper_type').then(response => { this.firstContractTypeOptions = response.data.contract_type_level1 this.secondContractTypeOptions = response.data.contract_type_level2 this.sealTypeOptions = response.data.sys_oper_type this.signTypeOptions = response.data.sys_oper_type }) }, methods: { resetOutboundStatus(record) { const index = this.contractmanageList.findIndex(item => item.id === record.id); if (index !== -1) { this.$set(this.contractmanageList[index], 'hasOutbound', false); // 更新前端状态 localStorage.removeItem(`outbound_${record.id}`); // 清除 localStorage 存储 this.$message.success("已重置为未出库"); } }, handleOutboundStatus(record, status) { const index = this.contractmanageList.findIndex(item => item.id === record.id); if (index !== -1 && status && !this.contractmanageList[index].hasOutbound) { this.$set(this.contractmanageList[index], 'hasOutbound', true); localStorage.setItem(`outbound_${record.id}`, 'true'); // 存储到 localStorage } }, onClose () { this.visible = false this.$emit('close') }, showDrawer(record) { this.visible = true const that = this that.$nextTick(() => ( that.$refs.outBoundref.handleList(record) )) }, // onClose() { // this.visible = false; // }, /** 查询合同管理列表 */ getList () { this.loading = true; listBtContractsDetailed(this.queryParam).then(response => { this.contractmanageList = response.data.list.map(item => { // 从 localStorage 读取是否已出库 const storedOutbound = localStorage.getItem(`outbound_${item.id}`); return { ...item, hasOutbound: storedOutbound === 'true' || false, }; }); this.total = response.data.total; this.loading = false; }); }, // 一级合同类型字典翻译 firstContractTypeFormat (row) { if (row.firstContractType) { return this.selectDictLabel(this.firstContractTypeOptions, row.firstContractType) } else { return '' } }, // 二级合同类型字典翻译 secondContractTypeFormat (row) { if (row.secondContractType) { return this.selectDictLabel(this.secondContractTypeOptions, row.secondContractType) } else { return '' } }, // 用章类别字典翻译 sealTypeFormat (row) { if (row.sealType) { return this.selectDictLabel(this.sealTypeOptions, row.sealType) } else { return '' } }, // 签署类型字典翻译 signTypeFormat (row) { if (row.signType) { return this.selectDictLabel(this.signTypeOptions, row.signType) } else { return '' } }, /** 搜索按钮操作 */ handleQuery () { this.queryParam.pageNum = 1 this.getList() }, /** 重置按钮操作 */ resetQuery () { this.queryParam = { pageNum: 1, pageSize: 10, contractName: undefined, contractId: undefined, organizer: undefined, counterpartContractUnit: undefined } this.handleQuery() }, /** 翻页操作 */ onShowSizeChange (current, pageSize) { this.queryParam.pageSize = pageSize this.getList() }, /** 翻页操作 */ onSizeChange (current, size) { this.queryParam.pageNum = 1 this.queryParam.pageSize = size this.getList() }, /** 翻页操作 */ changeSize (current, pageSize) { this.queryParam.pageNum = current this.queryParam.pageSize = pageSize this.getList() }, /** 翻页操作 */ onSelectChange (selectedRowKeys, selectedRows) { this.selectedRowKeys = selectedRowKeys this.selectedRows = selectedRows this.ids = this.selectedRows.map(item => item.id) this.single = selectedRowKeys.length !== 1 this.multiple = !selectedRowKeys.length }, /** 查询折叠和展开操作 */ toggleAdvanced () { this.advanced = !this.advanced }, handleAdd () { this.showAddModal = true this.$nextTick(() => ( this.$refs.contractmanageAddForm.handleAdd() )) }, //生活导出 handleUpdate1 (record, ids) { this.showLiveModal = true this.$nextTick(() => ( this.$refs.liveEidt.handleUpdate(record, ids) )) }, handleUpdate (record, ids) { this.showEditModal = true this.$nextTick(() => ( this.$refs.contractmanageEditForm.handleUpdate(record, ids) )) }, /** 删除按钮操作 */ handleDelete (row) { var that = this const contractmanageIds = row.id || this.ids this.$confirm({ title: '确认删除所选中数据?', onOk () { return delBtContractsDetailed(contractmanageIds) .then(() => { that.onSelectChange([], []) that.getList() that.$message.success( '删除成功', 3 ) }) }, onCancel () {} }) }, /** 导出按钮操作 */ handleExport () { var that = this this.$confirm({ title: '是否确认导出?', content: '此操作将导出当前条件下所有数据而非选中数据', onOk () { return exportBtContractsDetailed(that.queryParam) .then(response => { that.download(response.msg) that.$message.success( '导出成功', 3 ) }) }, onCancel () {} }) }, handleTableChange (pagination, filters, sorter) { if (sorter.field !== undefined && sorter.field !== null && sorter.field !== '') { this.queryParam.orderByColumn = 'a.' + sorter.field this.queryParam.isAsc = sorter.order } this.getList() } } } </script> 进行修改,我现在的未出库和已出库是存储在客户端,但现在要改成存储到数据库里,/** * 修改合同管理 */ @PreAuthorize("@ss.hasPermi('bt:btOutbound:edit')") @Log(title = "合同管理", businessType = BusinessType.UPDATE) @PutMapping public R edit(@RequestBody @Validated ContractsDetailed btContractsDetailed) { return R.status(btContractsDetailedService.save(btContractsDetailed)); }存储时调用这个接口里的 `ecc_transfer` varchar(50) DEFAULT NULL COMMENT '传输ECC', 这个字段,直接存储汉字
07-02
<template> <div class="app-container"> <!-- 搜索表 --> <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> <el-form-item label="客户名称" prop="customerName"> <el-input v-model="queryParams.customerName" placeholder="请输入客户名称" clearable size="small" @keyup.enter.native="handleQuery"/> </el-form-item> <el-form-item label="项目名称" prop="projectName"> <el-input v-model="queryParams.projectName" placeholder="请输入项目名称" clearable size="small" @keyup.enter.native="handleQuery"/> </el-form-item> <el-form-item label="成品料号" prop="batteryFinishedPartNumber"> <el-input v-model="queryParams.batteryFinishedPartNumber" placeholder="请输入成品料号" clearable size="small" @keyup.enter.native="handleQuery"/> </el-form-item> <el-form-item label="半成品料号" prop="pcbSemiFinishedPartNumber"> <el-input v-model="queryParams.pcbSemiFinishedPartNumber" placeholder="请输入半成品料号" clearable size="small" @keyup.enter.native="handleQuery"/> </el-form-item> <el-form-item label="丝印" prop="mainBoardSilkScreen"> <el-input v-model="queryParams.mainBoardSilkScreen" placeholder="请输入丝印" clearable size="small" @keyup.enter.native="handleQuery"/> </el-form-item> <el-form-item label="文档版次" prop="materialColor"> <el-input v-model="queryParams.materialColor" placeholder="请输入文档版次" clearable size="small" @keyup.enter.native="handleQuery"/> </el-form-item> <el-form-item> <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> </el-form-item> </el-form> <!-- 操作按钮 --> <el-row :gutter="10" class="mb8"> <el-col :span="1.5"> <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['cms:specificationdata:add']">新增</el-button> </el-col> <el-col :span="1.5"> <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['cms:specificationdata:edit']">修改</el-button> </el-col> <el-col :span="1.5"> <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['cms:specificationdata:remove']" >删除</el-button> </el-col> <el-col :span="1.5"> <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['cms:specificationdata:export']">导出列表</el-button> </el-col> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"/> </el-row> <!-- 表格 --> <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange"> <el-table-column type="selection" width="30" align="center"/> <el-table-column label="ID" fixed="left" width="50" align="center" prop="id"/> <el-table-column label="项目名称" fixed="left" align="center" width="130" prop="projectName" sortable/> <el-table-column label="电芯品牌" align="center" prop="cellBrand" width="130" show-overflow-tooltip/> <el-table-column label="电芯型号" align="center" prop="cellModel"/> <el-table-column label="丝印" align="center" width="130" prop="mainBoardSilkScreen"/> <el-table-column label="料号" align="center" width="100" prop="mainBoardPartNumber"/> <el-table-column label="客户名称" align="center" prop="customerName"/> <el-table-column label="文档版次" align="center" prop="revision"/> <el-table-column label="更新人" align="center" width="100" prop="updateBy" sortable/> <el-table-column label="更新时间" align="center" prop="updateTime" width="100" sortable> <template slot-scope="scope"> <span>{{ parseTime(scope.row.updateTime == null || scope.row.updateTime == '' ? scope.row.createTime : scope.row.updateTime) }}</span> </template> </el-table-column> <el-table-column label="PCB顶面贴片图" align="center" width="150" show-overflow-tooltip> <template slot-scope="scope"> <el-button v-if="scope.row.pcbPlacementDiagramTopImg" type="text" icon="el-icon-document" @click="previewFile(scope.row.pcbPlacementDiagramTopImg)">查看顶图</el-button> <span v-else>—</span> </template> </el-table-column> <el-table-column label="PCB底面贴片图" align="center" width="150" show-overflow-tooltip> <template slot-scope="scope"> <el-button v-if="scope.row.pcbPlacementDiagramBottomImg" type="text" icon="el-icon-document" @click="previewFile(scope.row.pcbPlacementDiagramBottomImg)">查看底图</el-button> <span v-else>—</span> </template> </el-table-column> <el-table-column label="操作" align="center" fixed="right" width="160" class-name="small-padding fixed-width"> <template slot-scope="scope"> <el-button size="mini" type="text" icon="el-icon-download" @click="handleExportWord(scope.row)" v-hasPermi="['cms:specificationdata:export']">导出</el-button> <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['cms:specificationdata:edit']">修改</el-button> <el-button size="mini" type="text" icon="el-icon-document-copy" @click="handleCopy(scope.row)" v-hasPermi="['cms:specificationdata:add']">复制</el-button> <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['cms:specificationdata:remove']">删除</el-button> <el-button size="mini" type="text" icon="el-icon-download" v-show="scope.row.dwgLocalPath" @click="handleDownload(scope.row)" v-hasPermi="['cms:specificationdata:export']">下载附件</el-button> </template> </el-table-column> </el-table> <!-- 分页 --> <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/> <!-- 添加/编辑对话框 --> <el-dialog :title="title" v-dialogDrag :visible.sync="open" :before-close="cancel" :close-on-click-modal="false" width="85%" append-to-body > <div class="specification-container"> <!-- 基础信息 --> <div class="form-section"> <h3>基本信息</h3> <div class="form-row"> <label>客户名称</label> <input type="text" v-model="customer_name" /> </div> <div class="form-row"> <label>项目名称</label> <input type="text" v-model="project_name" /> </div> <div class="form-row"> <label>成品料号</label> <input type="text" v-model="battery_finished_part_number" /> </div> <div class="form-row"> <label>半成品料号</label> <input type="text" v-model="pcb_semi_finished_part_number" /> </div> </div> <h1 class="centered">生产规格书</h1> <!-- 保密等级 --> <div class="form-section"> <h3>保密等级</h3> <div class="checkbox-group"> <!-- 禁用其他选项,仅“内部公开”可选且不可更改 --> <label><input type="radio" value="绝密" v-model="confidentialLevel" disabled /> 绝密</label> <label><input type="radio" value="机密" v-model="confidentialLevel" disabled /> 机密</label> <label><input type="radio" value="内部公开" v-model="confidentialLevel" checked disabled /> 内部公开</label> <label><input type="radio" value="外部公开" v-model="confidentialLevel" disabled /> 外部公开</label> </div> </div> <!-- 审批信息 --> <div class="form-section"> <h3>审批信息</h3> <div class="approval-row"> <label>拟制/日期</label> <span>电子工程师</span> </div> <div class="approval-row"> <label>审核/日期</label> <span>直接上级</span> </div> <div class="approval-row"> <label>审核/日期</label> <span>DQE</span> </div> <div class="approval-row"> <label>审核/日期</label> <span>NPI</span> </div> <div class="approval-row"> <label>批准/日期</label> <span>经理</span> </div> </div> <!-- 文件修正记录 --> <div class="form-section"> <h3>文件修正记录</h3> <table class="table-style"> <thead> <tr> <th>序号</th> <th>版次</th> <th>变更日期</th> <th>变更内容</th> <th>拟制</th> <th>审核</th> <th>批准</th> </tr> </thead> <tbody> <tr> <td><input type="text" v-model="revision" /></td> <td><input type="text" v-model="update_time" /></td> <td><input type="text" v-model="change_description" /></td> <td><input type="text" v-model="update_by" /></td> <td><input type="text" v-model="reviewed_by" /></td> <td><input type="text" v-model="approved_by" /></td> </tr> </tbody> </table> </div> <!-- 目录 --> <div class="form-section"> <h3>目录</h3> <ul class="directory-list"> <li>1 引言</li> <li>1.1 编写目的</li> <li>1.2 适用范围</li> <li>2 版本说明</li> <li>2.1 硬件版本</li> <li>2.2 软件版本</li> <li>2.3 上位机软件版本</li> <li>3 PCB贴片图</li> <li>4 PCM测试及检验规范</li> <li>4.1 PCM端口示意图</li> <li>4.2 烧录</li> <li>4.3 PCM测试</li> <li>4.4 PCBA半成品工艺要求</li> <li>5 半成品测试及检验规范</li> <li>5.1 电芯配组要求</li> <li>5.2 PCM组装上电顺序</li> <li>5.3 输出端口定义</li> <li>5.4 功能测试及检验标准</li> <li>6 成品测试及检验规范</li> <li>6.1 成品检测项目及标准</li> <li>6.2 成品结构尺寸</li> <li>6.3 成品打码规则</li> <li>6.4 追溯要求</li> <li>附录一</li> <li>附录二</li> </ul> </div> <!-- 引言 --> <div class="form-section"> <h3>1 引言</h3> <p>本文主要描述该项目产品的生产性能要求说明,明确整个产品在PCM、半成品、成品的性能测试标准及要求。</p> <h4>1.1 编写目的</h4> <p>本文档描述了本产品的生产过程性能测试要求及标准、工艺要求等。方便生产相关人员对本产品的制造和检验。</p> <h4>1.2 适用范围</h4> <p>本规格书适用于欣动能源科技有限公司设计的产品生产技术规范,适用于与之相关的生产和检验。</p> </div> <!-- 版本说明 --> <div class="form-section"> <h3>2 版本说明</h3> <h4>2.1 硬件版本</h4> <table class="table-style"> <thead> <tr> <th>序号</th> <th>PCB</th> <th>丝印</th> <th>料号</th> <th>备注</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>主板</td> <td><input type="text" v-model="main_board_silk_screen" /></td> <td><input type="text" v-model="main_board_part_number" /></td> <td></td> </tr> <tr> <td>2</td> <td>采集板</td> <td>/</td> <td>/</td> <td></td> </tr> <tr> <td>3</td> <td>灯板</td> <td>/</td> <td>/</td> <td></td> </tr> </tbody> </table> <h4>2.2 软件版本</h4> <table class="table-style"> <thead> <tr> <th>序号</th> <th>PCM 软件</th> <th>版本信息</th> <th>备注</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>主板 Bootloader</td> <td>/</td> <td></td> </tr> <tr> <td>2</td> <td>应用程序</td> <td>/</td> <td></td> </tr> <tr> <td>3</td> <td>一体程序</td> <td>/</td> <td></td> </tr> <tr> <td>4</td> <td>固件信息</td> <td>/</td> <td>/</td> </tr> </tbody> </table> <h4>2.3 上位机软件版本</h4> <table class="table-style"> <thead> <tr> <th>序号</th> <th>上位机</th> <th>版本</th> <th>备注</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>Bin对比上位机</td> <td>/</td> <td></td> </tr> <tr> <td>2</td> <td>通讯/升级上位机模板</td> <td>/</td> <td></td> </tr> </tbody> </table> </div> <!-- PCB贴片图 --> <div class="form-section"> <h3>3 PCB贴片图</h3> <div class="upload-group"> <label>顶面</label> <input type="file" @change="uploadPcbTopImage" /> <label>底面</label> <input type="file" @change="uploadPcbBottomImage" /> </div> </div> <!-- PCM测试及检验规范 --> <div class="form-section"> <h3>4 PCM测试及检验规范</h3> <h4>4.1 PCM端口示意图</h4> <input type="file" @change="uploadPcmPortImage" /> <h4>4.2 烧录</h4> <p>不涉及</p> <h4>4.3 PCM测试</h4> <table class="table-style"> <thead> <tr> <th>检验项目</th> <th>性能要求</th> <th>必检项</th> <th>抽检项</th> <th>备注</th> </tr> </thead> <tbody> <tr> <td>过充电保护电压</td> <td>4.175±0.025V</td> <td><input type="checkbox" /></td> <td><input type="checkbox" /></td> <td>每节电芯</td> </tr> <tr> <td>过充电保护延时</td> <td>1.0±0.5S</td> <td><input type="checkbox" /></td> <td><input type="checkbox" /></td> <td></td> </tr> </tbody> </table> </div> <!-- 附录上传 --> <div class="form-section"> <h3>附录</h3> <div class="upload-group"> <label>附录一</label> <input type="file" @change="uploadNtcTable1" /> </div> <div class="upload-group"> <label>附录二</label> <input type="file" @change="uploadNtcTable2" /> </div> </div> </div> </el-dialog> </div> </template> <script> import { listData, getData, delData, addData, updateData } from "@/api/cms/specificationData"; import { parseTime } from "@/utils"; import { getToken } from "@/utils/auth"; export default { name: "SpecificationData", data() { return { confidentialLevel: '内部公开', open: false, title: '生产规格书', // 基本信息 customer_name: '', project_name: '', battery_finished_part_number: '', pcb_semi_finished_part_number: '', // 文件修正记录 revision: '', update_time: '', change_description: '', update_by: '', reviewed_by: '', approved_by: '', // 硬件版本 main_board_silk_screen: '', main_board_part_number: '', // 电芯配组 cell_model: '', cell_brand: '', max_cell_internal_resistance_mohm: '', max_cell_group_resistance_diff_mohm: '', max_cell_group_voltage_diff_mv: '', max_cell_group_capacity_diff_mah: '', cell_power_on_sequence: '', // 功能测试 charge_overcurrent_protection: '', charge_overcurrent_delay: '', level1_discharge_overcurrent_protection: '', level1_discharge_overcurrent_delay: '', level2_discharge_overcurrent_protection: '', level2_discharge_overcurrent_delay: '', short_circuit_protection: '', short_circuit_delay: '', normal_charging: '', normal_discharging: '', open_circuit_voltage: '', pack_internal_resistance_mohm: '', jp_point_continuity_test: '', full_cc_cv_charging: '', full_standby: '', full_constant_current_discharge: '', full_charge_to_shipment_voltage: '', quick_charge_to_shipment_voltage: '', quick_standby: '', requiredinspection: false, sampling: false, // 图片上传 pcbTopImage: null, pcbBottomImage: null, pcmPortImage: null, batteryPortImage: null, ntcTable1: null, ntcTable2: null, loading: true, single: true, multiple: true, showSearch: true, total: 0, dataList: [], title: "", open: false, queryParams: { pageNum: 1, pageSize: 10, customerName: "", projectName: "", batteryFinishedPartNumber: "", pcbSemiFinishedPartNumber: "", mainBoardSilkScreen: "", materialColor: "" }, specForm: { id: null, customerName: "", projectName: "", batteryFinishedPartNumber: "", pcbSemiFinishedPartNumber: "", mainBoardSilkScreen: "", materialColor: "", topImgList: [], bottomImgList: [] }, rules: { customerName: [{ required: true, message: "客户名称不能为空", trigger: "blur" }], projectName: [{ required: true, message: "项目名称不能为空", trigger: "blur" }], batteryFinishedPartNumber: [{ required: true, message: "成品料号不能为空", trigger: "blur" }], pcbSemiFinishedPartNumber: [{ required: true, message: "半成品料号不能为空", trigger: "blur" }], mainBoardSilkScreen: [{ required: true, message: "丝印不能为空", trigger: "blur" }] } }; }, computed: { dynamicDischargeCapacity: { get() { return this.requiredinspection ? this.full_charge_to_shipment_voltage : this.quick_charge_to_shipment_voltage; }, set(value) { if (this.requiredinspection) { this.full_charge_to_shipment_voltage = value; } else { this.quick_charge_to_shipment_voltage = value; } } } }, created() { this.getList(); }, methods: { parseTime, getList() { this.loading = true; listData(this.queryParams).then(response => { this.dataList = response.rows; this.total = response.total; this.loading = false; }); }, handleQuery() { this.queryParams.pageNum = 1; this.getList(); }, resetQuery() { this.resetForm("queryForm"); this.handleQuery(); }, handleSelectionChange(selection) { this.ids = selection.map(item => item.id); this.single = selection.length !== 1; this.multiple = !selection.length; }, handleAdd() { this.resetForm(); this.open = true; this.title = "新增生产规格书"; }, handleUpdate(row) { const id = row.id || this.ids; getData(id).then(response => { this.specForm = response.data; this.open = true; this.title = "修改生产规格书"; }); }, handleDelete(row) { const ids = row.id || this.ids; this.$confirm('是否确认删除编号为"' + ids + '"的数据项?', "警告", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" }).then(() => { delData(ids).then(() => { this.getList(); this.$message.success("删除成功"); }); }); }, handleExport() { this.download('cms/specificationdata/export', { ...this.queryParams }, `data_${new Date().getTime()}.xlsx`); }, handleExportWord(row) { const id = row.id || this.ids; getData(id).then(response => { this.specForm = response.data; this.handleCreateArticleOutputHttp(); }); }, handleDownload(row) { const name = row.dwgLocalPath.substring(row.dwgLocalPath.lastIndexOf("-") + 1); const urlParts = row.dwgLocalPath.split("specificationDwg"); const url = '/profile/specificationDwg' + urlParts[1]; const a = document.createElement('a'); a.setAttribute('download', name); a.setAttribute('href', process.env.VUE_APP_BASE_API + url); a.click(); }, resetForm() { this.specForm = { id: null, customerName: "", projectName: "", batteryFinishedPartNumber: "", pcbSemiFinishedPartNumber: "", mainBoardSilkScreen: "", materialColor: "", topImgList: [], bottomImgList: [] }; }, submitForm() { this.$refs.form.validate(valid => { if (valid) { if (this.specForm.id) { updateData(this.specForm).then(() => { this.$message.success("修改成功"); this.open = false; this.getList(); }); } else { addData(this.specForm).then(() => { this.$message.success("新增成功"); this.open = false; this.getList(); }); } } }); }, cancel() { this.open = false; this.resetForm(); }, handleTopImgSuccess(response, file, fileList) { this.specForm.pcbPlacementDiagramTopImg = response.url; this.specForm.topImgList = fileList; }, handleBottomImgSuccess(response, file, fileList) { this.specForm.pcbPlacementDiagramBottomImg = response.url; this.specForm.bottomImgList = fileList; }, beforeImgUpload(file) { const isValid = file.type.startsWith("image/"); if (!isValid) this.$message.error("只能上传图片文件"); return isValid; }, handleExceed(files, fileList) { this.$message.warning(`最多上传 1 个文件,本次选择了 ${files.length} 个文件`); }, uploadPcbTopImage(e) { this.pcbTopImage = e.target.files[0]; }, uploadPcbBottomImage(e) { this.pcbBottomImage = e.target.files[0]; }, uploadPcmPortImage(e) { this.pcmPortImage = e.target.files[0]; }, uploadBatteryPortImage(e) { this.batteryPortImage = e.target.files[0]; }, uploadNtcTable1(e) { this.ntcTable1 = e.target.files[0]; }, uploadNtcTable2(e) { this.ntcTable2 = e.target.files[0]; } } }; </script> <style lang="scss"> .app-container { padding: 20px; } .el-table { width: 100%; overflow-x: auto; } .el-button--mini { padding: 5px 10px; font-size: 12px; } .el-form-item__content { width: 200px; } @media (max-width: 768px) { .el-form-item__content { width: 100%; } } .specification-container h3 { text-align: center; margin-bottom: 20px; } .specification-container p { margin: 8px 0; } .specification-container { white-space: pre-wrap; font-family: monospace; } h3 { margin-bottom: 10px; } h4, h5 { margin-top: 20px; } .avatar-uploader { display: inline-block; margin-right: 10px; } .specification-container { font-family: Arial, sans-serif; } .form-section { text-align: center; /* 标题和选框组整体居中 */ margin: 0 auto; max-width: 600px; padding: 20px; } .checkbox-group { display: flex; justify-content: center; gap: 15px; margin-top: 10px; flex-wrap: wrap; } .checkbox-group label { display: flex; align-items: center; gap: 5px; } .form-section h3 { margin-top: 0; color: #333; } .form-row { display: flex; align-items: center; margin-bottom: 10px; } .form-row label { width: 120px; font-weight: bold; } .form-row input { flex: 1; padding: 5px; border: 1px solid #ccc; border-radius: 4px; } .approval-row { display: flex; margin-bottom: 8px; } .approval-row label { width: 120px; font-weight: bold; } .table-style { width: 100%; border-collapse: collapse; } .table-style th, .table-style td { border: 1px solid #ccc; padding: 8px; text-align: center; } .directory-list { list-style: none; padding-left: 20px; margin: 0 auto; text-align: center; } .directory-list li { display: list-item; text-align: center; } .upload-group { margin-bottom: 10px; } .upload-group label { font-weight: bold; margin-right: 10px; } .centered { text-align: center; } </style> 帮我优化好这个页面的ui并删除无用的方法变量,优化玩后给我完整的代码
最新发布
11-20
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值