stock_warning.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: () => {
  4. const { reactive, onMounted } = Vue
  5. const index = {
  6. setup() {
  7. const state = reactive({
  8. data: [],
  9. order: '',
  10. sort: '',
  11. filter: {
  12. drawer: false,
  13. data: {
  14. stock_type: 'all',
  15. 'goods.title': '',
  16. },
  17. tools: {
  18. 'goods.title': {
  19. type: 'tinput',
  20. label: '商品名称',
  21. placeholder: '请输入商品名称',
  22. value: '',
  23. },
  24. },
  25. condition: {},
  26. },
  27. stockType: {
  28. all: { name: '全部' },
  29. over: { name: '已售罄', num: 0 },
  30. no_enough: { name: '预警中', num: 0 },
  31. }
  32. })
  33. const type = reactive({
  34. data: {
  35. stock_type: {
  36. all: { name: '全部' },
  37. over: { name: '已售罄', num: 0 },
  38. no_enough: { name: '预警中', num: 0 },
  39. }
  40. }
  41. })
  42. function getData() {
  43. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  44. let search = composeFilter(tempSearch, {
  45. 'goods.title': 'like',
  46. });
  47. Fast.api.ajax({
  48. url: 'shopro/goods/stock_warning',
  49. type: 'GET',
  50. data: {
  51. page: pagination.page,
  52. list_rows: pagination.list_rows,
  53. order: state.order,
  54. sort: state.sort,
  55. ...search,
  56. },
  57. }, function (ret, res) {
  58. state.data = res.data.rows.data
  59. pagination.total = res.data.rows.total
  60. type.data.stock_type.over.num = res.data.over_total;
  61. type.data.stock_type.no_enough.num = res.data.warning_total;
  62. return false
  63. }, function (ret, res) { })
  64. }
  65. function onChangeSort({ prop, order }) {
  66. state.order = order == 'ascending' ? 'asc' : 'desc';
  67. state.sort = prop;
  68. getData();
  69. }
  70. function onOpenFilter() {
  71. state.filter.drawer = true
  72. }
  73. function onChangeFilter() {
  74. pagination.page = 1
  75. getData()
  76. state.filter.drawer && (state.filter.drawer = false)
  77. }
  78. function onChangeTab() {
  79. pagination.page = 1
  80. getData()
  81. }
  82. const pagination = reactive({
  83. page: 1,
  84. list_rows: 10,
  85. total: 0,
  86. })
  87. function onAddStock(item) {
  88. Fast.api.open(`shopro/goods/stock_warning/addStock?id=${item.id}&stock=${item.stock}`, "补货", {
  89. callback() {
  90. getData()
  91. }
  92. })
  93. }
  94. function onRecyclebin() {
  95. Fast.api.open('shopro/goods/stock_warning/recyclebin', "历史记录", {
  96. callback() {
  97. getData()
  98. }
  99. })
  100. }
  101. onMounted(() => {
  102. getData()
  103. })
  104. return {
  105. state,
  106. type,
  107. getData,
  108. onChangeSort,
  109. onOpenFilter,
  110. onChangeFilter,
  111. onChangeTab,
  112. pagination,
  113. onAddStock,
  114. onRecyclebin,
  115. }
  116. }
  117. }
  118. createApp('index', index);
  119. },
  120. addstock: () => {
  121. const { reactive, getCurrentInstance } = Vue
  122. const addStock = {
  123. setup() {
  124. const { proxy } = getCurrentInstance();
  125. const state = reactive({
  126. id: new URLSearchParams(location.search).get('id'),
  127. stock: new URLSearchParams(location.search).get('stock')
  128. })
  129. const form = reactive({
  130. model: {
  131. stock: '',
  132. },
  133. rules: {
  134. stock: [{ required: true, message: '请输入补充库存', trigger: 'blur' }],
  135. },
  136. })
  137. function onConfirm() {
  138. proxy.$refs['formRef'].validate((valid) => {
  139. if (valid) {
  140. Fast.api.ajax({
  141. url: `shopro/goods/stock_warning/addStock/id/${state.id}`,
  142. type: 'POST',
  143. data: form.model,
  144. }, function (ret, res) {
  145. Fast.api.close()
  146. }, function (ret, res) { })
  147. }
  148. });
  149. }
  150. return {
  151. state,
  152. form,
  153. onConfirm
  154. }
  155. }
  156. }
  157. createApp('addStock', addStock);
  158. },
  159. recyclebin: () => {
  160. const { reactive, onMounted } = Vue
  161. const recyclebin = {
  162. setup() {
  163. const state = reactive({
  164. data: [],
  165. order: '',
  166. sort: '',
  167. })
  168. function getData() {
  169. Fast.api.ajax({
  170. url: 'shopro/goods/stock_warning/recyclebin',
  171. type: 'GET',
  172. data: {
  173. page: pagination.page,
  174. list_rows: pagination.list_rows,
  175. order: state.order,
  176. sort: state.sort,
  177. },
  178. }, function (ret, res) {
  179. state.data = res.data.data
  180. pagination.total = res.data.total
  181. return false
  182. }, function (ret, res) { })
  183. }
  184. function onChangeSort({ prop, order }) {
  185. state.order = order == 'ascending' ? 'asc' : 'desc';
  186. state.sort = prop;
  187. getData();
  188. }
  189. const pagination = reactive({
  190. page: 1,
  191. list_rows: 10,
  192. total: 0,
  193. })
  194. onMounted(() => {
  195. getData()
  196. })
  197. return {
  198. state,
  199. getData,
  200. onChangeSort,
  201. pagination,
  202. }
  203. }
  204. }
  205. createApp('recyclebin', recyclebin);
  206. },
  207. };
  208. return Controller;
  209. });