gaosp
2024-01-19 db79f0019d3f6ed98e9983de6b91d08212683c86
src/container/maintenance/dailyMAdd.vue
@@ -1,309 +1,239 @@
<!-- 日常保养 编辑 -->
<template>
    <!-- 新增弹框 -->
    <el-dialog
        :title="title"
        width="80%"
        :visible.sync="dialogVisibleAdd" class="role-select">
         <!-- 查询表单 -->
        <el-form :model="dataForm" ref="dataForm" label-width="150px" style="margin-top:10px;">
            <el-row :gutter="20">
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="统一编号" prop="uuid">
                        <el-input type="text" v-model="dataForm.uuid" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="设备名称" prop="machineName">
                        <el-select v-model="dataForm.machineName" placeholder="---请选择---">
                            <el-option
                            v-for="item in machineName"
                            :key="item.id"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="设备型号" prop="type">
                        <el-input size="mini" type="text" v-model="dataForm.type"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="设备规格" prop="specification">
                        <el-input size="mini" type="text" v-model="dataForm.specification" @input="getMachineInfo"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="安装地点" prop="location">
                        <el-input size="mini" type="text" v-model="dataForm.location"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="使用部门" prop="department">
                        <el-select v-model="dataForm.department" placeholder="---请选择---" clearable >
                            <el-option
                            v-for="item in departmentlist"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="保养者" prop="maintainPerson">
                        <el-select v-model="dataForm.maintainPerson" placeholder="---请选择---" clearable >
                            <el-option
                            v-for="item in maintainPerson"
                            :key="item.id"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <!-- <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="保养周期" prop="maintainPeriod">
                        <el-input size="mini" type="text" v-model="dataForm.maintainPeriod"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="投产日期" prop="productionDate">
                        <el-input size="mini" type="text" v-model="dataForm.productionDate"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="生产厂家" prop="manufacturer">
                        <el-input size="mini" type="text" v-model="dataForm.manufacturer"></el-input>
                    </el-form-item>
                </el-col> -->
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="计划状态" prop="planStatus">
                        <el-input size="mini" type="text" v-model="dataForm.planStatus" readonly></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="是否合格" prop="isQualified">
                        <el-select v-model="dataForm.isQualified" placeholder="---请选择---" clearable >
                            <el-option
                            v-for="item in isQualified"
                            :key="item.id"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="计划开始日期" prop="planStartDate">
                        <el-date-picker
                        format="yyyy 年 MM 月 dd 日"
                        value-format="yyyy-MM-dd"
                        v-model="dataForm.planStartDate"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="计划完成日期" prop="planFinishDate">
                        <el-date-picker
                        format="yyyy 年 MM 月 dd 日"
                        value-format="yyyy-MM-dd"
                        v-model="dataForm.planFinishDate"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="保养内容与存在问题" prop="detail">
                        <el-input size="mini" type="text" v-model="dataForm.detail"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <div style="display: flex;justify-content: center;align-items: center;margin-top:15px;">
            <el-button size="mini" type="primary" @click="savedata()" plain>保存</el-button>
            <el-button size="mini" type="warning" @click="resetForm()" plain>重置</el-button>
        </div>
   <!-- 新增弹框 -->
   <el-dialog :title="title" width="80%" :visible.sync="dialogVisibleAdd" class="role-select">
      <!-- 查询表单 -->
      <el-form :model="dataForm" ref="dataForm" label-width="150px" style="margin-top:10px;">
         <el-row :gutter="24">
            <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
               <el-form-item label="设备名称" prop="machineName">
                  <el-select v-model="dataForm.machineId" placeholder="---请选择---" clearable>
                     <el-option v-for="item in machineList" :key="item.id" :label="item.machineName"
                        :value="item.id">
                     </el-option>
                  </el-select>
               </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
               <el-form-item label="使用部门" prop="department">
                  <el-select v-model="dataForm.department" placeholder="---请选择---" clearable>
                     <el-option v-for="item in departmentlist" :key="item.value" :label="item.label"
                        :value="item.value">
                     </el-option>
                  </el-select>
               </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
               <el-form-item label="保养者" prop="maintainPerson">
                  <el-select v-model="dataForm.userId" placeholder="---请选择---" clearable>
                     <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id">
                     </el-option>
                  </el-select>
               </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
               <el-form-item label="是否合格" prop="isQualified">
                  <el-select v-model="dataForm.isQualified" placeholder="---请选择---" clearable>
                     <el-option v-for="item in isQualified" :key="item.value" :label="item.label" :value="item.value">
                     </el-option>
                  </el-select>
               </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
               <el-form-item label="保养内容与存在问题" prop="detail">
                  <el-input size="mini" type="text" v-model="dataForm.detail" clearable></el-input>
               </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
            </el-col>
            <el-col :xs="24" :sm="10" :md="10" :lg="10" :xl="10">
               <el-form-item label="计划开始日期" prop="planStartDate">
                  <el-date-picker format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" v-model="dataForm.planStartDate"
                     range-separator="至" clearable type="daterange" start-placeholder="开始日期" end-placeholder="结束日期">
                  </el-date-picker>
               </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="10" :md="10" :lg="10" :xl="10">
               <el-form-item label="计划完成日期" prop="planFinishDate">
                  <el-date-picker format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd"
                     v-model="dataForm.planFinishDate" range-separator="至" clearable type="daterange"
                     start-placeholder="开始日期" end-placeholder="结束日期">
                  </el-date-picker>
               </el-form-item>
            </el-col>
         </el-row>
      </el-form>
      <div style="display: flex;justify-content: center;align-items: center;margin-top:15px;">
         <el-button size="mini" type="primary" @click="savedata()" plain>保存</el-button>
         <el-button size="mini" type="warning" @click="resetForm()" plain>重置</el-button>
      </div>
    </el-dialog>
   </el-dialog>
</template>
<script>
// import { getMachineList, maintainCreate, maintainUpdate, deviceManage, userList, departmentGet } from '@/api/MdcApi'
import { getMachineList, maintainCreate, maintainUpdate, userList, departmentGet } from '@/api/MdcApi'
import { getRequest } from '@/api/Api'
export default {
  props: ['styles', 'departmentlist'],
  data() {
    return {
      dataForm: {
        style: '日常保养',
        state: 1,
        machineName: '', // 设备名称
        uuid: '', // 同意编码
        type: '', // 设备类型
        specification: '', // 设备规格
        location: '', // 安装位置
        department: '', // 使用单位
        maintainPerson: '', // 保养者
        productionDate: '', // 投产日期
        manufacturer: '', // 生产厂家
        planStatus: '1', // 计划状态
        isQualified: '合格',
        planStartDate: '',
        planFinishDate: '',
        detail: '' // 保养内容与存在问题
      },
      dialogVisibleAdd: false,
      // 下拉框
      machineName: [], // 设备名称
      department: [], // 使用部门
      maintainPerson: [], // 设备名称
      isQualified: [{ // 是否合格
        label: '合格',
        value: '合格'
      }, {
        label: '不合格',
        value: '不合格'
      }], // 设备名称
      title: '新增',
      data: null, // 编辑数据回填
      no: null
    }
  },
  methods: {
    // 初始化
    init(n, data) {
      this.data = data
      this.no = n
      if (this.styles === '1') {
        this.dataForm.style = '日常保养'
      } else if (this.styles === '2') {
        this.dataForm.style = '一级保养'
      } else if (this.styles === '3') {
        this.dataForm.style = '二级保养'
      } else {
        this.dataForm.style = '三级保养'
      }
      if (n === 1) {
        this.title = '新增' + this.dataForm.style
        this.dataForm.machineName = ''
        this.dataForm.uuid = ''
        this.dataForm.type = ''
        this.dataForm.specification = ''
        this.dataForm.location = ''
        this.dataForm.department = ''
        this.dataForm.maintainPerson = ''
        this.dataForm.productionDate = ''
        this.dataForm.manufacturer = ''
        this.dataForm.planStartDate = ''
        this.dataForm.planFinishDate = ''
        this.dataForm.isQualified = '合格'
        this.dataForm.detail = ''
      } else {
        this.title = '修改' + this.dataForm.styles
        this.dataForm.machineName = this.data.machineName
        this.dataForm.uuid = this.data.uuid
        this.dataForm.type = this.data.type
        this.dataForm.specification = this.data.specification
        this.dataForm.location = this.data.location
        this.dataForm.department = this.data.department
        this.dataForm.maintainPerson = this.data.userName
        this.dataForm.isQualified = this.data.isQualified === '0' ? '不合格' : '合格'
        this.dataForm.manufacturer = this.data.manufacturer
        this.dataForm.detail = this.data.detail
      }
      this.dialogVisibleAdd = true
      this.machineName = []
      this.maintainPerson = []
      // this.initDevices() // 初始化数据
    },
    // 保存
    savedata() {
      // 新增保存
      // const style = 1
      const startDateFrom = this.dataForm.planStartDate[0]
      const startDateTo = this.dataForm.planStartDate[1]
      const completeDateFrom = this.dataForm.planFinishDate[0]
      const completeDateTo = this.dataForm.planFinishDate[1]
      const isQualified = this.dataForm.isQualified === '合格' ? 1 : 0
      if (this.no === 1) {
        getRequest('maintainCreate',{})
        // maintainCreate(
        //   this.styles, this.dataForm.uuid, this.dataForm.machineName, this.dataForm.type,
        //   this.dataForm.specification, this.dataForm.department, this.dataForm.location,
        //   startDateFrom, startDateTo, completeDateFrom, completeDateTo, isQualified,
        //   this.dataForm.state, this.dataForm.detail
        // ).then(res => {
        //   if (res.result === 'SUCCESS') {
        //     this.$message({
        //       type: 'success',
        //       message: '保存成功!'
        //     })
        //     this.$emit('reflash')
        //     // const that = this
        //     this.dialogVisibleAdd = false
        //   } else {
        //     this.$message({
        //       type: 'error',
        //       message: res.result
        //     })
        //   }
        // })
      } else {
        getRequest('maintainUpdate',{})
        // 修改保存
        // maintainUpdate(this.styles, this.data.id, this.dataForm.uuid, this.dataForm.machineName, this.dataForm.type,
        //   this.dataForm.specification, this.dataForm.department, this.dataForm.location,
        //   startDateFrom, startDateTo, completeDateFrom, completeDateTo, isQualified,
        //   this.dataForm.state, this.dataForm.detail).then(res => {
        //   if (res.result === 'SUCCESS') {
        //     this.$message({
        //       type: 'success',
        //       message: '保存成功!'
        //     })
        //     this.$emit('reflash')
        //   } else {
        //     this.$message({
        //       type: 'error',
        //       message: res.result
        //     })
        //   }
        // })
      }
    },
    /**
         * 初始化已有机床
         */
    // 重置
    resetForm() {
      this.$refs.dataForm.resetFields()
    }
  },
  created() {
    this.initDevices()
  }
   props: ['styleName', 'styles', 'styleValue', 'departmentlist', 'machineList', 'userList'],
   data() {
      return {
         dataForm: {
            id: '',
            machineId: '',
            department: '',
            userId: '',
            isQualified: '',
            detail: '',
            style: '',
            planStartDate: [],
            planFinishDate: []
         },
         dialogVisibleAdd: false,
         // 下拉框
         isQualified: [{ // 是否合格
            label: '合格',
            value: true
         }, {
            label: '不合格',
            value: false
         }], // 设备名称
         title: '新增',
         data: null, // 编辑数据回填
         no: null,
      }
   },
   methods: {
      // 初始化
      init(n, data) {
         this.data = data
         this.no = n
         if (n === 1) {
            this.title = '新增' + this.styleName
            Object.keys(this.dataForm).forEach(key => {
               this.dataForm[key] = ''
            })
            this.dataForm['style'] = ''
         } else {
            this.title = '修改' + this.styleName
            Object.keys(this.dataForm).forEach(key => {
               this.dataForm[key] = data[key]
            })
            try {
               this.dataForm.planStartDate = [(data.startDateFrom || ''),(data.startDateTo || '')]
               this.dataForm.planFinishDate = [(data.completeDateFrom || ''),(data.completeDateTo || '')]
            } catch (error) {
            }
         }
         this.dialogVisibleAdd = true
         // this.initDevices() // 初始化数据
      },
      // 保存
      savedata() {
         // 新增保存
         // const style = 1
         let startDateFrom
         let startDateTo
         let completeDateFrom
         let completeDateTo
         try {
            startDateFrom = this.dataForm.planStartDate[0]
            startDateTo = this.dataForm.planStartDate[1]
            completeDateFrom = this.dataForm.planFinishDate[0]
            completeDateTo = this.dataForm.planFinishDate[1]
            } catch (error) {
            }
         if (this.no === 1) {
            console.log({
               ...this.dataForm,
               startDateFrom,
               startDateTo,
               completeDateFrom,
               completeDateTo,
               styles: this.style
            })
            // return
            getRequest('maintainCreate', {
               ...this.dataForm,
               startDateFrom,
               startDateTo,
               completeDateFrom,
               completeDateTo,
               style: this.styleValue
            }).then(res => {
               if (res.result === 'SUCCESS') {
                  this.$message({
                     type: 'success',
                     message: '保存成功!'
                  })
                  this.$emit('reflash')
                  // const that = this
                  this.dialogVisibleAdd = false
               } else {
                  this.$message({
                     type: 'error',
                     message: res.result
                  })
               }
            })
         } else {
            getRequest('maintainUpdate', {
               ...this.dataForm,
               startDateFrom,
               startDateTo,
               completeDateFrom,
               completeDateTo,
               style: this.styleValue
            }).then(res => {
               if (res.result === 'SUCCESS') {
                  this.$message({
                     type: 'success',
                     message: '保存成功!'
                  })
                  this.$emit('reflash')
                  // const that = this
                  this.dialogVisibleAdd = false
               } else {
                  this.$message({
                     type: 'error',
                     message: res.result
                  })
               }
            })
         }
      },
      /**
          * 初始化已有机床
          */
      // 重置
      resetForm() {
         Object.keys(this.dataForm).forEach(key => {
            this.dataForm[key] = ''
         })
      }
   },
   created() {
   }
}
</script>
<style lang="scss">
.el-form-item__content {
    .el-select,.el-input {
      width: 100%;
    }
  }
  .el-dialog__body {
    overflow: hidden;
  }
   .el-select,
   .el-input {
      width: 100%;
   }
}
.el-dialog__body {
   overflow: hidden;
}
</style>
<style scoped>
    /* .el-table__body .cell{padding:3px;}
/* .el-table__body .cell{padding:3px;}
    .el-input__icon{line-height: 30px;}
    .el-input__inner{height:30px;line-height: 30px;}
    .el-form-item__content{line-height: 40px;}