dealer_stock.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <template>
  2. <template-page
  3. ref="pageRef"
  4. :getList="getList"
  5. :optionsEvensGroup="optionsEvensGroup"
  6. :exportList="exportList"
  7. :operation="operation()"
  8. :tableEvents="tableEvents"
  9. :tableAttributes="tableAttributes"
  10. :columnParsing="columnParsing"
  11. >
  12. <el-dialog :title="title" :visible.sync="dialogForm" width="50%" :show-close="false" :close-on-click-modal="false">
  13. <el-form ref="addForm" :model="addForm" :rules="rules" label-width="100px" label-position="left">
  14. <el-row :gutter="20">
  15. <el-col :span="12">
  16. <el-form-item label="经销商名称" prop="customerId">
  17. <el-select
  18. filterable
  19. class="selectStyle"
  20. v-model="addForm.customerId"
  21. placeholder="请选择"
  22. @change="changeFn"
  23. >
  24. <el-option v-for="item in dealerList" :key="item.id" :label="item.name" :value="item.id"> </el-option>
  25. </el-select> </el-form-item
  26. ></el-col>
  27. <el-col :span="12"
  28. ><el-form-item label="经销商编码" prop="customerNumber">
  29. <el-input disabled v-model="addForm.customerNumber"></el-input> </el-form-item
  30. ></el-col>
  31. <el-col :span="12">
  32. <el-form-item label="金蝶部门编号" prop="k3OrgNumber">
  33. <el-select class="selectStyle" v-model="addForm.k3OrgNumber" placeholder="请选择" filterable>
  34. <el-option
  35. v-for="item in k3DepartmentList"
  36. :key="item.number"
  37. :label="item.name + '(' + item.number + ')'"
  38. :value="item.number"
  39. >
  40. </el-option>
  41. </el-select> </el-form-item
  42. ></el-col>
  43. <el-col :span="12"
  44. ><el-form-item label="钱包" prop="customerWalletId">
  45. <el-select class="selectStyle" v-model="addForm.customerWalletId" placeholder="请选择" filterable>
  46. <el-option
  47. v-for="item in walletList"
  48. :key="item.customerWalletId"
  49. :label="item.customerWalletName"
  50. :value="item.customerWalletId"
  51. >
  52. </el-option>
  53. </el-select> </el-form-item
  54. ></el-col>
  55. <el-col :span="12">
  56. <el-form-item label="区域" prop="region">
  57. <el-cascader
  58. ref="locationCascader"
  59. v-model="addForm.region"
  60. class="selectStyle"
  61. :options="options"
  62. :props="props"
  63. clearable
  64. ></el-cascader> </el-form-item
  65. ></el-col>
  66. <el-col :span="12"
  67. ><el-form-item label="对应业务员" prop="serviceId">
  68. <el-select class="selectStyle" v-model="addForm.serviceId" placeholder="请选择" filterable>
  69. <el-option v-for="(item, i) in userList" :key="i" :label="item.nickName" :value="item.adminUserId">
  70. </el-option>
  71. </el-select> </el-form-item
  72. ></el-col>
  73. </el-row>
  74. </el-form>
  75. <div slot="footer" class="dialog-footer">
  76. <el-button @click="cancelFn">取 消</el-button>
  77. <el-button type="primary" @click="addDataListFn">确 定</el-button>
  78. </div>
  79. </el-dialog>
  80. </template-page>
  81. </template>
  82. <script>
  83. import TemplatePage from '@/components/template/template-page-1.vue'
  84. import import_mixin from '@/components/template/import_mixin.js'
  85. import add_callback_mixin from '@/components/template/add_callback_mixin.js'
  86. import Popu from '@/components/template/popu.vue'
  87. import {
  88. getDealerStockListV2,
  89. exportDealerStockListV2,
  90. getDealerStockAdd,
  91. deleDealerStockList,
  92. getDictionaries,
  93. getProductCategoryList,
  94. getAdminWebsitByparent,
  95. getAdminUserList,
  96. getCustomerPtDetail,
  97. getCustomerPtUpdate,
  98. getWalletCustomerList,
  99. getK3DepartmentList,
  100. downloadCustomerPtV2,
  101. importCustomerPtV2
  102. } from '@/api/basic_data/dealer'
  103. import { getDealerList } from '@/api/basic_data/dealer'
  104. import { getDepartmentList } from '@/api/setting'
  105. export default {
  106. components: { TemplatePage, Popu },
  107. mixins: [import_mixin, add_callback_mixin],
  108. data() {
  109. return {
  110. visible: false,
  111. // 事件组合
  112. optionsEvensGroup: [
  113. [
  114. [
  115. {
  116. name: '新增',
  117. click: this.addOn(() => {
  118. this.addFn()
  119. }),
  120. isRole: this.$checkBtnRole('add', this.$route.meta.roles)
  121. }
  122. ]
  123. ],
  124. [
  125. [
  126. {
  127. name: '批量删除',
  128. click: async () => {
  129. if (this.recordSelected.length === 0) {
  130. this.$message.error('请选择需要删除的数据')
  131. return
  132. }
  133. let ids = this.recordSelected.map(v => {
  134. return v.id
  135. })
  136. let params = { ids: ids.toString() }
  137. await deleDealerStockList(params)
  138. this.$refs.pageRef.refreshList()
  139. this.$message.success('批量删除成功')
  140. },
  141. isRole: this.$checkBtnRole('del', this.$route.meta.roles)
  142. }
  143. ]
  144. ],
  145. [
  146. [
  147. {
  148. name: '导入',
  149. render: this.importButton(importCustomerPtV2)
  150. }
  151. ]
  152. ],
  153. [
  154. [
  155. {
  156. name: '导入模版',
  157. click: () => {
  158. downloadCustomerPtV2({}, `${this.$route.meta.title}`)
  159. .then(res => {
  160. this.$message({
  161. message: '下载成功',
  162. type: 'success'
  163. })
  164. })
  165. .catch(err => {
  166. this.$message.error('下载失败')
  167. })
  168. }
  169. }
  170. ]
  171. ]
  172. ],
  173. // 表格属性
  174. tableAttributes: {
  175. // 启用勾选列
  176. selectColumn: true
  177. }, // 关闭新增弹窗
  178. // 表格事件
  179. tableEvents: {
  180. 'selection-change': this.selectionChange
  181. },
  182. recordSelected: [],
  183. props: {
  184. checkStrictly: true,
  185. value: 'adminWebsitId',
  186. label: 'name'
  187. },
  188. options: [],
  189. importFileList: [],
  190. isDisabled: true,
  191. title: '',
  192. dialogForm: false,
  193. addForm: {
  194. customerId: '',
  195. customerName: '',
  196. customerNumber: '',
  197. k3OrgNumber: '',
  198. region: [],
  199. serviceId: '',
  200. customerWalletId: ''
  201. },
  202. mainId: null,
  203. rules: {
  204. customerId: [{ required: true, message: '请选择经销商名称', trigger: 'change' }],
  205. customerWalletId: [{ required: true, message: '请选择经销商钱包', trigger: 'change' }],
  206. region: [{ required: true, message: '请选择区域', trigger: 'change' }],
  207. serviceId: [{ required: true, message: '请选择业务员', trigger: 'change' }]
  208. },
  209. currentPage: 1, // 当前页码
  210. pageSize: 10, // 每页数量
  211. listTotal: 0, // 列表总数
  212. searchForm: {
  213. customerName: ''
  214. },
  215. isCollapse: true,
  216. dataList: [], // 列表数据
  217. listLoading: false, // 列表加载loading
  218. dealerList: [],
  219. walletList: [], //产品大类列表
  220. userList: [], //业务员
  221. ids: [],
  222. rowID: null, //编辑ID
  223. k3DepartmentList: []
  224. }
  225. },
  226. watch: {
  227. 'addForm.region': function (newValue) {
  228. // console.log(newValue, 888);
  229. if (newValue) {
  230. this.getUserList(newValue[newValue.length - 1])
  231. }
  232. },
  233. 'addForm.customerId': async function (newValue) {
  234. if (newValue) {
  235. // this.addForm.customerWalletId = "";
  236. const res = this.dealerList.filter(i => i.id == newValue)
  237. this.addForm.customerName = res[0].name
  238. this.addForm.customerNumber = res[0].number
  239. let res2 = await getWalletCustomerList({
  240. customerId: newValue,
  241. type: 'COMMONLY'
  242. })
  243. this.walletList = res2.data
  244. }
  245. }
  246. },
  247. async created() {
  248. this.getTree()
  249. this.getK3DepartmentList()
  250. this.getDealerDataList({ pageNum: 1, pageSize: -1 })
  251. this.getUserList(1)
  252. },
  253. methods: {
  254. // 列表请求函数
  255. getList(...p) {
  256. this.recordSelected = []
  257. return getDealerStockListV2(...p)
  258. },
  259. // 列表导出函数
  260. exportList: exportDealerStockListV2,
  261. // 表格列解析渲染数据更改
  262. columnParsing(item, defaultData) {
  263. return defaultData
  264. },
  265. // 监听勾选变化
  266. selectionChange(data) {
  267. this.recordSelected = data
  268. },
  269. operation() {
  270. return (h, { row, index, column }) => {
  271. return (
  272. <div class="operation-btns">
  273. {this.$checkBtnRole('edit', this.$route.meta.roles) ? (
  274. <el-button
  275. size="mini"
  276. type="text"
  277. onClick={() => {
  278. this.editFn(row.id)
  279. }}
  280. >
  281. 编辑
  282. </el-button>
  283. ) : null}
  284. {this.$checkBtnRole('del', this.$route.meta.roles) ? (
  285. <el-popconfirm onOnConfirm={() => this.deleFn(row.id)} title="这是一段内容确定删除吗?">
  286. <el-button style="font-size:12px" type="text" size="mini" slot="reference">
  287. 删除
  288. </el-button>
  289. </el-popconfirm>
  290. ) : null}
  291. </div>
  292. )
  293. }
  294. },
  295. handleClose() {
  296. this.addOff(() => {
  297. this.visible = false
  298. })()
  299. },
  300. // 导入
  301. async handleImport(param) {
  302. const file = param.file
  303. const formData = new FormData()
  304. formData.append('file', file)
  305. let result = await handleImport('customer/pt/importData', formData)
  306. this.importFileList = []
  307. if (result.code == 200) {
  308. this.$message.success('导入成功')
  309. await this.$refs.pageRef.refreshList()
  310. } else {
  311. this.$message.error(result.message)
  312. }
  313. },
  314. getK3DepartmentList() {
  315. getK3DepartmentList().then(res => {
  316. this.k3DepartmentList = res.data
  317. })
  318. },
  319. //下载模板
  320. downLoadFn() {
  321. downloadFiles('customer/pt/download')
  322. },
  323. //下载模板
  324. downLoadFns() {
  325. downloadFiles('customer/pt/export')
  326. },
  327. //编辑
  328. async changeFn(v) {
  329. this.addForm.customerWalletId = ''
  330. },
  331. async editFn(id) {
  332. this.title = '经销商业务关系管理 '
  333. this.rowID = id
  334. let res = await getCustomerPtDetail({ id })
  335. this.addForm.customerId = res.data.customerId
  336. this.addForm.customerWalletId = res.data.customerWalletId
  337. this.addForm.region = [res.data.adminWebsitId1, res.data.adminWebsitId2, res.data.adminWebsitId3]
  338. this.addForm.serviceId = res.data.serviceId
  339. this.addForm.k3OrgNumber = res.data.k3OrgNumber
  340. this.dialogForm = true
  341. },
  342. //获取业务员数据
  343. async getUserList(v) {
  344. let res = await getAdminUserList({
  345. pageNum: 1,
  346. pageSize: -1,
  347. isCustomer: 0,
  348. adminWebsitId: v
  349. })
  350. if (res.data.records.length == 0) {
  351. this.addForm.serviceId = ''
  352. }
  353. this.userList = res.data.records
  354. },
  355. // 获取部门列表
  356. getTree() {
  357. getDepartmentList().then(res => {
  358. // console.log(res, 8888);
  359. this.options = res.data[0].children
  360. })
  361. },
  362. // 筛选部分数据或者单个
  363. hanleSelect(selection) {
  364. // this.ids = selection.map((k) => {
  365. // return k.id;
  366. // });
  367. // console.log(selection);
  368. this.ids = selection.map(v => v.id)
  369. },
  370. // //存货分类
  371. // async getSelectList(data) {
  372. // const res = await getDictionaries(data);
  373. // console.log(res);
  374. // this.selectList = res.data;
  375. // },
  376. //删除
  377. async deleFn(id) {
  378. if (id) {
  379. let arr = []
  380. arr.push(id)
  381. let res2 = arr.toString()
  382. await deleDealerStockList({ ids: res2 })
  383. } else {
  384. let res = this.ids.toString()
  385. await deleDealerStockList({ ids: res })
  386. }
  387. this.$refs.pageRef.refreshList()
  388. this.$message.success('删除成功')
  389. this.ids = []
  390. },
  391. async addFn() {
  392. this.title = '经销商业务关系管理'
  393. this.dialogForm = true
  394. },
  395. async addDataListFn() {
  396. await this.$refs.addForm.validate()
  397. let data2 = this.walletList.filter(v => {
  398. return v.customerWalletId == this.addForm.customerWalletId
  399. })
  400. let data3 = this.userList.filter(v => {
  401. return v.adminUserId == this.addForm.serviceId
  402. })
  403. let value = {
  404. customerId: this.addForm.customerId,
  405. customerName: this.addForm.customerName,
  406. customerNumber: this.addForm.customerNumber,
  407. customerWalletId: this.addForm.customerWalletId,
  408. customerWalletName: data2[0].customerWalletName,
  409. k3OrgNumber: this.addForm.k3OrgNumber,
  410. serviceId: this.addForm.serviceId,
  411. serviceName: data3[0].nickName
  412. }
  413. if (this.title == '经销商业务关系管理 ') {
  414. await getCustomerPtUpdate({ ...value, id: this.rowID })
  415. this.$message.success('编辑成功')
  416. } else {
  417. await getDealerStockAdd(value)
  418. this.$message.success('添加成功')
  419. }
  420. if (this.$refs.locationCascader) {
  421. this.$refs.locationCascader.$refs.panel.activePath = []
  422. this.$refs.locationCascader.$refs.panel.calculateCheckedNodePaths()
  423. }
  424. this.addForm.customerId = ''
  425. this.addForm.customerNumber = ''
  426. this.addForm.customerName = ''
  427. this.addForm.customerWalletId = ''
  428. this.addForm.region = []
  429. this.addForm.k3OrgNumber = ''
  430. this.addForm.serviceId = ''
  431. this.walletList = []
  432. this.$nextTick(() => {
  433. this.$refs['addForm'].clearValidate()
  434. })
  435. this.$refs.pageRef.refreshList()
  436. this.dialogForm = false
  437. },
  438. //取消
  439. async cancelFn() {
  440. if (this.$refs.locationCascader) {
  441. this.$refs.locationCascader.$refs.panel.activePath = []
  442. this.$refs.locationCascader.$refs.panel.calculateCheckedNodePaths()
  443. }
  444. this.addForm.customerId = ''
  445. this.addForm.customerNumber = ''
  446. this.addForm.customerWalletId = ''
  447. this.addForm.region = []
  448. this.addForm.k3OrgNumber = ''
  449. // this.addForm.oneParentId = "";
  450. // this.addForm.twoParentId = "";
  451. // this.addForm.threeParentId = "";
  452. this.addForm.serviceId = ''
  453. // this.userList = [];
  454. // this.twoList = [];
  455. // this.threeList = [];
  456. this.walletList = []
  457. this.$nextTick(() => {
  458. this.$refs['addForm'].clearValidate()
  459. })
  460. this.dialogForm = false
  461. },
  462. //获取经销商数据
  463. async getDealerDataList(data) {
  464. const res = await getDealerList(data)
  465. this.dealerList = res.data.records
  466. }
  467. }
  468. }
  469. </script>
  470. <style lang="scss" scoped>
  471. .add-right {
  472. margin-right: 10px;
  473. }
  474. .import-btn {
  475. margin-left: 10px;
  476. display: inline-block;
  477. }
  478. // ::v-deep .selectStyle .el-input--suffix {
  479. // width: 200%;
  480. // }
  481. // ::v-deep .el-input--suffix {
  482. // width: 300px;
  483. // }
  484. // ::v-deep .el-dialog__header {
  485. // background-color: #dddddd;
  486. // }
  487. // ::v-deep .dialog-footer {
  488. // display: flex;
  489. // justify-content: center;
  490. // }
  491. // .formWidth {
  492. // width: 70%;
  493. // margin-right: 20px;
  494. // }
  495. .selectStyle {
  496. width: 100%;
  497. }
  498. </style>