| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import request from '../../Utils/RequestUtils';
- import Toast from '../../flooks/Toast';
- import User from '../../flooks/User';
- import submitPhone from '../../Utils/FormUtils';
- import { alert } from '../../Utils/TotastUtils';
- const AddressModel = (now) => ({
- addressList: [],
- goEdit: false,
- chooseAddressId: 0,
- getAddressList() {
- const { id } = now(User);
- return request
- .get(`/address/all`, {
- params: {
- query: {
- userId: id,
- enabled: true,
- },
- },
- })
- .then((res) => {
- res.content = res.content.filter((item) => {
- return item.latitude && item.longitude;
- });
- now({
- addressList: res.content,
- });
- const addressInfo = res.content.find((item) => {
- return item.isDefault;
- });
- if (addressInfo) {
- now({
- chooseAddressId: addressInfo.id,
- });
- }
- });
- },
- saveAddress(
- addressId,
- name,
- sex,
- phone,
- addressName,
- number,
- addressTag,
- isDefault,
- latitude,
- longitude
- ) {
- const { id } = now(User);
- const { success } = now(Toast);
- const { getAddressList } = now();
- return request
- .post(`/address/save`, {
- data: {
- userId: id,
- id: addressId || '',
- name,
- sex,
- phone: submitPhone(phone),
- addressName,
- number,
- addressTag: addressTag || null,
- isDefault,
- latitude,
- longitude,
- },
- })
- .then(() => {
- return getAddressList();
- })
- .then(() => {
- success('保存成功');
- });
- },
- delAddress(id) {
- alert('', '确定要删除该地址吗?删除后不可恢复!', () => {
- const { success } = now(Toast);
- const { getAddressList } = now();
- return request
- .post(`/address/del/${id}`)
- .then(() => {
- return getAddressList();
- })
- .then(() => {
- success('删除成功');
- });
- });
- },
- setShow(bool) {
- now({
- goEdit: bool,
- });
- },
- setChoose(id) {
- now({ chooseAddressId: id });
- },
- });
- export default AddressModel;
|