Browse Source

fix: 2025-2-24

cmy 9 months ago
parent
commit
8978f2c0e5

+ 1 - 0
src/api/goods/index.ts

@@ -83,6 +83,7 @@ export const getProductDetail = (
   IResponse<{
     storeInfo: any
     productValue: any[]
+    productAttr: any[]
   }>
 > => {
   return request.get({

+ 3 - 3
src/api/goods/types.ts

@@ -8,7 +8,7 @@ export interface categoryData {
 }
 interface attrs {
   attr_name: string //属性名
-  attr_values: string //属性值
+  attr_values: string[] //属性值
 }
 export interface attrsValue {
   suk: string //规格参数
@@ -17,6 +17,7 @@ export interface attrsValue {
   price: number //商品价格
   ot_price: number //商品原价
   cost: number //商品成本价
+  detail: object //商品规格详情
 }
 export interface goodsData {
   store_id: number | string
@@ -76,8 +77,7 @@ export interface productRule {
 export interface AttrBaseItem {
   bar_code: string
   cost: number
-  detail: any
-  integral: number
+  detail: object
   ot_price: number
   pic: string[]
   price: number

+ 2 - 0
src/utils/searchTime.ts

@@ -7,6 +7,8 @@ export const searchTime: FormSchema = {
   value: '',
   componentProps: {
     type: 'datetimerange',
+    valueFormat: 'YYYY/MM/DD HH:mm:ss',
+    rangeSeparator: '至',
     shortcuts: [
       {
         text: '今天',

+ 0 - 1
src/views/Authorization/Role/components/Write.vue

@@ -70,7 +70,6 @@ const formSchema = ref<FormSchema[]>([
                     show-checkbox
                     node-key="id"
                     highlight-current
-                    check-strictly
                     expand-on-click-node={false}
                     data={treeData.value}
                     onNode-click={nodeClick}

+ 27 - 12
src/views/Authorization/User/components/Write.vue

@@ -14,6 +14,7 @@ const props = defineProps({
     default: () => null
   }
 })
+const roleList = ref([])
 
 const formSchema = ref<FormSchema[]>([
   {
@@ -66,15 +67,6 @@ const formSchema = ref<FormSchema[]>([
     component: 'Select',
     componentProps: {
       multiple: true
-    },
-    optionApi: async () => {
-      const re = await getRoleListApi({ page: 1, limit: 9999 })
-      return re.data.list.map((res) => {
-        return {
-          label: res.role_name,
-          value: res.id
-        }
-      })
     }
   },
   {
@@ -135,7 +127,14 @@ const rules = ref<FormRules<RuleForm>>({
   real_name: [required('请填写管理员姓名')]
 })
 
-onMounted(() => {
+onMounted(async () => {
+  const re = await getRoleListApi({ page: 1, limit: 9999 })
+  roleList.value = re.data.list.map((res) => {
+    return {
+      label: res.role_name,
+      value: res.id
+    }
+  })
   if (props.currentRow) {
     rules.value.pwd = [
       {
@@ -151,7 +150,7 @@ onMounted(() => {
 })
 
 const { formRegister, formMethods } = useForm()
-const { setValues, getFormData, getElFormExpose } = formMethods
+const { setValues, getFormData, getElFormExpose, setSchema } = formMethods
 
 const submit = async () => {
   const elForm = await getElFormExpose()
@@ -176,7 +175,23 @@ watch(
     immediate: true
   }
 )
-
+watch(
+  () => roleList,
+  async (value) => {
+    if (!value) return
+    setSchema([
+      {
+        field: 'roles',
+        path: 'componentProps.options',
+        value: value
+      }
+    ])
+  },
+  {
+    deep: true,
+    immediate: true
+  }
+)
 defineExpose({
   submit
 })

+ 117 - 32
src/views/Goods/edit/add.vue

@@ -73,6 +73,7 @@ const attrs_value = reactive<
   suk: '默认',
   image: [],
   stock: 0,
+  detail: {},
   price: 0,
   ot_price: 0,
   cost: 0
@@ -147,7 +148,6 @@ const rules = reactive({
       trigger: 'change',
       required: true,
       validator: (_, val, callback) => {
-        console.log(val, formData.slider_image, 'val')
         if (!val || val.length === 0) {
           callback(new Error('请选择轮播图片'))
         } else {
@@ -248,8 +248,6 @@ const save = async (formEl: FormInstance | undefined) => {
   if (valid) {
     // 将分类ID转换为数组形式,以便后续处理
     const cateIds: number[] = Array.from(flattenCateIds(formData.cate_ids)).map((re) => re)
-    console.log(cateIds, 'cateIds')
-
     // 构建要保存的商品数据对象
     const data: goodsData = {
       store_id: formData.store_id,
@@ -280,8 +278,57 @@ const save = async (formEl: FormInstance | undefined) => {
     }
     // 多规格商品处理
     if (formData.spec_type == 1) {
-      data.attrs_value = productAttrList.value.value.map((res) => {
-        return res
+      try {
+        for (let i = 0; i < productAttrList.value.value.length; i++) {
+          const item = productAttrList.value.value[i]
+          if (item.pic.length == 0) {
+            return ElMessage.error('商品图片不能为空')
+          }
+          if (isNaN(item.price)) {
+            return ElMessage.error('请输入正确的商品价格')
+          }
+          if (item.price * 1 <= 0) {
+            return ElMessage.error('商品价格必须大于0')
+          }
+          if (item.stock * 1 <= 0) {
+            return ElMessage.error('商品库存必须大于0')
+          }
+          if (item.ot_price * 1 <= 0) {
+            return ElMessage.error('商品原价必须大于0')
+          }
+        }
+      } catch (error: any) {
+        return ElMessage.error(error.message)
+      }
+      const keyList = getKeyList()
+      data.attrs_value = productAttrList.value.value.map((res): attrsValue => {
+        const suk: any[] = []
+        for (const key in res.detail) {
+          suk.push(res.detail[key])
+        }
+        const item = {
+          suk: suk.join(','),
+          image: res.pic[0],
+          stock: res.stock,
+          price: res.price,
+          ot_price: res.ot_price,
+          cost: res.cost,
+          detail: res.detail
+        }
+        if (keyList.length > 0) {
+          for (let i = 0; i < keyList.length; i++) {
+            const key = keyList[i]
+            item[key] = res[key]
+          }
+        }
+        return item
+      })
+
+      data.attrs = actionAttrs.map((re) => {
+        return {
+          attr_name: re.value,
+          attr_values: re.detail
+        }
       })
     }
     try {
@@ -312,10 +359,20 @@ const save = async (formEl: FormInstance | undefined) => {
     } catch (error) {
       console.log(error)
     } finally {
-      console.log(data)
+      // console.log(data)
     }
   }
 }
+const getKeyList = () => {
+  const keyList: string[] = []
+  for (let i = 0; i < productAttrList.value.header.length; i++) {
+    const item = productAttrList.value.header[i]
+    if (item.key) {
+      keyList.push(item.key)
+    }
+  }
+  return keyList
+}
 const loadingData = ref(false)
 onMounted(async () => {
   //加载商品规格
@@ -358,9 +415,40 @@ onMounted(async () => {
         attrs_value.suk = values.suk
         attrs_value.image = [values.image]
       }
-      // if(formData.spec_type == 1){
-
-      // }
+      if (formData.spec_type == 1) {
+        const atrs = res.data.productAttr.map((ree): productRuleValue => {
+          return {
+            attrHidden: '',
+            detail: ree.attr_values,
+            detailValue: '',
+            value: ree.attr_name
+          }
+        })
+        actionAttrs.push(...atrs)
+        await attrsConfirm('header')
+        const keyList = getKeyList()
+        productAttrList.value.value = res.data.productValue.map((ree): AttrBaseItem => {
+          const item = {
+            pic: ree.image ? [ree.image] : [],
+            price: ree.price,
+            cost: ree.cost,
+            ot_price: ree.ot_price,
+            stock: ree.stock,
+            detail: ree.detail,
+            volume: ree.volume,
+            bar_code: ree.bar_code,
+            weight: ree.weight
+          }
+          if (keyList.length > 0) {
+            for (let i = 0; i < keyList.length; i++) {
+              const key = keyList[i]
+              item[key] = ree[key]
+            }
+          }
+          return item
+        })
+      }
+      //加载门店
       getStore('', data.store_id)
     } catch (error) {
       console.log(error, 'error')
@@ -432,7 +520,6 @@ const attrBase = reactive<AttrBaseItem[]>([
     bar_code: '', //产品编号
     cost: 0, //成本价
     detail: {},
-    integral: 0, //积分
     ot_price: 0, //原价
     pic: [], //图片
     price: 0, //售价
@@ -445,7 +532,7 @@ const attrBase = reactive<AttrBaseItem[]>([
 const productAttrList = ref<{
   attr: any[]
   header: any[]
-  value: any[]
+  value: AttrBaseItem[]
 }>({
   attr: [],
   header: [],
@@ -506,17 +593,22 @@ const addAttrItem = (tag: productRuleValue) => {
 /**
  * 生成多规格填写列表
  */
-const attrsConfirm = async () => {
+const attrsConfirm = async (header?: string) => {
   const { data } = await getAttrSelectList(formData.id || 0, actionAttrs)
-  const attrs = {
-    attr: data.attr,
-    header: data.header,
-    value: data.value.map((re) => {
-      re.pic = re.pic ? [re.pic] : []
-      return re
-    })
+  if (header == 'header') {
+    productAttrList.value.header = data.header
+  } else {
+    const attrs = {
+      attr: data.attr,
+      header: data.header,
+      value: data.value.map((re) => {
+        re.pic = re.pic ? [re.pic] : []
+        return re
+      })
+    }
+    productAttrList.value = attrs
   }
-  productAttrList.value = attrs
+  return true
 }
 
 /**
@@ -549,7 +641,6 @@ const initAttrBase = () => {
     bar_code: '', //产品编号
     cost: 0, //成本价
     detail: {},
-    integral: 0, //积分
     ot_price: 0, //原价
     pic: [], //图片
     price: 0, //售价
@@ -567,7 +658,6 @@ const batchSet = () => {
     value[i].pic = attrBase[0].pic
     value[i].bar_code = attrBase[0].bar_code
     value[i].cost = attrBase[0].cost
-    value[i].integral = attrBase[0].integral
     value[i].price = attrBase[0].price
     value[i].ot_price = attrBase[0].ot_price
     value[i].stock = attrBase[0].stock
@@ -577,9 +667,9 @@ const batchSet = () => {
 }
 const upImageButtomRef = useTemplateRef('upImageButtomRef')
 
-const selectPic = ref<string[]>([])
-const selectPicIndex = ref(0)
-const selectPicObj = ref('header')
+const selectPic = ref<string[]>([]) //选中的图片
+const selectPicIndex = ref(0) //上传图片选择对象
+const selectPicObj = ref('header') //上传图片类型
 
 /**
  * 点击上传图片回调函数
@@ -856,11 +946,6 @@ const changePic = (pic: string[]) => {
                       <ElInput type="number" v-model="row.price" />
                     </template>
                   </ElTableColumn>
-                  <!-- <ElTableColumn prop="integral" label="积分">
-                  <template #default="{ row }">
-                    <ElInput type="number" v-model="row.integral" />
-                  </template>
-                </ElTableColumn> -->
                   <ElTableColumn prop="cost" label="成本价">
                     <template #default="{ row }">
                       <ElInput type="number" v-model="row.cost" />
@@ -878,7 +963,7 @@ const changePic = (pic: string[]) => {
                       <ElInput type="number" v-model="row.stock" />
                     </template>
                   </ElTableColumn>
-                  <ElTableColumn prop="bar_code" label="产品编号">
+                  <!-- <ElTableColumn prop="bar_code" label="产品编号">
                     <template #default="{ row }">
                       <ElInput v-model="row.bar_code" />
                     </template>
@@ -892,7 +977,7 @@ const changePic = (pic: string[]) => {
                     <template #default="{ row }">
                       <ElInput v-model="row.volume" />
                     </template>
-                  </ElTableColumn>
+                  </ElTableColumn> -->
                   <ElTableColumn fixed="right" label="操作" width="140px">
                     <BaseButton link type="primary" @click="batchSet"> 批量设置 </BaseButton>
                     <ElDivider direction="vertical" />

+ 1 - 2
src/views/Goods/rule/index.vue

@@ -1,5 +1,5 @@
 <script setup lang="tsx">
-import { reactive, ref, unref, useTemplateRef } from 'vue'
+import { reactive, ref, unref } from 'vue'
 import { useTable } from '@/hooks/web/useTable'
 import { useI18n } from '@/hooks/web/useI18n'
 import { Table, TableColumn } from '@/components/Table'
@@ -104,7 +104,6 @@ const dialogVisible = ref(false)
 const currentRow = ref(0)
 const dialogTitle = ref('')
 const actionType = ref('')
-const writeRef = useTemplateRef('writeRef')
 
 const action = async (type: string, row?: any) => {
   actionType.value = type

+ 0 - 7
src/views/System/log/index.vue

@@ -154,13 +154,6 @@ const searchParams = ref<{
 })
 const setSearchParams = (data: any) => {
   searchParams.value = data
-  if (data.time) {
-    searchParams.value.time =
-      formatToDateTime(data.time[0], 'YYYY/MM/DD HH:mm:ss') +
-      '-' +
-      formatToDateTime(data.time[1], 'YYYY/MM/DD HH:mm:ss')
-  }
-  // console.log(data, 'data')
   getList()
 }
 

+ 0 - 3
src/views/User/level/index.vue

@@ -17,12 +17,9 @@ import Write from './components/Write.vue'
 import { BaseButton } from '@/components/Button'
 import { userLevelSearch } from '@/api/user/types'
 import { ElMessage, ElSwitch, ElDivider, ElMessageBox } from 'element-plus'
-import { searchTime } from '@/utils/searchTime'
 import { Dialog } from '@/components/Dialog'
 import { userLevelData } from '@/api/user/types'
 import { TableImage } from '@/components/tableImage'
-
-searchTime.field = 'user_time'
 const { t } = useI18n()
 
 const { tableRegister, tableState, tableMethods } = useTable({