list.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <template>
  2. <div class="SippliersList">
  3. <Toptitle title="客户列表">
  4. <slot name="titleButton">
  5. <!-- <Button @click="handleSet()"
  6. type="primary"
  7. style="margin-right:10px;">新增分类</Button> -->
  8. <Upload
  9. style="display:inline"
  10. name="your_file"
  11. :show-upload-list="false"
  12. :headers="headers"
  13. :on-error="uploadError"
  14. :on-success="uploadSuccess"
  15. :action="$store.state.ip + '/api/custom_import'"
  16. >
  17. <Button type="success" ghost icon="md-exit" style="margin-right:10px;"
  18. >导入</Button
  19. >
  20. </Upload>
  21. <Button type="success" ghost icon='ios-download-outline' style="margin-right:10px;" @click='exportData()'
  22. >导出</Button
  23. >
  24. <Button
  25. type="primary"
  26. @click="handleGoPage(1, '')"
  27. style="margin-right:10px;"
  28. >新增</Button
  29. >
  30. </slot>
  31. </Toptitle>
  32. <div class="content">
  33. <div class="content_left">
  34. <Tree
  35. :data="treeData"
  36. select-node
  37. children-key="sub"
  38. style="width:100%;"
  39. @on-select-change="handleTreeSelect"
  40. class="demo-tree-render"
  41. ></Tree>
  42. </div>
  43. <div class="content_right">
  44. <div class="content_right_topform">
  45. <Form :label-width="90" :model="searchData">
  46. <FormItem label="客户编码:">
  47. <Input
  48. type="text"
  49. size="small"
  50. clearable
  51. v-model="searchData.code"
  52. style="width: 150px"
  53. placeholder="客户编码"
  54. />
  55. </FormItem>
  56. <FormItem label="客户名称:">
  57. <Input
  58. type="text"
  59. size="small"
  60. clearable
  61. v-model="searchData.title"
  62. style="width: 150px"
  63. placeholder="客户名称"
  64. />
  65. </FormItem>
  66. <FormItem label="专营业务员:">
  67. <Select
  68. v-model="searchData.service_id"
  69. size="small"
  70. clearable
  71. filterable
  72. label-in-value
  73. style="width: 150px"
  74. >
  75. <Option
  76. v-for="sitem in userList"
  77. :key="sitem.id"
  78. :label="sitem.nickname"
  79. :value="sitem.id"
  80. >
  81. </Option>
  82. </Select>
  83. </FormItem>
  84. <FormItem label="超标方案:">
  85. <Select
  86. v-model="searchData.plan_id"
  87. size="small"
  88. clearable
  89. filterable
  90. label-in-value
  91. style="width: 150px"
  92. >
  93. <Option
  94. v-for="sitem in overStandardList"
  95. :key="sitem.id"
  96. :label="sitem.title"
  97. :value="sitem.id"
  98. >
  99. </Option>
  100. </Select>
  101. </FormItem>
  102. <!-- <FormItem label="是否启用:">
  103. <Select v-model="searchData.lock"
  104. size="small"
  105. clearable
  106. style="width: 150px">
  107. <Option label='是'
  108. value="1" />
  109. <Option label='否'
  110. value="2" />
  111. </Select>
  112. </FormItem> -->
  113. <FormItem label="创建时间:">
  114. <DatePicker
  115. type="date"
  116. clearable
  117. size="small"
  118. style="width: 150px"
  119. placeholder="年/月/日"
  120. v-model="searchData.date[0]"
  121. ></DatePicker>
  122. </FormItem>
  123. <FormItem label="~">
  124. <DatePicker
  125. type="date"
  126. size="small"
  127. clearable
  128. style="width: 150px"
  129. placeholder="年/月/日"
  130. v-model="searchData.date[1]"
  131. ></DatePicker>
  132. </FormItem>
  133. <FormItem>
  134. <Button
  135. type="primary"
  136. size="small"
  137. @click="initData(searchData)"
  138. style="margin-right:10px;"
  139. >搜索</Button
  140. >
  141. </FormItem>
  142. </Form>
  143. <div class="content_right_topfrom_btn"></div>
  144. </div>
  145. <div class="content_right_content">
  146. <div class="content_right_content_table">
  147. <Table
  148. :columns="tableColumns"
  149. border
  150. :max-height="400"
  151. :loading="tableLoading"
  152. :data="tableData"
  153. >
  154. <template slot="setSlot" slot-scope="{ row, index }">
  155. <a style="margin:0 5px" @click="handleSet(2, row, index)"
  156. >编辑</a
  157. >
  158. <a style="margin:0 5px" @click="handleSet(3, row, index)"
  159. >查看</a
  160. >
  161. <a style="margin:0 5px" @click="handleSet(4, row, index)"
  162. >删除</a
  163. >
  164. </template>
  165. </Table>
  166. <div class="content_right_content_page">
  167. <Page
  168. :page-size-opts="[10, 20, 30, 40, 100]"
  169. @on-page-size-change="changeSize"
  170. @on-change="changePage"
  171. :current="pageIndex"
  172. show-total
  173. show-elevator
  174. :total="total"
  175. show-sizer
  176. :page-size="pageSize"
  177. />
  178. </div>
  179. </div>
  180. </div>
  181. </div>
  182. </div>
  183. </div>
  184. </template>
  185. <script>
  186. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  187. // 例如:import 《组件名称》 from '《组件路径》';
  188. export default {
  189. name: "SippliersList",
  190. components: {},
  191. props: {},
  192. // import引入的组件需要注入到对象中才能使用
  193. data() {
  194. // 这里存放数据
  195. return {
  196. type: "",
  197. treeData: [
  198. {
  199. title: "客户分类",
  200. expand: true,
  201. sub: [],
  202. render: (h, { root, node, data }) => {
  203. return h(
  204. "span",
  205. {
  206. style: {
  207. display: "inline-block",
  208. width: "100%",
  209. },
  210. },
  211. [
  212. h("span", [
  213. h("Icon", {
  214. props: {
  215. type: "ios-folder-outline",
  216. },
  217. style: {
  218. marginRight: "8px",
  219. },
  220. }),
  221. h("span", data.title),
  222. ]),
  223. ]
  224. );
  225. },
  226. },
  227. ],
  228. buttonProps: {
  229. type: "default",
  230. size: "small",
  231. },
  232. headers: { Authorization: localStorage.getItem("token") },
  233. overStandardList: [],
  234. tableColumns: [
  235. {
  236. title: "客户编码",
  237. key: "code",
  238. align: "center",
  239. tooltip: true,
  240. minWidth: 140,
  241. },
  242. {
  243. title: "客户名称",
  244. key: "title",
  245. align: "center",
  246. tooltip: true,
  247. minWidth: 140,
  248. },
  249. {
  250. title: "折扣率(%)",
  251. key: "fax",
  252. align: "center",
  253. tooltip: true,
  254. minWidth: 140,
  255. },
  256. {
  257. title: "专营业务员",
  258. key: "nickname",
  259. align: "center",
  260. tooltip: true,
  261. minWidth: 140,
  262. },
  263. // {
  264. // title: '专营业务员', key: 'service_id', align: 'center', tooltip: true, minWidth: 140,
  265. // render: (h, params) => {
  266. // const { row } = params
  267. // let text
  268. // this.userList.forEach(element => {
  269. // (element.id == row.service_id) && (text = element.nickname)
  270. // });
  271. // return h('span', {}, text)
  272. // }
  273. // },
  274. {
  275. title: "超标方案",
  276. key: "plan_title",
  277. align: "center",
  278. tooltip: true,
  279. minWidth: 140,
  280. // render: (h, params) => {
  281. // const { row } = params
  282. // let text
  283. // this.overStandardList.forEach(element => {
  284. // (element.id == row.overdraft_plan_id) && (text = element.title)
  285. // });
  286. // return h('span', {}, text)
  287. // }
  288. },
  289. {
  290. title: "是否启用",
  291. key: "lock",
  292. align: "center",
  293. minWidth: 100,
  294. render: (h, params) => {
  295. const { row } = params;
  296. return h("span", {}, row.lock == 1 ? "是" : "否");
  297. },
  298. },
  299. {
  300. title: "创建时间",
  301. key: "crt_time",
  302. align: "center",
  303. tooltip: true,
  304. minWidth: 140,
  305. render: (h, params) => {
  306. return h("span", {}, this.func.replaceDate(params.row.crt_time));
  307. },
  308. },
  309. // {
  310. // title: '添加时间', key: 'crt_time', align: 'center', minWidth: 120,
  311. // render: (h, params) => {
  312. // const { row } = params
  313. // return h('span', {}, this.func.replaceDate(row.crt_time))
  314. // }
  315. // },
  316. {
  317. title: "操作",
  318. key: "code",
  319. align: "center",
  320. minWidth: 170,
  321. slot: "setSlot",
  322. },
  323. ],
  324. tableData: [],
  325. tableLoading: false,
  326. pageIndex: 1,
  327. pageSize: 10,
  328. total: 0,
  329. searchData: {
  330. title: "",
  331. code: "",
  332. service_id: "",
  333. lock: "",
  334. date: [],
  335. // start_time: '',
  336. // end_time: '',
  337. },
  338. suppliersTypeTitle: "",
  339. suppliersTypeId: "",
  340. userList: [],
  341. };
  342. },
  343. // 生命周期 - 创建完成(可以访问当前this实例)
  344. created() {
  345. // 获取超标方案
  346. this.axios({ method: "get", url: "/api/overdraft_list" }).then((res) => {
  347. this.overStandardList = res.data.data;
  348. });
  349. // 获取用户列表
  350. this.axios({ method: "get", url: "/api/employee_list" }).then((res) => {
  351. this.userList = res.data.data;
  352. });
  353. // 获取客户分类列表
  354. this.axios({
  355. method: "post",
  356. url: "/api/basic_custom_list",
  357. }).then((res) => {
  358. this.treeData[0].sub = res.data;
  359. });
  360. },
  361. // 生命周期 - 挂载完成(可以访问DOM元素)
  362. mounted() {
  363. this.initData(this.searchData);
  364. },
  365. methods: {
  366. initData(row) {
  367. this.searchData.date[0]
  368. ? (this.searchData.start_time = this.func.replaceDateNoHMS(
  369. this.searchData.date[0]
  370. ))
  371. : "";
  372. this.searchData.date[1]
  373. ? (this.searchData.end_time = this.func.replaceDateNoHMS(
  374. this.searchData.date[1]
  375. ))
  376. : "";
  377. const subForm = {
  378. start_time: this.func.replaceDateNoHMS(this.searchData.date[0]) || "",
  379. end_time: this.func.replaceDateNoHMS(this.searchData.date[1]) || "",
  380. title: row.title,
  381. code: row.code,
  382. service_id: row.service_id,
  383. };
  384. this.tableLoading = true;
  385. this.axios({
  386. method: "get",
  387. url: "/api/custom_list",
  388. params: {
  389. ...subForm,
  390. page_index: this.pageIndex,
  391. page_size: this.pageSize,
  392. },
  393. })
  394. .then((res) => {
  395. this.tableLoading = false;
  396. this.total = res.data.total;
  397. this.tableData = res.data.data;
  398. })
  399. .catch((err) => {});
  400. },
  401. handleSet(type, row, index) {
  402. // 2编辑 3查看 4删除
  403. switch (type) {
  404. case 2:
  405. case 3:
  406. this.handleGoPage(type, row.id);
  407. break;
  408. case 4:
  409. this.$Modal.confirm({
  410. title: "确认删除?",
  411. content: "此操作无法恢复,请确认!",
  412. onOk: () => {
  413. this.axios({
  414. method: "post",
  415. url: "/api/custom_del",
  416. data: {
  417. id: row.id,
  418. },
  419. })
  420. .then((res) => {
  421. this.$Message.success(res.msg);
  422. this.initData(this.searchData);
  423. })
  424. .catch((err) => {});
  425. },
  426. onCancel: () => {},
  427. });
  428. break;
  429. }
  430. },
  431. append(data) {
  432. const children = data.children || [];
  433. children.push({
  434. code: this.form.code,
  435. title: this.form.title,
  436. expand: true,
  437. });
  438. this.$set(data, "children", children);
  439. },
  440. remove(root, node, data) {
  441. if (node.children && node.children.length > 0) {
  442. this.$Message.error("有子集时不可删除");
  443. } else {
  444. const parentKey = root.find((el) => el === node).parent;
  445. const parent = root.find((el) => el.nodeKey === parentKey).node;
  446. const index = parent.children.indexOf(data);
  447. parent.children.splice(index, 1);
  448. }
  449. },
  450. handleModalOk() {
  451. this.append(this.treeData[0]);
  452. },
  453. handleTreeSelect(arr, row) {
  454. console.log("row :>> ", row);
  455. this.searchData.code = row.code;
  456. this.suppliersTypeTitle = row.title;
  457. this.suppliersTypeId = row.id;
  458. this.initData(this.searchData);
  459. },
  460. uploadSuccess(res) {
  461. if (res.code == 200) {
  462. this.$Message.success(res.msg || "上传成功");
  463. } else {
  464. this.$Message.warning(res.msg || "上传失败");
  465. }
  466. this.getData(this.proxyObj);
  467. },
  468. uploadError(err) {
  469. this.$Message.error(err.msg || "上传失败");
  470. },
  471. changeSize(e) {
  472. this.pageSize = e;
  473. this.initData(this.searchData);
  474. },
  475. changePage(e) {
  476. this.pageIndex = e;
  477. this.initData(this.searchData);
  478. },
  479. handleGoPage(type, id) {
  480. // if (type == 1 && this.suppliersTypeTitle == '') {
  481. // this.$Message.warning('新增请先选择左侧客户分类!')
  482. // } else {
  483. this.$router.push({
  484. path: "/cms/BasicSettings/CustomerFiles/detail",
  485. query: {
  486. type,
  487. id,
  488. },
  489. });
  490. // }
  491. },
  492. async exportData(){
  493. const res = await this.axios('/api/custom_export')
  494. if(res.code == 200){
  495. let url = `${this.$store.state.ip}/api/storage/${res.data.file}`
  496. location.href = url
  497. }
  498. },
  499. },
  500. // 监听属性 类似于data概念
  501. computed: {},
  502. // 监控data中的数据变化
  503. watch: {},
  504. beforeCreate() {}, // 生命周期 - 创建之前
  505. beforeMount() {}, // 生命周期 - 挂载之前
  506. beforeUpdate() {}, // 生命周期 - 更新之前
  507. updated() {}, // 生命周期 - 更新之后
  508. beforeDestroy() {}, // 生命周期 - 销毁之前
  509. destroyed() {}, // 生命周期 - 销毁完成
  510. activated() {}, // 如果页面有keep-alive缓存功能,这个函数会触发
  511. };
  512. </script>
  513. <style lang="scss" scoped>
  514. .content {
  515. width: 100%;
  516. display: flex;
  517. justify-content: space-between;
  518. padding-top: 30px;
  519. .content_left {
  520. width: 15%;
  521. height: 60vh;
  522. border-right: 1px solid #515a6e;
  523. }
  524. .content_right {
  525. width: 83%;
  526. .content_right_topform {
  527. /deep/.ivu-form {
  528. display: flex;
  529. justify-content: flex-start;
  530. flex-wrap: wrap;
  531. }
  532. /deep/.ivu-form-item {
  533. display: inline-block;
  534. width: 250px;
  535. }
  536. .content_right_topfrom_btn {
  537. display: flex;
  538. justify-content: flex-end;
  539. }
  540. }
  541. .content_right_content {
  542. border-top: 1px solid #f4f4f4;
  543. margin-top: 20px;
  544. padding-top: 20px;
  545. .content_right_content_btn {
  546. display: flex;
  547. justify-content: flex-end;
  548. margin-bottom: 20px;
  549. }
  550. .content_right_content_table {
  551. }
  552. .content_right_content_page {
  553. display: flex;
  554. justify-content: center;
  555. padding-top: 20px;
  556. }
  557. }
  558. }
  559. }
  560. .demo-tree-render {
  561. width: 100%;
  562. }
  563. </style>