TabelTransfer.vue 15 KB

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