goodsModel.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 } = model("loadingModel");
  65. return httpPost(
  66. "/classification/save",
  67. info,
  68. { body: "json" },
  69. true
  70. ).then(res => {
  71. if (!noTip) {
  72. success(info.id ? editSuccess : saveSuccess);
  73. }
  74. return Promise.resolve(res);
  75. });
  76. },
  77. // 移除分类商品
  78. removeClassGoods(classificationId, goodId, callBack) {
  79. const { showDialog } = model("dialogModel");
  80. const { removeTips, editSuccess } = model("wordsModel");
  81. const { httpGet } = model("httpModel");
  82. const { success } = model("loadingModel");
  83. showDialog({
  84. bodyText: removeTips,
  85. status: "danger",
  86. cancelable: true,
  87. confirmCallback: () => {
  88. httpGet(
  89. "/classification/delGoods",
  90. {
  91. classificationId,
  92. goodId,
  93. },
  94. true
  95. ).then(res => {
  96. success(editSuccess);
  97. callBack(res);
  98. });
  99. },
  100. });
  101. },
  102. // 添加分类商品
  103. addClassGoods(info) {
  104. const { successText } = model("wordsModel");
  105. const { success } = model("loadingModel");
  106. const { httpPost } = model("httpModel");
  107. return httpPost(
  108. "/goodsSpecification/save",
  109. info,
  110. {
  111. body: "json",
  112. },
  113. true
  114. ).then(res => {
  115. success(successText);
  116. return Promise.resolve(res);
  117. });
  118. },
  119. // 移除商品分类
  120. removeCLass(info, callBack) {
  121. const { showDialog } = model("dialogModel");
  122. const { removeTips, editSuccess } = model("wordsModel");
  123. const { httpPost } = model("httpModel");
  124. const { success } = model("loadingModel");
  125. showDialog({
  126. bodyText: removeTips,
  127. status: "danger",
  128. cancelable: true,
  129. confirmCallback: () => {
  130. const goods = new ListUtil(info.goodsIds);
  131. if (goods.length > 0) {
  132. showDialog({
  133. bodyText: "该分类下有商品,暂不可删除该商品分类",
  134. status: "danger",
  135. });
  136. } else {
  137. httpPost(`/classification/del/${info.id}`, {}, {}, true).then(
  138. res => {
  139. success(editSuccess);
  140. callBack(res);
  141. }
  142. );
  143. }
  144. },
  145. });
  146. },
  147. // 商品分类添加商品
  148. addClassification(selectId, goodsId) {
  149. const { httpGet } = model("httpModel");
  150. return httpGet(
  151. "/classification/saveGoods",
  152. {
  153. classificationId: selectId,
  154. string: goodsId,
  155. },
  156. { body: "json" }
  157. );
  158. },
  159. // 将当前选中的classId存入以便更好的刷新页面3
  160. setClassificationId(id) {
  161. setState({
  162. classificationId: id,
  163. });
  164. },
  165. // 获取我的全部商品分类
  166. getMyClassification() {
  167. const { httpGet } = model("httpModel");
  168. return httpGet("/classification/my", {}, true).then(res => {
  169. res = res.sort((a, b) => {
  170. return b.type || 0 - a.type || 0;
  171. });
  172. setState({ Classifications: res });
  173. return Promise.resolve(res);
  174. });
  175. },
  176. // 商品规格排序
  177. sortClassification(list) {
  178. const _list = [...list];
  179. let backList = [];
  180. const parents = _list.filter(item => {
  181. return !item.parent;
  182. });
  183. parents.forEach(item => {
  184. backList.push(item);
  185. const _chidrens = _list.filter(_f => {
  186. return _f.parent === item.id;
  187. });
  188. backList = backList.concat(_chidrens);
  189. });
  190. return backList;
  191. },
  192. }),
  193. };