| @@ -13,6 +13,7 @@ declare module 'vue' { | |||
| Counter: typeof import('./src/components/Counter.vue')['default'] | |||
| ExternalLink: typeof import('./src/components/ExternalLink.vue')['default'] | |||
| Notification: typeof import('./src/components/notification/index.vue')['default'] | |||
| NutActionSheet: typeof import('@nutui/nutui-taro')['ActionSheet'] | |||
| NutAvatar: typeof import('@nutui/nutui-taro')['Avatar'] | |||
| NutButton: typeof import('@nutui/nutui-taro')['Button'] | |||
| NutCalendar: typeof import('@nutui/nutui-taro')['Calendar'] | |||
| @@ -15,3 +15,6 @@ page { | |||
| font-size: 36px | |||
| } | |||
| .nut-action-sheet__item { | |||
| color: red !important; | |||
| } | |||
| @@ -4,12 +4,14 @@ import './index.scss' | |||
| import {useContactItemStore} from "../../stores/contact-item"; | |||
| import { useContactsStore } from "../../stores/contacts"; | |||
| import Taro from "@tarojs/taro"; | |||
| import {ref} from "vue"; | |||
| const contactData = Router.getData() | |||
| const contact = useContactItemStore() | |||
| const contacts = useContactsStore() | |||
| contact.setContact(contactData) | |||
| const showDeleteConfirmMenu = ref(false) | |||
| const goBack = () => { | |||
| Router.back() | |||
| @@ -36,6 +38,31 @@ const onSaveClicked = () => { | |||
| console.log("error", error) | |||
| }) | |||
| } | |||
| const onDeleteVisitor = () => { | |||
| showDeleteConfirmMenu.value = true | |||
| // | |||
| } | |||
| const onDeleteConfirm = (item) => { | |||
| console.log(item) | |||
| Taro.showLoading({ | |||
| title: 'loading', | |||
| }) | |||
| contact.deleteVisitor().then(r => { | |||
| contacts.loadContactsFromServer().then( contactsResult => { | |||
| Taro.hideLoading() | |||
| Router.back() | |||
| }) | |||
| }).catch(error => { | |||
| Taro.hideLoading() | |||
| Taro.showToast({ | |||
| title: '网络异常,请稍候重试', | |||
| icon: 'none', | |||
| duration: 2000 | |||
| }) | |||
| console.log("error", error) | |||
| }) | |||
| } | |||
| </script> | |||
| <template> | |||
| @@ -78,11 +105,14 @@ const onSaveClicked = () => { | |||
| </view> | |||
| <view class="p-3 pb-5"> | |||
| <nut-button block color="red">删除联系人</nut-button> | |||
| <nut-button block color="red" @tap="onDeleteVisitor">删除联系人</nut-button> | |||
| </view> | |||
| </view> | |||
| </view> | |||
| <nut-action-sheet v-model:visible="showDeleteConfirmMenu" :menu-items="[{name: '确认删除'}]" cancel-txt="取消" @choose="onDeleteConfirm"> | |||
| </nut-action-sheet> | |||
| @@ -1,11 +1,42 @@ | |||
| <script setup> | |||
| import { Router } from 'tarojs-router-next' | |||
| import './index.scss' | |||
| import {useContactItemStore} from "../../stores/contact-item"; | |||
| import {useContactsStore} from "../../stores/contacts"; | |||
| import Taro from "@tarojs/taro"; | |||
| const goBack = () => { | |||
| Router.back() | |||
| } | |||
| const contact = useContactItemStore() | |||
| contact.setContact(contact.getEmptyContactData()) | |||
| const contacts = useContactsStore() | |||
| const onSaveClicked = () => { | |||
| Taro.showLoading({ | |||
| title: 'loading', | |||
| }) | |||
| console.log("onSaveClicked") | |||
| console.log(contact.contact) | |||
| contact.createVisitor().then(r => { | |||
| contacts.loadContactsFromServer().then( contactsResult => { | |||
| Taro.hideLoading() | |||
| Router.back() | |||
| }) | |||
| }).catch(error => { | |||
| Taro.hideLoading() | |||
| Taro.showToast({ | |||
| title: '网络异常,请稍候重试', | |||
| icon: 'none', | |||
| duration: 2000 | |||
| }) | |||
| console.log("error", error) | |||
| }) | |||
| } | |||
| </script> | |||
| <template> | |||
| @@ -22,7 +53,7 @@ const goBack = () => { | |||
| <view class="text-black-50">新建来访联系人,并设置到访时间</view> | |||
| </view> | |||
| <view class="d-flex align-items-end"> | |||
| <view class="text-primary save-button">保存</view> | |||
| <view class="text-primary save-button" @tap="onSaveClicked">保存</view> | |||
| </view> | |||
| </view> | |||
| @@ -4,6 +4,8 @@ import { Router } from 'tarojs-router-next' | |||
| import {reactive, ref} from 'vue'; | |||
| import './index.scss' | |||
| import { useContactsStore, ContactData } from '../../stores/contacts' | |||
| import { registerRouterBackListener } from 'tarojs-router-next' | |||
| import {gql} from "graphql-tag"; | |||
| @@ -56,6 +58,16 @@ function init() { | |||
| state.isContactDataLoadError = false | |||
| state.isContactDataLoading = false | |||
| }) | |||
| registerRouterBackListener((to, from) => { | |||
| if ((from.url === "/pages/contact-new/index" && to.url === "/pages/contact/index") | |||
| || (from.url === "/pages/contact-edit/index" && to.url === "/pages/contact/index") | |||
| ) { | |||
| state.searchQuery = "" | |||
| generateContactGroupList(contacts.allContacts) | |||
| } | |||
| }) | |||
| } | |||
| const onAuthErrorRefresh = () => { | |||
| @@ -40,9 +40,7 @@ export const useContactItemStore = defineStore('contact-item', () => { | |||
| isVip: $isVIP, | |||
| flexVisit: $flexVisit, | |||
| resourceId: $resourceId | |||
| } ) { | |||
| result | |||
| } | |||
| } ) | |||
| } | |||
| ` | |||
| @@ -61,6 +59,12 @@ export const useContactItemStore = defineStore('contact-item', () => { | |||
| } | |||
| ` | |||
| const DELETE_VISITOR = gql` | |||
| mutation DeleteVisitor($id: Long! ) { | |||
| deleteVisitor( id: $id ) | |||
| } | |||
| ` | |||
| function createVisitor() { | |||
| const name = contact.value.name | |||
| const nickName = contact.value.nickName | |||
| @@ -85,6 +89,12 @@ export const useContactItemStore = defineStore('contact-item', () => { | |||
| return GQLRequest.query(UPDATE_VISITOR, {id, name, nickName, phone, company, isVIP, flexVisit }) | |||
| } | |||
| function deleteVisitor() { | |||
| const id = contact.value.id | |||
| return GQLRequest.query(DELETE_VISITOR, { id }) | |||
| } | |||
| return { contact, setContact, createVisitor, updateVisitor} | |||
| return { contact, setContact, createVisitor, updateVisitor, deleteVisitor, getEmptyContactData} | |||
| }) | |||