<!--
 * @Date: 2023-09-07 10:35:02
 * @LastEditors: 陈禹琨 chenyukun@prolog-int.com
 * @LastEditTime: 2023-09-07 10:49:10
 * @FilePath: /eis-3.0-fe-pc/src/views/EIS/project/qingniuEIS/takeStock/sxStoreCheck/index.vue
 * @Description: cyk
-->
<template>
  <div>
    <workFlow
      ref="workFlow"
      :formData="formData"
      :title="pageTitie"
      :disableItem="disableItem"
      :formItems="formItems"
      :btnEventArray="btnEventArray"
    ></workFlow>
  </div>
</template>
<script>
import { formItems } from './js/config'
import workFlow from '../../components/workFlow/index.vue'
import { getCheckContainerStore, checkConfirm } from './api'
import { setStationCode, getStationCode } from '@/views/util'

export default {
  components: {},
  name: 'sxStoreCheck',
  components: { workFlow },
  data() {
    return {
      disableItem: [
        'barcode',
        'goodsName',
        'lotFactName',
        'goodsOwnerName',
        'goodsType',
        'lotNo',
        'plantyQty',
        'packSize',
        'goodsStatusDecr',
        'approveDocNo',
        'prodDate',
        'validDate',
      ],
      formItems: formItems(this),
      btnEventArray: [
        {
          label: '盘点确认',
          type: 'primary',
          disabled: false,
          click: () => {
            this.checkConfirm()
          },
        },
      ],
      formData: {},
      pageTitie: '四向库盘点执行',
    }
  },
  created() {},
  destroyed() {},
  watch: {},
  methods: {
    checkApi(event, KeyboardEvent, vonde) {
      let value = KeyboardEvent.target['_value']
      let data = this.$refs.workFlow.$refs.formTarget.form.getFieldsValue()
      const { containerNo } = data
      if (event == 'containerNo') {
        const params = { containerNo }
        getCheckContainerStore(params).then((res) => {
          if (res.success) {
            this.formData = res.data
            this.$message.success(res.message)
          } else {
            this.$message.error(res.message)
          }
        })
      }
    },
    numEvent(event, form, num) {
      let qty = (form.getFieldsValue().qty ? form.getFieldsValue().qty : 0) + num
      form.setFieldsValue({ qty })
    },
    checkConfirm() {
      let data = this.$refs.workFlow.$refs.formTarget.form.getFieldsValue()
      const { containerNo, qty } = data
      var r = /^\+?[1-9][0-9]*$/ //正整数
      let flag = r.test(qty)
      if (!flag) {
        this.$message.error('实际数量必须是正整数')
        return
      }
      const operator = this.$store.getters.userInfo.enterpriseId
      const params = { ...data, operator }
      this.btnEventArray[0].disabled = true
      checkConfirm(params).then((res) => {
        this.btnEventArray[0].disabled = false
        if (res.success) {
          this.$refs.workFlow.$refs.formTarget.form.resetFields()
          this.$message.success(res.message)
        } else {
          this.$message.error(res.message)
        }
      })
    },
  },
}
</script>
<style lang="less">
.ant-input.ant-input-disabled {
  color: #108ee9;
}
</style>
