manage.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <base-page>
  3. <view class="manage">
  4. <view class="screen-warp common-form">
  5. <view class="common-form-item">
  6. <view class="form-inline">
  7. <label class="form-label">商品名称/编码</label>
  8. <view class="form-input-inline"><input type="text" v-model="searchData.search" placeholder="请输入商品名称/编码" class="form-input" /></view>
  9. </view>
  10. <view class="form-inline goods-category">
  11. <label class="form-label">商品分类</label>
  12. <view class="form-input-inline">
  13. <uni-data-picker v-model="searchData.category_id" :localdata="classifyData.data" popup-title="请选择商品分类"></uni-data-picker>
  14. </view>
  15. </view>
  16. <view class="form-inline common-btn-wrap">
  17. <button type="default" class="screen-btn" @click="searchFn()">筛选</button>
  18. <button type="default" @click="resetFn()">重置</button>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="manage-table">
  23. <uni-table ref="table" :loading="table.loading" border stripe emptyText="暂无更多数据">
  24. <uni-tr>
  25. <uni-th align="left">产品名称</uni-th>
  26. <uni-th width="140" align="center">规格</uni-th>
  27. <uni-th width="140" align="center">编码</uni-th>
  28. <uni-th width="140" align="center">库存</uni-th>
  29. <uni-th width="140" align="center">成本</uni-th>
  30. <uni-th width="200" align="center">添加时间</uni-th>
  31. <uni-th width="140" align="right">操作</uni-th>
  32. </uni-tr>
  33. <uni-tr v-for="(item, index) in table.data">
  34. <uni-td align="left" class="name">
  35. <image :src="$util.img(item.sku_image, { size: 'small' })" mode="aspectFill"></image>
  36. <text class="multi-hidden">{{ item.goods_name }}</text>
  37. </uni-td>
  38. <uni-td align="center">{{ item.spec_name }}</uni-td>
  39. <uni-td align="center">{{ item.sku_no }}</uni-td>
  40. <uni-td align="center">{{ item.real_stock || 0 }}</uni-td>
  41. <uni-td align="center">{{ item.cost_price }}</uni-td>
  42. <uni-td align="center">{{ $util.timeFormat(item.create_time) }}</uni-td>
  43. <uni-td align="right">
  44. <view class="action-btn"><text @click="toDetail()">查看流水</text></view>
  45. </uni-td>
  46. </uni-tr>
  47. </uni-table>
  48. <view class="paging-wrap-fill"></view>
  49. <view class="paging-wrap"><uni-pagination show-icon :page-size="paging.pageSize" :current="paging.pageCurrent" :total="paging.total" @change="paginChange" /></view>
  50. </view>
  51. </view>
  52. </base-page>
  53. </template>
  54. <script>
  55. import uniDataPicker from '@/components/uni-data-picker/uni-data-picker.vue';
  56. export default {
  57. components: {
  58. uniDataPicker
  59. },
  60. data() {
  61. return {
  62. classifyData: {
  63. data: []
  64. },
  65. table: {
  66. loading: false, //表格加载动画
  67. data: []
  68. },
  69. paging: {
  70. pageSize: 9, // 每页数据量
  71. pageCurrent: 1, // 当前页
  72. total: 0 // 数据总量
  73. },
  74. searchData: {
  75. search: '',
  76. category_id: '',
  77. min_stock: '',
  78. max_stock: ''
  79. }
  80. };
  81. },
  82. onLoad(option) {
  83. uni.hideTabBar();
  84. this.getCategory();
  85. },
  86. onShow() {
  87. this.getTableData();
  88. },
  89. methods: {
  90. searchFn() {
  91. this.table.loading = true;
  92. this.paging.pageCurrent = 1;
  93. this.getTableData(this.searchData);
  94. },
  95. resetFn() {
  96. this.table.loading = true;
  97. this.paging.pageCurrent = 1;
  98. this.searchData.search = '';
  99. this.searchData.category_id = '';
  100. this.searchData.min_stock = '';
  101. this.searchData.max_stock = '';
  102. this.getTableData(this.searchData);
  103. },
  104. getTableData(obj = {}) {
  105. let data = {
  106. page_size: this.paging.pageSize,
  107. page: this.paging.pageCurrent
  108. };
  109. Object.assign(data, obj);
  110. this.$api.sendRequest({
  111. url: '/stock/storeapi/manage/lists',
  112. data: data,
  113. success: res => {
  114. this.table.loading = false;
  115. if (res.code == 0) {
  116. this.table.data = res.data.list;
  117. this.$forceUpdate();
  118. } else {
  119. this.$util.showToast({ title: res.message });
  120. }
  121. this.paging.total = res.data.count;
  122. }
  123. });
  124. },
  125. getCategory() {
  126. this.$api.sendRequest({
  127. url: '/cashier/storeapi/goods/category',
  128. data: { level: 3 },
  129. success: res => {
  130. let data = res.data;
  131. if (res.code == 0 && data.length) {
  132. this.classifyData.data = this.analyzeCategory(data);
  133. this.$forceUpdate();
  134. } else {
  135. this.$util.showToast({ title: res.message });
  136. }
  137. }
  138. });
  139. },
  140. analyzeCategory(data) {
  141. var arr = data.map((item, index) => {
  142. var obj = {};
  143. obj.text = item.category_name;
  144. obj.value = item.category_id;
  145. if (item.child_list && item.child_list.length) {
  146. obj.children = this.analyzeCategory(item.child_list);
  147. }
  148. return obj;
  149. });
  150. return arr;
  151. },
  152. // 切换分页
  153. paginChange(e) {
  154. this.table.loading = true;
  155. this.paging.pageCurrent = e.current;
  156. this.getTableData();
  157. },
  158. toDetail() {
  159. this.$util.redirectTo('/pages/stock/records');
  160. }
  161. }
  162. };
  163. </script>
  164. <style lang="scss">
  165. .manage {
  166. position: relative;
  167. background-color: #fff;
  168. padding: 0.15rem;
  169. min-height: 100vh;
  170. box-sizing: border-box;
  171. }
  172. // 筛选面板
  173. .screen-warp {
  174. padding: 0.15rem;
  175. background-color: #f2f3f5;
  176. margin-bottom: 0.15rem;
  177. .common-form-item .form-label {
  178. width: 1.2rem;
  179. }
  180. .common-btn-wrap {
  181. margin-left: 1.2rem;
  182. }
  183. .goods-category .form-input-inline {
  184. width: 2.8rem;
  185. }
  186. .common-form-item {
  187. margin-bottom: 0;
  188. }
  189. }
  190. .paging-wrap-fill {
  191. height: 0.6rem;
  192. }
  193. .paging-wrap {
  194. position: fixed;
  195. left: 0;
  196. right: 0;
  197. bottom: 0;
  198. display: flex;
  199. justify-content: flex-end;
  200. padding: 0.1rem 0.15rem;
  201. margin-top: 0.1rem;
  202. background-color: #fff;
  203. }
  204. // 表格详情
  205. .manage-table {
  206. .name {
  207. display: flex;
  208. image {
  209. margin-right: 0.1rem;
  210. flex-shrink: 0;
  211. width: 0.5rem;
  212. height: 0.5rem;
  213. }
  214. }
  215. .action-btn {
  216. text {
  217. color: $uni-color-primary;
  218. }
  219. }
  220. }
  221. </style>