li.shaoyi преди 3 години
родител
ревизия
d8a54c4a96

+ 10 - 3
src/hooks/component/index.ts

@@ -7,6 +7,7 @@ import { ref } from 'vue'
 export function useComponent(callback?: (componentName?: string) => void) {
     const components = new Set<string>() // 已打开的组件列表
     const componentId = ref<string>() // 当前显示的组件
+    const componentRef = ref() // 组件实例
 
     /**
      * 是否存在组件
@@ -48,9 +49,14 @@ export function useComponent(callback?: (componentName?: string) => void) {
      * 组件关闭守卫
      * @returns 
      */
-    const closeEach = () => {
+    const closeComponentEach = () => {
         if (hasComponent()) {
-            closeComponent()
+            const { closed } = componentRef.value ?? {}
+            if (closed instanceof Function) {
+                closed()
+            } else {
+                closeComponent()
+            }
             return false
         }
         return true
@@ -58,9 +64,10 @@ export function useComponent(callback?: (componentName?: string) => void) {
 
     return {
         componentId,
+        componentRef,
         hasComponent,
         openComponent,
         closeComponent,
-        closeEach,
+        closeComponentEach,
     }
 }

+ 5 - 0
src/packages/mobile/views/goods/details/components/address/index.vue

@@ -18,6 +18,11 @@ const showModal = shallowRef(true);
 const closed = () => {
     showModal.value = false
 }
+
+// 暴露组件属性给父组件调用
+defineExpose({
+    closed,
+})
 </script>
 
 <style lang="less">

+ 9 - 4
src/packages/mobile/views/goods/details/index.vue

@@ -21,11 +21,11 @@
                     :options="presaleApplyDeposits" v-if="presaleApplyId" />
                 <Field v-model="formData.Qty" name="Qty" type="digit" label="采购数量" placeholder="必填"
                     :rules="formRules.Qty" />
-                <Field label="收货信息" placeholder="请输入" @click="openComponent('address')" is-link />
+                <Field label="收货信息" placeholder="请输入" @click="openComponent('address')" is-link v-if="showAddress" />
             </CellGroup>
         </Form>
         <Button type="primary" @click="formRef?.submit" round block>采购下单</Button>
-        <component :is="componentMap.get(componentId)" @closed="closeComponent" v-if="componentId" />
+        <component ref="componentRef" :is="componentMap.get(componentId)" @closed="closeComponent" v-if="componentId" />
     </app-view>
 </template>
 
@@ -44,7 +44,7 @@ const componentMap = new Map<string, unknown>([
     ['address', defineAsyncComponent(() => import('./components/address/index.vue'))],
 ])
 
-const { componentId, openComponent, closeComponent, closeEach } = useComponent()
+const { componentRef, componentId, openComponent, closeComponent, closeComponentEach } = useComponent()
 const { getQueryStringToNumber, beforeRouteLeave } = useNavigation()
 
 const wrstandardid = getQueryStringToNumber('wrstandardid')
@@ -63,6 +63,11 @@ const formRules: { [key in keyof Proto.SpotPresaleDestingOrderReq]?: FieldRule[]
     }],
 }
 
+// 是否显示收货信息
+const showAddress = computed(() => {
+    return formData.THJDeliveryMode === 2 || formData.THJDeliveryMode === 3
+})
+
 // 交割月份列表
 const deliveryMonths = computed(() => {
     const months = details.value.deliverymonth ?? []
@@ -116,7 +121,7 @@ const onSubmit = () => {
 }
 
 getWrstandardDetails()
-beforeRouteLeave(() => closeEach())
+beforeRouteLeave(() => closeComponentEach())
 </script>
 
 <style lang="less">

+ 1 - 1
src/packages/mobile/views/home/index.vue

@@ -59,7 +59,7 @@ const tabList: Tabbar[] = [
 ]
 
 const onChange = (index: number) => {
-  if (![1, 2].includes(index)) {
+  if (![2].includes(index)) {
     componentId.value = tabList[index].name
   }
 }