Transfer.vue 8.9 KB

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