123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: () => {
- const { reactive, onMounted } = Vue
- const index = {
- setup() {
- const state = reactive({
- data: [],
- order: '',
- sort: '',
- filter: {
- drawer: false,
- data: {
- stock_type: 'all',
- 'goods.title': '',
- },
- tools: {
- 'goods.title': {
- type: 'tinput',
- label: '商品名称',
- placeholder: '请输入商品名称',
- value: '',
- },
- },
- condition: {},
- },
- stockType: {
- all: { name: '全部' },
- over: { name: '已售罄', num: 0 },
- no_enough: { name: '预警中', num: 0 },
- }
- })
- const type = reactive({
- data: {
- stock_type: {
- all: { name: '全部' },
- over: { name: '已售罄', num: 0 },
- no_enough: { name: '预警中', num: 0 },
- }
- }
- })
- function getData() {
- let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
- let search = composeFilter(tempSearch, {
- 'goods.title': 'like',
- });
- Fast.api.ajax({
- url: 'shopro/goods/stock_warning',
- type: 'GET',
- data: {
- page: pagination.page,
- list_rows: pagination.list_rows,
- order: state.order,
- sort: state.sort,
- ...search,
- },
- }, function (ret, res) {
- state.data = res.data.rows.data
- pagination.total = res.data.rows.total
- type.data.stock_type.over.num = res.data.over_total;
- type.data.stock_type.no_enough.num = res.data.warning_total;
- return false
- }, function (ret, res) { })
- }
- function onChangeSort({ prop, order }) {
- state.order = order == 'ascending' ? 'asc' : 'desc';
- state.sort = prop;
- getData();
- }
- function onOpenFilter() {
- state.filter.drawer = true
- }
- function onChangeFilter() {
- pagination.page = 1
- getData()
- state.filter.drawer && (state.filter.drawer = false)
- }
- function onChangeTab() {
- pagination.page = 1
- getData()
- }
- const pagination = reactive({
- page: 1,
- list_rows: 10,
- total: 0,
- })
- function onAddStock(item) {
- Fast.api.open(`shopro/goods/stock_warning/addStock?id=${item.id}&stock=${item.stock}`, "补货", {
- callback() {
- getData()
- }
- })
- }
- function onRecyclebin() {
- Fast.api.open('shopro/goods/stock_warning/recyclebin', "历史记录", {
- callback() {
- getData()
- }
- })
- }
- onMounted(() => {
- getData()
- })
- return {
- state,
- type,
- getData,
- onChangeSort,
- onOpenFilter,
- onChangeFilter,
- onChangeTab,
- pagination,
- onAddStock,
- onRecyclebin,
- }
- }
- }
- createApp('index', index);
- },
- addstock: () => {
- const { reactive, getCurrentInstance } = Vue
- const addStock = {
- setup() {
- const { proxy } = getCurrentInstance();
- const state = reactive({
- id: new URLSearchParams(location.search).get('id'),
- stock: new URLSearchParams(location.search).get('stock')
- })
- const form = reactive({
- model: {
- stock: '',
- },
- rules: {
- stock: [{ required: true, message: '请输入补充库存', trigger: 'blur' }],
- },
- })
- function onConfirm() {
- proxy.$refs['formRef'].validate((valid) => {
- if (valid) {
- Fast.api.ajax({
- url: `shopro/goods/stock_warning/addStock/id/${state.id}`,
- type: 'POST',
- data: form.model,
- }, function (ret, res) {
- Fast.api.close()
- }, function (ret, res) { })
- }
- });
- }
- return {
- state,
- form,
- onConfirm
- }
- }
- }
- createApp('addStock', addStock);
- },
- recyclebin: () => {
- const { reactive, onMounted } = Vue
- const recyclebin = {
- setup() {
- const state = reactive({
- data: [],
- order: '',
- sort: '',
- })
- function getData() {
- Fast.api.ajax({
- url: 'shopro/goods/stock_warning/recyclebin',
- type: 'GET',
- data: {
- page: pagination.page,
- list_rows: pagination.list_rows,
- order: state.order,
- sort: state.sort,
- },
- }, function (ret, res) {
- state.data = res.data.data
- pagination.total = res.data.total
- return false
- }, function (ret, res) { })
- }
- function onChangeSort({ prop, order }) {
- state.order = order == 'ascending' ? 'asc' : 'desc';
- state.sort = prop;
- getData();
- }
- const pagination = reactive({
- page: 1,
- list_rows: 10,
- total: 0,
- })
- onMounted(() => {
- getData()
- })
- return {
- state,
- getData,
- onChangeSort,
- pagination,
- }
- }
- }
- createApp('recyclebin', recyclebin);
- },
- };
- return Controller;
- });
|