zhangherong
2025-05-27 5e31103125cb1ff33be29ec400c9c8d007448462
src/views/tms/lossBound/modules/LossboundModal.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,434 @@
<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="报损单单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderCode">
              <j-input v-model="model.orderCode" placeholder="系统自动生成" :disabled="true"></j-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="报损人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="losser">
              <j-dict-select-tag :disabled="disableSubmit"
                                 v-model="model.losser" dictCode="sys_user,realname,id"
                                 placeholder="请选择" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="报损时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lossTime">
              <j-date placeholder="请选择报损时间" :disabled="disableSubmit" date-format="YYYY-MM-DD HH:mm:ss" v-model="model.lossTime"
                      style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="审核人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reviewer">
              <!--              <j-dict-select-tag :disabled="disableSubmit"-->
              <!--                                 v-model="model.reviewer" dictCode="sys_user,realname,id"-->
              <!--                                 placeholder="请选择" />-->
              <j-select-user-by-dep :disabled="disableSubmit" v-model="model.reviewer" :store="'username'"
                                    :text="'realname'" :multi="false" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item v-if="addShow" label="经手人" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="handler">
              <j-dict-select-tag :disabled="disableSubmit"
                                 v-model="model.handler" dictCode="sys_user,realname,id"
                                 placeholder="请选择" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item v-if="addShow" label="审核状态" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="orderStatus">
              <j-dict-select-tag type="list" v-model="model.orderStatus" dictCode="out_bill_status"
                                 placeholder="请选择审核状态" disabled />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item v-if="addShow" label="审核时间" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="approvalDate">
              <j-date placeholder="请选择审核时间"  :disabled="disableSubmit" date-format="YYYY-MM-DD HH:mm:ss" v-model="model.approvalDate"
                      style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item v-if="addShow" label="审核意见" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="approvalOpinion">
              <a-input v-model="model.approvalOpinion" placeholder="请输入审核意见" disabled></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea :disabled="disableSubmit" v-model="model.remark" rows="4" placeholder="请输入备注" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="报损原因" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lossReason">
              <a-textarea :disabled="disableSubmit" v-model="model.lossReason" rows="4" placeholder="请输入备注" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
    <a-button type="primary" :style="{ marginBottom: '8px' }"  :disabled="disableSubmit" @click="selectTools">
      é€‰æ‹©å·¥å…·
    </a-button>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :scroll="{x:true}"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :rowSelection="null"
      @change="handleTableChange">
      <template v-for="col in columns" :slot="col.dataIndex" slot-scope="text, record, index">
        <a-input-number :disabled="disableSubmit" :value="text" v-if="col.dataIndex == 'lossNumber'" :min="0"
                        :max="99999"
                        @change="(e) => handleChange(e, record.key, col, index)" style="width: 100%;" />
        <a-textarea
          v-if="col.dataIndex == 'lossReason'"
          :disabled="disableSubmit"
          style="margin: -5px 0"
          :value="text"
          @change="(e) => handleChange(e.target.value, record.key, col, index)"
        />
      </template>
      <span slot="action" v-if="disableSubmit === false" slot-scope="text, record, index">
        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record, index)">
          <a>删除</a>
        </a-popconfirm>
      </span>
    </a-table>
    <template slot="footer" v-if="disableSubmit === false">
      <a-button :style="{ marginRight: '8px' }" @click="handleCancel">关闭</a-button>
      <a-button @click="handleOk" :disabled="isDisabled" type="primary">确定</a-button>
    </template>
    <j-select-lossbound-tool-modal ref="selectLossBoundToolModal"></j-select-lossbound-tool-modal>
  </j-modal>
</template>
<script>
import { httpAction } from '@/api/manage'
import LossboundDetailList from '../LossboundDetailList.vue'
import JSelectLossboundToolModal from './JSelectLossboundToolModal.vue'
import { getAction } from '../../../../api/manage'
export default {
  name: 'LossboundModal',
  components: {
    LossboundDetailList,
    JSelectLossboundToolModal
  },
  data() {
    return {
      title: '',
      width: 1200,
      visible: false,
      disableSubmit: false,
      isDisabled: false,
      addShow: true,
      selectBorrowTool: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      //表格参数
      ipagination: {
        current: 1,
        pageSize: 10,
        total: 0
      },
      dataSource: [],
      loading: false,
      // è¡¨å¤´
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          },
          width: 50
        },
        {
          title: '刀具编号',
          dataIndex: 'toolCode',
          align: 'center',
          width: 150
        },
        {
          title: '工具类型',
          dataIndex: 'applicationType',
          align: 'center',
          width: 150
        },
        {
          title: '报损原因',
          width: 150,
          dataIndex: 'lossReason',
          align: 'center',
          scopedSlots: { customRender: 'lossReason' }
        },
        {
          title: '报损数量',
          dataIndex: 'lossNumber',
          align: 'center',
          width: 150,
          scopedSlots: { customRender: 'lossNumber' }
        },
        {
          title: '中文名称',
          dataIndex: 'chineseName',
          width: 150,
          align: 'center'
        },
        {
          title: '型号/图号',
          dataIndex: 'toolModel',
          width: 150,
          align: 'center'
        },
        {
          title: '刀具材料',
          width: 150,
          dataIndex: 'toolMaterial',
          align: 'center'
        },
        {
          title: '零件材料',
          width: 150,
          dataIndex: 'partMaterial',
          align: 'center'
        },
        {
          title: '厂家',
          width: 150,
          dataIndex: 'supplierId',
          align: 'center'
        },
        {
          title: '存储位置',
          width: 150,
          dataIndex: 'goodsShelvesId',
          align: 'center'
        },
        {
          title: '备注',
          width: 150,
          dataIndex: 'remark',
          align: 'center'
        },
        {
          title: '操作',
          width: 150,
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
          align: 'center'
        }
      ],
      confirmLoading: false,
      validatorRules: {
        lossReason: [
          { required: true, message: '请输入报损原因' }
        ],
        lossTime: [
          { required: true, message: '请输入报损时间!' }
        ],
        losser: [
          { required: true, message: '请输入报损人!' }
        ],
      },
      url: {
        list: '/tms/toolsLossBound/listlossboundDetailByMainId',
        add: '/tms/toolsLossBound/addTotal',
        edit: '/tms/toolsLossBound/editTotal'
      }
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  mounted() {
    this.$bus.$on('selectionRows', (data) => {
      for (let i = 0; i < data.length; i++) {
        this.dataSource.push({
          toolId: data[i].id,
          toolCode: data[i].toolCode,
          classifyId: data[i].classifyId,
          applicationType: data[i].applicationType_dictText,
          chineseName: data[i].chineseName,
          toolModel: data[i].toolModel,
          material: data[i].material,
          supplierId: data[i].supplierId,
          goodsShelvesId: data[i].positionCode,
          toolMaterial: data[i].toolMaterial,
          partMaterial: data[i].partMaterial
        })
      }
      this.ipagination.total = this.dataSource.length
    })
  },
  methods: {
    handleDelete(record, index) {
      this.dataSource.splice(index, 1)
    },
    handleChange(value, key, column, index) {
      console.log(value, key, column, index)
      const temp = [...this.dataSource]
      const target = temp.filter(item => key === item.key)[index]
      if (target) {
        target[column.dataIndex] = value
        this.dataSource = temp
        if (column.dataIndex === 'lossNumber') {
          target[column.dataIndex] = value
        }
        if (column.dataIndex === 'lossReason') {
          target[column.dataIndex] = value
        }
        this.dataSource = temp
      }
    },
    selectTools: function() {
      let ids = []
      for (let i = 0; i < this.dataSource.length; i++) {
        ids.push(this.dataSource[i].id)
      }
      this.$refs.selectLossBoundToolModal.showModal(ids)
      this.$refs.selectLossBoundToolModal.title = '选择工具信息'
      this.$refs.selectLossBoundToolModal.disableSubmit = false
    },
    add() {
      this.addShow = false
      this.edit({}) // ä¼ å…¥ç©ºå¯¹è±¡ä½œä¸ºé»˜è®¤å€¼
      this.dataSource = []
    },
    edit(record) {
      console.log(record)
      if (record && record.id) {
        this.model = Object.assign({}, record)
        this.visible = true
        getAction(this.url.list, {
          lossBoundId: record.id,
          pageNo: 1,
          pageSize: 99999
        }).then((res) => {
          if (res.success) {
            console.log(res.result.records)
            this.dataSource = res.result.records
          } else {
            this.dataSource = null
          }
        })
      } else {
        this.model = {} // å¦‚果是新增模式,则初始化 model
        this.visible = true
        this.dataSource = [] // æ¸…空数据源
      }
    },
    close() {
      this.$emit('close')
      this.addShow = true
      this.selectBorrowTool = false
      this.visible = false
      this.$refs.form.clearValidate()
    },
    handleTableChange(pagination, filters, sorter) {
      this.ipagination = pagination
    },
    handleOk() {
      const that = this
      // è§¦å‘表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          this.model.toolsLossBoundDetailList = this.dataSource
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
            that.close()
          })
        } else {
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>