Blame view

src/views/xxba/yhjgba/components/clxx/dialog/clxxDetailDialog.vue 5.4 KB
1 2 3
<!--
 * @Description:
 * @Autor: renchao
4
 * @LastEditTime: 2023-09-15 15:38:53
5 6 7
-->
<template>
  <div class="clmlmx-box">
8 9
    <lb-table :column="column" :key="key" row-key="bsmMaterial" ref="listTable" :heightNumSetting="true" :calcHeight="500" :pagination="false"
      :data="tableData">
10 11
    </lb-table>
    <div class="text-center">
12
      <el-button @click="handleCancel">取消</el-button>
13
      <el-button type="primary" @click="handleSubmit" :loading="loading">保存</el-button>
14 15 16 17 18
    </div>
  </div>
</template>
<script>
  import store from '@/store/index.js'
19
  import Sortable from 'sortablejs'
20
  import { ywPopupCacel } from "@/utils/popup.js";
21
  import { editCompanyMaterialList } from "@/api/company.js";
22 23 24 25 26 27 28 29 30 31 32 33
  export default {
    props: {
      formData: {
        type: Object,
        default: () => {
          return {}
        }
      }
    },
    data () {
      return {
        loading: false,
34
        sortable: null,
35 36 37 38 39
        column: [
          {
            label: "材料名称",
            render: (h, scope) => {
              return (
40 41 42 43 44 45 46 47 48
                <el-input value={scope.row.clmc} onInput={(val) => { scope.row.clmc = val }}></el-input>
              )
            }
          },
          {
            label: "材料编码",
            render: (h, scope) => {
              return (
                <el-input value={scope.row.clbm} onInput={(val) => { scope.row.clbm = val }}></el-input>
49 50 51 52 53 54 55 56
              )
            }
          },
          {
            label: "材料类型",
            width: "110",
            render: (h, scope) => {
              return (
57 58 59 60 61 62 63 64 65 66
                <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>
67 68 69 70
              )
            }
          },
          {
71
            label: "页数",
72 73
            width: "80",
            render: (h, scope) => {
74
              if (scope.row.count && scope.row.count > 0) {
75 76
                return (
                  <div>
77
                    <span>{scope.row.count}</span>
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
                  </div>
                );
              } else {
                return (
                  <div>
                    <span>0</span>
                  </div>
                );
              }
            },
          },
          {
            label: "操作",
            width: "100",
            render: (h, scope) => {
              return (
94 95 96
                <el-button
                  type="text"
                  icon="el-icon-delete"
97
                  disabled={scope.row.count != 0}
98 99 100 101 102 103
                  onClick={() => {
                    this.handleDelete(scope.$index, scope.row);
                  }}
                >
                  删除
                </el-button>
104 105 106 107 108 109 110 111
              )
            }
          }
        ],
        key: 0,
        tableData: []
      }
    },
112 113
    mounted () {
      this.initSort()
114
      this.tableData = _.cloneDeep(this.formData.data)
115 116 117 118 119 120
    },
    beforeDestroy () {
      if (this.sortable) {
        this.sortable.destroy();
      }
    },
121 122 123 124 125 126 127 128 129 130
    watch: {
      'formData.data': {
        handler: function (val, oldVal) {
          this.tableData = _.cloneDeep(val)
        },
        immediate: true,
        deep: true
      }
    },
    methods: {
131 132 133
      handleCancel () {
        ywPopupCacel()
      },
134 135
      handleSubmit () {
        this.loading = true
136
        store.dispatch('user/reWorkFresh', false)
137
        editCompanyMaterialList(this.tableData, this.formData.bsmCompany).then(res => {
138 139 140 141 142 143 144
          this.loading = false
          if (res.code == 200) {
            this.$message({
              message: '保存成功',
              type: 'success'
            })
            store.dispatch('user/reWorkFresh', true)
145
            ywPopupCacel()
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
          }
        }).catch(() => {
          this.loading = false
        })
      },
      /**
       * @description: 材料目录删除
       * @param {*} index
       * @param {*} row
       * @author: renchao
       */
      handleDelete (index, row) {
        this.$confirm('此操作将永久删除该 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
163
          this.tableData.splice(index, 1);
164 165 166 167 168 169
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
170 171 172 173 174 175 176 177 178 179 180 181 182
      },
      initSort () {
        const el = this.$refs.listTable.$el.querySelectorAll('.el-table__body-wrapper > table > tbody')[0]
        this.sortable = Sortable.create(el, {
          ghostClass: 'sortable-ghost',
          setData: function (dataTransfer) {
            dataTransfer.setData('Text', '')
          },
          onEnd: evt => {
            const targetRow = this.tableData.splice(evt.oldIndex, 1)[0];
            this.tableData.splice(evt.newIndex, 0, targetRow);
          }
        })
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
      }
    }
  }
</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>