clxxDetailDialog.vue 8.56 KB
<!--
 * @Description:
 * @Autor: renchao
 * @LastEditTime: 2023-09-12 15:18:52
-->
<template>
  <div class="clmlmx-box">
    <lb-table :column="column" :key="key" :heightNumSetting="true" :calcHeight="500" :pagination="false" :data="tableData">
    </lb-table>
    <div class="text-center">
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleSubmit" :loading="loading">保存</el-button>
    </div>
  </div>
</template>
<script>
  import Vue from 'vue'
  import store from '@/store/index.js'
  import { ywPopupCacel } from "@/utils/popup.js";
  import { InitClml, updateClml, deleteSjClml, moveClml } from "@/api/clxx.js";
  export default {
    props: {
      formData: {
        type: Object,
        default: () => {
          return {}
        }
      }
    },
    data () {
      return {
        loading: false,
        column: [
          {
            width: '50',
            renderHeader: (h, scope) => {
              return <div> {
                <i class="el-icon-plus pointer" onClick={() => { this.handleAdd() }}></i>
              }
              </div>
            },
            render: (h, scope) => {
              return (
                <div>
                  {
                    <i class="el-icon-minus pointer" onClick={() => { this.handleDelete(scope.$index, scope.row) }}></i>
                  }
                </div>
              )
            }
          },
          {
            label: "材料名称",
            render: (h, scope) => {
              return (
                <el-input value={scope.row.clmc} onInput={(val) => { scope.row.clmc = val }}></el-input>
              )
            }
          },
          {
            label: "材料类型",
            width: "110",
            render: (h, scope) => {
              return (
                <el-select value={scope.row.cllx}
                  onChange={(val) => { scope.row.cllx = val }}>
                  {
                    store.getters.dictData['A40'].map(option => {
                      return (
                        <el-option label={option.dname} value={option.dcode}></el-option>
                      )
                    })
                  }
                </el-select>
              )
            }
          },
          {
            label: "份数",
            width: "50",
            render: (h, scope) => {
              return (
                <el-input value={scope.row.sjsl} onInput={(val) => { scope.row.sjsl = val }}></el-input>
              )
            }
          },
          {
            prop: "smzt",
            label: "扫描状态",
            width: "80",
            render: (h, scope) => {
              if (scope.row.children && scope.row.children.length > 0) {
                return (
                  <div>
                    <span>已扫描</span>
                  </div>
                );
              } else {
                return (
                  <div>
                    <span>未扫描</span>
                  </div>
                );
              }
            },
          },
          {
            label: "扫描页数",
            width: "80",
            render: (h, scope) => {
              if (scope.row.count && scope.row.count > 0) {
                return (
                  <div>
                    <span>{scope.row.count}</span>
                  </div>
                );
              } else {
                return (
                  <div>
                    <span>0</span>
                  </div>
                );
              }
            },
          },
          {
            label: "操作",
            width: "100",
            render: (h, scope) => {
              return (
                <div>
                  <el-button
                    type="text"
                    disabled={scope.$index == 0}
                    onClick={() => {
                      this.moveUpward(scope.$index, scope.row);
                    }}
                  >
                    上移
                  </el-button>
                  <el-button
                    type="text"
                    disabled={scope.$index + 1 == this.tableData.length}
                    onClick={() => {
                      this.moveDown(scope.$index, scope.row);
                    }}
                  >
                    下移
                  </el-button>
                </div >
              )
            }
          }
        ],
        key: 0,
        tableData: []
      }
    },
    watch: {
      'formData.data': {
        handler: function (val, oldVal) {
          this.tableData = _.cloneDeep(val)
        },
        immediate: true,
        deep: true
      }
    },
    methods: {
      handleCancel () {
        ywPopupCacel()
      },
      handleAdd () {
        this.tableData.push({
          clmc: '',
          cllx: '1',
          sjsl: '',
          smzt: '',
          count: 0
        })
      },
      handleSubmit () {
        this.loading = true
        updateClml(this.tableData).then(res => {
          this.loading = false
          if (res.code == 200) {
            this.$message({
              message: '保存成功',
              type: 'success'
            })
            this.$popupCacel()
            store.dispatch('user/reWorkFresh', true)
          }
        }).catch(() => {
          this.loading = false
        })
      },
      /**
       * @description: 材料目录明细初始化
       * @author: renchao
       */
      clmlInitList () {
        return new Promise(resolve => {
          this.unitData = this.$parent.unitData;
          var formdata = new FormData();
          formdata.append("bsmSlsq", Vue.prototype.$currentRoute.query.bsmSlsq);
          InitClml(formdata).then((res) => {
            if (res.code == 200) {
              resolve(res.code)
              if (res.result && res.result.length > 0) {
                this.tableData = res.result;
              } else {
                this.tableData = []
              }
            } else {
              this.$message.error(res.message)
            }
          })
        })
      },
      /**
       * @description: 上移
       * @param {*} index
       * @param {*} row
       * @author: renchao
       */
      moveUpward (index, row) {
        let obj = {
          xh: row.xh,
          bsmSlsq: row.bsmSlsq,
          moveDirection: "UP",
        };
        // 接口待调
        moveClml(obj).then(async (res) => {
          if (res.code == 200) {
            let res = await this.clmlInitList()
            if (res == 200) {
              this.$message({
                message: '上移成功',
                type: 'success'
              })
            }
          } else {
            this.$message.error(res.message);
          }
        })
      },
      /**
       * @description: 下移
       * @param {*} index
       * @param {*} row
       * @author: renchao
       */
      moveDown (index, row) {
        let obj = {
          xh: row.xh,
          bsmSlsq: row.bsmSlsq,
          moveDirection: "DOWN",
        }
        // 接口待调
        moveClml(obj).then(async (res) => {
          if (res.code == 200) {
            let res = await this.clmlInitList()
            if (res == 200) {
              this.$message({
                message: '下移成功',
                type: 'success'
              })
            }
          } else {
            this.$message.error(res.message);
          }
        })
      },
      /**
       * @description: 材料目录删除
       * @param {*} index
       * @param {*} row
       * @author: renchao
       */
      handleDelete (index, row) {
        let that = this
        this.$confirm('此操作将永久删除该 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteSjClml({ sjBsm: row.bsmSj }).then(async (res) => {
            if (res.code == 200) {
              let res = await that.clmlInitList()
              if (res == 200) {
                that.$message({
                  message: "删除成功",
                  type: "success"
                })
              }
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      }
    }
  }
</script>
<style scoped lang='scss'>
  @import "~@/styles/mixin.scss";
  .clmlmx-box {
    margin: 0 auto;
    .title {
      text-align: center;
      height: 60px;
      line-height: 60px;
      border: 1px solid #dfe6ec;
      font-size: 20px;
      background: #81d3f81a;
      margin-bottom: -1px;
    }
  }
</style>