ProductText.vue 6.72 KB
<template>
  <!-- <BasicModal
    v-bind="$attrs"
    destroyOnClose
    @register="register"
    title="生产指标书"
    width="500px"
    :height="80"
    wrapClassName="h-[340px]"
    @visible-change="handleShow"
    :footer="null"
  > -->
  <BasicModal
    v-bind="$attrs"
    destroyOnClose
    @register="register"
    title="生产指标书"
    width="500px"
    @visible-change="handleShow"
    :footer="null"
    :bodyStyle="{ height: '180px' }"
  >
    <div class="container">
      <div v-if="isShow1 == true" style="margin-top: 50px; text-align: center">
        <RadioGroup v-model:value="choose" :options="options" />
      </div>
      <div class="showPdf" v-if="isShow2 == true" style="margin-top: 35px; text-align: center">
        <!-- <img src="/pdf.png" /> -->
        <FilePptOutlined :style="{ fontSize: '20px' }" class="FilePptOutlined" />
        <div style="margin-top: 1px; margin-left: 10px">生产指标书</div>
        <EyeOutlined :style="{ fontSize: '20px' }" class="EyeOutlined" @click="handlePdf" />
      </div>
      <div class="bottom">
        <a-button type="primary" @click="handleProduct" className="ml-4" v-if="isShow1 == true"
          >生成</a-button
        >
        <a-button
          type="primary"
          @click="handleExport"
          className="ml-4"
          :loading="exportLoading"
          v-if="isShow1 == false"
          >发送</a-button
        >
        <a-button type="primary" @click="handleCancel" className="ml-4" style="margin-left: 6px"
          >取消</a-button
        >
      </div>
    </div>
  </BasicModal>
</template>
<script lang="ts">
  import { defineComponent, ref, computed, onMounted, onUpdated } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { RadioGroup } from 'ant-design-vue';
  import { EyeOutlined, FilePptOutlined } from '@ant-design/icons-vue';
  import { useMessage } from '@/hooks/web/useMessage';

  export default defineComponent({
    props: {
      role: {
        type: String,
      },
      customerCodes: {
        type: Array<string | number>,
      },
    },
    components: { BasicModal, RadioGroup, EyeOutlined, FilePptOutlined },
    setup(props) {
      const loading = ref(true);
      const exportLoading = ref(false);
      const info = ref();
      const choose = ref(); //选择公司
      const isShow1 = ref(true); //选择公司页面
      const isShow2 = ref(false); //生成PDF页面
      const pdf = ref(['/pdf.png']);
      const [register, { setModalProps, closeModal }] = useModalInner(async (data) => {
        // if (data.customers.length == 0) {
        //   error('请选择订单');
        //   closeModal();
        // }
        console.log(data, '5656data');
      });
      const options = computed(() => {
        // 运营总监-基本信息,跟单,质检
        return [
          { label: '青岛翱特逸格饰品有限公司', value: '青岛翱特逸格饰品有限公司' },
          { label: ' 青岛吉庆天成饰品有限公司', value: '青岛吉庆天成饰品有限公司' },
        ];
      });
      const { createMessage } = useMessage();
      const { error } = createMessage;
      const customerCodeToCompanyMap: Record<string, string> = {
        A01: '青岛翱特逸格饰品有限公司',
        A04: '青岛吉庆天成饰品有限公司',
        A05: '青岛吉庆天成饰品有限公司',
        A06: '青岛翱特逸格饰品有限公司',
        A07: '青岛吉庆天成饰品有限公司',
        A08: '青岛翱特逸格饰品有限公司',
        A09: '青岛翱特逸格饰品有限公司',
        A10: '青岛翱特逸格饰品有限公司',
        A11: '青岛翱特逸格饰品有限公司',
        M03: '青岛吉庆天成饰品有限公司',
        M05: '青岛吉庆天成饰品有限公司',
      };
      function handleCancel() {
        loading.value = true;
        choose.value = '';
        setModalProps({ loading: false, confirmLoading: false });
        isShow1.value = true;
        isShow2.value = false;
        closeModal();
      }
      function handleShow(visible: boolean) {
        if (visible) {
          loading.value = true;
          choose.value = '';
          setModalProps({ loading: false, confirmLoading: false });
          isShow1.value = true;
          isShow2.value = false;
        }
      }
      function validateCompany(selectedCodes: any, company: string): boolean {
        for (const [customerCode] of selectedCodes) {
          const mappedCompany = customerCodeToCompanyMap[customerCode];

          if (mappedCompany === undefined) {
            // 如果 customerCode 不在 customerCodeToCompanyMap 中,跳过
            console.warn(`Customer code ${customerCode} not found in the mapping, skipping.`);
            continue;
          }

          if (mappedCompany !== company) {
            // 如果有一个不匹配,返回 false
            return false;
          }
        }
        // 如果所有匹配,返回 true
        return true;
      }
      //生成pdf
      // const customerCodeList: string[] = props.customerCodes;
      function handleProduct() {
        const customerCodeList = props.customerCodes;
        const areValid = validateCompany(customerCodeList, choose.value);
        //如果选错了,弹出提示
        if (!areValid) {
          error('勾选订单与选择的公司不匹配');
        } else {
          if (
            choose.value == '青岛翱特逸格饰品有限公司' ||
            choose.value == '青岛吉庆天成饰品有限公司'
          ) {
            //此处设置接口,传递选择的公司值
            isShow1.value = false;
            isShow2.value = true;
          }
        }
      }
      //查看pdf
      function handlePdf() {
        // const pdfUrl = './pdfs.pdf';
        // window.open(pdfUrl, '_blank');
      }
      //发送按钮
      async function handleExport() {
        closeModal();
      }
      return {
        register,
        loading,
        choose,
        handleShow,
        handleCancel,
        info,
        handleExport,
        handleProduct,
        handlePdf,
        exportLoading,
        isShow1,
        isShow2,
        options,
        pdf,
      };
    },
  });
</script>
<style scoped>
  /* .container {
    position: relative;
  }
  .bottom {
    position: absolute;
    bottom: 0;
  } */
  .container {
    display: flex;
    flex-direction: column;
    min-height: 20vh;
  }
  .bottom {
    margin-top: auto;
    margin-left: auto;
    margin-right: 20px;
  }
  .showPdf {
    border: 2px solid;
    border-color: #d8d8d8;
    border-radius: 5px;
    height: 30px;
    position: relative;
    display: flex;
  }
  .FilePptOutlined {
    margin-top: 3px;
    margin-left: 30px;
  }
  .EyeOutlined {
    margin-top: 3px;
    margin-left: 290px;
  }
</style>