| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- import request from '../../Utils/RequestUtils';
- import Toast from '../../flooks/Toast';
- import User from '../../flooks/User';
- import MapModel from '../Map/model';
- const DetailModel = (now) => ({
- id: 0,
- merchantInfo: {},
- cartMap: new Map([]),
- showSelect: false,
- selectInfo: null,
- cartRequest: null,
- heardColor: '',
- selectClass: '',
- goodsList: [], // 全部商品
- payMethod: 'ALI_PAY',
- remark: '',
- tablewareNum: 1,
- cartMoneyInfo: {},
- init(id) {
- now({ id: 0, merchantInfo: {}, goodsList: [] });
- return request
- .get(`/merchant/getDTO/${id}`)
- .then((res) => {
- now({
- id,
- merchantInfo: res,
- });
- return request.get('/goods/goods', {
- params: {
- merchantId: id,
- },
- });
- })
- .then((res) => {
- now({ goodsList: res });
- });
- },
- setHeaderColor(color) {
- now({
- heardColor: color,
- });
- },
- getRecomend() {
- const { id } = now();
- now({ recommendGoods: [] });
- if (!id) {
- return Promise.resolve();
- }
- return request
- .get(`/goods/all`, {
- params: {
- query: {
- recommend: true,
- merchantId: id,
- },
- },
- })
- .then((res) => {
- return Promise.resolve(res.content);
- });
- },
- getCart() {
- const { id, calculatePrice } = now();
- now({ cartList: [] });
- if (!id) {
- return Promise.resolve([]);
- }
- return request
- .get('/shoppingCart/my/merchant', {
- params: {
- merchantId: id,
- },
- })
- .then((res) => {
- now({ remark: '' });
- calculatePrice(res);
- return Promise.resolve(res);
- });
- },
- setCartMap(map) {
- now({
- cartMap: map,
- });
- },
- changeSelect(show) {
- now({
- showSelect: show,
- });
- },
- checkgoodsSpecification(goodsInfo) {
- now({
- selectInfo: goodsInfo,
- showSelect: true,
- });
- },
- addCart(goodsId, goodsSpecificationIds, num) {
- const { warnning } = now(Toast);
- const { cartRequest } = now();
- const { chooseInfo } = now(MapModel);
- const { location } = chooseInfo;
- return request
- .post('/shoppingCart/cart', {
- data: {
- goodsId,
- goodsSpecificationIds,
- num,
- longitude: location.lng,
- latitude: location.lat,
- },
- requestType: 'form',
- })
- .then(() => {
- now({ showSelect: false });
- if (cartRequest) {
- cartRequest.refresh();
- }
- })
- .catch((e) => {
- warnning(e.error);
- });
- },
- setCartRequest(cartRequest) {
- now({ cartRequest });
- },
- clearCart() {
- const { warnning, success } = now(Toast);
- const { cartRequest } = now();
- return request
- .get('/shoppingCart/clearCart')
- .then(() => {
- if (cartRequest) {
- cartRequest.refresh();
- success('清除成功');
- }
- })
- .catch((e) => {
- warnning(e.error);
- });
- },
- delLike(id) {
- return request.post(`/myCollection/del/${id}`);
- },
- // 收藏
- like() {
- const { merchantInfo } = now();
- const { id } = now(User);
- return request.post('/myCollection/save', {
- data: {
- userId: id,
- merchantId: merchantInfo.mid,
- },
- });
- },
- changeSelectClass(id) {
- now({ selectClass: id });
- },
- setPage(name) {
- now({
- pageName: name,
- });
- },
- getUserAppraisal() {
- const { id } = now();
- return request
- .get(`/appraisal/my`, {
- params: { merchantId: id, appraisalSort: 'ALL' },
- })
- .then((res) => {
- // return Promise.resolve(res.content);
- });
- },
- changeNum(specIds, num) {
- const { warnning } = now(Toast);
- const { cartRefreash } = now();
- if (specIds.size > 1) {
- warnning('当前商品存在多个规格,需要在购物车中清理');
- return Promise.resolve();
- } else if (num === 0) {
- return request
- .get(`/shoppingCart/delGoods`, {
- params: { specId: [...specIds][0] },
- })
- .then(() => {
- cartRefreash();
- });
- } else {
- return request
- .get(`/shoppingCart/changeNum`, {
- params: { specId: [...specIds][0], num },
- })
- .then(() => {
- cartRefreash();
- });
- }
- },
- changePay(method) {
- now({ payMethod: method });
- },
- setRemark(remark, tabs) {
- if (remark) {
- tabs.add(remark);
- }
- now({
- remark: [...tabs].join(';'),
- });
- },
- changetablewareNum(num) {
- now({
- tablewareNum: num,
- });
- },
- cartRefreash() {
- const { cartRequest } = now();
- if (cartRequest) {
- cartRequest.refresh();
- now({ remark: '', tablewareNum: 1 });
- }
- },
- calculatePrice(cartList) {
- const { chooseInfo } = now(MapModel);
- if (cartList.length > 0 && chooseInfo.location) {
- const ids = cartList.map((item) => {
- return item.shoppingCartId;
- });
- request
- .get(`/shoppingCart/calculatePrice`, {
- params: {
- cartId: ids[0],
- longitude: chooseInfo.location.lng,
- latitude: chooseInfo.location.lat,
- },
- })
- .then((res) => {
- now({ cartMoneyInfo: res });
- });
- } else {
- now({ cartMoneyInfo: {} });
- }
- },
- // 投诉
- complaintSave(userId, merchantId, type, content, img) {
- const { loading, warnning, success } = now(Toast);
- loading();
- return request
- .post(`/merchantComplaint/save`, {
- data: {
- userId,
- merchantId,
- type,
- content,
- img,
- },
- })
- .then(() => {
- success('提交成功');
- return Promise.resolve();
- })
- .catch((e) => {
- warnning(e.error);
- });
- },
- });
- export default DetailModel;
|