goodsModel.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import ListUtil from "../Utils/ListUtil";
  2. export default {
  3. state: {
  4. selectInfos: [],
  5. Classifications: [], // 商户分类列表
  6. classificationId: 0, // 当前操作的商品分类
  7. },
  8. actions: ({ model, setState }) => ({
  9. // 商家分类选择商品
  10. changeSelect(list) {
  11. setState({
  12. selectInfos: list,
  13. });
  14. },
  15. // 下架提示
  16. takeOffInfo(callBack) {
  17. const { showDialog } = model("dialogModel");
  18. const { takeOffTips } = model("wordsModel");
  19. showDialog({
  20. bodyText: takeOffTips,
  21. status: "danger",
  22. cancelable: true,
  23. confirmCallback: () => callBack(),
  24. });
  25. },
  26. // 商品上下架
  27. ChangeTakeOff(info) {
  28. const { id } = info;
  29. const { getWordsStr, successText } = model("wordsModel");
  30. const { httpGet } = model("httpModel");
  31. const { success } = model("loadingModel");
  32. return httpGet(
  33. "/goods/take",
  34. {
  35. id,
  36. },
  37. true
  38. )
  39. .then(() => {
  40. return httpGet(`/goods/get/${ id}`, {}, true);
  41. })
  42. .then(res => {
  43. success(
  44. getWordsStr(res.takeOff ? "takeOff" : "takeUp") +
  45. 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(
  138. `/classification/del/${ info.id}`,
  139. {},
  140. {},
  141. true
  142. ).then(res => {
  143. success(editSuccess);
  144. callBack(res);
  145. });
  146. }
  147. },
  148. });
  149. },
  150. // 商品分类添加商品
  151. addClassification(selectId, goodsId) {
  152. const { httpGet } = model("httpModel");
  153. return httpGet(
  154. "/classification/saveGoods",
  155. {
  156. classificationId: selectId,
  157. string: goodsId,
  158. },
  159. { body: "json" }
  160. );
  161. },
  162. // 将当前选中的classId存入以便更好的刷新页面3
  163. setClassificationId(id) {
  164. setState({
  165. classificationId: id,
  166. });
  167. },
  168. // 获取我的全部商品分类
  169. getMyClassification() {
  170. const { httpGet } = model("httpModel");
  171. return httpGet("/classification/my", {}, true).then(res => {
  172. res = res.sort((a, b) => {
  173. return b.type || 0 - a.type || 0;
  174. });
  175. setState({ Classifications: res });
  176. return Promise.resolve(res);
  177. });
  178. },
  179. }),
  180. };