Browse Source

feat: store-add

lhl 10 months ago
parent
commit
442372b6e3
3 changed files with 201 additions and 78 deletions
  1. 4 0
      src/api/store/index.ts
  2. 46 42
      src/views/Store/list/components/Write.vue
  3. 151 36
      src/views/Store/list/index.vue

+ 4 - 0
src/api/store/index.ts

@@ -12,3 +12,7 @@ export const addStore = (data: any): Promise<IResponse> => {
 export const editStore = (data: any): Promise<IResponse> => {
   return request.put({ url: `${REQUEST_BASE}/store/${data.id}`, data })
 }
+
+export const delStore = (id: number): Promise<IResponse> => {
+  return request.delete({ url: `${REQUEST_BASE}/store/${id}` })
+}

+ 46 - 42
src/views/Store/list/components/Write.vue

@@ -5,30 +5,29 @@ import { useForm } from '@/hooks/web/useForm'
 import { PropType, watch, ref, onMounted, unref } from 'vue'
 import { useValidator } from '@/hooks/web/useValidator'
 import { cloneDeep } from 'lodash-es'
-import { ElAutocomplete, ElAvatar, ElText } from 'element-plus'
+import { ElAutocomplete } from 'element-plus'
 import { getConfigKey, getMapSearch } from '@/api/system/admin'
 import { mapAddressData } from '@/api/system/admin/types'
-import { UserList } from '@/components/UserList'
-import { BaseButton } from '@/components/Button'
+// import { UserList } from '@/components/UserList'
+// import { BaseButton } from '@/components/Button'
+import { UserButtom } from '@/components/UserList'
 
 const mapKey = ref('')
 const actionAddress = ref<mapAddressData>()
 const { required } = useValidator()
 const center = ref({ lat: 28.655759, lng: 121.420808 })
 const geometries = ref([{ styleId: 'marker', position: { lat: 28.655759, lng: 121.420808 } }])
-const userDetail = ref<any>()
-const showDrawer = ref(false)
+// const userDetail = ref<any>()
 
 const checkedUser = async (res: any) => {
-  userDetail.value = res
   setValues({
     uid: res.uid
     // name: res.real_name,
     // avatar: [res.avatar],
     // birth_day_time: res.birthday,
-    // phone: res.phone
+    // phone: res.phone,
+    // gender: res.sex || 0
   })
-  showDrawer.value = false
 }
 
 onMounted(async () => {
@@ -36,6 +35,19 @@ onMounted(async () => {
   if (res) {
     mapKey.value = res.data.tengxun_map_key
   }
+  if (props.currentRow) {
+    console.log(props.currentRow, 'props.currentRow')
+    rules.value.store_account = [
+      {
+        required: false
+      }
+    ]
+    rules.value.store_password = [
+      {
+        required: false
+      }
+    ]
+  }
 })
 
 const props = defineProps({
@@ -50,7 +62,6 @@ const selectAddress = (item: mapAddressData) => {
     console.error('Invalid input item:', item)
     return
   }
-
   const adcodeStr = String(item.adcode).padStart(6, '0') // 确保 adcode 至少有6位
   const province = adcodeStr.slice(0, 2)
   const city = adcodeStr.slice(2, 4)
@@ -61,7 +72,9 @@ const selectAddress = (item: mapAddressData) => {
     city: `${province}${city}00000000`,
     area: `${area}000000`,
     longitude: item.lng,
-    latitude: item.lat
+    latitude: item.lat,
+    address: item.address,
+    detailed_address: item.label
   })
 
   actionAddress.value = item
@@ -101,32 +114,17 @@ const formSchema = ref<FormSchema[]>([
     component: 'CheckboxGroup',
     formItemProps: {
       slots: {
-        default: () => {
-          if (userDetail?.value) {
-            return (
-              <>
-                <BaseButton size="large" onClick={() => (showDrawer.value = true)}>
-                  <div class={'flex items-center'}>
-                    <ElAvatar shape="circle" size="small" src={userDetail?.value?.avatar}>
-                      <img src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" />
-                    </ElAvatar>
-                    <div class={'flex flex-col ml-5px items-start justify-start'}>
-                      <ElText class={'self-start!'}>{userDetail?.value?.nickname}</ElText>
-                      <ElText size="small" class={'self-start!'}>
-                        UID:{userDetail?.value?.uid}
-                      </ElText>
-                    </div>
-                  </div>
-                </BaseButton>
-              </>
-            )
-          } else {
-            return (
-              <>
-                <BaseButton onClick={() => (showDrawer.value = true)}>选择用户</BaseButton>
-              </>
-            )
-          }
+        default: (data) => {
+          return (
+            <>
+              <UserButtom
+                v-model={data.uid}
+                onChangeUser={(res) => {
+                  checkedUser(res)
+                }}
+              ></UserButtom>
+            </>
+          )
         }
       }
     }
@@ -205,7 +203,7 @@ const formSchema = ref<FormSchema[]>([
         default: (data) => {
           return (
             <>
-              <UpImgButtom v-model={data.slide_images}></UpImgButtom>
+              <UpImgButtom num={3} v-model={data.slide_images}></UpImgButtom>
             </>
           )
         }
@@ -303,7 +301,7 @@ const formSchema = ref<FormSchema[]>([
     component: 'Switch'
   },
   {
-    field: 'detail_address',
+    field: 'detailed_address',
     label: '省市区地址',
     colProps: {
       span: 24
@@ -315,7 +313,7 @@ const formSchema = ref<FormSchema[]>([
           return (
             <>
               <ElAutocomplete
-                v-model={data.detail_address}
+                v-model={data.detailed_address}
                 value-key="label"
                 onSelect={(val: any) => {
                   selectAddress(val)
@@ -373,7 +371,6 @@ const formSchema = ref<FormSchema[]>([
     hidden: true,
     component: 'Input'
   },
-
   {
     field: 'id',
     label: 'id',
@@ -384,6 +381,7 @@ const formSchema = ref<FormSchema[]>([
 
 const rules = ref({
   name: [required('请填写门店名称')],
+  uid: [required('请选择绑定用户')],
   introduction: [required('请填写门店简介')],
   phone: [required('请填写联系号码')],
   logo: [required('请选择logo')],
@@ -392,10 +390,11 @@ const rules = ref({
   valid_range: [required('请填写有效距离')],
   store_account: [required('请填写登录账号')],
   store_password: [required('请填写登录密码')],
-  detail_address: [
+  detailed_address: [
     {
       required: true,
       validator: (_, val, callback) => {
+        console.log(actionAddress.value, val, 'actionAddress.value')
         if (!actionAddress.value || !val) {
           callback(new Error('请选择地址'))
         } else {
@@ -425,6 +424,12 @@ watch(
   async (value) => {
     if (!value) return
     const currentRow = cloneDeep(value)
+    actionAddress.value = {
+      adcode: currentRow.area,
+      label: currentRow.detail_address,
+      lng: currentRow.longitude,
+      lat: currentRow.latitude
+    }
     setValues(currentRow)
   },
   {
@@ -464,5 +469,4 @@ defineExpose({
       }"
     />
   </TlbsMap>
-  <UserList v-model="showDrawer" @confirm="checkedUser" />
 </template>

+ 151 - 36
src/views/Store/list/index.vue

@@ -1,7 +1,6 @@
 <script setup lang="tsx">
 import { reactive, ref, unref, useTemplateRef } from 'vue'
-import { delStaffCategory } from '@/api/staff'
-import { getStoreList, addStore, editStore } from '@/api/store'
+import { getStoreList, addStore, editStore, delStore } from '@/api/store'
 import { useTable } from '@/hooks/web/useTable'
 import { useI18n } from '@/hooks/web/useI18n'
 import { Table, TableColumn } from '@/components/Table'
@@ -10,7 +9,8 @@ import { FormSchema } from '@/components/Form'
 import { ContentWrap } from '@/components/ContentWrap'
 import { Dialog } from '@/components/Dialog'
 import { BaseButton } from '@/components/Button'
-import { ElDivider, ElMessage, ElMessageBox } from 'element-plus'
+import { ElDivider, ElMessage, ElMessageBox, ElTag } from 'element-plus'
+import { TableImage } from '@/components/tableImage'
 import Write from './components/Write.vue'
 
 const { t } = useI18n()
@@ -40,19 +40,106 @@ const tableColumns = reactive<TableColumn[]>([
     width: 70
   },
   {
-    field: 'type_chs',
-    label: '类型',
-    minWidth: 100
+    field: 'logo',
+    label: 'LOGO',
+    width: 80,
+    slots: {
+      default: ({ row }: any) => {
+        return (
+          <>
+            <TableImage src={row.logo} />
+          </>
+        )
+      }
+    }
   },
   {
     field: 'name',
-    label: '分类',
-    minWidth: 140
+    label: '门店名称',
+    minWidth: 100
+  },
+  {
+    field: 'introduction',
+    label: '简介',
+    minWidth: 150
   },
   {
-    field: 'is_show_chs',
+    field: 'type',
+    label: '类型',
+    width: 80,
+    slots: {
+      default: ({ row }: any) => {
+        return <>{row.type == 1 ? '自营' : '加盟'}</>
+      }
+    }
+  },
+  {
+    field: 'manager_name',
+    label: '店长',
+    width: 80
+  },
+  {
+    field: 'phone',
+    label: '联系号码',
+    width: 150
+  },
+  {
+    field: 'detailed_address',
+    label: '地址',
+    minWidth: 150
+  },
+  {
+    field: 'valid_range',
+    label: '有效距离(km)',
+    width: 150
+  },
+  {
+    field: 'product_verify_status',
+    label: '商品免审核',
+    width: 150,
+    slots: {
+      default: ({ row }: any) => {
+        return (
+          <>
+            <ElTag class="mr-5px" type={row.product_verify_status ? 'primary' : 'danger'}>
+              {row.product_verify_status ? '开启' : '关闭'}
+            </ElTag>
+          </>
+        )
+      }
+    }
+  },
+  {
+    field: 'product_status',
+    label: '自主添加商品',
+    width: 150,
+    slots: {
+      default: ({ row }: any) => {
+        return (
+          <>
+            <ElTag class="mr-5px" type={row.product_status ? 'primary' : 'danger'}>
+              {row.product_status ? '开启' : '关闭'}
+            </ElTag>
+          </>
+        )
+      }
+    }
+  },
+  {
+    field: 'is_show',
     label: '是否显示',
-    width: 120
+    width: 190,
+    slots: {
+      default: ({ row }: any) => {
+        return (
+          <>
+            <ElTag class="mr-5px" type={row.is_show ? 'primary' : 'danger'}>
+              {row.is_show ? '显示' : '隐藏'}
+            </ElTag>
+          </>
+        )
+      }
+    }
   },
   {
     field: 'action',
@@ -85,14 +172,10 @@ const searchSchema = reactive<FormSchema[]>([
     field: 'type',
     label: '类型',
     component: 'Select',
-    value: '',
+    value: '1',
     componentProps: {
-      placeholder: '全部',
+      placeholder: '自营',
       options: [
-        {
-          label: '全部',
-          value: ''
-        },
         {
           label: '自营',
           value: '1'
@@ -109,7 +192,7 @@ const searchSchema = reactive<FormSchema[]>([
 const searchParams = ref<{
   type?: string
 }>({
-  type: ''
+  type: '1'
 })
 const setSearchParams = (data: any) => {
   searchParams.value = data
@@ -123,6 +206,13 @@ const actionType = ref('')
 const saveLoading = ref(false)
 const writeRef = useTemplateRef('writeRef')
 
+// function arrayToObject(array) {
+//     var obj = {};
+//     for (var i = 0; i < array.length; i++) {
+//         obj[i] = array[i];
+//     }
+//     return obj;
+// }
 const action = async (type: string, row?: any) => {
   actionType.value = type
   if (type == 'add') {
@@ -132,10 +222,27 @@ const action = async (type: string, row?: any) => {
   if (type == 'edit') {
     dialogTitle.value = t('exampleDemo.edit')
     currentRow.value = {
+      uid: row.uid,
       id: row.id,
       name: row.name,
-      is_show: row.is_show == 1 ? true : false
+      is_show: row.is_show == 1 ? true : false,
+      introduction: row.introduction,
+      address: row.address,
+      area: row.area,
+      city: row.city,
+      province: row.province,
+      detailed_address: row.detailed_address,
+      latitude: row.latitude,
+      logo: [row.logo],
+      longitude: row.longitude,
+      manager_name: row.manager_name,
+      phone: row.phone,
+      product_verify_status: row.product_verify_status == 1 ? true : false,
+      product_status: row.product_status == 1 ? true : false,
+      valid_range: row.valid_range,
+      slide_images: row.slide_images_chs
     }
+    console.log(currentRow, 'currentRow')
   }
   dialogVisible.value = true
 }
@@ -146,7 +253,7 @@ const delAction = (row: any) => {
     type: 'warning'
   })
     .then(async () => {
-      const re = await delStaffCategory(row.id)
+      const re = await delStore(row.id)
       if (re) {
         ElMessage({
           showClose: true,
@@ -162,7 +269,10 @@ const save = async () => {
   const write = unref(writeRef)
   const formData = await write?.submit()
   if (formData) {
-    saveLoading.value = true
+    let arr: string[] = []
+    for (let key in formData.slide_images) {
+      arr.push(formData.slide_images[key] || '')
+    }
     const data: any = {
       uid: formData.uid,
       id: formData.id || '',
@@ -170,14 +280,14 @@ const save = async () => {
       type: formData.type,
       logo: formData.logo[0],
       introduction: formData.introduction,
-      slide_images: formData.slide_images[0],
+      slide_images: arr,
       manager_name: formData.manager_name,
       phone: formData.phone,
       valid_range: formData.valid_range,
       product_status: formData.product_status ? 1 : 0,
       product_verify_status: formData.product_verify_status ? 1 : 0,
-      detailed_address: formData.detail_address,
-      address: formData.detail_address,
+      detailed_address: formData.detailed_address,
+      address: formData.address,
       area: formData.area,
       city: formData.city,
       province: formData.province,
@@ -187,20 +297,25 @@ const save = async () => {
       store_account: formData.store_account,
       store_password: formData.store_password
     }
-    console.log(data, 'data')
-    if (actionType.value === 'edit') {
-      await editStore(data)
-    } else if (actionType.value === 'add') {
-      await addStore(data)
+    try {
+      if (actionType.value === 'edit') {
+        await editStore(data)
+      } else if (actionType.value === 'add') {
+        await addStore(data)
+      }
+      ElMessage({
+        showClose: true,
+        message: '保存成功',
+        type: 'success'
+      })
+      getList()
+      saveLoading.value = false
+      dialogVisible.value = false
+    } catch (error) {
+      console.log(error)
+    } finally {
+      saveLoading.value = false
     }
-    ElMessage({
-      showClose: true,
-      message: '保存成功',
-      type: 'success'
-    })
-    getList()
-    saveLoading.value = false
-    dialogVisible.value = false
   }
 }
 </script>