123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637 |
- <template>
- <a-modal
- :title="modalTitle"
- :width="1200"
- :visible="visible"
- :confirmLoading="confirmLoading"
- @cancel="handleCancel"
- >
- <a-form :form="form">
- <a-form-item v-show="false">
- <a-input v-decorator="['id']" type="hidden"/>
- <a-input v-decorator="['sbId']" type="hidden"/>
- <a-input v-decorator="['part']" type="hidden"/>
- </a-form-item>
- <row-list :col="2">
- <row-item>
- <a-form-item
- label="检定单号"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-input
- v-decorator="['no', {rules: [{required: false, message: '检定单号不能为空'}]}]"/>
- </a-form-item>
- </row-item>
- <row-item>
- <a-form-item
- label="检定日期"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-date-picker
- style="width: 100%"
- :format="BaseTool.Date.PICKER_NORM_DATE_PATTERN"
- v-decorator="['lastDate', {rules: [{required: false, message: '检定日期不能为空'}]}]" />
- </a-form-item>
- </row-item>
- <!-- <row-item>
- <a-form-item
- label="检查部位"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-input
- disabled
- style="width: 80%"
- v-decorator="['partName', {rules: [{required: false, message: '检查部位不能为空'}]}]"/>
- <a-button type="primary" style="width: 20%" @click="handlePartSelect">选择</a-button>
- </a-form-item>
- </row-item>-->
- <row-item>
- <a-form-item
- label="检定人"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-input
- v-decorator="['name']"/>
- </a-form-item>
- </row-item>
- </row-list>
- <row-list :col="1">
- <row-item>
- <a-form-item
- label="备注"
- :labelCol="BaseTool.Constant.labelCol2"
- :wrapperCol="BaseTool.Constant.wrapperCol2"
- >
- <a-textarea
- :rows="4"
- v-decorator="['requirement', {rules: [{required: true, message: '备注不能为空'}]}]"/>
- </a-form-item>
- </row-item>
- </row-list>
- <row-list :col="2">
- <row-item>
- <a-form-item
- label="图片"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-upload
- :action="uploadUrl"
- :multiple="false"
- list-type="picture"
- accept="image/*"
- :file-list="this.defaultCheckImgList"
- @change="handleCheckImgChange"
- :headers="headers"
- >
- <a-button> <a-icon type="upload" /> 选择上传图片 </a-button>
- </a-upload>
- </a-form-item>
- </row-item>
- <row-item>
- <a-form-item
- label="文件"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-upload
- :action="uploadUrl"
- :multiple="true"
- :file-list="this.defaultCheckFileList"
- @change="handleCheckFileChange"
- :headers="headers"
- >
- <a-button> <a-icon type="upload" /> 选择上传文件 </a-button>
- </a-upload>
- </a-form-item>
- </row-item>
- </row-list>
- </a-form>
- <!-- <a-tabs type="card" default-active-key="1">
- <a-tab-pane key="1" tab="点检标准参数">
- <div class="table-operator">
- <a-button size="small" type="primary" @click="handleAdd">
- <a-icon type="plus"/>
- 添加
- </a-button>
- <a-button class="margin-left8" size="small" type="danger" @click="handleDel">
- <a-icon type="delete"/>
- 删除
- </a-button>
- </div>
- <a-table
- bordered
- :data-source="data"
- :columns="columns"
- tableLayout="auto"
- rowKey="id"
- :row-selection="rowSelection">
- <template
- slot="name"
- slot-scope="text, record, index"
- >
- <div>
- <a-input
- class="my-form-item-required"
- v-if="record.editable"
- style="margin: -5px 0"
- :value="text"
- @change="e => handleChange(e.target.value, record.id, 'name')"
- />
- <template v-else>
- {{ text }}
- </template>
- </div>
- </template>
- <template
- slot="type"
- slot-scope="text, record, index"
- >
- <div>
- <a-select
- v-if="record.editable"
- style="width: 80px"
- :defaultValue="1"
- @change="e => handleChange(e, record.id, 'type')"
- placeholder="请选择">
- <a-select-option
- v-for="(label,value) in paramTypeMap"
- :key="value"
- :label="label"
- :value="parseInt(value)">{{ label }}
- </a-select-option>
- </a-select>
- <template v-else>
- {{ BaseTool.Table.getMapText(paramTypeMap, text) }}
- </template>
- </div>
- </template>
- <template
- slot="upperLimit"
- slot-scope="text, record, index"
- >
- <div>
- <a-input
- v-if="record.editable"
- style="margin: -5px 0"
- :value="text"
- @change="e => handleChange(e.target.value, record.id, 'upperLimit')"
- />
- <template v-else>
- {{ text }}
- </template>
- </div>
- </template>
- <template
- slot="lowerrLimit"
- slot-scope="text, record, index"
- >
- <div>
- <a-input
- v-if="record.editable"
- style="margin: -5px 0"
- :value="text"
- @change="e => handleChange(e.target.value, record.id, 'lowerrLimit')"
- />
- <template v-else>
- {{ text }}
- </template>
- </div>
- </template>
- <template
- slot="referenceValue"
- slot-scope="text, record, index"
- >
- <div>
- <a-input
- v-if="record.editable"
- style="margin: -5px 0"
- :value="text"
- @change="e => handleChange(e.target.value, record.id, 'referenceValue')"
- />
- <template v-else>
- {{ text }}
- </template>
- </div>
- </template>
- <template
- slot="normalSelection"
- slot-scope="text, record, index"
- >
- <div>
- <a-input
- v-if="record.editable"
- style="margin: -5px 0"
- :value="text"
- @change="e => handleChange(e.target.value, record.id, 'normalSelection')"
- />
- <template v-else>
- {{ text }}
- </template>
- </div>
- </template>
- <template
- slot="instruction"
- slot-scope="text, record, index"
- >
- <div>
- <a-input
- v-if="record.editable"
- style="margin: -5px 0"
- :value="text"
- @change="e => handleChange(e.target.value, record.id, 'instruction')"
- />
- <template v-else>
- {{ text }}
- </template>
- </div>
- </template>
- <template slot="operation" slot-scope="text, record, index">
- <div class="editable-row-operations">
- <span v-if="record.editable">
- <a @click="() => saveParam(record.id)">保存</a>
- <a-divider type="vertical"/>
- <a-popconfirm title="确定取消吗?" @confirm="() => cancel(record.id)">
- <a>取消</a>
- </a-popconfirm>
- </span>
- <span v-else>
- <a :disabled="editingKey !== ''" @click="() => edit(record.id)">编辑</a>
- </span>
- </div>
- </template>
- </a-table>
- </a-tab-pane>
- </a-tabs>-->
- <template slot="footer">
- <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
- </template>
- <part-info-select-modal ref="partInfoSelectModal" @selected="handlePartSelected"/>
- </a-modal>
- </template>
- <script>
- import pick from 'lodash.pick'
- import { STable, Ellipsis } from '@/components'
- import { addCheckStandard, updateCheckStandard } from '@/api/sb/measurelog'
- import BaseTool from '../../../../utils/tool'
- import { queryUser } from '@/api/upms/user'
- import { uploadUrl } from '@/api/upms/file'
- import PartInfoSelectModal from '@/views/part/info/modules/PartInfoSelectModal'
- import Vue from 'vue'
- import { ACCESS_TOKEN } from '@/store/mutation-types'
- export default {
- name: 'BaseCheckStandard',
- components: {
- STable,
- Ellipsis,
- PartInfoSelectModal
- },
- data () {
- return {
- confirmLoading: false,
- modalTitle: null,
- form: this.$form.createForm(this),
- visible: false,
- // 下拉框map
- typeMap: {},
- actionTypeMap: {},
- paramTypeMap: {},
- enableMap: {},
- periodTypeMap: {},
- checkImgList: [], // 图片
- checkFileList: [], // 文档
- defaultCheckImgList: [],
- defaultCheckFileList: [],
- uploadUrl: uploadUrl,
- userList: {},
- editingKey: '',
- headers: {
- Authorization: 'Bearer ' + Vue.ls.get(ACCESS_TOKEN)
- },
- rowSelection: {
- onChange: (selectedRowKeys, selectedRows) => {
- this.selectedRowKeys = selectedRowKeys
- this.selectedRows = selectedRows
- }
- },
- // 表头
- columns: [
- {
- title: '序号',
- dataIndex: 'index',
- customRender: (text, record, index) => {
- return index + 1
- }
- },
- {
- title: '名称',
- dataIndex: 'name',
- scopedSlots: { customRender: 'name' }
- },
- {
- title: '类型',
- dataIndex: 'type',
- scopedSlots: { customRender: 'type' }
- },
- {
- title: '上限',
- dataIndex: 'upperLimit',
- scopedSlots: { customRender: 'upperLimit' }
- },
- {
- title: '下限',
- dataIndex: 'lowerrLimit',
- scopedSlots: { customRender: 'lowerrLimit' }
- },
- {
- title: '参考值',
- dataIndex: 'referenceValue',
- scopedSlots: { customRender: 'referenceValue' }
- },
- {
- title: '正常选型',
- dataIndex: 'normalSelection',
- scopedSlots: { customRender: 'normalSelection' }
- },
- {
- title: '说明',
- dataIndex: 'instruction',
- scopedSlots: { customRender: 'instruction' }
- },
- {
- title: '操作',
- dataIndex: 'operation',
- width: 150,
- scopedSlots: { customRender: 'operation' }
- }
- ],
- data: [],
- cacheData: [],
- selectedRowKeys: [],
- selectedRows: [],
- options: {
- rowSelection: {
- selectedRowKeys: this.selectedRowKeys
- }
- }
- }
- },
- props: {
- },
- created () {
- // 下拉框map
- this.paramTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_STANDARD_PARAM_TYPE)
- this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_STANDARD_TYPE)
- this.periodTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_PERIOD_TYPE)
- this.actionTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_ACTION_TYPE)
- this.enableMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
- },
- methods: {
- base (record, sbId) {
- this.visible = true
- queryUser({}).then(res => {
- this.userList = res.data
- })
- // 如果是空标识添加
- if (this.BaseTool.Object.isBlank(record)) {
- this.modalTitle = '添加'
- this.data = []
- this.cacheData = []
- if (sbId != null) {
- const { form: { setFieldsValue } } = this
- // 日期处理
- this.$nextTick(() => {
- setFieldsValue({ sbId: sbId })
- })
- }
- return
- }
- this.modalTitle = '编辑'
- if (this.BaseTool.Object.isBlank(record.id)) {
- this.modalTitle = '复制'
- }
- this.checkImgList = record.checkImgList
- this.checkFileList = record.checkFileList
- this.defaultCheckImgList = this.BaseTool.UPLOAD.transImg(this.checkImgList)
- this.defaultCheckFileList = this.BaseTool.UPLOAD.transImg(this.checkFileList)
- const { form: { setFieldsValue } } = this
- if (record.lastDate != null) {
- record.lastDate = this.BaseTool.Moment(record.lastDate, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN)
- this.$nextTick(() => {
- setFieldsValue(Object.assign(pick(record, [
- 'lastDate'
- ])))
- })
- }
- // 日期处理
- this.$nextTick(() => {
- setFieldsValue(Object.assign(pick(record, [
- 'id',
- 'sbId',
- 'name',
- 'no',
- 'type',
- 'period',
- 'part',
- 'partName',
- 'checkUserId',
- 'periodType',
- 'actionType',
- 'enable',
- 'requirement',
- 'remark'
- ])))
- })
- this.data = BaseTool.Object.copy(record.paramList)
- this.cacheData = BaseTool.Object.copy(record.paramList)
- this.editingKey = ''
- },
- save () {
- const { form: { validateFieldsAndScroll } } = this
- this.confirmLoading = true
- validateFieldsAndScroll((errors, values) => {
- if (errors) {
- this.confirmLoading = false
- return
- }
- values.paramList = this.data
- // 上传文件
- values.checkImgList = this.checkImgList
- values.checkFileList = this.checkFileList
- // 日期数据的处理
- values.lastDate = BaseTool.Date.formatter(values.lastDate, BaseTool.Date.PICKER_NORM_DATE_PATTERN)
- if (this.BaseTool.String.isBlank(values.id)) {
- addCheckStandard(values)
- .then(() => {
- this.handleCancel(values)
- }).catch(() => {
- this.confirmLoading = false
- })
- } else {
- updateCheckStandard(values)
- .then(() => {
- this.handleCancel(values)
- }).catch(() => {
- this.confirmLoading = false
- })
- }
- })
- },
- handleCancel (values) {
- this.visible = false
- this.confirmLoading = false
- this.form.resetFields()
- if (this.BaseTool.Object.isNotBlank(values)) {
- this.$emit('ok', values)
- }
- },
- handleChange (value, key, column) {
- const newData = [...this.data]
- const target = newData.filter(item => key === item.id)[0]
- if (target) {
- target[column] = value
- this.data = newData
- }
- },
- edit (key) {
- const newData = [...this.data]
- const target = newData.filter(item => key === item.id)[0]
- this.editingKey = key
- if (target) {
- target.editable = true
- this.data = newData
- }
- },
- saveParam (key) {
- const newData = [...this.data]
- const newCacheData = [...this.cacheData]
- const target = newData.filter(item => key === item.id)[0]
- // 校验数据
- if (!this.checkParams(target)) {
- return false
- }
- const targetCache = newCacheData.filter(item => key === item.id)[0]
- console.log(targetCache, 686688)
- if (target && targetCache) {
- delete target.editable
- this.data = newData
- Object.assign(targetCache, target)
- this.cacheData = newCacheData
- }
- this.editingKey = ''
- },
- checkParams (param) {
- if (BaseTool.Object.isBlank(param.name)) {
- this.$message.error('参数名称不能为空')
- return false
- }
- return true
- },
- cancel (key) {
- const newData = [...this.data]
- const target = newData.filter(item => key === item.id)[0]
- this.editingKey = ''
- if (!this.checkParams(target)) {
- const data = [...this.data]
- const cacheData = [...this.cacheData]
- this.data = data.filter(item => item.id !== key)
- this.cacheData = cacheData.filter(item => item.id !== key)
- return
- }
- if (target) {
- Object.assign(target, this.cacheData.filter(item => key === item.id)[0])
- console.log(target, 'target')
- delete target.editable
- this.data = newData
- }
- },
- handleAdd () {
- if (this.editingKey !== '') {
- this.$message.error('请保存后再添加')
- return false
- }
- const { data, cacheData } = this
- console.log(this.data, this.cacheData)
- const newParam = this.getNewParam()
- const newCache = { ...newParam }
- data.push(newParam)
- cacheData.push(newCache)
- },
- handleDel () {
- const data = [...this.data]
- const cacheData = [...this.cacheData]
- this.data = data.filter(item => !this.selectedRowKeys.includes(item.id))
- this.cacheData = cacheData.filter(item => !this.selectedRowKeys.includes(item.id))
- if (this.selectedRowKeys.includes(this.editingKey)) {
- this.editingKey = ''
- }
- },
- getNewParam () {
- const newParam = {
- name: '',
- type: '1',
- upperLimit: '',
- lowerrLimit: '',
- referenceValue: '',
- normalSelection: '',
- instruction: ''
- }
- newParam.id = new Date().getTime()
- newParam.editable = true
- this.editingKey = newParam.id
- console.log(newParam, 'newparam')
- return newParam
- },
- handlePartSelect () {
- const sbId = this.form.getFieldValue('sbId')
- this.$refs.partInfoSelectModal.base({ sbId })
- },
- handlePartSelected (keys, rows) {
- const [ key ] = keys
- const [ row ] = rows
- const { form: { setFieldsValue } } = this
- this.$nextTick(() => {
- setFieldsValue(Object.assign({
- 'part': key,
- 'partName': row.name
- }))
- })
- },
- handleCheckImgChange (info) {
- this.defaultCheckImgList = info.fileList
- this.checkImgList = this.setFileList(info, 31)
- },
- handleCheckFileChange (info) {
- this.defaultCheckFileList = info.fileList
- this.checkFileList = this.setFileList(info, 32)
- },
- setFileList (info, type) {
- const file = info.file
- const fileList = info.fileList
- if (file.status === 'done') {
- return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
- } else if (file.status === 'removed') {
- return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
- } else if (file.status === 'error') {
- this.$message.error('上传失败')
- return null
- }
- }
- }
- }
- </script>
|