| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import request from '../../Utils/RequestUtils';
- import Toast from '../../flooks/Toast';
- import User from '../../flooks/User';
- import submitPhone from '../../Utils/FormUtils';
- const AddressModel = (now) => ({
- addressList: [],
- goEdit: false,
- chooseAddressId: 0,
- getAddressList() {
- const { id } = now(User);
- return request
- .get(`/address/all`, {
- params: {
- query: {
- userId: id,
- },
- },
- })
- .then((res) => {
- 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
- ) {
- 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,
- isDefault,
- },
- })
- .then(() => {
- return getAddressList();
- })
- .then(() => {
- success('保存成功');
- });
- },
- setShow(bool) {
- now({
- goEdit: bool,
- });
- },
- setChoose(id) {
- now({ chooseAddressId: id });
- },
- });
- export default AddressModel;
|