index.vue 5.71 KB
Newer Older
huhaiqing's avatar
huhaiqing committed
1 2
<template>
  <div>
huhaiqing's avatar
huhaiqing committed
3
    <el-form ref="cabinetForm" :rules="rules" :model="cabinetObj" label-width="80px">
4 5
      <el-form-item :label="$t('到仓时间')">
        <el-date-picker type="datetime" :placeholder="$t('请选择日期')" v-model="cabinetObj.ldInWarehouseTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
huhaiqing's avatar
huhaiqing committed
6
      </el-form-item>
7 8
      <el-form-item :label="$t('仓库')">
        <el-select v-model="cabinetObj.ldWarehouseType" :placeholder="$t('请选择仓库')" filterable>
huhaiqing's avatar
huhaiqing committed
9
          <el-option v-for="warehouse in $attrs.warehouseList" :key="warehouse.id" :label="$l(warehouse,'title')" :value="warehouse.id"></el-option>
huhaiqing's avatar
huhaiqing committed
10 11
        </el-select>
      </el-form-item>
12
      <el-form-item :label="$t('装柜时间')" prop="ldBoxTime">
13 14
        <!-- {{cabinetObj.ldBoxTime?new Date(cabinetObj.ldBoxTime).format('yyyy-MM-dd hh:mm:ss'):new Date().format('yyyy-MM-dd hh:mm:ss')}} -->
        <el-date-picker type="datetime" :placeholder="$t('请选择日期')" v-model="cabinetObj.ldBoxTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
huhaiqing's avatar
huhaiqing committed
15
      </el-form-item>
16 17
      <el-form-item :label="$t('出仓时间')">
        <el-date-picker type="datetime" :placeholder="$t('请选择日期')" v-model="cabinetObj.ldOutWarehouseTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
huhaiqing's avatar
huhaiqing committed
18
      </el-form-item>
19
      <el-form-item :label="$t('装柜图片')">
zhoutong's avatar
zhoutong committed
20
        <ImageUpload :limit="1" :isShowTip=false v-model="cabinetObj.ldPictures" @input="saveImage" />
huhaiqing's avatar
huhaiqing committed
21 22 23 24
      </el-form-item>
    </el-form>

    <!-- 开始装柜 -->
25
    <el-dialog :title="$t('开始装柜')" :visible.sync="dialogVisible" fullscreen :modal-append-to-body=false append-to-body>
26
      <startPacking v-bind="$attrs" v-if="dialogVisible" v-on="$listeners" @closeDialog1="closeDialog1" />
huhaiqing's avatar
huhaiqing committed
27 28 29 30
    </el-dialog>

    <!-- 操作 -->
    <el-row class="operate-button">
31 32 33 34
      <el-button type="primary" @click="onSubmit(1)">{{$t('保存')}}</el-button>
      <el-button type="success" @click="onSubmit(2)" :disabled="isSeal">{{$t('封柜')}}</el-button>
      <el-button @click="cancel">{{$t('关闭')}}</el-button>
      <el-button type="danger" @click="startCabinet" :disabled="isStartCabinet">{{$t('开始装柜')}}</el-button>
huhaiqing's avatar
huhaiqing committed
35 36 37 38 39 40
    </el-row>
  </div>
</template>

<script>
import startPacking from "./startPacking.vue";
huhaiqing's avatar
huhaiqing committed
41 42
import { cabinetCreate } from "@/api/ecw/boxSea";
import { formatDateStr, serviceMsg } from "../../utils";
huhaiqing's avatar
huhaiqing committed
43
import ImageUpload from "@/components/ImageUpload";
huhaiqing's avatar
huhaiqing committed
44 45 46 47 48 49

/**
 * 装柜
 */
export default {
  name: "cabinet",
huhaiqing's avatar
huhaiqing committed
50
  inheritAttrs: false,
huhaiqing's avatar
huhaiqing committed
51
  components: { startPacking, ImageUpload },
huhaiqing's avatar
huhaiqing committed
52 53 54 55 56
  data() {
    return {
      // 弹窗
      dialogVisible: false,
      // 装柜对象
huhaiqing's avatar
huhaiqing committed
57
      cabinetObj: {},
huhaiqing's avatar
huhaiqing committed
58
      // 校验
zhoutong's avatar
zhoutong committed
59
      rules: {},
huhaiqing's avatar
huhaiqing committed
60 61
    };
  },
huhaiqing's avatar
huhaiqing committed
62 63 64 65 66 67 68 69
  created() {
    const voName = this.$attrs.currNode.voName;
    let oldData = { ...this.$attrs.shipmentObj[voName] };
    oldData = formatDateStr(oldData, [
      "ldInWarehouseTime",
      "ldBoxTime",
      "ldOutWarehouseTime",
    ]);
huhaiqing's avatar
huhaiqing committed
70 71 72 73 74 75 76 77 78

    let pictures = oldData.ldPictures;
    if (oldData.ldPictures) {
      pictures = JSON.parse(oldData.ldPictures);
      if (Array.isArray(pictures)) {
        pictures = pictures.map((item) => item.url).join(",");
      }
    }

huhaiqing's avatar
huhaiqing committed
79 80 81 82
    this.cabinetObj = {
      ...oldData,
      ldWarehouseType:
        oldData.ldWarehouseType === 0 ? undefined : oldData.ldWarehouseType,
huhaiqing's avatar
huhaiqing committed
83
      ldPictures: pictures,
huhaiqing's avatar
huhaiqing committed
84
    };
huhaiqing's avatar
huhaiqing committed
85
  },
huhaiqing's avatar
huhaiqing committed
86 87
  methods: {
    /** 提交 */
huhaiqing's avatar
huhaiqing committed
88
    onSubmit(operateType) {
huhaiqing's avatar
huhaiqing committed
89 90
      this.$refs["cabinetForm"].validate((valid) => {
        if (valid) {
huhaiqing's avatar
huhaiqing committed
91 92 93 94
          if (operateType === 2) {
            const { currNode, shipmentObj } = this.$attrs;
            const status = shipmentObj[currNode.keyName];
            if (status !== 46) {
95
              this.$message.error(this.$t("请先进行装柜->审批->确认封柜"));
huhaiqing's avatar
huhaiqing committed
96 97 98
              return;
            }
          }
huhaiqing's avatar
huhaiqing committed
99 100
          const { ldPictures } = this.cabinetObj;
          let pictures = ldPictures?.split(",") ?? [];
huhaiqing's avatar
huhaiqing committed
101 102 103 104 105 106 107 108 109
          let newPictures = [];
          for (const item of pictures) {
            if (item) {
              newPictures.push({
                type: "image",
                url: item,
              });
            }
          }
huhaiqing's avatar
huhaiqing committed
110

huhaiqing's avatar
huhaiqing committed
111 112 113
          cabinetCreate({
            shipmentId: this.$attrs.shipmentObj.id,
            ...this.cabinetObj,
huhaiqing's avatar
huhaiqing committed
114
            ldPictures: newPictures.length ? JSON.stringify(newPictures) : "",
huhaiqing's avatar
huhaiqing committed
115 116
            operateType,
          }).then((res) => {
huhaiqing's avatar
huhaiqing committed
117 118 119
            serviceMsg(res, this).then(() => {
              this.cancel("submit");
            });
huhaiqing's avatar
huhaiqing committed
120
          });
huhaiqing's avatar
huhaiqing committed
121 122 123
        }
      });
    },
124
    closeDialog1(type) {
huhaiqing's avatar
huhaiqing committed
125 126 127
      this.dialogVisible = false;
      if (type) this.cancel(type);
    },
huhaiqing's avatar
huhaiqing committed
128
    /** 取消 */
huhaiqing's avatar
huhaiqing committed
129 130
    cancel(type) {
      this.$emit("closeDialog", type);
huhaiqing's avatar
huhaiqing committed
131 132 133 134 135
    },
    /** 开始装柜 */
    startCabinet() {
      this.dialogVisible = true;
    },
zhoutong's avatar
zhoutong committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
    //自动保存图片
    saveImage() {
      const { ldPictures } = this.cabinetObj;
      let pictures = ldPictures?.split(",") ?? [];
      let newPictures = [];
      for (const item of pictures) {
        if (item) {
          newPictures.push({
            type: "image",
            url: item,
          });
        }
      }
      cabinetCreate({
        shipmentId: this.$attrs.shipmentObj.id,
        ldPictures: newPictures.length ? JSON.stringify(newPictures) : "",
        operateType: 1,
      }).then(()=>{
        this.$emit("getBoxInfo");
      })
    }
huhaiqing's avatar
huhaiqing committed
157
  },
158 159
  computed: {
    isStartCabinet() {
huhaiqing's avatar
huhaiqing committed
160 161 162 163 164
      const { currNode, shipmentObj } = this.$attrs;
      const status = shipmentObj[currNode.keyName];
      return [46, 47].includes(status) ? true : false;
    },
    isSeal() {
165 166
      const { currNode, shipmentObj } = this.$attrs;
      const status = shipmentObj[currNode.keyName];
167
      return status === 47 ? true : false;
168 169
    },
  },
huhaiqing's avatar
huhaiqing committed
170 171 172 173 174
};
</script>

<style lang="scss" scoped>
</style>