zhangherong
2025-05-27 5e31103125cb1ff33be29ec400c9c8d007448462
src/views/tms/stocktakingBound/modules/ToolsStocktakingBoundModal.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,515 @@
<template>
  <a-modal :title="title" :width="1500" :height="1500" :visible="visible" :maskClosable="false" @ok="handleOk"
           cancelText="关闭"
           @cancel="handleCancel" :confirmLoading="confirmLoading">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="盘点单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderCode">
              <a-input :disabled="true" v-model="model.orderCode" placeholder="系统自动生成"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="盘点类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approvalStatus">
              <j-dict-select-tag dictCode="stocktakingType" placeholder="请选择盘点类型" v-model="model.stocktakingType"
                                 :disabled="disableSubmit"></j-dict-select-tag>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="盘点名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stocktakingName">
              <a-input v-model="model.stocktakingName" placeholder="请输入盘点名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="审核人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reviewer">
              <j-select-user-by-dep :disabled="disableSubmit" v-model="model.reviewer" :store="'username'"
                                    :text="'realname'" :multi="false" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="盘点时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inventoryTime">
              <j-date placeholder="请选择盘点时间" date-format="YYYY-MM-DD HH:mm:ss" v-model="model.inventoryTime"
                      style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item v-show="addShow" label="经手人" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="handler">
              <j-dict-select-tag dictCode="sys_user,realname,id" placeholder="请选择经手人" v-model="model.handler"
                                 :disabled="disableSubmit" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item v-show="addShow" label="审核状态" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="approvalStatus">
              <j-dict-select-tag dictCode="approval_status" placeholder="请选择审核状态" v-model="model.approvalStatus"
                                 :disabled="true"></j-dict-select-tag>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item v-show="addShow" label="审核意见" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="approvalOpinion">
              <a-input v-model="model.approvalOpinion" placeholder="请输入审核意见" type="textarea"
                       :disabled="model.approvalStatus==1"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item  v-show="addShow" label="审核时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inventoryTime">
              <j-date placeholder="请选择审核时间" date-format="YYYY-MM-DD HH:mm:ss" v-model="model.approvalDate"
                      style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注" type="textarea"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
    <a-button type="primary" :style="{ marginRight: '8px', marginBottom: '8px' }" :loading="confirmLoading"
              :disabled="disableSubmit" @click="selectTools()">工具明细
    </a-button>
    <a-table ref="table" bordered size="middle" rowKey="id" :columns="columns" :dataSource="dataSource"
             :scroll="{x:true}">
      <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 == 'practicalQuantity'" :min="0"
                        :max="99999"
                        @change="(e) => handleChange(e, record.key, col, index)" style="width: 100%;" />
        <a-input-number :value="text" v-if="col.dataIndex == 'differenceValue'" :min="0" :max="99999"
                        :disabled="true" @change="(e) => handleChange(e, record.key, col, index)"
                        style="width: 100%;" />
        <j-dict-select-tag :value="text" v-if="col.dataIndex == 'surplusDeficit'"
                           dictCode="surplusDeficit"
                           :disabled="true"
                           style="width: 100%;"
                           @change="(e) => handleChange(e, record.key, col, index)" />
        <!--        <j-dict-select-tag :value="text" v-if="col.dataIndex == 'classifyId'"-->
        <!--                           dictCode="tms_tools_classify,type_name,id"-->
        <!--                           style="width: 100%;"-->
        <!--                           :disabled="true"-->
        <!--                           @change="(e) => handleChange(e, record.key, col, index)" />-->
        <j-date
          :value="text"
          v-if="col.dataIndex == 'stocktakingDate'"
          placeholder="选择盘库时间"
          @change="(e) => handleChange(e, record.key, col, index)"
          style="width: 100%;"
        />
        <a-textarea
          v-if="col.dataIndex == 'remark'"
          :disabled="disableSubmit"
          style="margin: -5px 0"
          :value="text"
          @change="(e) => handleChange(e.target.value, record.key, col, index)"
        />
      </template>
      <span slot="action" slot-scope="text, record, index">
        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(text, record, index)">
          <a :disabled="disableSubmit">删除</a>
        </a-popconfirm>
      </span>
    </a-table>
    <template slot="footer">
      <a-button :style="{ marginRight: '8px' }" @click="handleCancel()">
        å…³é—­
      </a-button>
      <a-button @click="handleOk()" :disabled="disableSubmit" type="primary" :loading="confirmLoading">确定</a-button>
    </template>
    <tool-selector-modal ref="toolsModalForm"></tool-selector-modal>
  </a-modal>
</template>
<script>
import { getAction, postAction, requestPut } from '@/api/manage'
import JMultiSelectTag from '@/components/dict/JMultiSelectTag'
import Tooltip from 'ant-design-vue/es/tooltip'
import ToolSelectorModal from '@views/tms/stocktakingBound/modules/ToolSelectorModal.vue'
export default {
  name: 'ToolsStocktakingBoundModal',
  components: {
    ToolSelectorModal,
    JMultiSelectTag,
    Tooltip
  },
  data() {
    return {
      addShow: true,
      model: {},
      formDisabled: false,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0
      },
      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: 'bookQuantity',
          align: 'center'
        },
        {
          title: '可用数量',
          width: 150,
          dataIndex: 'availableQuantity',
          align: 'center'
        },
        {
          title: '实盘数量',
          dataIndex: 'practicalQuantity',
          align: 'center',
          width: 150,
          scopedSlots: { customRender: 'practicalQuantity' }
        },
        {
          title: '差异值',
          dataIndex: 'differenceValue',
          align: 'center',
          width: 150,
          scopedSlots: { customRender: 'differenceValue' }
        },
        {
          title: '盘亏盘盈',
          width: 150,
          dataIndex: 'surplusDeficit',
          align: 'center',
          scopedSlots: { customRender: 'surplusDeficit' }
        },
        {
          title: '盘库时间',
          width: 150,
          dataIndex: 'stocktakingDate',
          align: 'center',
          scopedSlots: { customRender: 'stocktakingDate' }
        },
        {
          title: '备注',
          width: 150,
          dataIndex: 'remark',
          align: 'center',
          scopedSlots: { customRender: 'remark' }
        },
        {
          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: 'action',
          scopedSlots: { customRender: 'action' },
          align: 'center'
        }
      ],
      title: '操作',
      visible: false,
      disableSubmit: false,
      codeDisable: true,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 }
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {
        orderCode: [
          { required: true, message: '请输入盘点单号!' }
        ],
        handler: [
          { required: true, message: '请输入经手人!' }
        ],
        stocktakingName: [
          { required: true, message: '请输入盘点名称!' }
        ],
        approvalStatus: [
          { required: true, message: '请输入审核状态!' }
        ],
        inventoryTime: [
          { required: true, message: '请输入盘点时间!' }
        ]
      },
      url: {
        add: '/tms/toolsStocktakingBound/add',
        edit: '/tms/toolsStocktakingBound/edit',
        queryDetailList: '/tms/toolsStocktakingBound/listToolsStocktakingBoundControllerDetailsByMainId'
      },
      dataSource: []
    }
  },
  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,
          toolMaterial: data[i].toolMaterial,
          partMaterial: data[i].partMaterial,
          bookQuantity: data[i].totalCount,
          supplierId: data[i].supplierId,
          goodsShelvesId: data[i].positionCode
        })
      }
    })
  },
  methods: {
    selectTools: function() {
      let ids = []
      for (let i = 0; i < this.dataSource.length; i++) {
        ids.push(this.dataSource[i].partId)
      }
      this.$refs.toolsModalForm.showModals(ids)
      this.$refs.toolsModalForm.title = '选择工具信息'
      this.$refs.toolsModalForm.disableSubmit = false
    },
    add() {
      this.addShow = false
      this.edit()
    },
    edit(record) {
      console.log(record)
      console.log(this.auditFlag)
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      getAction(this.url.queryDetailList, {
        stocktakingBoundId: 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
        }
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleCancel() {
      this.model = {}
      this.dataSource = []
      this.close()
    },
    handleOk() {
      const that = this
      let data = that.dataSource
      for (let i = 0; i < data.length; i++) {
        if (data[i].practicalQuantity == undefined || data[i].practicalQuantity == null || data[i].practicalQuantity == '') {
          that.$message.warning('请输入第' + (i + 1) + '行的实盘数量数据!')
          return false
        }
      }
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let formData = Object.assign(this.model, values)
          if (that.dataSource.length === 0) {
            that.$message.warning('请选择工具!')
            that.confirmLoading = false
            return
          }
          formData.toolsStocktakingBoundDetailList = that.dataSource
          // formData.status = '0';
          let obj
          if (!this.model.id) {
            obj = postAction(this.url.add, formData)
          } else {
            obj = requestPut(this.url.edit, formData, { id: this.model.id })
          }
          obj.then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
              that.close()
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        }
      })
    },
    handleDelete(text, record, index) {
      this.dataSource.splice(index, 1)
    },
    handleChange(value, key, column, index) {
      let that = this
      const temp = [...that.dataSource]
      const target = temp.filter(item => key === item.key)[index]
      if (target) {
        // if (column.dataIndex == 'practicalQuantity') {
        //   target[column.dataIndex] = value
        // }
        if (column.dataIndex === 'practicalQuantity') {
          target[column.dataIndex] = value
          // è®¡ç®—差异值
          target.differenceValue = value - target.availableQuantity
          // æ ¹æ®å·®å¼‚值判断盘亏盘盈
          if (target.differenceValue > 0) {
            target.surplusDeficit = 1
          } else if (target.differenceValue < 0) {
            target.surplusDeficit = 2
          } else {
            target.surplusDeficit = 0
          }
        }
        if (column.dataIndex == 'differenceValue') {
          target[column.dataIndex] = value
        }
        if (column.dataIndex == 'classifyId') {
          target[column.dataIndex] = value
        }
        if (column.dataIndex == 'surplusDeficit') {
          target[column.dataIndex] = value  // å‡è®¾ value æ˜¯å­—符串格式的日期
        }
        if (column.dataIndex == 'stocktakingDate') {
          target[column.dataIndex] = value  // å‡è®¾ value æ˜¯å­—符串格式的日期
        }
        if (column.dataIndex === 'remark') {
          // æ³¨æ„è¿™é‡Œä½¿ç”¨çš„æ˜¯ e.target.value
          target[column.dataIndex] = value
        }
        that.dataSource = temp
      }
    }
  }
}
</script>
<style lang="less" scoped>
.frozenRowClass {
  color: #c9c9c9;
}
.fontweight {
  font-weight: bold;
}
.ant-btn {
  padding: 0 10px;
  margin-left: 3px;
}
.ant-form-item-control {
  line-height: 0px;
}
/** ä¸»è¡¨å•行间距 */
.ant-form .ant-form-item {
  margin-bottom: 10px;
}
/** Tab页面行间距 */
.ant-tabs-content .ant-form-item {
  margin-bottom: 0px;
}
</style>