index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <div>
  3. <basic-container v-show="show" class="page-crad">
  4. <avue-crud
  5. ref="crud"
  6. :option="option"
  7. :data="dataList"
  8. v-model="form"
  9. :page.sync="page"
  10. :search.sync="search"
  11. :table-loading="loading"
  12. :cell-style="cellStyle"
  13. @selection-change="selectionChange"
  14. @search-change="searchChange"
  15. @current-change="currentChange"
  16. @size-change="sizeChange"
  17. @refresh-change="refreshChange"
  18. @on-load="onLoad"
  19. @search-criteria-switch="searchCriteriaSwitch"
  20. @saveColumn="saveColumn"
  21. @resetColumn="resetColumn"
  22. >
  23. <template slot="cnameSearch">
  24. <el-select
  25. v-model="search.goodsId"
  26. filterable
  27. clearable
  28. remote
  29. :remote-method="cnameMethod"
  30. @clear="cnameClear"
  31. >
  32. <el-option
  33. v-for="(item, index) in goodsOption"
  34. :label="item.cname"
  35. :value="item.id"
  36. :key="index"
  37. ></el-option>
  38. </el-select>
  39. </template>
  40. </avue-crud>
  41. </basic-container>
  42. </div>
  43. </template>
  44. <script>
  45. import option from "./config/mainList.json";
  46. import {getList as goodsSelect} from "@/api/basicData/commodityType";
  47. import {getStockList} from "@/api/officeSupplies/stock";
  48. export default {
  49. name: "index",
  50. data() {
  51. return {
  52. option: {},
  53. dataList: [],
  54. form: {},
  55. page: {
  56. pageSize: 10,
  57. currentPage: 1,
  58. total: 0,
  59. pageSizes: [10, 50, 100, 200, 300, 400, 500]
  60. },
  61. search: {},
  62. show: true,
  63. loading: false,
  64. selection: [],
  65. goodsOption: [],
  66. }
  67. },
  68. async created() {
  69. this.option = await this.getColumnData(this.getColumnName(105), option);
  70. goodsSelect(1, 10).then(res => {
  71. this.goodsOption = res.data.data.records;
  72. })
  73. let i = 0;
  74. this.option.column.forEach(item => {
  75. if (item.search) i++
  76. })
  77. if (i % 3 !== 0){
  78. const num = 3 - Number(i % 3)
  79. this.option.searchMenuSpan = num * 8;
  80. this.option.searchMenuPosition = "right";
  81. }
  82. },
  83. methods: {
  84. searchCriteriaSwitch(type) {
  85. if (type){
  86. this.option.height = this.option.height - 90
  87. }else {
  88. this.option.height = this.option.height + 90
  89. }
  90. this.$refs.crud.getTableHeight()
  91. },
  92. newAdd() {
  93. this.show = false;
  94. },
  95. onLoad(page, params) {
  96. // 重置掉展开
  97. this.dataList.forEach(item => {
  98. this.$refs.crud.toggleRowExpansion(item, false)
  99. })
  100. let queryParams = Object.assign({}, params, {
  101. size: page.pageSize,
  102. current: page.currentPage,
  103. tradeType: 'BGYP',
  104. })
  105. if (queryParams.inDate && queryParams.inDate.length > 0) {
  106. queryParams = {
  107. ...queryParams,
  108. beginInDate: queryParams.inDate[0],
  109. endInDate: queryParams.inDate[1],
  110. }
  111. }
  112. delete queryParams.inDate;
  113. this.loading = true;
  114. getStockList(queryParams).then(res => {
  115. this.dataList = res.data.data.records;
  116. this.page.total = res.data.data.total;
  117. this.option.height = window.innerHeight - 240;
  118. this.$nextTick(() => {
  119. this.$refs.crud.doLayout()
  120. })
  121. }).finally(() => {
  122. this.loading = false;
  123. })
  124. },
  125. async saveColumn() {
  126. const inSave = await this.saveColumnData(
  127. this.getColumnName(105),
  128. this.option
  129. );
  130. if (inSave) {
  131. this.$message.success("保存成功");
  132. //关闭窗口
  133. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  134. this.$nextTick(() => {
  135. this.$refs.crud.doLayout()
  136. })
  137. }
  138. },
  139. async resetColumn() {
  140. this.option = option;
  141. const inSave = await this.delColumnData(this.getColumnName(105), option);
  142. if (inSave) {
  143. this.$nextTick(() => {
  144. this.$refs.crud.doLayout()
  145. })
  146. this.$message.success("重置成功");
  147. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  148. }
  149. },
  150. //点击搜索按钮触发
  151. searchChange(params, done) {
  152. this.onLoad(this.page, params);
  153. done();
  154. },
  155. currentChange(val) {
  156. this.page.currentPage = val;
  157. },
  158. sizeChange(val) {
  159. this.page.currentPage = 1;
  160. this.page.pageSize = val;
  161. },
  162. refreshChange() {
  163. this.onLoad(this.page, this.search);
  164. },
  165. cellStyle() {
  166. return "padding:0;height:40px;";
  167. },
  168. copyDoc() {},
  169. selectionChange(list) {
  170. this.selection = list;
  171. },
  172. cnameMethod(name) {
  173. if (name) {
  174. goodsSelect(1, 20, {cname: name}).then(res => {
  175. this.goodsOption = res.data.data.records;
  176. })
  177. } else {
  178. goodsSelect(1, 10).then(res => {
  179. this.goodsOption = res.data.data.records;
  180. })
  181. }
  182. },
  183. cnameClear() {
  184. goodsSelect(1, 10).then(res => {
  185. this.goodsOption = res.data.data.records;
  186. })
  187. },
  188. },
  189. }
  190. </script>
  191. <style scoped>
  192. </style>