dealer_stock.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <template>
  2. <div class="app-container">
  3. <!-- 筛选条件 -->
  4. <div>
  5. <el-form ref="searchForm" :model="searchForm" label-width="100px" size="mini" label-position="left">
  6. <el-row :gutter="20">
  7. <el-col :xs="24" :sm="12" :lg="6">
  8. <el-form-item label="经销商名称" prop="customerName">
  9. <el-input v-model="searchForm.customerName" placeholder="请输入经销商名称"></el-input>
  10. </el-form-item>
  11. </el-col>
  12. <el-col :xs="24" :sm="12" :lg="18">
  13. <el-form-item label="" class="fr">
  14. <el-button size="mini" @click="clearFn">清空</el-button>
  15. <el-button size="mini" type="primary" @click="searchFn">搜索</el-button>
  16. </el-form-item>
  17. </el-col>
  18. </el-row>
  19. </el-form>
  20. </div>
  21. <div class="btn-group clearfix">
  22. <div class="fl">
  23. <el-button v-if="$checkBtnRole('add', $route.meta.roles)" type="primary" size="mini" @click="addFn" class="add-right" icon="el-icon-plus">新增</el-button>
  24. <el-popconfirm v-if="$checkBtnRole('del', $route.meta.roles)" @onConfirm="deleFn" title="这是一段内容确定删除吗?">
  25. <el-button :disabled="ids.length < 1" type="danger" size="mini" class="textColor" icon="el-icon-minus" slot="reference">批量删除</el-button>
  26. </el-popconfirm>
  27. </div>
  28. <div class="fr">
  29. <el-button type="primary" size="mini" @click="downLoadFn">下载模板</el-button>
  30. <el-upload class="import-btn" action="" :http-request="handleImport" :file-list="importFileList" :show-file-list="false">
  31. <el-button type="primary" size="mini">导入</el-button>
  32. </el-upload>
  33. </div>
  34. </div>
  35. <div class="mymain-container">
  36. <!-- 列表 -->
  37. <div class="table">
  38. <el-table v-loading="listLoading" :data="dataList" @select="hanleSelect" @select-all="hanleSelect" element-loading-text="Loading" border fit highlight-current-row stripe>
  39. <el-table-column type="selection" align="center" min-width="51"></el-table-column>
  40. <el-table-column align="left" label="经销商编码" prop="customerNumber" min-width="100" show-overflow-tooltip>
  41. <template slot-scope="scope">
  42. <CopyButton :copyText="scope.row.customerNumber" />
  43. <span>{{scope.row.customerNumber}}</span>
  44. </template>
  45. </el-table-column>
  46. <el-table-column align="left" label="经销商名称" prop="customerName" min-width="260" show-overflow-tooltip>
  47. <template slot-scope="scope">
  48. <CopyButton :copyText="scope.row.customerName" />
  49. <span>{{scope.row.customerName}}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column align="left" label="钱包名称" prop="customerWalletName" min-width="200" show-overflow-tooltip></el-table-column>
  53. <el-table-column align="left" label="业务员" prop="serviceName" min-width="160" show-overflow-tooltip></el-table-column>
  54. <el-table-column align="left" label="创建人" prop="createBy" min-width="180" show-overflow-tooltip></el-table-column>
  55. <el-table-column align="left" label="创建时间" prop="createTime" min-width="160" show-overflow-tooltip></el-table-column>
  56. <el-table-column align="left" label="更新人" prop="updateBy" min-width="180" show-overflow-tooltip></el-table-column>
  57. <el-table-column align="left" label="更新时间" prop="updateTime" min-width="160" show-overflow-tooltip></el-table-column>
  58. <el-table-column align="center" label="操作" prop="caozuo" min-width="160" show-overflow-tooltip fixed="right">
  59. <template slot-scope="scope">
  60. <el-button type="text" class="textColor" v-if="$checkBtnRole('edit', $route.meta.roles)" @click="editFn(scope.row.id)">编辑</el-button>
  61. <el-popconfirm @onConfirm="deleFn(scope.row.id)" v-if="$checkBtnRole('del', $route.meta.roles)" title="这是一段内容确定删除吗?">
  62. <el-button type="text" class="textColor" slot="reference">删除</el-button>
  63. </el-popconfirm>
  64. </template>
  65. </el-table-column>
  66. </el-table>
  67. </div>
  68. <!-- 分页 -->
  69. <div class="fr">
  70. <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 30, 50]" :page-size="10" layout="total, sizes, prev, pager, next, jumper" :total="listTotal">
  71. </el-pagination>
  72. </div>
  73. </div>
  74. <!-- 弹窗 -->
  75. <el-dialog :title="title" :visible.sync="dialogForm" width="30%" :show-close="false" :close-on-click-modal="false">
  76. <el-form ref="addForm" :model="addForm" :rules="rules" label-width="100px" label-position="right">
  77. <el-form-item label="经销商名称" prop="customerId">
  78. <el-select filterable class="selectStyle" v-model="addForm.customerId" placeholder="请选择" @change="changeFn">
  79. <el-option v-for="item in dealerList" :key="item.id" :label="item.name" :value="item.id">
  80. </el-option>
  81. </el-select>
  82. </el-form-item>
  83. <el-form-item label="经销商编码" prop="">
  84. <el-input disabled v-model="addForm.customerNumber"></el-input>
  85. <!-- <template slot-scope="scope">
  86. {{ scope.row }}
  87. </template> -->
  88. </el-form-item>
  89. <el-form-item label="钱包" prop="customerWalletId">
  90. <el-select class="selectStyle" v-model="addForm.customerWalletId" placeholder="请选择" filterable>
  91. <el-option v-for="item in walletList" :key="item.customerWalletId" :label="item.customerWalletName" :value="item.customerWalletId">
  92. </el-option>
  93. </el-select>
  94. </el-form-item>
  95. <el-form-item label="区域" prop="region">
  96. <el-cascader ref="locationCascader" v-model="addForm.region" class="selectStyle" :options="options" :props="props" clearable></el-cascader>
  97. </el-form-item>
  98. <!-- <el-form-item label="一级区域" prop="oneParentId">
  99. <el-select
  100. class="selectStyle"
  101. v-model="addForm.oneParentId"
  102. placeholder="请选择"
  103. filterable
  104. @change="changeOneFn"
  105. >
  106. <el-option
  107. v-for="item in oneList"
  108. :key="item.adminWebsitId"
  109. :label="item.name"
  110. :value="item.adminWebsitId"
  111. >
  112. </el-option>
  113. </el-select>
  114. </el-form-item>
  115. <el-form-item label="二级区域" prop="">
  116. <el-select
  117. filterable
  118. class="selectStyle"
  119. v-model="addForm.twoParentId"
  120. placeholder="请选择"
  121. @change="changeTwoFn"
  122. >
  123. <el-option
  124. v-for="item in twoList"
  125. :key="item.adminWebsitId"
  126. :label="item.name"
  127. :value="item.adminWebsitId"
  128. >
  129. </el-option>
  130. </el-select>
  131. </el-form-item>
  132. <el-form-item label="三级区域" prop=""
  133. ><el-select
  134. class="selectStyle"
  135. v-model="addForm.threeParentId"
  136. placeholder="请选择"
  137. filterable
  138. @change="changeThreeFn"
  139. >
  140. <el-option
  141. v-for="item in threeList"
  142. :key="item.adminWebsitId"
  143. :label="item.name"
  144. :value="item.adminWebsitId"
  145. >
  146. </el-option>
  147. </el-select>
  148. </el-form-item> -->
  149. <el-form-item label="对应业务员" prop="serviceId">
  150. <el-select class="selectStyle" v-model="addForm.serviceId" placeholder="请选择" filterable>
  151. <el-option v-for="(item, i) in userList" :key="i" :label="item.nickName" :value="item.adminUserId">
  152. </el-option>
  153. </el-select>
  154. </el-form-item>
  155. </el-form>
  156. <div slot="footer" class="dialog-footer">
  157. <el-button @click="cancelFn">取 消</el-button>
  158. <el-button type="primary" @click="addDataListFn">确 定</el-button>
  159. </div>
  160. </el-dialog>
  161. </div>
  162. </template>
  163. <script>
  164. import {
  165. getDealerStockList,
  166. getDealerStockAdd,
  167. deleDealerStockList,
  168. getDictionaries,
  169. getProductCategoryList,
  170. getAdminWebsitByparent,
  171. getAdminUserList,
  172. getCustomerPtDetail,
  173. getCustomerPtUpdate,
  174. getWalletCustomerList,
  175. } from "@/api/basic_data/dealer";
  176. import { getDealerList } from "@/api/basic_data/dealer";
  177. import { getDepartmentList } from "@/api/setting";
  178. import { downloadFiles, handleImport } from "@/utils/util";
  179. export default {
  180. data() {
  181. return {
  182. props: {
  183. checkStrictly: true,
  184. value: "adminWebsitId",
  185. label: "name",
  186. // expandTrigger: "hover",
  187. // lazy: true,
  188. // lazyLoad(node, resolve) {
  189. // console.log(node);
  190. // const { value } = node;
  191. // setTimeout(async () => {
  192. // let res = await getAdminWebsitByparent({
  193. // parentId: value,
  194. // });
  195. // let aaa = res.data.map((v) => {
  196. // return { value: v.adminWebsitId, label: v.name };
  197. // });
  198. // resolve(aaa);
  199. // }, 0);
  200. // },
  201. },
  202. options: [],
  203. importFileList: [],
  204. isDisabled: true,
  205. title: "",
  206. dialogForm: false,
  207. addForm: {
  208. customerId: "",
  209. customerName: "",
  210. customerNumber: "",
  211. region: [],
  212. // oneParentId: "",
  213. // twoParentId: "",
  214. // threeParentId: "",
  215. serviceId: "",
  216. customerWalletId: "",
  217. },
  218. mainId: null,
  219. rules: {
  220. customerId: [
  221. { required: true, message: "请选择经销商名称", trigger: "change" },
  222. ],
  223. customerWalletId: [
  224. { required: true, message: "请选择经销商钱包", trigger: "change" },
  225. ],
  226. region: [{ required: true, message: "请选择区域", trigger: "change" }],
  227. // oneParentId: [
  228. // { required: true, message: "请选择一级区域", trigger: "blur" },
  229. // ],
  230. // twoParentId: [
  231. // { required: true, message: "请选择二级区域", trigger: "blur" },
  232. // ],
  233. // threeParentId: [
  234. // { required: true, message: "请选择三级区域", trigger: "blur" },
  235. // ],
  236. serviceId: [
  237. { required: true, message: "请选择业务员", trigger: "change" },
  238. ],
  239. },
  240. currentPage: 1, // 当前页码
  241. pageSize: 10, // 每页数量
  242. listTotal: 0, // 列表总数
  243. searchForm: {
  244. customerName: "",
  245. },
  246. dataList: [], // 列表数据
  247. listLoading: false, // 列表加载loading
  248. dealerList: [],
  249. // selectList: [],
  250. walletList: [], //产品大类列表
  251. // oneList: [], //一级区域数据
  252. // twoList: [], //二级区域数据
  253. // threeList: [], //三级区域数据
  254. userList: [], //业务员
  255. ids: [],
  256. rowID: null, //编辑ID
  257. };
  258. },
  259. async created() {
  260. this.getTree();
  261. // this.getAdminWebsit(1);
  262. this.getList({ pageNum: 1, pageSize: 10 });
  263. this.getDealerDataList({ pageNum: 1, pageSize: -1 });
  264. this.getUserList(1);
  265. // this.getSelectList({ sysDictEnum: "PRODUCT_TYPE" });
  266. },
  267. computed: {},
  268. watch: {
  269. "addForm.region": function (newValue) {
  270. // console.log(newValue, 888);
  271. if (newValue) {
  272. this.getUserList(newValue[newValue.length - 1]);
  273. }
  274. },
  275. "addForm.customerId": async function (newValue) {
  276. if (newValue) {
  277. // this.addForm.customerWalletId = "";
  278. const res = this.dealerList.filter((i) => i.id == newValue);
  279. this.addForm.customerName = res[0].name;
  280. this.addForm.customerNumber = res[0].number;
  281. let res2 = await getWalletCustomerList({
  282. customerId: newValue,
  283. type: "COMMONLY",
  284. });
  285. this.walletList = res2.data;
  286. }
  287. },
  288. // "addForm.oneParentId": async function (newValue) {
  289. // if (newValue) {
  290. // let res = await getAdminWebsitByparent({
  291. // parentId: newValue,
  292. // // mainId: this.mainId,
  293. // });
  294. // this.twoList = res.data;
  295. // }
  296. // },
  297. // "addForm.twoParentId": async function (newValue) {
  298. // if (newValue) {
  299. // let res = await getAdminWebsitByparent({
  300. // parentId: newValue,
  301. // // mainId: this.mainId,
  302. // });
  303. // this.getUserList(newValue);
  304. // this.threeList = res.data;
  305. // }
  306. // },
  307. // "addForm.threeParentId": async function (newValue) {
  308. // if (newValue) {
  309. // this.getUserList(newValue);
  310. // }
  311. // },
  312. },
  313. methods: {
  314. // 导入
  315. async handleImport(param) {
  316. const file = param.file;
  317. const formData = new FormData();
  318. formData.append("file", file);
  319. let result = await handleImport("/customer/pt/importData", formData);
  320. console.log(result);
  321. this.importFileList = [];
  322. if (result.code == 200) {
  323. this.$message.success("导入成功");
  324. await this.getList({
  325. customerName: this.searchForm.customerName,
  326. pageNum: 1,
  327. pageSize: 10,
  328. });
  329. } else {
  330. this.$message.error(result.message);
  331. }
  332. },
  333. //下载模板
  334. downLoadFn() {
  335. downloadFiles("/customer/pt/download");
  336. },
  337. // //改变产品大类
  338. // changeSelectFn(value) {
  339. // // const res = this.categoryList.filter((v) => v.productCategoryId == value);
  340. // // console.log(res);
  341. // // this.mainId = res[0].productCategoryNumber;
  342. // },
  343. //编辑
  344. async changeFn(v) {
  345. this.addForm.customerWalletId = "";
  346. },
  347. // async changeOneFn(v) {
  348. // this.addForm.twoParentId = "";
  349. // this.addForm.threeParentId = "";
  350. // this.addForm.serviceId = "";
  351. // },
  352. // async changeTwoFn(v) {
  353. // this.addForm.threeParentId = "";
  354. // this.addForm.serviceId = "";
  355. // },
  356. // async changeThreeFn(v) {
  357. // this.addForm.serviceId = "";
  358. // },
  359. async editFn(id) {
  360. this.title = "经销商业务关系管理 ";
  361. this.rowID = id;
  362. let res = await getCustomerPtDetail({ id });
  363. // console.log(res);
  364. this.addForm.customerId = res.data.customerId;
  365. this.addForm.customerWalletId = res.data.customerWalletId;
  366. // this.addForm.oneParentId = res.data.adminWebsitId1;
  367. // this.addForm.twoParentId = res.data.adminWebsitId2;
  368. // this.addForm.threeParentId = res.data.adminWebsitId3;
  369. this.addForm.region = [
  370. res.data.adminWebsitId1,
  371. res.data.adminWebsitId2,
  372. res.data.adminWebsitId3,
  373. ];
  374. this.addForm.serviceId = res.data.serviceId;
  375. this.dialogForm = true;
  376. },
  377. //获取业务员数据
  378. async getUserList(v) {
  379. let res = await getAdminUserList({
  380. pageNum: 1,
  381. pageSize: -1,
  382. isCustomer: 0,
  383. adminWebsitId: v,
  384. });
  385. if (res.data.records.length == 0) {
  386. this.addForm.serviceId = "";
  387. }
  388. this.userList = res.data.records;
  389. },
  390. // 获取部门列表
  391. getTree() {
  392. getDepartmentList().then((res) => {
  393. // console.log(res, 8888);
  394. this.options = res.data[0].children;
  395. });
  396. },
  397. // //根据父级查询部门
  398. // async getAdminWebsit(data) {
  399. // let res = await getAdminWebsitByparent({
  400. // parentId: data,
  401. // // mainId: this.mainId,
  402. // });
  403. // let arr = res.data.map((v) => {
  404. // return {
  405. // value: v.adminWebsitId,
  406. // label: v.name,
  407. // };
  408. // });
  409. // // this.options = arr;
  410. // this.oneList = res.data;
  411. // },
  412. // //获取产品品类数据
  413. // async getCategoryList() {
  414. // let res = await getProductCategoryList();
  415. // console.log(res);
  416. // this.categoryList = res.data;
  417. // },
  418. // 筛选部分数据或者单个
  419. hanleSelect(selection) {
  420. // this.ids = selection.map((k) => {
  421. // return k.id;
  422. // });
  423. // console.log(selection);
  424. this.ids = selection.map((v) => v.id);
  425. },
  426. // //存货分类
  427. // async getSelectList(data) {
  428. // const res = await getDictionaries(data);
  429. // console.log(res);
  430. // this.selectList = res.data;
  431. // },
  432. //删除
  433. async deleFn(id) {
  434. if (id) {
  435. let arr = [];
  436. arr.push(id);
  437. let res2 = arr.toString();
  438. await deleDealerStockList({ ids: res2 });
  439. } else {
  440. let res = this.ids.toString();
  441. await deleDealerStockList({ ids: res });
  442. }
  443. this.getList({ pageNum: 1, pageSize: 10 });
  444. this.$message.success("删除成功");
  445. this.ids = [];
  446. },
  447. async addFn() {
  448. this.title = "经销商业务关系管理";
  449. this.dialogForm = true;
  450. },
  451. async addDataListFn() {
  452. await this.$refs.addForm.validate();
  453. let data2 = this.walletList.filter((v) => {
  454. return v.customerWalletId == this.addForm.customerWalletId;
  455. });
  456. let data3 = this.userList.filter((v) => {
  457. return v.adminUserId == this.addForm.serviceId;
  458. });
  459. // console.log(data3);
  460. // console.log(data2, 22222);
  461. let value = {
  462. customerId: this.addForm.customerId,
  463. customerName: this.addForm.customerName,
  464. customerNumber: this.addForm.customerNumber,
  465. customerWalletId: this.addForm.customerWalletId,
  466. customerWalletName: data2[0].customerWalletName,
  467. serviceId: this.addForm.serviceId,
  468. serviceName: data3[0].nickName,
  469. };
  470. if (this.title == "经销商业务关系管理 ") {
  471. await getCustomerPtUpdate({ ...value, id: this.rowID });
  472. this.$message.success("编辑成功");
  473. } else {
  474. await getDealerStockAdd(value);
  475. this.$message.success("添加成功");
  476. }
  477. if (this.$refs.locationCascader) {
  478. this.$refs.locationCascader.$refs.panel.activePath = [];
  479. this.$refs.locationCascader.$refs.panel.calculateCheckedNodePaths();
  480. }
  481. this.addForm.customerId = "";
  482. this.addForm.customerNumber = "";
  483. this.addForm.customerName = "";
  484. this.addForm.customerWalletId = "";
  485. this.addForm.region = [];
  486. // this.addForm.oneParentId = "";
  487. // this.addForm.twoParentId = "";
  488. // this.addForm.threeParentId = "";
  489. this.addForm.serviceId = "";
  490. // this.userList = [];
  491. // this.twoList = [];
  492. // this.threeList = [];
  493. this.walletList = [];
  494. this.$nextTick(() => {
  495. this.$refs["addForm"].clearValidate();
  496. });
  497. this.getList({ pageNum: 1, pageSize: 10 });
  498. this.dialogForm = false;
  499. },
  500. //取消
  501. async cancelFn() {
  502. if (this.$refs.locationCascader) {
  503. this.$refs.locationCascader.$refs.panel.activePath = [];
  504. this.$refs.locationCascader.$refs.panel.calculateCheckedNodePaths();
  505. }
  506. this.addForm.customerId = "";
  507. this.addForm.customerNumber = "";
  508. this.addForm.customerWalletId = "";
  509. this.addForm.region = [];
  510. // this.addForm.oneParentId = "";
  511. // this.addForm.twoParentId = "";
  512. // this.addForm.threeParentId = "";
  513. this.addForm.serviceId = "";
  514. // this.userList = [];
  515. // this.twoList = [];
  516. // this.threeList = [];
  517. this.walletList = [];
  518. this.$nextTick(() => {
  519. this.$refs["addForm"].clearValidate();
  520. });
  521. this.dialogForm = false;
  522. },
  523. //获取经销商数据
  524. async getDealerDataList(data) {
  525. const res = await getDealerList(data);
  526. this.dealerList = res.data.records;
  527. },
  528. // 更改每页数量
  529. handleSizeChange(val) {
  530. this.pageSize = val;
  531. this.currentPage = 1;
  532. this.getList({
  533. pageNum: 1,
  534. pageSize: this.pageSize,
  535. customerName: this.searchForm.customerName,
  536. });
  537. },
  538. // 更改当前页
  539. handleCurrentChange(val) {
  540. this.currentPage = val;
  541. this.getList({
  542. pageNum: val,
  543. pageSize: 10,
  544. customerName: this.searchForm.customerName,
  545. });
  546. },
  547. //搜索功能
  548. async searchFn() {
  549. console.log(this.searchForm);
  550. await this.getList({
  551. customerName: this.searchForm.customerName,
  552. pageNum: 1,
  553. pageSize: 10,
  554. });
  555. },
  556. //重置
  557. clearFn() {
  558. console.log(this.$refs.searchForm);
  559. this.$refs.searchForm.resetFields();
  560. },
  561. //获取列表数据
  562. async getList(data) {
  563. const res = await getDealerStockList(data);
  564. this.dataList = res.data.records;
  565. this.listTotal = res.data.total;
  566. },
  567. },
  568. };
  569. </script>
  570. <style lang="scss" scoped>
  571. .add-right {
  572. margin-right: 10px;
  573. }
  574. .import-btn {
  575. margin-left: 10px;
  576. display: inline-block;
  577. }
  578. // ::v-deep .selectStyle .el-input--suffix {
  579. // width: 200%;
  580. // }
  581. // ::v-deep .el-input--suffix {
  582. // width: 300px;
  583. // }
  584. // ::v-deep .el-dialog__header {
  585. // background-color: #dddddd;
  586. // }
  587. // ::v-deep .dialog-footer {
  588. // display: flex;
  589. // justify-content: center;
  590. // }
  591. // .formWidth {
  592. // width: 70%;
  593. // margin-right: 20px;
  594. // }
  595. .selectStyle {
  596. width: 100%;
  597. }
  598. </style>