Explorar o código

承运商选择问题
添加删除提示
店铺选择
合并商品

zengjun hai 7 meses
pai
achega
6642ad78b9
Modificáronse 1 ficheiros con 156 adicións e 70 borrados
  1. 156 70
      src/views/returned/register/index.vue

+ 156 - 70
src/views/returned/register/index.vue

@@ -114,19 +114,8 @@
                 label="货主"
                 placeholder="选择货主"
                 :model-value="getOwnerName(params.ownerCode)"
-                @click="ownerPickerShow = true"
+                @click="showOwnerSelectFunc"
               />
-              <van-popup
-                v-model:show="ownerPickerShow"
-                position="bottom"
-                destroy-on-close
-              >
-                <van-picker
-                  :columns="owners"
-                  @cancel="ownerPickerShow = false"
-                  @confirm="selectedOwner"
-                />
-              </van-popup>
 
               <van-field
                 readonly
@@ -227,7 +216,7 @@
                 <div class="card-div-content">
                   <div class="info-row">
                     <div class="info-label">sku</div>
-                    <div class="info-value">{{ item.barCode }}</div>
+                    <div class="info-value">{{ item.sku }}</div>
                     <div class="info-label">质量状态</div>
                     <div class="info-value">
                       <van-tag :color="getTagColor(item.qualityStatus)">
@@ -387,8 +376,6 @@
             :show-confirm-button="checkUploadImages()"
             @confirm="addDetails"
           >
-
-
             <div style="max-height: 70vh; overflow-y: auto">
               <van-field
                 v-model="selectDetail.sku"
@@ -444,6 +431,8 @@
                 position="bottom"
               >
                 <van-date-picker
+                  :max-date="maxDate"
+                  :min-date="minDate"
                   :model-value="parseDateValue(selectDetail.manufactureTime)"
                   @confirm="manufactureTimeConfirm"
                   @cancel="showManufactureTime = false"
@@ -465,6 +454,8 @@
                 position="bottom"
               >
                 <van-date-picker
+                  :max-date="maxDate"
+                  :min-date="minDate"
                   :model-value="parseDateValue(selectDetail.validityTime)"
                   @confirm="validityTimeConfirm"
                   @cancel="showValidityTime = false"
@@ -480,6 +471,7 @@
 
               <van-field
                 v-model="selectDetail.number"
+                label="数量"
                 type="digit"
                 placeholder="数量"
                 clearable
@@ -493,23 +485,26 @@
               />
 
               <van-row v-if="showAccessories">
-                <div style="font-size: 12px;">
-                  <template v-for="(item,index) in accessories">
+                <div style="font-size: 12px">
+                  <template v-for="(item, index) in accessories">
                     <p>
-                      配件条码:
-                      [<span style="color: #2ca547">{{ item.accessory }}</span>]
-                      [<span style="color: #277b39 ">{{ item.descrC }}</span>]
-                      数量:
-                      [<span style="color: #2ca547">{{ item.qty }}</span>]件
+                      配件条码: [<span style="color: #2ca547">{{
+                        item.accessory
+                      }}</span
+                      >] [<span style="color: #277b39">{{ item.descrC }}</span
+                      >] 数量: [<span style="color: #2ca547">{{
+                        item.qty
+                      }}</span
+                      >]件
                     </p>
                   </template>
                   <p style="font-size: 12px">
-                    请检查商品:
-                    【<span style="color: #ff2020">{{ selectDetail.sku}}</span>】
-                    {{ selectDetail.tradeName }} 配件
+                    请检查商品: 【<span style="color: #ff2020">{{
+                      selectDetail.sku
+                    }}</span
+                    >】 {{ selectDetail.tradeName }} 配件
                   </p>
                 </div>
-
               </van-row>
 
               <template
@@ -517,7 +512,9 @@
                   selectDetail.boxPhotos && selectDetail.boxPhotos.length > 0
                 "
               >
-                <van-divider content-position="left" style="margin: 0px">外箱图</van-divider>
+                <van-divider content-position="left" style="margin: 0px"
+                  >外箱图
+                </van-divider>
                 <van-row>
                   <template
                     v-if="
@@ -571,7 +568,9 @@
                   selectDetail.productPhotos.length > 0
                 "
               >
-                <van-divider content-position="left" style="margin: 0px">内物图</van-divider>
+                <van-divider content-position="left" style="margin: 0px"
+                  >内物图
+                </van-divider>
                 <van-row>
                   <template v-for="(item, index) in selectDetail.productPhotos">
                     <van-col span="4">
@@ -666,6 +665,7 @@
         @confirm="selectOwner"
       />
     </van-popup>
+    <owner ref="ownerRef" @onOwner="onOwner" />
   </div>
 </template>
 
@@ -673,12 +673,11 @@
 import { ref, computed, nextTick, onMounted } from 'vue'
 import {
   showFailToast,
-  showSuccessToast,
   showNotify,
   showLoadingToast,
   closeToast,
   showConfirmDialog,
-  showToast,
+  showDialog,
 } from 'vant'
 import { getHeader, goBack } from '@/utils/android'
 import {
@@ -701,6 +700,7 @@ import {
 import { carrierOptions, getOwner, getWarehouse } from '@/api/basic/index.ts'
 import { useStore } from '@/store/modules/user'
 import { getStatus } from '@/utils/returned.ts'
+import Owner from '@/components/Owner.vue'
 
 try {
   getHeader()
@@ -708,6 +708,9 @@ try {
   console.log(error)
 }
 
+const minDate = ref(new Date(new Date().getFullYear() - 5, 0, 1))
+const maxDate = ref(new Date((new Date().getFullYear() + 50, 0, 1)))
+
 const showInitialPage = ref(true)
 const expressNo = ref(null)
 const warehouse = ref(useStore.warehouse)
@@ -745,9 +748,15 @@ const boxFiles = ref([])
 const productFiles = ref([])
 
 onMounted(() => {
-  if (!warehouse.value){
+  const now = new Date()
+  const currentYear = now.getFullYear()
+  const currentCentury = Math.floor(currentYear / 100) * 100
+  const endOfCenturyYear = currentCentury + 99
+  maxDate.value = new Date(endOfCenturyYear, 0, 1)
+
+  if (!warehouse.value) {
     warehouse.value = ref(useStore.warehouse)
-    console.log(`on mounted:${warehouse.value}`)
+    console.log(`on mounted:${warehouse.value} : ${useStore.warehouse}`)
   }
 
   getOwner().then((res) => {
@@ -763,9 +772,13 @@ onMounted(() => {
   })
   getQualityStatus().then((res) => {
     const { data } = res
-    qualityStatusOptions.value = data.map((item) => {
-      return { value: item, text: item }
-    })
+    qualityStatusOptions.value = data
+      .filter((item) => {
+        return item !== '机损'
+      })
+      .map((item) => {
+        return { value: item, text: item }
+      })
   })
   getWarehouse().then((res) => {
     const { data } = res
@@ -857,7 +870,7 @@ async function getStoreOptionsBy(owner) {
     return
   }
   storeOptions.value = data.map((item) => {
-    return { value: item, text: item }
+    return { value: item.name, text: item.name }
   })
 }
 
@@ -1055,21 +1068,21 @@ function inputExpressNo() {
     }
   })
   matchReturned(express_no)
-  expressNo.value = null
-  showInitialPage.value = false
 }
 
-function matchReturned(expressNo) {
-  getReturnedByExpress(expressNo).then((res) => {
+function matchReturned(express_no) {
+  getReturnedByExpress(express_no).then((res) => {
     const { data } = res
     if (!data) {
-      matchOrder(expressNo)
+      matchOrder(express_no)
       return
     }
     const { id, headStatus, returnNo, warehouseCode } = data
     if (!id) {
       console.log('没有退件记录')
-      matchOrder(expressNo)
+      matchOrder(express_no)
+      expressNo.value = null
+      showInitialPage.value = false
       return
     }
     if (id) {
@@ -1084,7 +1097,14 @@ function matchReturned(expressNo) {
         params.value.warehouseCode = warehouseCode
         params.value.warehousingStatus = null
         selectDetailIndex.value = -1
-        matchOrder(expressNo)
+        matchOrder(express_no)
+        expressNo.value = null
+        showInitialPage.value = false
+      } else {
+        showNotify({
+          type: 'danger',
+          message: '当前退回单号已进行过登记 如需修改请前往PC端进行',
+        })
       }
     }
   })
@@ -1266,6 +1286,7 @@ function initExpressNo(no) {
 function init(showInputPage = true) {
   warehouseName.value = null
   ownerName.value = null
+  clearImageFileCache()
   params.value = {
     orderUpstream: null,
     returnNo: null,
@@ -1282,6 +1303,7 @@ function init(showInputPage = true) {
     remark: null,
     details: [],
   }
+  storeOptions.value = []
   expressNo.value = null
   showInitialPage.value = showInputPage
   initDetail()
@@ -1328,7 +1350,7 @@ async function queryBarcode() {
     message: '查询商品信息中.....',
   })
   const barcode = scancode.value
-  const { ownerCode } = params.value
+  const { ownerCode,details } = params.value
   if (ownerCode) {
     const result = await queryOwnerBarcode(ownerCode, barcode)
     if (result) {
@@ -1338,7 +1360,6 @@ async function queryBarcode() {
       return
     }
   }
-  const { details } = params.value
   if (!details || details.length === 0) {
     await queryBarcodeBy(barcode)
     scancodeDialog.value = false
@@ -1405,6 +1426,7 @@ function addDetailByBasSku(basSku) {
   if (!params.value.ownerCode) {
     params.value.ownerCode = ownerCode
     initQualityInspection(params.value.ownerCode)
+    getStoreOptionsBy(params.value.ownerCode)
   }
   selectDetail.value.barCode = barCode
   selectDetail.value.qualityStatus = qualityStatus.value
@@ -1416,8 +1438,10 @@ function addDetailByBasSku(basSku) {
   // 显示
   showAccessoriesItems(accessories)
 }
+
 const accessories = ref([])
 const showAccessories = ref(false)
+
 function showAccessoriesItems(items) {
   console.log(items)
   console.log(!items || items.length === 0)
@@ -1526,9 +1550,45 @@ const addDetails = async () => {
     initDetail()
     return true
   }
-  // 查找对应的详情进行合并
-  params.value.details.push(detail)
-  // 重置详情
+  const {
+    sku: detailSku,
+    batchNumber: detailBatchNumber,
+    validityTime: detailValidityTime,
+    manufactureTime: detailManufactureTime,
+    qualityStatus: detailQualityStatus,
+    number: detailNumber,
+  } = selectDetail.value
+  if (['次品', '待修复'].includes(detailQualityStatus)) {
+    params.value.details.push(detail)
+    return
+  }
+  const searchIndex = params.value.details.findIndex((item) => {
+    const { sku, batchNumber, qualityStatus, validityTime, manufactureTime } = item
+    return (
+      sku === detailSku &&
+      batchNumber === detailBatchNumber &&
+      detailValidityTime === validityTime &&
+      detailManufactureTime === manufactureTime &&
+      detailQualityStatus === qualityStatus
+    )
+  })
+  if (searchIndex > -1) {
+    showConfirmDialog({
+      title: '系统提示',
+      message: '查询到有对应的商品详情是否进行合并',
+    })
+      .then(() => {
+        const { number } = params.value.details[searchIndex]
+        params.value.details[searchIndex].number = Number(detailNumber) + Number(number)
+        showNotify({ type: 'success', message: '合并成功' })
+      })
+      .catch(() => {
+        params.value.details.push(detail)
+        showNotify({ type: 'success', message: '添加成功' })
+      })
+  } else {
+    params.value.details.push(detail)
+  }
   initDetail()
   return true
 }
@@ -1539,20 +1599,29 @@ function removeDetails(index) {
     showFailToast('未找到对应的详情')
     return
   }
-  const { id } = params.value.details[index]
-  if (!id) {
-    params.value.details.splice(index, 1)
-    showSuccessToast('删除成功')
-  } else {
-    deleteDetails(id).then((res) => {
-      if (res.data) {
+  showConfirmDialog({
+    title: '系统提示',
+    message: '是否删除当前登记信息',
+  })
+    .then(() => {
+      const { id } = params.value.details[index]
+      if (!id) {
         params.value.details.splice(index, 1)
-        showSuccessToast('删除成功')
+        showNotify({ type: 'success', message: '删除成功' })
       } else {
-        showFailToast('删除失败')
+        deleteDetails(id).then((res) => {
+          if (res.data) {
+            params.value.details.splice(index, 1)
+            showNotify({ type: 'success', message: '删除成功' })
+          } else {
+            showNotify({ type: 'danger', message: '删除失败' })
+          }
+        })
       }
     })
-  }
+    .catch(() => {
+      showNotify({ type: 'primary', message: '取消删除' })
+    })
 }
 
 function selectOwner({ selectedValues }) {
@@ -1565,6 +1634,17 @@ function selectOwner({ selectedValues }) {
   getStoreOptionsBy(ownerCode)
   // 货主
 }
+const ownerRef=ref(null)
+
+function showOwnerSelectFunc(){
+  ownerRef.value?.show(1)
+}
+
+// 指定货主
+const onOwner = (item,type)=>{
+  params.value.ownerCode = item.code
+  getStoreOptionsBy(item.code)
+}
 
 const showOwnerSelect = ref(false)
 const ownerSelectedOptions = ref([])
@@ -1607,7 +1687,7 @@ async function checkValidateDate(ownerCode, sku, newDate, fieldName) {
     return true
   } catch (error) {
     showNotify({
-      type: 'warning',
+      type: 'danger',
       message: `校验${type}出现异常`,
     })
     return false
@@ -1868,7 +1948,7 @@ const handlePhotosDelete = () => {
   })
     .then(() => {
       selectDetail.value.productPhotos.splice(startBoxPosition.value, 1)
-      showToast('删除成功')
+      showNotify({ type: 'success', message: '删除成功' })
       if (selectDetail.value.productPhotos.length === 0) {
         showPhotosPreview.value = false
       } else if (
@@ -1876,12 +1956,9 @@ const handlePhotosDelete = () => {
       ) {
         startPhotosPosition.value = selectDetail.value.productPhotos.length - 1
       }
-
-      // 这里可以添加实际删除图片的API调用
-      // deleteImageAPI(deletedImage).then(...)
     })
     .catch(() => {
-      // 取消删除
+      showNotify({ type: 'primary', message: '取消删除' })
     })
 }
 
@@ -1899,11 +1976,11 @@ const onBoxPreviewChange = (index) => {
 const handleBoxDelete = () => {
   showConfirmDialog({
     title: '提示',
-    message: '确定要删除这张图片吗',
+    message: '确定要删除这张图片吗?',
   })
     .then(() => {
       selectDetail.value.boxPhotos.splice(startBoxPosition.value, 1)
-      showToast('删除成功')
+      showNotify({ type: 'success', message: '删除成功' })
       if (selectDetail.value.boxPhotos.length === 0) {
         showBoxPreview.value = false
       } else if (
@@ -1911,12 +1988,9 @@ const handleBoxDelete = () => {
       ) {
         startBoxPosition.value = selectDetail.value.boxPhotos.length - 1
       }
-
-      // 这里可以添加实际删除图片的API调用
-      // deleteImageAPI(deletedImage).then(...)
     })
     .catch(() => {
-      // 取消删除
+      showNotify({ type: 'primary', message: '取消删除' })
     })
 }
 
@@ -1975,6 +2049,18 @@ function checkUploadImages() {
 window.onRefresh = async () => {
   console.log('window.onRefresh')
 }
+
+function clearImageFileCache(){
+  if(productFiles.value && productFiles.value.length > 0) {
+    productFiles.value.map(item=> item.src)
+      .forEach(item=>URL.revokeObjectURL(item))
+  }
+  if(boxFiles.value && boxFiles.value.length > 0) {
+    boxFiles.value.map(item=> item.src)
+      .forEach(item=>URL.revokeObjectURL(item))
+  }
+
+}
 </script>
 
 <style scoped lang="sass">