Transfer.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 type="primary" size="small">导入经销商</el-button>
  18. </el-upload>
  19. <el-button type="primary" size="small" @click="hanleDownloadFiles">下载模板</el-button>
  20. </el-row>
  21. <el-row type="flex">
  22. <el-col>
  23. <el-input v-model="keyword" placeholder="查找经销商" size="small" />
  24. </el-col>
  25. <el-col style="margin-left: 10px"><el-button size="small" @click="getcList">确定</el-button></el-col>
  26. </el-row>
  27. </slot>
  28. <div>
  29. <el-row type="flex" align="moddle" class="transfer">
  30. <el-col class="left_box" :span="9">
  31. <div>
  32. <h4 class="transfer_title">可选经销商</h4>
  33. <el-checkbox-group v-model="leftData" class="left_box_flex" @change="handleLeft">
  34. <el-checkbox v-for="(item, index) in dataL" :key="index" :label="item.id" :disabled="item.disabled">
  35. {{ item.name }}</el-checkbox
  36. >
  37. </el-checkbox-group>
  38. </div>
  39. <!-- 分页 -->
  40. <div>
  41. <el-pagination
  42. :current-page="currentPage"
  43. :page-sizes="[10, 20, 30, 50]"
  44. :page-size="10"
  45. layout="total, sizes, prev, pager, next, jumper"
  46. :total="listTotal"
  47. @size-change="handleSizeChange"
  48. @current-change="handleCurrentChange"
  49. />
  50. </div>
  51. </el-col>
  52. <el-col class="middle_box" :span="6">
  53. <el-row>
  54. <el-col>
  55. <el-button size="small" :disabled="type === 2 || !dataL.length" @click="handleAllAdd"
  56. >全部添加</el-button
  57. ></el-col
  58. >
  59. <el-col>
  60. <el-button size="small" :disabled="type === 2 || !dataL.length" @click="handleAdd"
  61. >增加</el-button
  62. ></el-col
  63. >
  64. <el-col>
  65. <el-button size="small" :disabled="type === 1 || !dataR.length" @click="handleDelete"
  66. >删除</el-button
  67. ></el-col
  68. >
  69. <el-col>
  70. <el-button size="small" :disabled="type === 1 || !dataR.length" @click="handleAllDelete"
  71. >全部删除</el-button
  72. ></el-col
  73. >
  74. </el-row>
  75. </el-col>
  76. <el-col class="right_box" :span="9" @mouseover="type = 1" @mouseleave="type = 2">
  77. <h4 class="transfer_title">已选经销商</h4>
  78. <el-checkbox-group v-model="rightData" class="right_box_flex" @change="handleRight">
  79. <el-checkbox v-for="(item, index) in dataR" :key="index" :label="item.id"> {{ item.name }}</el-checkbox>
  80. </el-checkbox-group>
  81. </el-col>
  82. </el-row>
  83. </div>
  84. <slot name="footer">
  85. <el-row style="margin: 50px 0 0 0">
  86. <el-button type="primary" size="small" @click="handleSubmit">提交审核</el-button>
  87. <el-button type="primary" size="small" @click="handleReset">重置</el-button>
  88. </el-row>
  89. </slot>
  90. </div>
  91. </template>
  92. <script>
  93. import Minxin from '@/mixin'
  94. import { getCrList } from '@/api/policy_list'
  95. import { downloadFiles, handleImport } from '@/utils/util'
  96. export default {
  97. mixins: [Minxin],
  98. data() {
  99. return {
  100. baseURL: '',
  101. type: '',
  102. radio: '',
  103. leftData: [],
  104. dataL: [],
  105. dataR: [],
  106. rightData: [],
  107. options: [],
  108. value: '',
  109. region: '',
  110. keyword: '',
  111. importFileList: []
  112. }
  113. },
  114. methods: {
  115. // 初始话数据
  116. getList() {
  117. this.getcList()
  118. },
  119. // 获取经销商列表
  120. getcList: function () {
  121. const customerParams = {
  122. pageNum: this.currentPage,
  123. pageSize: this.pageSize,
  124. keyword: this.keyword,
  125. region: ''
  126. }
  127. // 获取经销商列表
  128. getCrList(customerParams).then(res => {
  129. for (let i = 0; i < res.data.records.length; i++) {
  130. res.data.records[i].disabled = false
  131. }
  132. this.dataL = res.data.records
  133. console.log(res, '获取经销商列表')
  134. this.listTotal = res.data.total
  135. })
  136. },
  137. // 左边框
  138. handleLeft(e) {
  139. console.log(e)
  140. this.type = 1
  141. },
  142. // 右边框
  143. handleRight(e) {
  144. this.type = 2
  145. },
  146. // 全部添加
  147. handleAllAdd() {
  148. this.dataR = [...new Set([...this.dataR, ...this.dataL])]
  149. },
  150. // 全部删除
  151. handleAllDelete() {
  152. this.dataR = []
  153. this.rightData = []
  154. },
  155. // 单个删除或者多个删除
  156. handleAdd() {
  157. if (this.type == 1) {
  158. // console.log(this.leftData,44545);
  159. for (let i = 0; i < this.dataL.length; i++) {
  160. for (let k = 0; k < this.leftData.length; k++) {
  161. if (this.dataL[i].id == this.leftData[k]) {
  162. this.dataR = [...new Set([...this.dataR, this.dataL[i]])]
  163. // this.rightData =[...this.rightData,this.leftData[k]]
  164. // this.dataL[i].disabled = true
  165. }
  166. }
  167. }
  168. this.leftData = []
  169. }
  170. },
  171. // 单个删除或者多个删除
  172. handleDelete() {
  173. if (this.type === 2) {
  174. const dataArr = JSON.parse(JSON.stringify(this.dataR))
  175. for (let k = dataArr.length - 1; k >= 0; k--) {
  176. for (let i = 0; i < this.rightData.length; i++) {
  177. if (this.rightData[i] === this.dataR[k].id) {
  178. dataArr.splice(k, 1)
  179. }
  180. }
  181. }
  182. this.dataR = dataArr
  183. this.rightData = []
  184. }
  185. },
  186. // 提交数据
  187. handleSubmit() {
  188. this.$emit('handleAddPolicy', this.dataR)
  189. },
  190. // 去掉相同数据
  191. resArr(arr1, arr2) {
  192. return arr1.filter(v => arr2.every(val => val.id !== v.id))
  193. },
  194. // 导入经销商模板
  195. async handleImport(param) {
  196. this.importLoading = true
  197. const file = param.file
  198. const formData = new FormData()
  199. formData.append('file', file)
  200. // formData.append('policyId', this.searchForm.code)
  201. // formData.append("mainId", this.searchForm.mainId);
  202. const result = await handleImport('/policy/importCustomer', formData)
  203. console.log(result)
  204. this.importLoading = false
  205. this.importFileList = []
  206. if (result.code === 200) {
  207. await this.$alert(result.message, '导入成功', {
  208. confirmButtonText: '确定'
  209. })
  210. if (this.dataR.length) {
  211. this.dataR = [...this.dataR, ...this.resArr(this.dataR, result.data)]
  212. console.log(this.dataR)
  213. } else {
  214. this.dataR = result.data
  215. }
  216. } else {
  217. await this.$alert(result.message, '导入失败', {
  218. confirmButtonText: '确定'
  219. })
  220. }
  221. },
  222. // 下载经销商模板
  223. hanleDownloadFiles() {
  224. downloadFiles('policy/downloadCustomer')
  225. },
  226. handleReset() {
  227. this.dataR = this.rightData = []
  228. this.keyword = ''
  229. this.$emit('handleReset')
  230. }
  231. }
  232. }
  233. </script>
  234. <style lang="scss" scoped>
  235. // 穿梭框
  236. .radio {
  237. display: flex;
  238. align-items: center;
  239. }
  240. .import-btn {
  241. margin: 0 10px;
  242. }
  243. .transfer {
  244. margin: 20px 0;
  245. &_title {
  246. margin: 20px 20px 0 20px;
  247. }
  248. .left_box {
  249. display: flex;
  250. flex-direction: column;
  251. justify-content: space-between;
  252. width: 440px;
  253. height: 450px;
  254. border: 1px solid #eee;
  255. &_flex {
  256. display: flex;
  257. flex-direction: column;
  258. margin: 20px;
  259. .el-checkbox {
  260. padding: 10px 0;
  261. }
  262. }
  263. }
  264. .right_box {
  265. width: 440px;
  266. height: 450px;
  267. border: 1px solid #eee;
  268. overflow-y: auto;
  269. &_flex {
  270. display: flex;
  271. flex-direction: column;
  272. margin: 20px;
  273. .el-checkbox {
  274. padding: 10px 0;
  275. }
  276. }
  277. }
  278. }
  279. .middle_box {
  280. text-align: center;
  281. height: 430px;
  282. display: flex;
  283. align-content: center;
  284. justify-content: center;
  285. align-items: center;
  286. }
  287. .el-row .el-col {
  288. margin: 20px 0;
  289. }
  290. .select_height {
  291. width: 100%;
  292. }
  293. </style>