goodsModel.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* eslint-disable no-underscore-dangle */
  2. import ListUtil from "../Utils/ListUtil";
  3. export default {
  4. state: {
  5. selectInfos: [],
  6. Classifications: [], // 商户分类列表
  7. classificationId: 0, // 当前操作的商品分类
  8. },
  9. actions: ({ model, setState }) => ({
  10. // 商家分类选择商品
  11. changeSelect(list) {
  12. setState({
  13. selectInfos: list,
  14. });
  15. },
  16. // 下架提示
  17. takeOffInfo(callBack) {
  18. const { showDialog } = model("dialogModel");
  19. const { takeOffTips } = model("wordsModel");
  20. showDialog({
  21. bodyText: takeOffTips,
  22. status: "danger",
  23. cancelable: true,
  24. confirmCallback: () => callBack(),
  25. });
  26. },
  27. // 商品上下架
  28. ChangeTakeOff(info) {
  29. const { id } = info;
  30. const { getWordsStr, successText } = model("wordsModel");
  31. const { httpGet } = model("httpModel");
  32. const { success } = model("loadingModel");
  33. return httpGet(
  34. "/goods/take",
  35. {
  36. id,
  37. },
  38. true
  39. )
  40. .then(() => {
  41. return httpGet(`/goods/get/${id}`, {}, true);
  42. })
  43. .then(res => {
  44. success(
  45. getWordsStr(res.takeOff ? "takeOff" : "takeUp") + successText
  46. );
  47. return Promise.resolve(res);
  48. });
  49. },
  50. // 关闭分类提示
  51. clossClassTip(callBack) {
  52. const { showDialog } = model("dialogModel");
  53. const { systemClassTips1 } = model("wordsModel");
  54. showDialog({
  55. bodyText: systemClassTips1,
  56. status: "danger",
  57. cancelable: true,
  58. confirmCallback: () => callBack(),
  59. });
  60. },
  61. saveInfo(info, noTip) {
  62. const { saveSuccess, editSuccess } = model("wordsModel");
  63. const { httpPost } = model("httpModel");
  64. const { success, loading } = model("loadingModel");
  65. loading();
  66. return httpPost(
  67. "/classification/save",
  68. info,
  69. { body: "json" },
  70. true
  71. ).then(res => {
  72. if (!noTip) {
  73. success(info.id ? editSuccess : saveSuccess);
  74. }
  75. return Promise.resolve(res);
  76. });
  77. },
  78. // 移除分类商品
  79. removeClassGoods(classificationId, goodId, callBack) {
  80. const { showDialog } = model("dialogModel");
  81. const { removeTips, editSuccess } = model("wordsModel");
  82. const { httpGet } = model("httpModel");
  83. const { success, loading } = model("loadingModel");
  84. loading();
  85. showDialog({
  86. bodyText: removeTips,
  87. status: "danger",
  88. cancelable: true,
  89. confirmCallback: () => {
  90. httpGet(
  91. "/classification/delGoods",
  92. {
  93. classificationId,
  94. goodId,
  95. },
  96. true
  97. ).then(res => {
  98. success(editSuccess);
  99. callBack(res);
  100. });
  101. },
  102. });
  103. },
  104. // 添加分类商品
  105. addClassGoods(info) {
  106. const { successText } = model("wordsModel");
  107. const { success, loading } = model("loadingModel");
  108. const { httpPost} = model("httpModel");
  109. loading();
  110. return httpPost(
  111. "/goodsSpecification/save",
  112. info,
  113. {
  114. body: "json",
  115. },
  116. true
  117. ).then(res => {
  118. success(successText);
  119. return Promise.resolve(res);
  120. });
  121. },
  122. // 移除商品分类
  123. removeCLass(info, callBack) {
  124. const { showDialog } = model("dialogModel");
  125. const { removeTips, editSuccess } = model("wordsModel");
  126. const { httpPost } = model("httpModel");
  127. const { success, loading } = model("loadingModel");
  128. loading();
  129. showDialog({
  130. bodyText: removeTips,
  131. status: "danger",
  132. cancelable: true,
  133. confirmCallback: () => {
  134. const goods = new ListUtil(info.goodsIds);
  135. if (goods.length > 0) {
  136. showDialog({
  137. bodyText: "该分类下有商品,暂不可删除该商品分类",
  138. status: "danger",
  139. });
  140. } else {
  141. httpPost(`/classification/del/${info.id}`, {}, {}, true).then(
  142. res => {
  143. success(editSuccess);
  144. callBack(res);
  145. }
  146. );
  147. }
  148. },
  149. });
  150. },
  151. // 商品分类添加商品
  152. addClassification(selectId, goodsId) {
  153. const { httpGet } = model("httpModel");
  154. return httpGet(
  155. "/classification/saveGoods",
  156. {
  157. classificationId: selectId,
  158. string: goodsId,
  159. },
  160. { body: "json" }
  161. );
  162. },
  163. // 将当前选中的classId存入以便更好的刷新页面3
  164. setClassificationId(id) {
  165. setState({
  166. classificationId: id,
  167. });
  168. },
  169. // 获取我的全部商品分类
  170. getMyClassification() {
  171. const { httpGet } = model("httpModel");
  172. return httpGet("/classification/my", {}, true).then(res => {
  173. res = res.sort((a, b) => {
  174. return b.type || 0 - a.type || 0;
  175. });
  176. setState({ Classifications: res });
  177. return Promise.resolve(res);
  178. });
  179. },
  180. // 商品规格排序
  181. sortClassification(list) {
  182. const _list = [...list];
  183. let backList = [];
  184. const parents = _list.filter(item => {
  185. return !item.parent;
  186. });
  187. parents.forEach(item => {
  188. backList.push(item);
  189. const _chidrens = _list.filter(_f => {
  190. return _f.parent === item.id;
  191. });
  192. backList = backList.concat(_chidrens);
  193. });
  194. return backList;
  195. },
  196. }),
  197. };