openSea.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. <!--
  2. * @Author: wanglj 471442253@qq.com
  3. * @Date: 2022-12-15 15:38:21
  4. * @LastEditors: niezch@dashoo.cn
  5. * @La
  6. * @Description: file content
  7. * @FilePath: \opms_frontend\src\views\customer\openSea.vue
  8. -->
  9. <template>
  10. <div class="open-sea-container">
  11. <vab-query-form>
  12. <vab-query-form-top-panel>
  13. <el-form :inline="true" :model="queryForm" @submit.native.prevent>
  14. <!-- <el-form-item>
  15. <el-input v-model="queryForm.custCode" placeholder="客户编码" />
  16. </el-form-item> -->
  17. <el-form-item>
  18. <el-input
  19. v-model="queryForm.custName"
  20. clearable
  21. placeholder="客户名称"
  22. @keyup.enter.native="handleSearch" />
  23. </el-form-item>
  24. <!-- <el-form-item>
  25. <el-input
  26. v-model="queryForm.custProvince"
  27. clearable
  28. placeholder="所在省"
  29. @keyup.enter.native="handleSearch" />
  30. </el-form-item> -->
  31. <el-form-item>
  32. <el-select v-model="queryForm.province" clearable placeholder="所在省" value-key="id">
  33. <el-option v-for="item in provinceOptions" :key="item.id" :label="item.distName" :value="item" />
  34. </el-select>
  35. </el-form-item>
  36. <el-form-item>
  37. <!-- <el-input v-model="queryForm.custCity" clearable placeholder="所在市" @keyup.enter.native="handleSearch" /> -->
  38. <el-select v-model="queryForm.custCity" clearable placeholder="所在市" value-key="id">
  39. <el-option
  40. v-for="item in queryForm.province ? queryForm.province.children : []"
  41. :key="item.id"
  42. clearable
  43. :label="item.distName"
  44. :value="item.distName" />
  45. </el-select>
  46. </el-form-item>
  47. <el-form-item>
  48. <el-select
  49. v-model="queryForm.custIndustry"
  50. clearable
  51. placeholder="客户类型"
  52. style="width: 100%"
  53. @keyup.enter.native="handleSearch">
  54. <el-option v-for="item in industryOptions" :key="item.key" :label="item.value" :value="item.key" />
  55. </el-select>
  56. </el-form-item>
  57. <!-- <el-form-item>
  58. <el-select v-model="queryForm.custLevel" placeholder="客户级别" style="width: 100%">
  59. <el-option v-for="item in levelOptions" :key="item.value" :label="item.value" :value="item.value" />
  60. </el-select>
  61. </el-form-item> -->
  62. <el-form-item>
  63. <!-- <el-date-picker
  64. v-model="queryForm.followUpDate"
  65. end-placeholder="跟进结束时间"
  66. placeholder="时间范围"
  67. start-placeholder="跟进开始时间"
  68. style="width: 100%"
  69. type="daterange"
  70. value-format="yyyy-MM-dd"
  71. @keyup.enter.native="fetchData" /> -->
  72. <el-date-picker
  73. v-model="queryForm.followUpDate"
  74. end-placeholder="跟进结束时间"
  75. range-separator="至"
  76. start-placeholder="跟进开始时间"
  77. style="width: 100%"
  78. type="daterange"
  79. value-format="yyyy-MM-dd" />
  80. </el-form-item>
  81. <el-form-item>
  82. <el-button icon="el-icon-plus" type="primary" @click="handleSearch">查询</el-button>
  83. <el-button icon="el-icon-refresh-right" @click="reset">重置</el-button>
  84. </el-form-item>
  85. </el-form>
  86. </vab-query-form-top-panel>
  87. <vab-query-form-left-panel :span="12">
  88. <el-button v-permissions="['cust:open:add']" icon="el-icon-plus" type="primary" @click="$refs.edit.init()">
  89. 新建
  90. </el-button>
  91. <el-button v-permissions="['cust:open:allocate']" icon="el-icon-plus" type="primary" @click="handleAllocate">
  92. 分配
  93. </el-button>
  94. <el-button v-permissions="['cust:open:receive']" icon="el-icon-plus" type="primary" @click="handleReceive">
  95. 领取
  96. </el-button>
  97. <el-button
  98. v-permissions="['cust:open:import']"
  99. icon="el-icon-download"
  100. type="primary"
  101. @click="downloadTemplate">
  102. 下载模板
  103. </el-button>
  104. <el-upload
  105. ref="uploadRef"
  106. v-permissions="['cust:open:import']"
  107. :accept="fileSettings.types"
  108. action="#"
  109. :before-upload="
  110. (file) => {
  111. return beforeUpload(file)
  112. }
  113. "
  114. :file-list="fileList"
  115. :http-request="uploadRequest"
  116. :show-file-list="false"
  117. style="margin: 0 10px 10px 0 !important">
  118. <el-button icon="el-icon-upload2" :loading="importLoading" type="primary">导入</el-button>
  119. </el-upload>
  120. </vab-query-form-left-panel>
  121. <vab-query-form-right-panel :span="12">
  122. <!-- <el-button icon="el-icon-download" @click="exportData" />-->
  123. <table-tool :columns="columns" :show-columns.sync="showColumns" table-type="openSeaCustomerTable" />
  124. </vab-query-form-right-panel>
  125. </vab-query-form>
  126. <el-table
  127. ref="table"
  128. v-loading="listLoading"
  129. border
  130. :data="list"
  131. :height="$baseTableHeight(2)"
  132. @selection-change="setSelectRows">
  133. <el-table-column align="center" show-overflow-tooltip type="selection" />
  134. <el-table-column
  135. v-for="(item, index) in showColumns"
  136. :key="index"
  137. align="center"
  138. :label="item.label"
  139. :min-width="item.width"
  140. :prop="item.prop"
  141. show-overflow-tooltip
  142. :sortable="item.sortable">
  143. <template #default="{ row }">
  144. <el-button v-if="item.prop === 'custName'" class="link-button" type="text" @click="handleDetail(row)">
  145. {{ row.custName }}
  146. </el-button>
  147. <span v-else-if="item.prop === 'custStatus'">
  148. {{ row.custStatus == 10 ? '正常' : '异常' }}
  149. </span>
  150. <span v-else-if="item.prop === 'custIndustry'">
  151. {{ selectDictLabel(industryOptions, row.custIndustry) }}
  152. </span>
  153. <span v-else-if="item.prop === 'followUpDate'">
  154. {{ parseTime(row.followUpDate, '{y}-{m}-{d}') }}
  155. </span>
  156. <span v-else-if="item.prop === 'createdTime'">
  157. {{ parseTime(row.createdTime, '{y}-{m}-{d}') }}
  158. </span>
  159. <span v-else>{{ row[item.prop] }}</span>
  160. </template>
  161. </el-table-column>
  162. <!-- <el-table-column
  163. align="center"
  164. label="客户编码"
  165. min-width="120px"
  166. prop="custCode" />
  167. <el-table-column
  168. align="center"
  169. label="客户名称"
  170. min-width="120px"
  171. prop="custName">
  172. <template slot-scope="scope">
  173. <el-button
  174. style="font-size: 14px"
  175. type="text"
  176. @click="handleDetail(scope.row)">
  177. {{ scope.row.custName }}
  178. </el-button>
  179. </template>
  180. </el-table-column>
  181. <el-table-column align="center" label="助记名" prop="abbrName" />
  182. <el-table-column align="center" label="所在地区" prop="custLocation" />
  183. <el-table-column align="center" label="客户类型" prop="custIndustry" />
  184. <el-table-column align="center" label="客户级别" prop="custLevel" />
  185. <el-table-column align="center" label="客户状态" prop="custStatus">
  186. <template slot-scope="scope">
  187. {{ scope.row.custStatus == 10 ? '正常' : '异常' }}
  188. </template>
  189. </el-table-column>
  190. <el-table-column
  191. align="center"
  192. label="最后跟进时间"
  193. min-width="140px"
  194. prop="followUpDate" />
  195. <el-table-column align="center" label="创建人" prop="createdName" />
  196. <el-table-column
  197. align="center"
  198. label="创建时间"
  199. min-width="140px"
  200. prop="createdTime" /> -->
  201. <el-table-column align="center" fixed="right" label="操作" width="90px">
  202. <template slot-scope="scope">
  203. <el-button v-permissions="['cust:open:edit']" type="text" @click="handleEdit(scope.row)">编辑</el-button>
  204. <el-button v-permissions="['cust:open:delete']" type="text" @click="handleDelete(scope.row)">删除</el-button>
  205. </template>
  206. </el-table-column>
  207. </el-table>
  208. <el-pagination
  209. background
  210. :current-page="queryForm.pageNum"
  211. :layout="layout"
  212. :page-size="queryForm.pageSize"
  213. :total="total"
  214. @current-change="handleCurrentChange"
  215. @size-change="handleSizeChange" />
  216. <!-- 新增编辑客户弹窗 -->
  217. <Edit ref="edit" @createContact="createContact" @customerSave="customerSave" />
  218. <!-- 新建联系人弹窗 -->
  219. <Contact ref="contact" />
  220. <!-- 分配客户 -->
  221. <Allocate ref="allocate" @refresh="fetchData" />
  222. <!-- 领取客户 -->
  223. <Pick ref="pick" @refresh="fetchData" />
  224. </div>
  225. </template>
  226. <script>
  227. import to from 'await-to-js'
  228. import api from '@/api/customer'
  229. import Contact from './components/Contact'
  230. import Edit from './components/Edit'
  231. import Allocate from './components/Allocate'
  232. import Pick from './components/Pick'
  233. import TableTool from '@/components/table/TableTool'
  234. import downloadFileByByte from '@/utils/base64ToFile'
  235. import axios from 'axios'
  236. import asyncUploadFile from '@/utils/uploadajax'
  237. export default {
  238. name: 'OpenSeaCustomer',
  239. components: {
  240. Contact,
  241. Edit,
  242. Allocate,
  243. Pick,
  244. TableTool,
  245. },
  246. data() {
  247. return {
  248. listLoading: false,
  249. layout: 'total, sizes, prev, pager, next, jumper',
  250. list: [],
  251. total: 0,
  252. queryForm: {
  253. pageNum: 1,
  254. pageSize: 10,
  255. custCode: '', // 客户编码
  256. custName: '', //客户名称
  257. custIndustry: '', // 客户类型 ()
  258. custLevel: '', //客户级别
  259. followUpDate: [], //最后跟进时间
  260. isPublic: true,
  261. custProvince: '',
  262. province: {},
  263. custCity: '',
  264. },
  265. selectRows: [],
  266. industryOptions: [], //客户类型
  267. levelOptions: [], //客户级别
  268. provinceOptions: [],
  269. provinceDetail: [],
  270. sellOptions: [],
  271. // 自定义列表
  272. showColumns: [],
  273. columns: [
  274. {
  275. label: '客户编码',
  276. width: '120px',
  277. prop: 'custCode',
  278. sortable: false,
  279. disableCheck: false,
  280. },
  281. {
  282. label: '客户名称',
  283. width: '200px',
  284. prop: 'custName',
  285. sortable: false,
  286. disableCheck: true,
  287. },
  288. {
  289. label: '助记名',
  290. width: '120px',
  291. prop: 'abbrName',
  292. sortable: false,
  293. disableCheck: false,
  294. },
  295. {
  296. label: '所在省',
  297. width: '120px',
  298. prop: 'custProvince',
  299. sortable: false,
  300. disableCheck: false,
  301. },
  302. {
  303. label: '所在市',
  304. width: '100px',
  305. prop: 'custCity',
  306. sortable: false,
  307. disableCheck: false,
  308. },
  309. {
  310. label: '客户类型',
  311. width: '100px',
  312. prop: 'custIndustry',
  313. sortable: false,
  314. disableCheck: false,
  315. },
  316. // {
  317. // label: '客户级别',
  318. // width: 'auto',
  319. // prop: 'custLevel',
  320. // sortable: false,
  321. // disableCheck: false,
  322. // },
  323. // {
  324. // label: '客户状态',
  325. // width: '100px',
  326. // prop: 'custStatus',
  327. // sortable: false,
  328. // disableCheck: false,
  329. // },
  330. {
  331. label: '最后跟进时间',
  332. width: '100px',
  333. prop: 'followUpDate',
  334. sortable: false,
  335. disableCheck: false,
  336. },
  337. {
  338. label: '最后跟进人',
  339. width: '100px',
  340. prop: 'followUpMan',
  341. sortable: false,
  342. disableCheck: false,
  343. },
  344. {
  345. label: '创建人',
  346. width: '100px',
  347. prop: 'createdName',
  348. sortable: false,
  349. disableCheck: false,
  350. },
  351. {
  352. label: '创建时间',
  353. width: '100px',
  354. prop: 'createdTime',
  355. sortable: false,
  356. disableCheck: false,
  357. },
  358. ],
  359. fileList: [],
  360. fileSettings: {
  361. // 文件配置信息
  362. fileSize: 52428800,
  363. fileTypes: '.xlsx',
  364. pictureSize: 52428800,
  365. types: '.xlsx',
  366. },
  367. importLoading: false,
  368. }
  369. },
  370. watch: {
  371. showColumns: function () {
  372. this.$nextTick(() => this.$refs.table.doLayout())
  373. },
  374. },
  375. activated() {
  376. this.fetchData()
  377. },
  378. mounted() {
  379. this.fetchData()
  380. this.getOptions()
  381. },
  382. methods: {
  383. getOptions() {
  384. Promise.all([api.getProvinceDetail(), this.getDicts('cust_level'), this.getDicts('cust_idy')])
  385. .then(([province, level, industry, sell]) => {
  386. this.provinceOptions = province.data.list || []
  387. this.levelOptions = level.data.values || []
  388. this.industryOptions = industry.data.values || []
  389. this.sellOptions = sell.data.list || []
  390. })
  391. .catch((err) => console.log(err))
  392. },
  393. async fetchData() {
  394. this.listLoading = true
  395. const params = { ...this.queryForm }
  396. if (!params.followUpDate) params.followUpDate = null
  397. if (this.queryForm.followUpDate && this.queryForm.followUpDate.length === 2) {
  398. params.beginTime = this.queryForm.followUpDate[0]
  399. params.endTime = this.queryForm.followUpDate[1]
  400. }
  401. params.custProvince = params.province.distName ? params.province.distName : ''
  402. const [err, res] = await to(api.getPublicList(params))
  403. if (err) return (this.listLoading = false)
  404. this.list = res.data.list || []
  405. this.total = res.data.total
  406. this.listLoading = false
  407. this.$nextTick(() => this.$refs.table.doLayout())
  408. },
  409. handleSearch() {
  410. this.queryForm.pageNum = 1
  411. this.fetchData()
  412. },
  413. exportData() {
  414. this.queryForm.isPublic = true
  415. let exportFrom = JSON.parse(JSON.stringify(this.queryForm))
  416. exportFrom.columns = this.showColumns.map((item) => item.label)
  417. api
  418. .deriveList(exportFrom)
  419. .then((res) => {
  420. if (res.data.list.content) {
  421. downloadFileByByte(res.data.list.content, '公海客户数据.xlsx')
  422. }
  423. })
  424. .catch((err) => {
  425. console.error(err)
  426. })
  427. },
  428. reset() {
  429. this.queryForm = {
  430. pageNum: 1,
  431. pageSize: 10,
  432. custCode: '', // 客户编码
  433. custName: '', //客户名称
  434. custIndustry: '', // 客户类型 ()
  435. custLevel: '', //客户级别
  436. followUpDate: [], //最后跟进时间
  437. isPublic: true,
  438. custProvince: '',
  439. custCity: '',
  440. province: {},
  441. }
  442. this.fetchData()
  443. },
  444. handleSizeChange(val) {
  445. this.queryForm.pageSize = val
  446. this.fetchData()
  447. },
  448. handleCurrentChange(val) {
  449. this.queryForm.pageNum = val
  450. this.fetchData()
  451. },
  452. setSelectRows(val) {
  453. this.selectRows = val
  454. },
  455. // 客户编辑
  456. async handleEdit(row) {
  457. this.$refs.edit.init([row.id])
  458. },
  459. // 客户详情
  460. handleDetail(row) {
  461. this.$router.push({
  462. path: '/customer/detail',
  463. query: {
  464. id: row.id,
  465. },
  466. })
  467. },
  468. // 客户删除
  469. handleDelete(row) {
  470. this.$confirm('确认删除?', '提示', {
  471. confirmButtonText: '确定',
  472. cancelButtonText: '取消',
  473. type: 'warning',
  474. })
  475. .then(async () => {
  476. const [err, res] = await to(api.deleteCustomer({ Ids: [row.id] }))
  477. if (err) return
  478. if (res.code == 200) {
  479. this.$message({
  480. type: 'success',
  481. message: '删除成功!',
  482. })
  483. this.fetchData()
  484. }
  485. })
  486. .catch(() => {})
  487. },
  488. // 联系人弹窗
  489. createContact(res) {
  490. this.$refs.contact.contactForm.custId = res.id
  491. this.$refs.contact.contactForm.custName = res.name
  492. this.$refs.contact.contactVisible = true
  493. },
  494. customerSave() {
  495. this.fetchData()
  496. },
  497. handleClose(form) {
  498. this.$refs[form].resetFields()
  499. },
  500. // 分配
  501. handleAllocate() {
  502. if (!this.selectRows.length) return this.$message.warning('请选择客户')
  503. const arr = this.selectRows.map((item) => item.id)
  504. this.$refs.allocate.ids = arr
  505. this.$refs.allocate.visible = true
  506. },
  507. // 领取
  508. handleReceive() {
  509. if (!this.selectRows.length) return this.$message.warning('请选择客户')
  510. const arr = this.selectRows.map((item) => item.id)
  511. this.$refs.pick.ids = arr
  512. this.$refs.pick.visible = true
  513. // this.$confirm('确认领取客户?', '提示', {
  514. // confirmButtonText: '确定',
  515. // cancelButtonText: '取消',
  516. // type: 'warning',
  517. // })
  518. // .then(async () => {
  519. // const [err, res] = await to(
  520. // api.receiveCustomer({
  521. // ids: arr,
  522. // salesId: this.$store.state.user.id,
  523. // salesName: this.$store.state.user.nickName,
  524. // receive: '1',
  525. // })
  526. // )
  527. // if (err) return
  528. // if (res.code == 200) {
  529. // this.$message({
  530. // type: 'success',
  531. // message: '领取成功!',
  532. // })
  533. // this.fetchData()
  534. // }
  535. // })
  536. // .catch((err) => console.log(err))
  537. },
  538. beforeUpload(file) {
  539. let flag1 = file.size < this.fileSettings.fileSize
  540. if (!flag1) {
  541. this.$message.warning('文件过大,请重新选择!')
  542. return false
  543. }
  544. let flag2 = this.fileSettings.fileTypes.split(',').includes('.' + file.name.split('.').pop())
  545. if (!flag2) {
  546. this.$message.warning('文件类型不符合,请重新选择!')
  547. return false
  548. }
  549. return true
  550. },
  551. uploadRequest(option) {
  552. this.importLoading = true
  553. let _this = this
  554. let url = process.env.VUE_APP_UPLOAD_WEED
  555. axios
  556. .post(url)
  557. .then((res) => {
  558. if (res.data && res.data.fid && res.data.fid !== '') {
  559. option.action = `${process.env.VUE_APP_PROTOCOL}${res.data.publicUrl}/${res.data.fid}`
  560. let fileUrl = `${process.env.VUE_APP_PROTOCOL}${res.data.publicUrl}/${res.data.fid}` // 资料存储url
  561. asyncUploadFile(option).then(async () => {
  562. console.log('fileUrl', fileUrl)
  563. const params = {
  564. excelUrl: fileUrl,
  565. }
  566. const [err, res] = await to(api.import(params))
  567. if (err) {
  568. this.importLoading = false
  569. return
  570. }
  571. if (res.code == 200) {
  572. this.importLoading = false
  573. _this.fetchData()
  574. _this.$message({
  575. type: 'success',
  576. message: '操作成功',
  577. })
  578. }
  579. })
  580. } else {
  581. this.importLoading = false
  582. _this.$message({
  583. type: 'warning',
  584. message: '未上传成功!请刷新界面重新上传!',
  585. })
  586. }
  587. })
  588. .catch(function () {
  589. this.importLoading = false
  590. _this.$message({
  591. type: 'warning',
  592. message: '未上传成功!请重新上传!',
  593. })
  594. })
  595. },
  596. downloadTemplate() {
  597. api
  598. .excelTemplate({})
  599. .then((res) => {
  600. if (res.code == 200) {
  601. downloadFileByByte(res.data, '客户导入模板.xlsx')
  602. }
  603. })
  604. .catch((err) => {
  605. console.error(err)
  606. })
  607. },
  608. },
  609. }
  610. </script>
  611. <style lang="scss" scoped>
  612. $base: '.open-sea';
  613. .link-button {
  614. font-size: 14px;
  615. width: 100%;
  616. overflow: hidden;
  617. text-overflow: ellipsis;
  618. white-space: nowrap;
  619. }
  620. </style>