<template>
  <!-- 搜索 -->
  <div class="search-one">
    <div style="text-align: right;" class="search-input">
      <el-input v-model="queryParams.name" placeholder="门店名称" clearable @keyup.enter="handleQuery">
        <template #suffix>
          <Icon class="mr-5px" icon="ep:search" @click="handleQuery" style="cursor: pointer;" />
        </template>
        <template #append>
          <el-button :icon="Operation" @click="showSearchMore" />
        </template>
      </el-input>
      <el-button v-hasPermi="['trade:delivery:pick-up-store:create']" plain type="primary" @click="openForm('create')" v-show="!mobile">
        <Icon class="mr-5px" icon="ep:plus" />
        新增
      </el-button>
    </div>
  </div>
  <div class="searchMore" v-show="searchMoreShow" :style="{ width: (mobile ? '88.7%' : '96%') }">
    <el-form ref="queryFormRef" :inline="true" :model="queryParams" class="-mb-15px">
      <el-form-item label="门店手机" prop="phone">
        <el-input v-model="queryParams.phone" class="!w-240px" clearable placeholder="请输门店手机"
          @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="门店名称" prop="name">
        <el-input v-model="queryParams.name" class="!w-240px" clearable placeholder="请输门店名称"
          @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="门店状态" prop="status">
        <el-select v-model="queryParams.status" class="!w-240px" clearable placeholder="门店状态">
          <el-option v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker v-model="queryParams.createTime" class="!w-240px" end-placeholder="结束日期"
          start-placeholder="开始日期" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss" />
      </el-form-item>

      <el-row>
        <el-col>
          <el-form-item>
            <el-button @click="hideSearchMore">
              收起
            </el-button>
            <el-button @click="resetQuery">
              重置
            </el-button>
            <el-button @click="handleQuery">
              <Icon icon="ep:search" />搜索
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
  <el-row>
    <el-col v-for="(o, index) in list" class="card" :key="index" :span="7" :xl="7" :lg="7" :md="7" :sm="24" :xs="24">
      <el-card @click="openTabs('view', o)">
        <div style="display: flex;justify-content: space-between;align-items: center;margin-bottom: 5px;">
          <p style="width: 100%;white-space: nowrap;text-overflow: ellipsis;overflow: hidden;font-size: 16px;color:#000"
            :title="o.name">{{ o.name }}
          </p>
          <div v-show="!mobile" v-hasPermi="['trade:delivery:pick-up-store:update']" class="setting" @click.stop="openTabs('update', o)" >
            <el-icon size="20" color="rgb(220 223 231)">
              <Setting />
            </el-icon>
          </div>
        </div>
        <div style="display:flex;">
          <div
							style="width: 178px;height: 100px;margin-right:10px;border:1px solid rgb(220 223 231);border-radius: 5px;display: flex;align-items: center;justify-content: center;overflow: hidden;">
							<img :src="o.logo" style="width: 100%; height: 100%; object-fit: cover; object-position: center;" />
						</div>

          <div style='line-height: 25px;'>
            <p>{{ o.phone }}</p>
            <p>{{ getDictLabel(DICT_TYPE.COMMON_STATUS,o.status) }}</p>
            <p>{{ o.openingTime }} ~ {{ o.closingTime }}</p>
            <p>{{o.detailAddress}}</p>
          </div>
        </div>
      </el-card>
    </el-col>
  </el-row>
  <div v-if="list.length == 0">
    <p style="text-align: center;margin-top: 100px;">暂无门店</p>
  </div>
  <Pagination v-model:limit="queryParams.pageSize" v-model:page="queryParams.pageNo" :total="total"
    @pagination="getList" />

  <!-- 列表 -->
  <!-- <ContentWrap>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="编号" min-width="80" prop="id" />
      <el-table-column label="门店 logo" min-width="100" prop="logo">
        <template #default="scope">
          <img v-if="scope.row.logo" :src="scope.row.logo" alt="门店 logo" class="h-50px" />
        </template>
      </el-table-column>
      <el-table-column label="门店名称" min-width="150" prop="name" />
      <el-table-column label="门店手机" min-width="100" prop="phone" />
      <el-table-column label="地址" min-width="100" prop="detailAddress" />
      <el-table-column label="营业时间" min-width="180">
        <template #default="scope">
          {{ scope.row.openingTime }} ~ {{ scope.row.closingTime }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="开启状态" min-width="100" prop="status">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column :formatter="dateFormatter" align="center" label="创建时间" prop="createTime" width="180" />
      <el-table-column align="center" label="操作">
        <template #default="scope">
          <el-button v-hasPermi="['trade:delivery:pick-up-store:update']" link type="primary"
            @click="openForm('update', scope.row.id)">
            编辑
          </el-button>
          <el-button v-hasPermi="['trade:delivery:pick-up-store:delete']" link type="danger"
            @click="handleDelete(scope.row.id)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </ContentWrap> -->
  <!-- 表单弹窗：添加/修改 -->
  <PickUpStoreTabs ref="formRef" @success="getList" />
</template>
<script lang="ts" name="DeliveryPickUpStore" setup>
import * as DeliveryPickUpStoreApi from '@/api/mall/trade/delivery/pickUpStore'
import PickUpStoreTabs from './components/PickUpStoreTabs.vue'
import { DICT_TYPE, getIntDictOptions,getDictLabel } from '@/utils/dict'

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const total = ref(0) // 列表的总页数
const loading = ref(true) // 列表的加载中
const list = ref<any[]>([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  status: undefined,
  phone: undefined,
  name: undefined,
  createTime: []
})
const queryFormRef = ref() // 搜索的表单



/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await DeliveryPickUpStoreApi.deleteDeliveryPickUpStore(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch { }
}

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await DeliveryPickUpStoreApi.getDeliveryPickUpStorePage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/*********************** 中星查询列表开始 **********************/

import { Setting, Search, Operation } from '@element-plus/icons-vue'
// 从路由中引入store中的app仓库
import { useAppStore } from '@/store/modules/app'
const { push } = useRouter() // 路由跳转

const appStore = useAppStore()
const mobile = computed(() => appStore.getMobile)

const searchMoreShow = ref(false)
// 打开更多搜索条件
const showSearchMore = () => {
  searchMoreShow.value = !searchMoreShow.value
}
const hideSearchMore = () => {
  searchMoreShow.value = false
}
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
  formRef.value.open(type, id)
}
// const MemberUserTabRef = ref()
const openTabs = (type: string, obj?: object) => {
  if (mobile.value) {
    const userObj = JSON.stringify(obj)
    // MemberUserMobileTab
    push({ name: 'PickUpStoreMobileTab', query: { 'type': type, 'obj': userObj } })
  } else {
    formRef.value.open(type, obj)
  }
}
/************************ 中星查询列表结束 ***************************/

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
<style src="@/styles/SearchIndex.css"  lang="scss" scoped></style>
<style lang="scss" scoped>
.setting {
  display: none !important;
}

.card:hover {
  .setting {
    display: block !important;

    .el-icon {
      margin-top: 5px;
    }
  }
}
</style>
