loulijun2021
2022-08-27 3cbb9eb9e6f594721239bde5754db6df924472a6
src/views/sbgl/djbz.vue
@@ -155,8 +155,8 @@
      :close-on-click-modal="false"
      top="8vh"
      @closed="handleClose"
      @close="handleClose"
    >
      <!--      @close="handleClose"-->
      <div>
        <i class="el-icon-s-operation" style="color:#42b983;margin: -20px 10px 20px 0" />设备点检标准信息
      </div>
@@ -415,7 +415,7 @@
import { getCookie } from '@/utils/auth'
import ImportPicker from '@/components/ImportPicker'
import {
  AddUpdateDeviceCheckStandArd,
  AddUpdateDeviceCheckStandArd, DeleteDeviceCheckStaned,
  DeviceCheckItemSelect,
  DeviceCheckStandArdSearch,
  ViewDeviceCheckStanedSearch
@@ -488,9 +488,9 @@
        ]
      },
      tableDataDialog: [], // 表格数据
      tableDataDialogSelected: [], // 已选code
      // tableDataDialogSelected: [], // 已选code
      checkItemSelectArr: [],
      checkItemIsCancel: true,
      dialogVisibleEqp: false,
      dialogFormEqp: {
@@ -523,6 +523,8 @@
  mounted() {
    window.addEventListener('resize', this.getHeight)
    this.getHeight()
    this.getDeviceCheckItemSelect()
  },
  methods: {
    async getDeviceCheckStandArdSearch() {
@@ -558,10 +560,9 @@
    },
    // 重置
    reset() {
      this.form.OrgCode = ''
      this.form.OrgName = ''
      this.form.OrgType = ''
      this.form.UserName = ''
      this.form.checkstandcode = ''
      this.form.checkstandname = ''
      this.form.checkcontr = ''
      this.getDeviceCheckStandArdSearch()
    },
@@ -574,25 +575,46 @@
    add(operation) {
      this.operation = operation
      this.dialogVisible = true
      this.getDeviceCheckItemSelect()
      // this.getDeviceCheckItemSelect()
      this.$nextTick(() => {
        this.$refs.tableDataDialogRef.doLayout()
      })
    },
    // 修改按钮
    edit(operation, row) {
      // this.getDeviceCheckItemSelect()
      this.operation = operation
      this.getViewDeviceCheckStanedSearch(row.code)
      this.dialogVisible = true
      this.getDeviceCheckItemSelect()
      this.$nextTick(() => {
        this.$refs.tableDataDialogRef.doLayout()
      })
      this.$nextTick(() => {
        this.dialogForm.code = row.code
        this.dialogForm.name = row.name
        this.dialogForm.enable = row.enable
        this.dialogForm.description = row.description
      // this.$nextTick(() => {
      //   this.dialogForm.code = row.code
      //   this.dialogForm.name = row.name
      //   this.dialogForm.enable = row.enable
      //   this.dialogForm.description = row.description
      // })
    },
    // 修改前请求接口
    async getViewDeviceCheckStanedSearch(checkstand_code) {
      const { data: res } = await ViewDeviceCheckStanedSearch({ checkstand_code })
      this.tableDataDialog = res.Data
      this.dialogForm.code = res.code
      this.dialogForm.name = res.name
      this.dialogForm.enable = res.enable
      this.dialogForm.description = res.description
      this.tableDataDialog.forEach(item => {
        item.isVisible = 0
        item.checkitem_code = item.code
        item.checkitem_name = item.name
        item.checkitem_descr = item.chkdesc
      })
      this.checkItemSelectArr = [...this.checkItemSelectArr].filter(x => [...this.tableDataDialog].every(y => y.checkitem_code !== x.code))
    },
    // 删除按钮
    async del(row) {
@@ -601,7 +623,7 @@
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        DeleteOrganization({ orgid: row.code }).then(res => {
        DeleteDeviceCheckStaned({ checkstand_code: row.code }).then(res => {
          if (res.code === '200') {
            this.$message.success('删除成功!')
            this.getDeviceCheckStandArdSearch()
@@ -611,10 +633,7 @@
        this.$message.info('已取消删除')
      })
    },
    // 修改前请求接口
    // async    getViewDeviceCheckStanedSearch(checkstand_code) {
    //   const { data: res } = await ViewDeviceCheckStanedSearch()
    // },
    // 对话框关闭事件
    handleClose() {
      this.dialogForm.code = ''
@@ -622,6 +641,7 @@
      this.dialogForm.enable = 'Y'
      this.dialogForm.description = ''
      this.tableDataDialog = []
      this.getDeviceCheckItemSelect()
      this.$refs.dialogForm.clearValidate()
    },
    // 对话框取消
@@ -632,6 +652,14 @@
    dialogVisibleConfirm() {
      this.$refs.dialogForm.validate(valid => {
        if (valid) {
          // this.tableDataDialog.forEach((item, index) => { // 去掉正在编辑且是空checkitem_code
          //   if (item.isVisible === 1 && item.checkitem_code === '') {
          //     this.tableDataDialog.splice(index, 1)
          //   }
          // })
          this.tableDataDialog.filter(item => item.checkitem_code !== '')
          let Data = []
          // 数组中对象相同的去重
          Data = this.tableDataDialog.filter((currentValue, currentIndex, selfArr) => {
@@ -669,16 +697,6 @@
      row.checkitem_descr = res.description
      row.checkitem_code = res.code
      row.checkitem_name = res.name
      // row.checkitem_descr = this.checkItemSelectArr.find(item => {
      //   return item.code === val || item.name === val
      // }).description
      //
      // row.checkitem_code = this.checkItemSelectArr.find(item => {
      //   return item.code === val || item.name === val
      // }).code
      // row.checkitem_name = this.checkItemSelectArr.find(item => {
      //   return item.code === val || item.name === val
      // }).name
    },
    // 新增行
    addRow() {
@@ -700,12 +718,25 @@
        cycle: 'D',
        isVisible: 1
      })
      this.checkItemIsCancel = false
    },
    editRow(row) {
      this.tableDataDialogSelected.forEach((item, index) => {
        if (item === row.checkitem_code) {
          this.tableDataDialogSelected.splice(index, 1)
      let flag = false
      this.tableDataDialog.forEach((item, index) => {
        if (item.isVisible === 1) {
          flag = true
        }
      })
      if (flag) {
        return this.$message.info('请先确认或取消其它行!')
      }
      this.checkItemIsCancel = false
      this.checkItemSelectArr.splice(0, 0, {
        code: row.checkitem_code,
        name: row.checkitem_name,
        description: row.checkitem_descr
      })
      this.tableDataDialog.forEach((item, index) => {
@@ -722,30 +753,45 @@
      })
    },
    delRow(row) {
      console.log(row)
      this.checkItemSelectArr.splice(0, 0, {
        code: row.checkitem_code,
        name: row.checkitem_name,
        description: row.checkitem_descr
      })
      this.tableDataDialog.forEach((item, index) => {
        if (item.checkitem_code === row.checkitem_code) {
          this.tableDataDialog.splice(index, 1)
        }
      })
      this.tableDataDialogSelected.forEach((item, index) => {
        if (item === row.checkitem_code) {
          this.tableDataDialogSelected.splice(index, 1)
    },
    saveRow(row) {
      if (row.checkitem_code === '' && row.checkitem_name === '') {
        return this.$message.info('点检部位不能为空!')
      }
      row.isVisible = 0
      this.checkItemSelectArr.forEach((item, index) => {
        if (item.code === row.checkitem_code) {
          this.checkItemSelectArr.splice(index, 1)
        }
      })
    },
    saveRow(row) {
      if (this.tableDataDialogSelected.includes(row.checkitem_code)) {
        return this.$message.info('点检部位不能选择相同!')
      }
      this.tableDataDialogSelected.push(row.checkitem_code)
      row.isVisible = 0
      console.log(this.tableDataDialog)
    },
    cancelRow(row) {
      // this.checkItemSelectArr.forEach((item, index) => {
      //   if (item.code === row.checkitem_code) {
      if (this.checkItemIsCancel) {
        this.checkItemSelectArr.splice(0, 0, {
          code: row.checkitem_code,
          name: row.checkitem_name,
          description: row.checkitem_descr
        })
      }
      this.JYIsCancel = true
      // }
      // })
      this.tableDataDialog.forEach((item, index) => {
        if (item.checkitem_code === row.checkitem_code && item.isVisible === 1) {
          console.log(item)
          row.isVisible = 0
          this.tableDataDialog.splice(index, 1)
        }