addmaterial.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <div>
  3. <el-button type="primary" size="mini" @click="openDialog">增行</el-button>
  4. <el-dialog title="物料信息查询" :visible.sync="open" :before-close="useClose">
  5. <el-form size="mini" label-width="120px" >
  6. <el-row :gutter="10">
  7. <el-col :span="1.5">
  8. <el-form-item label="物料编码">
  9. <el-input
  10. v-model="queryParams.code"
  11. clearable
  12. style="width: 200px"
  13. />
  14. </el-form-item>
  15. </el-col>
  16. <el-col :span="1.5">
  17. <el-form-item label="物料名称">
  18. <el-input
  19. v-model="queryParams.name"
  20. clearable
  21. style="width: 200px"
  22. />
  23. </el-form-item>
  24. </el-col>
  25. <el-col :span="1.5">
  26. <el-form-item>
  27. <el-button type="primary" icon="el-icon-search" plain @click="useSearch">搜索</el-button>
  28. <el-button icon="el-icon-refresh" plain @click="useReset">重置</el-button>
  29. </el-form-item>
  30. </el-col>
  31. </el-row>
  32. </el-form>
  33. <el-table :data="tableData" size="mini" @row-dblclick="useDoubleClick" @selection-change="useSelectChange" v-loading="loading" height="450px">
  34. <el-table-column type="selection" width="55"> </el-table-column>
  35. <el-table-column show-overflow-tooltip label="编码" align="center" width="150" prop="code"/>
  36. <el-table-column show-overflow-tooltip label="名称" align="center" width="200" prop="name"/>
  37. <el-table-column show-overflow-tooltip label="物料分类" align="center" width="150" prop="fourClass" />
  38. <el-table-column show-overflow-tooltip label="单位" align="center" width="100" prop="unitIdName"/>
  39. <el-table-column show-overflow-tooltip label="规格" align="center" width="200" prop="specification" />
  40. </el-table>
  41. <el-pagination
  42. background
  43. @size-change="useChangePageSize"
  44. @current-change="useCurrentChange"
  45. :current-page="queryParams.pageNum"
  46. :page-sizes="[10, 15, 20]"
  47. :page-size="100"
  48. layout="total, sizes, prev, pager, next, jumper"
  49. :total=total>
  50. </el-pagination>
  51. <el-card>
  52. <div class="btn_group">
  53. <el-col :span="1.5" style="margin: 0 10px;">
  54. <el-button type="primary" size="mini" plain @click="useConfirm">确认</el-button>
  55. </el-col>
  56. </div>
  57. </el-card>
  58. </el-dialog>
  59. </div>
  60. </template>
  61. <script>
  62. import materialApi from "@/api/material/basic";
  63. import { saveItems } from "@/api/business/spd/fillin/dailysale_quantity_assess_item";
  64. export default {
  65. name: "dailysaleQuantityAssessDetailAddmaterial",
  66. props: ["form"],
  67. data() {
  68. return {
  69. loading: false,
  70. //是否打开弹窗
  71. open:false,
  72. //搜索框参数
  73. queryParams:{
  74. code: null,
  75. name: null,
  76. },
  77. page:{
  78. pageNum:1,
  79. pageSize:10,
  80. },
  81. //总条数
  82. total: 0,
  83. //列表数据
  84. tableData:[],
  85. //选择的数据
  86. selectionData:[],
  87. };
  88. },
  89. methods: {
  90. //打开弹窗
  91. openDialog(){
  92. this.open = true;
  93. this.getList();
  94. },
  95. //关闭弹窗
  96. useClose(done){
  97. this.selectionData = [];
  98. this.queryParams = {
  99. code: null,
  100. name: null,
  101. }
  102. this.page = {
  103. pageNum:1,
  104. pageSize:10,
  105. }
  106. done();
  107. },
  108. //获取列表数据
  109. async getList() {
  110. try {
  111. this.loading = true;
  112. const { code, data } = await materialApi.materialList(this.queryParams, this.page);
  113. if (code === 200) {
  114. this.tableData = data.tableBody.rows;
  115. this.total = data.tableBody.total;
  116. }
  117. } catch (err) {
  118. // catch
  119. console.error(err);
  120. } finally {
  121. // finally
  122. this.loading = false;
  123. }
  124. },
  125. //多选
  126. useSelectChange(selection){
  127. this.selectionData = selection;
  128. },
  129. //确认多选
  130. async useConfirm(){
  131. if(this.selectionData.length < 1){
  132. this.$modal.msgError("未选择数据!");
  133. return;
  134. }
  135. const arr = [];
  136. for(let i in this.selectionData){
  137. arr.push({
  138. dailysaleQuantityAssessId:this.form.id,
  139. oneClassName:this.selectionData[i].oneClass,
  140. twoClassName:this.selectionData[i].twoClass,
  141. material:this.selectionData[i].id,
  142. materialCode:this.selectionData[i].code,
  143. materialName:this.selectionData[i].name,
  144. unitName:this.selectionData[i].unitIdName,
  145. price:this.selectionData[i].price,
  146. });
  147. }
  148. let res = await saveItems(arr);
  149. if(res.code == '200'){
  150. this.$modal.msgSuccess("添加成功");
  151. this.$emit("useReset");
  152. this.open = false;
  153. }else{
  154. this.$modal.msgError("保存失败,请联系管理员!");
  155. }
  156. },
  157. //双击选择
  158. async useDoubleClick(row){
  159. const arr = [];
  160. arr.push({
  161. dailysaleQuantityAssessId:this.form.id,
  162. oneClassName:row.oneClass,
  163. twoClassName:row.twoClass,
  164. material:row.id,
  165. materialCode:row.code,
  166. materialName:row.name,
  167. unitName:row.unitIdName,
  168. price:row.price,
  169. });
  170. let res = await saveItems(arr);
  171. if(res.code == '200'){
  172. this.$modal.msgSuccess("添加成功");
  173. this.$emit("useReset");
  174. this.open = false;
  175. }else{
  176. this.$modal.msgError("保存失败,请联系管理员!");
  177. }
  178. },
  179. //搜索
  180. useSearch(){
  181. this.getList();
  182. },
  183. //重置
  184. useReset(){
  185. this.queryParams = {
  186. code: null,
  187. name: null,
  188. }
  189. this.page = {
  190. pageNum:1,
  191. pageSize:10,
  192. }
  193. this.getList();
  194. },
  195. //改变一页显示条数
  196. useChangePageSize(val){
  197. this.page.pageSize = val
  198. this.getList()
  199. },
  200. //翻页
  201. useCurrentChange(val){
  202. this.page.pageNum = val
  203. this.getList()
  204. },
  205. },
  206. created() {},
  207. mounted() {},
  208. destroyed() {},
  209. };
  210. </script>
  211. <style scoped lang="scss">
  212. .btn_group {
  213. width: 100%;
  214. margin: 20px 0;
  215. display: flex;
  216. justify-content: right;
  217. }
  218. .el-pagination {
  219. margin-top: 10px;
  220. text-align: right;
  221. }
  222. </style>