TabelTransfer.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <template>
  2. <div>
  3. <slot name="header">
  4. <el-row class="radio">
  5. <el-radio-group v-model="region">
  6. <el-radio label="">全部经销商</el-radio>
  7. <!-- <el-radio label="1">地区</el-radio>-->
  8. <!-- <el-radio label="2">指定</el-radio>-->
  9. </el-radio-group>
  10. <el-upload
  11. class="import-btn"
  12. :action="baseURL + 'student/import'"
  13. :http-request="handleImport"
  14. :file-list="importFileList"
  15. :show-file-list="false"
  16. >
  17. <el-button
  18. type="primary"
  19. size="small"
  20. >导入经销商</el-button>
  21. </el-upload>
  22. <el-button
  23. type="primary"
  24. size="small"
  25. @click="hanleDownloadFiles"
  26. >下载模板</el-button>
  27. <el-button
  28. type="primary"
  29. size="small"
  30. >导出已选</el-button
  31. >
  32. </el-row>
  33. <el-row type="flex">
  34. <el-col>
  35. <el-input
  36. v-model="keyword"
  37. placeholder="查找经销商"
  38. size="small"
  39. />
  40. </el-col>
  41. <el-col style="margin-left: 10px"><el-button size="small" @click="submitScreenForm">确定</el-button></el-col>
  42. <el-col style="margin-left: 10px"><el-button size="small" @click="resetScreenForm">重置</el-button></el-col>
  43. </el-row>
  44. </slot>
  45. <el-row :gutter="20">
  46. <el-col :span="10" :offset="0">
  47. <h5>未选经销商</h5>
  48. <el-divider
  49. direction="horizontal"
  50. content-position="left"
  51. />
  52. <el-table
  53. ref="multipleTable"
  54. :data="dataL"
  55. element-loading-text="Loading"
  56. border
  57. height="480px"
  58. fit
  59. highlight-current-row
  60. @select-all="handleSelectionAllChange"
  61. @selection-change="handleSelectionChange"
  62. >
  63. <el-table-column
  64. type="selection"
  65. width="55"
  66. :selectable="selectable"
  67. align="left"
  68. />
  69. <!-- <el-table-column-->
  70. <!-- prop="number"-->
  71. <!-- label="经销商编码"-->
  72. <!-- align="left"-->
  73. <!-- />-->
  74. <el-table-column
  75. prop="name"
  76. label="经销商名称"
  77. align="left"
  78. ><template slot-scope="scope">
  79. <CopyButton :copy-text="scope.row.name" />
  80. <span>{{ scope.row.name }}</span>
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. <!-- 分页 -->
  85. <div style="margin: 20px 0">
  86. <el-pagination
  87. :current-page="currentPages"
  88. :page-sizes="[10, 20, 30, 50]"
  89. :page-size="10"
  90. layout="total, sizes, prev, pager, next, jumper"
  91. :total="clistTotal"
  92. @size-change="handleSizeChanges"
  93. @current-change="handleCurrentChanges"
  94. />
  95. </div>
  96. </el-col>
  97. <el-col :span="4" class="middle_box" :offset="0">
  98. <el-col>
  99. <el-button
  100. size="small"
  101. :disabled="type == 2"
  102. @click="handleAllAdd"
  103. >全部添加</el-button></el-col>
  104. <el-col>
  105. <el-button
  106. size="small"
  107. :disabled="type == 2"
  108. @click="handleAdd"
  109. >增加</el-button></el-col>
  110. <el-col>
  111. <el-button
  112. size="small"
  113. :disabled="type == 1"
  114. @click="handleDelete"
  115. >删除</el-button></el-col>
  116. <el-col>
  117. <el-button
  118. size="small"
  119. :disabled="type == 1"
  120. @click="handleAllDelete"
  121. >全部删除</el-button></el-col>
  122. </el-col>
  123. <el-col :span="10" :offset="0">
  124. <h5>已选经销商</h5>
  125. <el-divider
  126. direction="horizontal"
  127. content-position="left"
  128. />
  129. <el-table
  130. v-loading="listLoading"
  131. :data="custoList"
  132. element-loading-text="Loading"
  133. border
  134. height="480px"
  135. fit
  136. highlight-current-row
  137. stripe
  138. @select-all="handleSelectionAllChange2"
  139. @selection-change="handleSelectionChange2"
  140. >
  141. <el-table-column type="selection" width="55" align="left" />
  142. <!-- <el-table-column-->
  143. <!-- prop="customerNumber"-->
  144. <!-- label="经销商编码"-->
  145. <!-- align="left"-->
  146. <!-- />-->
  147. <el-table-column
  148. prop="customerName"
  149. label="经销商名称"
  150. align="left"
  151. >
  152. <template slot-scope="scope">
  153. <CopyButton :copy-text="scope.row.customerName" />
  154. <span>{{ scope.row.customerName }}</span>
  155. </template>
  156. </el-table-column>
  157. </el-table>
  158. </el-col>
  159. </el-row>
  160. <slot name="footer">
  161. <el-row style="margin:20px 0 0 0;">
  162. <el-button
  163. type="primary"
  164. size="small"
  165. @click="handleSave"
  166. > {{ comCode?'保存':'提交审核' }} </el-button>
  167. <el-button type="primary" size="small" @click="handleReset">重置</el-button>
  168. </el-row>
  169. </slot>
  170. </div>
  171. </template>
  172. <script>
  173. import { deleteCondition, deleteMaterialPolicy, getConditionList, getCrList, getCustomerList } from '@/api/policy_list'
  174. import { downloadFiles, handleImport } from '@/utils/util'
  175. import EditCondition from './EditCondition'
  176. import ImageUpload from '@/components/Common/image-upload.vue'
  177. import Minxin from '@/mixin'
  178. export default {
  179. name: 'Examine',
  180. components: {
  181. EditCondition,
  182. ImageUpload
  183. },
  184. mixins: [Minxin],
  185. // eslint-disable-next-line vue/require-prop-types
  186. props: ['code'],
  187. data() {
  188. return {
  189. keyword: '',
  190. region: '',
  191. baseURL: '',
  192. dcurrentPage: 1,
  193. dpageSize: 10,
  194. dlistTotal: 0,
  195. currentPages: 1, // 当前页码
  196. pageSizes: 10, // 每页数量
  197. input: '',
  198. remark: '',
  199. fileList: [],
  200. listLoading: false,
  201. imageUrl: '',
  202. dataList: [],
  203. examineStatus: 'OK',
  204. options: {},
  205. value: '',
  206. detail: {},
  207. srcList: [],
  208. screenForm: {
  209. code: '',
  210. createBy: '',
  211. endCreateTime: '',
  212. endTime1: '',
  213. endTime2: '',
  214. examineBy: '',
  215. remark: '',
  216. startCreateTime: '',
  217. startTime1: '',
  218. startTime2: '',
  219. status: '',
  220. title: '',
  221. type: ''
  222. },
  223. conditionList: [],
  224. custoList: [],
  225. isEdit: 1,
  226. cid: '',
  227. cpolicyId: '',
  228. dataL: [],
  229. clistTotal: 0,
  230. clistTotals: 0,
  231. type: 1,
  232. importFileList: [],
  233. leftData: [],
  234. rightData: [],
  235. typeOptions: [
  236. {
  237. value: 'PROVISION',
  238. label: '配提'
  239. },
  240. {
  241. value: 'LIMIT',
  242. label: '限量'
  243. }
  244. ],
  245. comCode: ''
  246. }
  247. },
  248. watch: {
  249. 'dataL': (val, oval) => {
  250. console.log(val, oval)
  251. }
  252. },
  253. created() {
  254. this.comCode = this.code
  255. if (this.comCode) {
  256. this.getCond()
  257. }
  258. },
  259. methods: {
  260. getList() {
  261. this.getCrList()
  262. },
  263. getCrList() {
  264. const customerParams = {
  265. pageNum: this.currentPages,
  266. pageSize: this.pageSizes,
  267. keyword: this.keyword,
  268. region: ''
  269. }
  270. // 获取经销商列表
  271. getCrList(customerParams).then((res) => {
  272. for (let j = 0; j < this.custoList.length; j++) {
  273. for (let i = 0; i < res.data.records.length; i++) {
  274. if (res.data.records[i].id === this.custoList[j].customerId) {
  275. res.data.records[i].disabled = true
  276. }
  277. }
  278. }
  279. this.dataL = res.data.records
  280. for (let k = 0; k < this.dataL.length; k++) {
  281. (this.dataL[k].customerId = this.dataL[k].id),
  282. (this.dataL[k].customerName = this.dataL[k].name),
  283. (this.dataL[k].customerNumber = this.dataL[k].number)
  284. }
  285. this.clistTotal = res.data.total
  286. })
  287. },
  288. // 更改每页数量
  289. handleSizeChanges(val) {
  290. this.pageSizes = val
  291. this.currentPages = 1
  292. this.getCrList()
  293. },
  294. // 更改当前页
  295. handleCurrentChanges(val) {
  296. this.currentPages = val
  297. this.getCrList()
  298. },
  299. // 提交筛选表单
  300. submitScreenForm() {
  301. this.currentPages = 1
  302. this.getCrList()
  303. },
  304. // 重置筛选表单
  305. resetScreenForm() {
  306. this.keyword = ''
  307. this.currentPages = 1
  308. this.getCrList()
  309. },
  310. // 去掉相同数据
  311. resArr(arr1, arr2) {
  312. return arr1.filter((v) => arr2.every((val) => val.id !== v.id))
  313. },
  314. // 导入经销商模板
  315. async handleImport(param) {
  316. this.importLoading = true
  317. const file = param.file
  318. const formData = new FormData()
  319. formData.append('file', file)
  320. // formData.append('policyId', this.searchForm.code)
  321. // formData.append("mainId", this.searchForm.mainId);
  322. const result = await handleImport('/policy/importCustomer', formData)
  323. console.log(result)
  324. this.importLoading = false
  325. this.importFileList = []
  326. if (result.code === 200) {
  327. await this.$alert(result.message, '导入成功', {
  328. confirmButtonText: '确定'
  329. })
  330. for (let i = 0; i < result.data.length; i++) {
  331. result.data[i].customerNumber = result.data[i].number
  332. result.data[i].customerName = result.data[i].name
  333. }
  334. if (this.custoList.length) {
  335. this.custoList = [...this.custoList, ...this.resArr(this.custoList, result.data)]
  336. } else {
  337. this.custoList = result.data
  338. }
  339. } else {
  340. await this.$alert(result.message, '导入失败', {
  341. confirmButtonText: '确定'
  342. })
  343. }
  344. },
  345. // 下载经销商模板
  346. hanleDownloadFiles() {
  347. downloadFiles('/policy/downloadCustomer')
  348. },
  349. getCommonApi(row) {
  350. (this.isEdit = 2), (this.cid = row.id), (this.cpolicyId = row.policyId)
  351. console.log(
  352. this.cpolicyId,
  353. this.comCode,
  354. this.cpolicyId === this.comCode
  355. )
  356. },
  357. getCond() {
  358. this.listLoading = true
  359. const custoParams = {
  360. pageNum: 1,
  361. pageSize: -1,
  362. policyId: this.comCode || this.code
  363. }
  364. getCustomerList(custoParams).then((res) => {
  365. this.custoList = res.data.records
  366. console.log(this.custoList, '已选的')
  367. this.clistTotals = res.data.total
  368. this.listLoading = false
  369. // this.getCrList()
  370. })
  371. },
  372. handleCondition(id, index) {
  373. deleteCondition({ id }).then((res) => {
  374. this.getConditionList()
  375. this.$successMsg('删除成功')
  376. })
  377. },
  378. getConditionList() {
  379. const condParams = {
  380. policyId: this.comCode
  381. }
  382. getConditionList(condParams).then((res) => {
  383. this.conditionList = res.data
  384. })
  385. },
  386. // 删除
  387. hanleDelete(id) {
  388. const params = { policyMaterialId: id }
  389. deleteMaterialPolicy(params).then((res) => {
  390. this.$successMsg('删除成功')
  391. })
  392. },
  393. /**
  394. * 根据条件禁用行复选框
  395. * 函数返回值为false则禁用选择(反之亦然)
  396. * @param {Object} row - 行数据
  397. * @param {String} index - 索引值
  398. * @return Boolean
  399. */
  400. selectable: function(row, index) {
  401. // row.disabled == undefined 才能被选中
  402. if (row.disabled === undefined || row.disabled === false) {
  403. return true
  404. } else {
  405. return false
  406. }
  407. // 函数必须有返回值且是布尔值
  408. // 页面刷新后该函数会执行 N 次进行判断(N 为表格行数)
  409. // 如果没有返回值则默认返回false(全部无法选中)
  410. },
  411. handleSelectionAllChange(e) {
  412. this.leftData = e
  413. this.type = 1
  414. },
  415. handleSelectionChange(e) {
  416. this.leftData = e
  417. this.type = 1
  418. },
  419. handleSelectionAllChange2(e) {
  420. this.rightData = e
  421. this.type = 2
  422. },
  423. handleSelectionChange2(e) {
  424. this.rightData = e
  425. this.type = 2
  426. },
  427. handleLeft(e) {
  428. this.type = 1
  429. },
  430. handleRight(e) {
  431. this.type = 2
  432. },
  433. handleAllAdd() {
  434. if (this.type === 1 && this.leftData.length) {
  435. for (let i = 0; i < this.dataL.length; i++) {
  436. for (let j = 0; j < this.leftData.length; j++) {
  437. if (this.dataL[i].id === this.leftData[j].id) {
  438. this.dataL[i].disabled = true
  439. }
  440. }
  441. }
  442. this.custoList = [...this.custoList, ...this.leftData]
  443. this.$refs.multipleTable.clearSelection()
  444. } else {
  445. this.$errorMsg('请选择要添加的经销商')
  446. }
  447. },
  448. handleAllDelete() {
  449. if (this.type === 2 && this.rightData.length) {
  450. for (let i = 0; i < this.dataL.length; i++) {
  451. for (let j = 0; j < this.rightData.length; j++) {
  452. if (this.dataL[i].id === this.rightData[j].customerId) {
  453. this.$set(this.dataL[i], 'disabled', false)
  454. // this.dataL[i].disabled = false
  455. }
  456. }
  457. }
  458. this.custoList = this.resArr(this.custoList, this.rightData)
  459. this.$refs.multipleTable.clearSelection()
  460. } else {
  461. this.$errorMsg('请选择要删除的经销商')
  462. }
  463. },
  464. handleAdd() {
  465. if (this.type === 1 && this.leftData.length) {
  466. for (let i = 0; i < this.dataL.length; i++) {
  467. for (let j = 0; j < this.leftData.length; j++) {
  468. if (this.dataL[i].id === this.leftData[j].id) {
  469. this.dataL[i].disabled = true
  470. }
  471. }
  472. }
  473. this.custoList = [...this.custoList, ...this.leftData]
  474. this.leftData = []
  475. this.$refs.multipleTable.clearSelection()
  476. } else {
  477. this.$errorMsg('请选择要添加的经销商')
  478. }
  479. },
  480. handleDelete() {
  481. if (this.type === 2 && this.rightData.length) {
  482. for (let i = 0; i < this.dataL.length; i++) {
  483. for (let j = 0; j < this.rightData.length; j++) {
  484. if (this.dataL[i].id === this.rightData[j].customerId) {
  485. this.$set(this.dataL[i], 'disabled', false)
  486. // this.dataL[i].disabled = false
  487. }
  488. }
  489. }
  490. this.custoList = this.resArr(this.custoList, this.rightData)
  491. this.$refs.multipleTable.clearSelection()
  492. } else {
  493. this.$errorMsg('请选择要删除的经销商')
  494. }
  495. },
  496. // 提交数据
  497. async handleSave() {
  498. this.$emit('handlEditPolicy', this.custoList)
  499. },
  500. handleReset() {
  501. this.dataR = this.rightData = []
  502. this.keyword = ''
  503. this.$emit('handleReset')
  504. }
  505. }
  506. }
  507. </script>
  508. <style lang="scss" scoped>
  509. .radio{
  510. display: flex;
  511. align-items: center;
  512. margin: 0 0 20px 0;
  513. }
  514. .import-btn{
  515. margin:0 10px;
  516. }
  517. .el-col {
  518. //overflow: hidden;
  519. }
  520. .value{
  521. ::v-deep .el-input__prefix{
  522. display: none;
  523. }
  524. }
  525. .descriptions {
  526. // border: #EBEEF5;
  527. border: 1px solid #ebeef5;
  528. border-bottom: none;
  529. .el-row {
  530. height: 40px;
  531. line-height: 40px;
  532. }
  533. .el-col:nth-child(odd) {
  534. background-color: #ebeef5;
  535. }
  536. .el-col {
  537. padding: 0 15px;
  538. height: 100%;
  539. border-bottom: 1px solid #ebeef5;
  540. }
  541. }
  542. .el-divider--horizontal {
  543. margin: 20px 0;
  544. }
  545. .col {
  546. height: 100px;
  547. }
  548. .import-btn {
  549. margin-right: 10px;
  550. display: inline-block;
  551. }
  552. ::v-deep .el-input__icon .el-icon-time{
  553. display: none;
  554. }
  555. .middle_box {
  556. margin-top: 80px;
  557. text-align: center;
  558. height: 430px;
  559. display: flex;
  560. flex-direction: column;
  561. align-content: center;
  562. justify-content: space-between;
  563. align-items: center;
  564. }
  565. .img-box {
  566. height: 150px;
  567. display: flex;
  568. align-items: center;
  569. }
  570. </style>