index.vue 14.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
<template>
  <BasicDrawer
    v-bind="$attrs"
    showFooter
    @register="register"
    @ok="handleSubmit"
    title=""
    :destroyOnClose="true"
    width="28%"
    ref="formRef"
    :isDetail="true"
    :showDetailBack="false"
    okText="保存"
    :mask="false"
    class="z-20"
  >
    <div className="mt-[-16px] order-drawer-panel">
      <Tabs v-model:activeKey="activeKey">
        <TabPanel
          key="1"
          tab="基本信息"
          :forceRender="true"
          v-if="role === ROLE.ADMIN || role === ROLE.TRACKER"
        >
          <span className="text-red-600">{{ checkingMsg }}</span>
          <BaseFormPanel ref="baseFormPanelRef" :id="id" :businessUsers="businessUsers" />
        </TabPanel>
        <TabPanel
          key="2"
          tab="利润分析"
          :forceRender="true"
          v-if="!!id && (role === ROLE.ADMIN || role === ROLE.BUSINESS)"
        >
          <span className="text-red-600">{{ checkingMsg }}</span>

          <ProfitFormPanel
            ref="profitFormPanelRef"
            :orderCount="orderCount"
            :id="id"
            :profitFormData="profitFormData"
          />
        </TabPanel>
        <TabPanel
          key="3"
          tab="项目报告书"
          :forceRender="true"
          v-if="!!id && (role === ROLE.ADMIN || role === ROLE.BUSINESS)"
        >
          <span className="text-red-600">{{ checkingMsg }}</span>

          <ReportFormPanel ref="reportFormPanelRef" :id="id" :reportFormData="reportFormData" />
        </TabPanel>
        <TabPanel
          key="4"
          tab="跟单信息"
          :forceRender="true"
          v-if="!!id && (role === ROLE.ADMIN || role === ROLE.TRACKER)"
        >
          <span className="text-red-600">{{ checkingMsg }}</span>

          <TrackFormPanel ref="trackFormPanelRef" :id="id" :trackFormData="trackFormData" />
        </TabPanel>
        <TabPanel
          key="5"
          tab="质检信息"
          :forceRender="true"
          v-if="!!id && (role === ROLE.ADMIN || role === ROLE.INSPECT)"
        >
          <span className="text-red-600">{{ checkingMsg }}</span>

          <InspectionFormPanel
            ref="inspectionFormPanelRef"
            :id="id"
            :inspectFormData="inspectFormData"
          />
        </TabPanel>
      </Tabs>
    </div>
    <!-- <template #titleToolbar> <a-button type="primary"> 申请编辑权限 </a-button></template> -->

    <!-- <template #appendFooter>
      <a-button type="primary" @click="onGoCheckDetail"> 申请权限</a-button>
    </template> -->
  </BasicDrawer>
</template>
<script lang="ts">
  import { computed, defineComponent, reactive, ref, toRaw, watch, toRefs, onMounted } from 'vue';
  import { FormActionType, FormSchema, useForm } from '/@/components/Form/index';
  import { orderCreate, orderUpdate, uploadImg } from '/@/api/project/order';
  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
  import { dateUtil } from '/@/utils/dateUtil';
  import ProfitFormPanel from './ProfitFormPanel.vue';
  import ReportFormPanel from './ReportFormPanel.vue';
  import TrackFormPanel from './TrackFormPanel.vue';
  import InspectionFormPanel from './InspectionFormPanel.vue';
  import BaseFormPanel from './BaseFormPanel.vue';
  import { useUserStoreWithOut } from '/@/store/modules/user';
  import { ROLE } from '../type.d';
  import { getList as getConfigList } from '/@/api/sys/config';

  import { Tabs } from 'ant-design-vue';
  import { find } from 'lodash-es';
  import { getUserList } from '/@/api/project/account';
  import message from '/@/views/form-design/utils/message';

  const userStore = useUserStoreWithOut();

  const TabPanel = Tabs.TabPane;

  export default defineComponent({
    components: {
      BasicDrawer,
      BaseFormPanel,
      Tabs,
      TabPanel,
      ProfitFormPanel,
      ReportFormPanel,
      TrackFormPanel,
      InspectionFormPanel,
    },

    props: {
      detailData: {
        type: Object,
      },
      onGoCheckDetail: {
        type: Function,
      },
    },
    emits: ['success'],

    setup(_, { emit }) {
      const activeKey = ref('1');
      const baseFormPanelRef = ref();
      const profitFormPanelRef = ref();
      const reportFormPanelRef = ref();
      const trackFormPanelRef = ref();
      const inspectionFormPanelRef = ref();
      const orderCount = ref(0);

      // 编辑从接口获取的value
      const baseFormData = ref();
      const profitFormData = ref();
      const reportFormData = ref();
      const trackFormData = ref();
      const inspectFormData = ref();

      const formRef = ref<FormActionType | null>(null);
      const id = ref('');
      const configList = ref([]);
      const businessUsers = ref([]);
      const checkingMsg = ref('');

      onMounted(async () => {
        // 获取包装费用和客户编码的关联关系
        const res = await getConfigList({
          page: 1,
          pageSize: 1000,
          // relationCode: 'packetPrice',
        });

        configList.value = res?.items || [];

        // 获取业务员
        const res1 = await getUserList({ page: 1, pageSize: 1000 });
        businessUsers.value = res1.items
          .filter((item) => item.roleCode === ROLE.BUSINESS)
          .map((item) => ({ value: item.userName, label: item.userName }));
      });

      const role = computed(() => {
        return userStore.getUserInfo?.roleSmallVO?.code;
      });

      const picUrl = ref('');
      let fields = reactive({ baseFields: {} });

      const [register, { closeDrawer }] = useDrawerInner((data) => {
        activeKey.value =
          role.value === ROLE.INSPECT ? '5' : role.value === ROLE.BUSINESS ? '2' : '1';

        checkingMsg.value = '';
        if (!data.id) {
          id.value = '';
          picUrl.value = '';
          // 新建
          baseFormPanelRef?.value?.resetFields();
          profitFormPanelRef?.value?.resetFields();
          reportFormPanelRef?.value?.resetFields();
          trackFormPanelRef?.value?.resetFields();
          inspectionFormPanelRef?.value?.resetFields();

          return;
        }
        id.value = data.id;
        profitFormData.value =
          data?.orderUpdateInfoVO?.profitAnalysisFields || data.profitAnalysisInfo;
        inspectFormData.value = data.inspectionStageInfo;
        reportFormData.value = data?.orderUpdateInfoVO?.reportFields || data.reportInfo;
        trackFormData.value = data.trackStageInfo;

        // 方式1
        picUrl.value = data.picUrl;
        data.orderHodTime = data.orderHodTime ? dateUtil(data.orderHodTime) : null;
        data.productionDepartmentConsignTime = data.productionDepartmentConsignTime
          ? dateUtil(data.productionDepartmentConsignTime)
          : null;

        fields.baseFields = {
          ...fields.baseFields,
          ...data.lockFields.baseFields,
        };

        if (id.value) {
          orderCount.value = data.orderCount;

          setTimeout(() => {
            // 基本信息
            if (baseFormPanelRef.value) {
              baseFormPanelRef.value.fields = { ...data.lockFields?.baseFields } || {};
              baseFormPanelRef.value.setFieldsValue({
                ...toRaw(data),
              });
              baseFormPanelRef.value.picUrl = data.picUrl;
              baseFormPanelRef.value.smallPicUrl = data.smallPicUrl;
            }

            if (profitFormPanelRef.value) {
              // 包装费用通过客户编码去查
              const packetPrice = find(configList.value, (item) => {
                return (
                  data.customerCode === item.settingValue && item.relationCode === 'packetPrice'
                );
              });

              const exchangeRate = find(configList.value, (item) => {
                return item.settingCode === 'exchangeRate';
              });
              // 利润分析
              profitFormPanelRef.value.fields = { ...data.lockFields?.profitAnalysisFields } || {};

              if (data?.orderUpdateInfoVO?.profitAnalysisFields) {
                const { customerPrice, productionDepartmentPrice, customerRmbPrice } =
                  data?.orderUpdateInfoVO?.profitAnalysisFields || {};

                //给个审核中提示
                checkingMsg.value = '当前订单利润分析审核中';

                // 编辑了但是还没审核,先将页面的值变化
                profitFormPanelRef?.value?.setFieldsValue({
                  ...toRaw(data?.orderUpdateInfoVO?.profitAnalysisFields),
                  customerPrice: Number(customerPrice || 0),
                  customerRmbPrice: Number(customerRmbPrice || 0),
                  productionDepartmentPrice: Number(productionDepartmentPrice || 0),
                  packetPrice: packetPrice?.relationValue || 0,
                  exchangeRate: exchangeRate?.settingValue,
                });
              } else {
                profitFormPanelRef?.value?.setFieldsValue({
                  ...toRaw(data.profitAnalysisInfo),
                  packetPrice: packetPrice?.relationValue || 0,
                  exchangeRate: exchangeRate?.settingValue,
                });
              }
            }

            if (reportFormPanelRef.value) {
              // 项目报告书
              reportFormPanelRef.value.fields = { ...data.lockFields?.reportFields } || {};
              if (data?.orderUpdateInfoVO?.reportFields) {
                const { ideaSourceRate, manualPreform1Rate, manualPreform2Rate } =
                  data?.orderUpdateInfoVO?.reportFields || {};
                data?.orderUpdateInfoVO?.reportFields;

                //给个审核中提示
                checkingMsg.value = '当前订单项目报告书审核中';

                // 编辑了但是还没审核,先将页面的值变化
                reportFormPanelRef?.value?.setFieldsValue({
                  ...toRaw(data?.orderUpdateInfoVO?.reportFields),
                  ideaSourceRate: Number(ideaSourceRate || 0),
                  manualPreform1Rate: Number(manualPreform1Rate || 0),
                  manualPreform2Rate: Number(manualPreform2Rate || 0),
                });
              } else {
                reportFormPanelRef?.value?.setFieldsValue({
                  ...toRaw(data.reportInfo),
                });
              }
            }
            if (trackFormPanelRef.value) {
              // 跟单信息
              trackFormPanelRef.value.fields = { ...data.lockFields?.trackStageFields } || {};
              trackFormPanelRef?.value?.setFieldsValue({
                ...toRaw(data.trackStageInfo),
              });
            }

            if (inspectionFormPanelRef.value) {
              // 质检信息
              inspectionFormPanelRef.value.fields =
                { ...data.lockFields?.inspectionStageFields } || {};
              inspectionFormPanelRef?.value?.setFieldsValue({
                ...toRaw(data.inspectionStageInfo),
              });
            }
          }, 100);
        } else {
          baseFormPanelRef.value.resetFields();
        }
      });

      const handleSubmit = async () => {
        try {
          if (id.value) {
            const forms = { orderId: id.value } as any;
            if (activeKey.value === '1') {
              await baseFormPanelRef?.value?.validate();

              forms.baseInfo = baseFormPanelRef?.value?.getFieldsValue() || {};
              forms.baseInfo = {
                ...forms.baseInfo,
                picUrl: baseFormPanelRef?.value?.picUrl || '',
                smallPicUrl: baseFormPanelRef?.value?.smallPicUrl || '',
              };
              await orderUpdate(forms);
              closeDrawer();
              emit('success', {});
            } else {
              // 利润分析
              if (activeKey.value === '2') {
                await profitFormPanelRef?.value?.validate();
                forms.profitAnalysisInfo = profitFormPanelRef?.value?.getFieldsValue() || {};
                delete forms.profitAnalysisInfo.profitRate;
                forms.profitAnalysisInfo.customerRmbPrice =
                  forms.profitAnalysisInfo.customerRmbPrice.toFixed(2); // 客户单价¥
                forms.profitAnalysisInfo.customerRmbTotalPrice = (
                  forms.profitAnalysisInfo.customerRmbPrice * orderCount.value
                ).toFixed(2); // 客户总价¥
                forms.profitAnalysisInfo.customerPrice =
                  forms.profitAnalysisInfo.customerPrice.toFixed(2); // 客户单价$
                // 方式如果没有变化,默认方式1
                if (!forms.profitAnalysisInfo.profitType) {
                  forms.profitAnalysisInfo.profitType = '0';
                }
              } else if (activeKey.value === '3') {
                // 项目报告书
                await reportFormPanelRef?.value?.validate();
                // 比重相加等于1
                const values = reportFormPanelRef?.value?.getFieldsValue() || {};
                if (
                  values.ideaSourceRate + values.manualPreform1Rate + values.manualPreform2Rate !==
                  1
                ) {
                  return message.error('占比相加不等于1');
                }

                forms.reportInfo = values;
              } else if (activeKey.value === '4') {
                forms.trackStageInfo = trackFormPanelRef?.value?.getFieldsValue() || {};
              } else if (activeKey.value === '5') {
                forms.inspectionStageInfo = inspectionFormPanelRef?.value?.getFieldsValue() || {};
              }
              await orderUpdate(forms);
              closeDrawer();
              emit('success', {});
            }
          } else {
            await baseFormPanelRef?.value?.validate();

            // 新建只有基本信息
            const values = baseFormPanelRef?.value?.getFieldsValue() || {};

            const forms = {
              baseInfo: {
                ...values,
                picUrl: baseFormPanelRef?.value?.picUrl || '',
                smallPicUrl: baseFormPanelRef?.value?.smallPicUrl || '',
              },
            };
            await orderCreate(forms);
            closeDrawer();
            emit('success', {});
          }
        } catch (error) {
          console.log(error);
        }
      };
      return {
        id,
        profitFormPanelRef,
        reportFormPanelRef,
        trackFormPanelRef,
        baseFormPanelRef,
        inspectionFormPanelRef,
        activeKey,
        formRef,
        ROLE,
        role,
        profitFormData,
        inspectFormData,
        reportFormData,
        trackFormData,
        register,
        handleSubmit,
        businessUsers,
        checkingMsg,
        orderCount,
      };
    },
  });
</script>

<style>
  .ant-drawer {
    position: fixed;
    z-index: 9999;
  }

  .order-drawer-panel .ant-picker {
    width: 100% !important;
  }
</style>