dealer_stock.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <div class="app-container">
  3. <!-- 筛选条件 -->
  4. <div>
  5. <el-form
  6. ref="searchForm"
  7. :model="searchForm"
  8. label-width="100px"
  9. size="small"
  10. label-position="left"
  11. >
  12. <el-row :gutter="20">
  13. <el-col :xs="24" :sm="12" :lg="6">
  14. <el-form-item label="经销商名称" prop="customerName">
  15. <el-input
  16. v-model="searchForm.customerName"
  17. placeholder="请输入经销商名称"
  18. ></el-input>
  19. </el-form-item>
  20. </el-col>
  21. <el-col :xs="24" :sm="12" :lg="6">
  22. <el-form-item label="存货分类编码" prop="bianMa">
  23. <el-input
  24. v-model="searchForm.mainId"
  25. placeholder="请输入"
  26. ></el-input>
  27. </el-form-item>
  28. </el-col>
  29. <el-col :xs="24" :sm="12" :lg="6">
  30. <el-form-item label="存货分类" prop="mainName">
  31. <el-input
  32. v-model="searchForm.mainName"
  33. placeholder="请输入"
  34. ></el-input>
  35. </el-form-item>
  36. </el-col>
  37. <el-col :xs="24" :sm="12" :lg="6">
  38. <el-form-item label="" class="fr">
  39. <el-button size="small" @click="clearFn">清空</el-button>
  40. <el-button size="small" type="primary" @click="searchFn"
  41. >搜索</el-button
  42. >
  43. </el-form-item>
  44. </el-col>
  45. </el-row>
  46. </el-form>
  47. </div>
  48. <div class="btn-group clearfix">
  49. <div class="fl">
  50. <el-button type="primary" size="small" @click="addFn">新增</el-button>
  51. <el-popconfirm @onConfirm="deleFn" title="这是一段内容确定删除吗?">
  52. <el-button
  53. type="primary"
  54. size="small"
  55. class="textColor"
  56. slot="reference"
  57. >删除</el-button
  58. >
  59. </el-popconfirm>
  60. </div>
  61. <div class="fr">
  62. <el-button type="primary" size="small">打印</el-button>
  63. </div>
  64. </div>
  65. <div class="mymain-container">
  66. <!-- 列表 -->
  67. <div class="table">
  68. <el-table
  69. v-loading="listLoading"
  70. :data="dataList"
  71. @select="hanleSelect"
  72. @select-all="hanleSelect"
  73. element-loading-text="Loading"
  74. border
  75. fit
  76. highlight-current-row
  77. stripe
  78. >
  79. <el-table-column
  80. type="selection"
  81. align="center"
  82. min-width="100"
  83. ></el-table-column>
  84. <el-table-column
  85. align="center"
  86. label="经销商名称"
  87. prop="customerName"
  88. min-width="160"
  89. show-overflow-tooltip
  90. ></el-table-column>
  91. <el-table-column
  92. align="center"
  93. label="存货分类编码"
  94. prop="mainId"
  95. min-width="160"
  96. show-overflow-tooltip
  97. ></el-table-column>
  98. <el-table-column
  99. align="center"
  100. label="存货分类名称"
  101. prop="mainName"
  102. min-width="160"
  103. show-overflow-tooltip
  104. ></el-table-column>
  105. <el-table-column
  106. align="center"
  107. label="创建人"
  108. prop="createBy"
  109. min-width="160"
  110. show-overflow-tooltip
  111. ></el-table-column>
  112. <el-table-column
  113. align="center"
  114. label="创建时间"
  115. prop="createTime"
  116. min-width="160"
  117. show-overflow-tooltip
  118. ></el-table-column>
  119. <el-table-column
  120. align="center"
  121. label="更新人"
  122. prop="updateBy"
  123. min-width="160"
  124. show-overflow-tooltip
  125. ></el-table-column>
  126. <el-table-column
  127. align="center"
  128. label="更新时间"
  129. prop="updateTime"
  130. min-width="160"
  131. show-overflow-tooltip
  132. ></el-table-column>
  133. <el-table-column
  134. align="center"
  135. label="操作"
  136. prop="caozuo"
  137. min-width="160"
  138. show-overflow-tooltip
  139. >
  140. <template slot-scope="scope">
  141. <el-popconfirm
  142. @onConfirm="deleFn(scope.row.id)"
  143. title="这是一段内容确定删除吗?"
  144. >
  145. <el-button type="text" class="textColor" slot="reference"
  146. >删除</el-button
  147. ></el-popconfirm
  148. >
  149. </template>
  150. </el-table-column>
  151. </el-table>
  152. </div>
  153. <!-- 分页 -->
  154. <div class="fr">
  155. <el-pagination
  156. @size-change="handleSizeChange"
  157. @current-change="handleCurrentChange"
  158. :current-page="currentPage"
  159. :page-sizes="[10, 20, 30, 50]"
  160. :page-size="10"
  161. layout="total, sizes, prev, pager, next, jumper"
  162. :total="listTotal"
  163. >
  164. </el-pagination>
  165. </div>
  166. </div>
  167. <!-- 弹窗 -->
  168. <el-dialog
  169. title="编辑"
  170. :visible.sync="dialogForm"
  171. width="30%"
  172. :show-close="false"
  173. :close-on-click-modal="false"
  174. >
  175. <el-form
  176. ref="addForm"
  177. :rules="rules"
  178. :model="addForm"
  179. label-width="100px"
  180. label-position="right"
  181. >
  182. <el-form-item label="经销商名称" prop="customerId">
  183. <el-select
  184. class="selectStyle"
  185. v-model="addForm.customerId"
  186. placeholder="名称"
  187. >
  188. <el-option
  189. v-for="item in dealerList"
  190. :key="item.id"
  191. :label="item.name"
  192. :value="item.id"
  193. >
  194. </el-option>
  195. </el-select>
  196. </el-form-item>
  197. <el-form-item label="存货分类" prop="mainId">
  198. <el-select
  199. class="selectStyle"
  200. v-model="addForm.mainId"
  201. placeholder="请选择"
  202. >
  203. <el-option
  204. v-for="item in selectList"
  205. :key="item.value"
  206. :label="item.dictValue"
  207. :value="item.sysDictId"
  208. >
  209. </el-option>
  210. </el-select>
  211. </el-form-item>
  212. </el-form>
  213. <div slot="footer" class="dialog-footer">
  214. <el-button @click="cancelFn">取 消</el-button>
  215. <el-button type="primary" @click="addDataListFn">确 定</el-button>
  216. </div>
  217. </el-dialog>
  218. </div>
  219. </template>
  220. <script>
  221. import {
  222. getDealerStockList,
  223. getDealerStockAdd,
  224. deleDealerStockList,
  225. getDictionaries,
  226. } from "@/api/basic_data/dealer";
  227. import { getDealerList } from "@/api/basic_data/dealer";
  228. export default {
  229. data() {
  230. return {
  231. dialogForm: false,
  232. addForm: {
  233. customerName: "",
  234. customerId: "",
  235. customerNumber: "",
  236. mainId: "",
  237. mainName: "",
  238. },
  239. rules: {
  240. mainId: [
  241. { required: true, message: "请选择存货分类", trigger: "change" },
  242. ],
  243. customerId: [
  244. { required: true, message: "请选择经销商", trigger: "change" },
  245. ],
  246. },
  247. currentPage: 1, // 当前页码
  248. pageSize: 10, // 每页数量
  249. listTotal: 0, // 列表总数
  250. searchForm: {
  251. customerName: "",
  252. mainId: "",
  253. mainName: "",
  254. },
  255. dataList: [], // 列表数据
  256. listLoading: false, // 列表加载loading
  257. dealerList: [],
  258. selectList: [],
  259. ids: [],
  260. };
  261. },
  262. async created() {
  263. this.getList({ pageNum: 1, pageSize: 10 });
  264. this.getDealerDataList({ pageNum: 1, pageSize: 10 });
  265. this.getSelectList({ sysDictEnum: "PRODUCT_TYPE" });
  266. },
  267. computed: {},
  268. methods: {
  269. // 筛选部分数据或者单个
  270. hanleSelect(selection) {
  271. // this.ids = selection.map((k) => {
  272. // return k.id;
  273. // });
  274. console.log(selection);
  275. this.ids = selection.map((v) => v.id);
  276. },
  277. //存货分类
  278. async getSelectList(data) {
  279. const res = await getDictionaries(data);
  280. console.log(res);
  281. this.selectList = res.data;
  282. },
  283. //删除
  284. async deleFn(id) {
  285. this.ids.push(id);
  286. let res = this.ids.toString();
  287. await deleDealerStockList({ ids: res });
  288. this.getList({ pageNum: 1, pageSize: 10 });
  289. this.$message.success("删除成功");
  290. },
  291. addFn() {
  292. this.dialogForm = true;
  293. },
  294. async addDataListFn() {
  295. await this.$refs.addForm.validate();
  296. // let id = this.dealerList.filter((i) => {
  297. // return i.id === this.addForm.customerId;
  298. // })[0];
  299. // console.log(id, "id");
  300. // let res = findElem(this.dealerList, "id", this.addForm.customerId);
  301. // console.log(11111, res);
  302. let res = this.dealerList.filter(
  303. (v) => v.id === this.addForm.customerId
  304. )[0];
  305. console.log(res);
  306. this.addForm.customerName = res.name;
  307. this.addForm.customerNumber = res.number;
  308. let res2 = this.selectList.filter(
  309. (v) => v.sysDictId === this.addForm.mainId
  310. )[0];
  311. console.log(res2);
  312. this.addForm.mainName = res2.dictValue;
  313. console.log(this.addForm);
  314. await getDealerStockAdd({ ...this.addForm });
  315. this.$message.success("添加成功");
  316. await this.$refs.addForm.resetFields();
  317. await this.getList({ pageNum: 1, pageSize: 10 });
  318. this.dialogForm = false;
  319. },
  320. //取消
  321. async cancelFn() {
  322. await this.$refs.addForm.resetFields();
  323. this.dialogForm = false;
  324. },
  325. //获取经销商数据
  326. async getDealerDataList(data) {
  327. const res = await getDealerList(data);
  328. this.dealerList = res.data.records;
  329. },
  330. // 更改每页数量
  331. handleSizeChange(val) {
  332. this.pageSize = val;
  333. this.currentPage = 1;
  334. this.getList({ pageNum: 1, pageSize: this.pageSize });
  335. },
  336. // 更改当前页
  337. handleCurrentChange(val) {
  338. this.currentPage = val;
  339. this.getList({ pageNum: val, pageSize: 10 });
  340. },
  341. //搜索功能
  342. async searchFn() {
  343. console.log(this.searchForm);
  344. await this.getList({
  345. cusotmerName: this.searchForm.customerName,
  346. pageNum: 1,
  347. pageSize: 10,
  348. });
  349. },
  350. //重置
  351. clearFn() {
  352. console.log(this.$refs.searchForm);
  353. this.$refs.searchForm.resetFields();
  354. },
  355. //获取列表数据
  356. async getList(data) {
  357. const res = await getDealerStockList(data);
  358. console.log(res);
  359. this.dataList = res.data.records;
  360. this.listTotal = res.data.total;
  361. },
  362. },
  363. };
  364. </script>
  365. <style lang="scss" scoped>
  366. ::v-deep .el-popover__reference {
  367. margin-left: 10px;
  368. }
  369. ::v-deep .selectStyle .el-input--suffix {
  370. width: 200%;
  371. }
  372. ::v-deep .el-input--suffix {
  373. width: 300px;
  374. }
  375. ::v-deep .el-dialog__header {
  376. background-color: #dddddd;
  377. }
  378. ::v-deep .dialog-footer {
  379. display: flex;
  380. justify-content: center;
  381. }
  382. .formWidth {
  383. width: 70%;
  384. margin-right: 20px;
  385. }
  386. </style>