<template>
  <el-dialog
    :visible.sync="visible"
    title="计划提交"
    width="60vw"
    append-to-body
  >
    <div class="main_container">
      <el-descriptions
        title=""
        :column="3"
        size="medium"
        border
        label-class-name="title-col"
        content-class-name="title-col"
      >
        <el-descriptions-item>
          <template slot="label"> 计划编号 </template>
          {{ info.code }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 计划类型 </template>
          {{ getDictValue('订单计划类型', info.planType) }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 产品编码</template>
          {{ info.productCode }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 牌号 </template>
          {{ info.brandNo }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 型号 </template>
          {{ info.model }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 规格 </template>
          {{ info.specification }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 销售单数量 </template>
          {{ info.codeNum }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 生产类型 </template>
          {{ info.produceVersionName }}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label"> 工艺路线 </template>
          {{ info.produceRoutingName }}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label"> 订单总数量 </template>
          {{ info.contractNum }}{{ info.measuringUnit }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 订单重量 </template>
          {{ info.sumOrderWeight }} {{ info.weightUnit }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 要求生产数量 </template>
          {{ Number(info.requiredFormingNum) }}{{ info.measuringUnit }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 要求生产重量 </template>
          {{ info.newSumOrderWeight }} {{ info.newWeightUnit }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 要求完成日期 </template>
          {{ info.reqMoldTime }}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label"> 批次号 </template>
          {{ info.batchNo }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 所属工厂 </template>
          {{ info.factoriesIdName }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 生产要求 </template>
          {{ info.productionRequirements }}
        </el-descriptions-item>
        <el-descriptions-item :span="3">
          <template slot="label"> </template>
        </el-descriptions-item>
      </el-descriptions>
    </div>
    <div slot="footer" class="footer">
      <div>
        <el-button @click="cancel">取消</el-button>
        <el-button
          @click="submit(2)"
          type="primary"
          :loading="loading"
          v-if="type != 'edit'"
          >提交并发布</el-button
        >
        <el-button type="primary" @click="submit(1)" :loading="loading"
          >提交</el-button
        >
      </div>
    </div>
  </el-dialog>
</template>

<script>
  import { getCode } from '@/api/codeManagement';
  import dictMixins from '@/mixins/dictMixins';
  import { debounce } from 'lodash';

  export default {
    mixins: [dictMixins],
    props: {
      info: Object,
      type: String
    },
    data() {
      return {
        visible: false,
        loading: false,
        tableList: []
      };
    },
    computed: {},
    created() {
      this.requestDict('订单计划类型');
    },
    methods: {
      open() {
        this.visible = true;
        if (this.type != 'edit') {
          this.getPlanCode();
        }
      },
      cancel() {
        this.visible = false;
      },

      async getPlanCode() {
        this.loading = true;
        try {
          const code = await getCode('product_code');
          this.$set(this.info, 'code', code);
        } catch (err) {}
        this.loading = false;
      },

      submit: debounce(function (type) {
        this.$emit('publish', type);
        this.visible = false;
      }, 800)
    }
  };
</script>
<style lang="scss">
  .basic-details-title {
    margin: 10px 0;
  }

  .title-col {
    color: #000000 !important;
    background-color: #fff;
  }
</style>
