goodsManage.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. var app = getApp();
  2. Page({
  3. data: {
  4. placeholdeImg: app.globalData.placeholdeImg,
  5. navList: [{
  6. name: "出售中",
  7. status: "1"
  8. }, {
  9. name: "库存预警",
  10. status: "8"
  11. }, {
  12. name: "已下架",
  13. status: "0"
  14. }, {
  15. name: "待审核",
  16. status: "4"
  17. }
  18. ],
  19. currentTab: 1,
  20. list: [],
  21. loadText: "加载中...",
  22. noData: 0,
  23. loadMore: true,
  24. showActionsheet: false,
  25. groups: [
  26. { text: '删除', type: 'warn', value: 1 },
  27. { text: '下架', value: 2 },
  28. { text: '修改库存', value: 5 }
  29. // { text: '编辑', value: 3 }
  30. ],
  31. buttons: [{text: '取消'}, {text: '确定'}],
  32. editSkuNum: 0
  33. },
  34. page: 1,
  35. keywords: '',
  36. goodsId: '', //当前操作的商品id
  37. onLoad: function (options) {
  38. let currentTab = options.status || 1;
  39. this.setData({
  40. currentTab
  41. }, ()=>{
  42. this.initFn();
  43. })
  44. },
  45. initFn: function(keywords=''){
  46. this.page = 1;
  47. this.keywords = keywords;
  48. this.setData({
  49. list: [],
  50. loadText: "加载中...",
  51. noData: 0,
  52. loadMore: true,
  53. },()=>{
  54. this.getData();
  55. })
  56. },
  57. /**
  58. * 切换导航
  59. */
  60. switchNav: function (e) {
  61. let that = this;
  62. let curIdx = e.target.dataset.current*1;
  63. if (this.data.currentTab === curIdx) return false;
  64. let groups = [
  65. { text: '删除', type: 'warn', value: 1 },
  66. { text: '下架', value: 2 },
  67. { text: '修改库存', value: 5 }
  68. // { text: '编辑', value: 3 }
  69. ]
  70. if(curIdx==0) {
  71. groups = [
  72. { text: '删除', type: 'warn', value: 1 },
  73. { text: '上架', value: 4 },
  74. { text: '修改库存', value: 5 }
  75. // { text: '编辑', value: 3 }
  76. ]
  77. } else if(curIdx==4){
  78. groups = [
  79. { text: '删除', type: 'warn', value: 1 },
  80. { text: '修改库存', value: 5 }
  81. // { text: '编辑', value: 3 }
  82. ]
  83. } else if(curIdx==8){
  84. groups = [
  85. { text: '删除', type: 'warn', value: 1 },
  86. { text: '下架', value: 2 },
  87. { text: '修改库存', value: 5 }
  88. ]
  89. }
  90. this.setData({
  91. currentTab: 1 * e.target.dataset.current,
  92. groups
  93. }, ()=>{
  94. that.initFn();
  95. });
  96. },
  97. goResult: function(e) {
  98. let keyword = e.detail.value.replace(/\s+/g, '');
  99. // if (!keyword) {
  100. // wx.showToast({
  101. // title: '请输入关键词',
  102. // icon: 'none'
  103. // })
  104. // return;
  105. // }
  106. this.initFn(keyword);
  107. },
  108. getData: function () {
  109. let that = this;
  110. let token = wx.getStorageSync('token');
  111. let grounding = this.data.currentTab;
  112. let keywords = this.keywords;
  113. wx.showLoading();
  114. app.util.request({
  115. url: 'entry/wxapp/index',
  116. data: {
  117. controller: 'supplymobile.get_supply_goodslist',
  118. token,
  119. grounding,
  120. page: this.page,
  121. keywords
  122. },
  123. dataType: 'json',
  124. success: function (res) {
  125. if (res.data.code == 0) {
  126. let h = {};
  127. let list = res.data.data;
  128. if (list.length == 0) {
  129. if(that.page==1) {
  130. h.noData = 1;
  131. } else {
  132. h.loadMore = false;
  133. h.noMore = false;
  134. h.loadText = "没有更多记录了~"
  135. }
  136. }
  137. if (list.length < 10) h.noMore = true;
  138. let oldList = that.data.list;
  139. list = oldList.concat(list);
  140. that.page++;
  141. that.setData({ list, ...h })
  142. } else {
  143. app.util.message(res.data.msg, 'switchTo:/lionfish_comshop/pages/user/me', 'error');
  144. }
  145. wx.hideLoading();
  146. }
  147. })
  148. },
  149. handleActionsheet: function (e) {
  150. let idx = (e && e.currentTarget.dataset.index) || 0;
  151. let id = (e && e.currentTarget.dataset.id) || 0;
  152. let list = this.data.list;
  153. let goodsItem = list[idx];
  154. let h = {};
  155. if(id) { h.goodsItem = goodsItem }
  156. this.setData({
  157. showActionsheet: !this.data.showActionsheet,
  158. ...h
  159. })
  160. },
  161. handleBtn(e) {
  162. let goodsItem = this.data.goodsItem;
  163. let goodsId = goodsItem.id;
  164. let hasoption = goodsItem.hasoption;
  165. let type = e.detail.value; // 1删除 2下架 3编辑 4上下架 5修改库存
  166. this.handleActionsheet();
  167. switch(type) {
  168. case 1:
  169. this.actionConfirm('是否删除该商品').then(()=>{
  170. this.delGoods(goodsId)
  171. });
  172. break;
  173. case 2:
  174. this.actionConfirm('是否下架该商品').then(()=>{
  175. this.undercarriage(goodsId)
  176. });
  177. break;
  178. case 3:
  179. console.log('3编辑')
  180. break;
  181. case 4:
  182. this.actionConfirm('是否上架该商品').then(()=>{
  183. this.upcarriage(goodsId)
  184. });
  185. break;
  186. case 5:
  187. // 修改库存
  188. if(hasoption==1) {
  189. wx.navigateTo({ url: `/lionfish_comshop/moduleB/supply/editSku?id=${goodsId}` })
  190. } else {
  191. // 显示弹窗
  192. this.setData({ editSkuVisible: true, editSkuNum: goodsItem.total || 0 })
  193. }
  194. break;
  195. default:
  196. console.log('默认操作')
  197. }
  198. },
  199. /**
  200. * 下架
  201. * @param {*} goods_id
  202. */
  203. undercarriage: function (goods_id) {
  204. let that = this;
  205. let token = wx.getStorageSync('token');
  206. wx.showLoading();
  207. app.util.request({
  208. url: 'entry/wxapp/index',
  209. data: {
  210. controller: 'supplymobile.down_supply_goods',
  211. token,
  212. goods_id
  213. },
  214. dataType: 'json',
  215. success: function (res) {
  216. wx.hideLoading();
  217. if (res.data.code == 0) {
  218. let list = that.data.list || [];
  219. list = list.filter(item=>item.id!=goods_id);
  220. let h = {};
  221. if(list.length==0) h.noData = 1;
  222. h.list = list;
  223. that.setData(h);
  224. wx.showToast({
  225. title: '下架成功',
  226. icon: 'none'
  227. })
  228. } else {
  229. app.util.message(res.data.msg, '', 'error');
  230. }
  231. }
  232. })
  233. },
  234. /**
  235. * 上架
  236. * @param {*} goods_id
  237. */
  238. upcarriage: function (goods_id) {
  239. let that = this;
  240. let token = wx.getStorageSync('token');
  241. wx.showLoading();
  242. app.util.request({
  243. url: 'entry/wxapp/index',
  244. data: {
  245. controller: 'supplymobile.up_supply_goods',
  246. token,
  247. goods_id
  248. },
  249. dataType: 'json',
  250. success: function (res) {
  251. wx.hideLoading();
  252. if (res.data.code == 0) {
  253. let list = that.data.list || [];
  254. list = list.filter(item=>item.id!=goods_id);
  255. let h = {};
  256. if(list.length==0) h.noData = 1;
  257. h.list = list;
  258. that.setData(h);
  259. wx.showToast({
  260. title: '上架成功',
  261. icon: 'none'
  262. })
  263. } else {
  264. that.initFn();
  265. app.util.message(res.data.msg, '', 'error');
  266. }
  267. }
  268. })
  269. },
  270. delGoods: function (goods_id) {
  271. let that = this;
  272. let token = wx.getStorageSync('token');
  273. wx.showLoading();
  274. app.util.request({
  275. url: 'entry/wxapp/index',
  276. data: {
  277. controller: 'supplymobile.delete_supply_goods',
  278. token,
  279. goods_id
  280. },
  281. dataType: 'json',
  282. success: function (res) {
  283. wx.hideLoading();
  284. if (res.data.code == 0) {
  285. let list = that.data.list || [];
  286. list = list.filter(item=>item.id!=goods_id);
  287. let h = {};
  288. if(list.length==0) h.noData = 1;
  289. h.list = list;
  290. that.setData(h);
  291. wx.showToast({
  292. title: '删除成功',
  293. icon: 'none'
  294. })
  295. } else {
  296. app.util.message(res.data.msg, '', 'error');
  297. }
  298. }
  299. })
  300. },
  301. actionConfirm: function(content) {
  302. return new Promise((resolve, reject)=>{
  303. wx.showModal({
  304. title: '提示',
  305. content,
  306. showCancel: true,
  307. success: (result) => {
  308. if (result.confirm) {
  309. resolve();
  310. } else if (result.cancel) {
  311. console.log('用户点击取消')
  312. }
  313. }
  314. })
  315. })
  316. },
  317. /**
  318. * 修改库存
  319. */
  320. editSku: function(e){
  321. if(e.detail.index==0) {
  322. this.setData({ editSkuVisible: false })
  323. } else {
  324. let editSkuNum = this.data.editSkuNum;
  325. if(editSkuNum==='') {
  326. return wx.showToast({
  327. title: '请输入正确的数量',
  328. icon: 'none'
  329. })
  330. }
  331. this.subSku();
  332. }
  333. },
  334. subSku: function(){
  335. let goodsItem = this.data.goodsItem;
  336. let goodsId = goodsItem.id;
  337. console.log(goodsId);
  338. let editSkuNum = this.data.editSkuNum;
  339. let token = wx.getStorageSync('token');
  340. let params = {
  341. token,
  342. goods_id: goodsId,
  343. is_has_option: 0,
  344. quantity: editSkuNum
  345. };
  346. app.util.ProReq('supplymobile.modify_supply_goods_quantity', params).then(res=>{
  347. let list = this.data.list || [];
  348. list.map(item=>{ if(item.id == goodsId) item.total = editSkuNum; })
  349. this.setData({ list, editSkuVisible: false, editSkuNum: 0, goodsItem: '' })
  350. }).catch(err=>{
  351. app.util.message(err.msg || '请求出错', 'switchTo:/lionfish_comshop/pages/user/me', 'error');
  352. })
  353. },
  354. bindSkuIpt: function(e) {
  355. let val = e.detail.value || 0;
  356. this.setData({ editSkuNum: parseInt(val) });
  357. return parseInt(val)
  358. },
  359. /**
  360. * 页面相关事件处理函数--监听用户下拉动作
  361. */
  362. onPullDownRefresh: function () {
  363. },
  364. /**
  365. * 页面上拉触底事件的处理函数
  366. */
  367. onReachBottom: function () {
  368. if (!this.data.loadMore) return false;
  369. this.getData();
  370. }
  371. })