SippliersList.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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. <Button type="primary" style="margin-right: 10px">导入</Button>
  9. <Button @click="exportData()" type="primary" style="margin-right: 10px">导出</Button>
  10. <Button
  11. type="primary"
  12. @click="handleGoPage(1, '')"
  13. style="margin-right: 10px"
  14. >新增</Button
  15. >
  16. </slot>
  17. </Toptitle>
  18. <div class="content">
  19. <div class="content_left">
  20. <Tree
  21. :data="treeData"
  22. select-node
  23. children-key="sub"
  24. style="width: 100%;height:100%;overflow:auto"
  25. @on-select-change="handleTreeSelect"
  26. class="demo-tree-render"
  27. ></Tree>
  28. </div>
  29. <div class="content_right">
  30. <div class="content_right_topform">
  31. <Form :label-width="90" :model="searchData">
  32. <FormItem label="供应商编码:">
  33. <Input
  34. type="text"
  35. size="small"
  36. v-model="searchData.code"
  37. style="width: 150px"
  38. placeholder="供应商编码"
  39. />
  40. </FormItem>
  41. <FormItem label="供应商名称:">
  42. <Input
  43. type="text"
  44. size="small"
  45. v-model="searchData.title"
  46. style="width: 150px"
  47. placeholder="供应商名称"
  48. />
  49. </FormItem>
  50. <FormItem label="负责人:">
  51. <Select
  52. v-model="searchData.contact"
  53. size="small"
  54. clearable
  55. filterable
  56. label-in-value
  57. style="width: 150px"
  58. >
  59. <Option
  60. v-for="sitem in contactList"
  61. :key="sitem"
  62. :label="sitem"
  63. :value="sitem"
  64. >
  65. </Option>
  66. </Select>
  67. </FormItem>
  68. <FormItem label="是否启用:">
  69. <Select
  70. v-model="searchData.state"
  71. size="small"
  72. clearable
  73. style="width: 150px"
  74. >
  75. <Option label="是" value="1" />
  76. <Option label="否" value="2" />
  77. </Select>
  78. </FormItem>
  79. <FormItem label="新增时间:">
  80. <DatePicker
  81. type="date"
  82. size="small"
  83. style="width: 150px"
  84. placeholder="年/月/日"
  85. v-model="searchData.date[0]"
  86. ></DatePicker>
  87. </FormItem>
  88. <FormItem label="~">
  89. <DatePicker
  90. type="date"
  91. size="small"
  92. style="width: 150px"
  93. placeholder="年/月/日"
  94. v-model="searchData.date[1]"
  95. ></DatePicker>
  96. </FormItem>
  97. <FormItem>
  98. <Button
  99. type="primary"
  100. size="small"
  101. @click="initData(searchData)"
  102. style="margin-right: 10px"
  103. >搜索</Button
  104. >
  105. </FormItem>
  106. </Form>
  107. <div class="content_right_topfrom_btn"></div>
  108. </div>
  109. <div class="content_right_content">
  110. <div class="content_right_content_table">
  111. <Table
  112. :columns="tableColumns"
  113. border
  114. :loading="tableLoading"
  115. :data="tableData"
  116. >
  117. <template slot="setSlot" slot-scope="{ row, index }">
  118. <a style="margin: 0 5px" @click="handleSet(4, row, index)"
  119. >查看</a
  120. >
  121. <a style="margin: 0 5px" @click="handleSet(2, row, index)"
  122. >编辑</a
  123. >
  124. <a
  125. style="margin: 0 5px; color: red"
  126. @click="handleSet(3, row, index)"
  127. >删除</a
  128. >
  129. </template>
  130. </Table>
  131. <div class="content_right_content_page">
  132. <Page
  133. :page-size-opts="[10, 20, 30, 40, 100]"
  134. @on-page-size-change="changeSize"
  135. @on-change="changePage"
  136. :current="pageIndex"
  137. show-total
  138. show-elevator
  139. :total="total"
  140. show-sizer
  141. :page-size="pageSize"
  142. />
  143. </div>
  144. </div>
  145. </div>
  146. </div>
  147. </div>
  148. </div>
  149. </template>
  150. <script>
  151. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  152. // 例如:import 《组件名称》 from '《组件路径》';
  153. export default {
  154. name: "SippliersList",
  155. components: {},
  156. props: {},
  157. // import引入的组件需要注入到对象中才能使用
  158. data() {
  159. // 这里存放数据
  160. return {
  161. type: "",
  162. contactList: [],
  163. treeData: [
  164. {
  165. title: "供应商分类",
  166. expand: true,
  167. sub: [],
  168. render: (h, { root, node, data }) => {
  169. return h(
  170. "span",
  171. {
  172. style: {
  173. display: "inline-block",
  174. width: "100%",
  175. },
  176. },
  177. [
  178. h("span", [
  179. h("Icon", {
  180. props: {
  181. type: "ios-folder-outline",
  182. },
  183. style: {
  184. marginRight: "8px",
  185. },
  186. }),
  187. h("span", data.title),
  188. ]),
  189. ]
  190. );
  191. },
  192. },
  193. ],
  194. buttonProps: {
  195. type: "default",
  196. size: "small",
  197. },
  198. tableColumns: [
  199. { title: "供应商编码", key: "code", align: "center", resizable: true,width: 150 },
  200. { title: "供应商名称", key: "title", align: "center", resizable: true,width: 300 },
  201. { title: "业务员", key: "nickname", align: "center",resizable: true,width: 130 },
  202. { title: "负责人", key: "contact", align: "center",resizable: true,width: 130 },
  203. { title: "手机号", key: "mobile", align: "center", resizable: true,width: 200 },
  204. {
  205. title: "是否启用",
  206. key: "state",
  207. align: "center",
  208. resizable: true,width: 100,
  209. render: (h, params) => {
  210. const { row } = params;
  211. return h("span", {}, row.state == 1 ? "是" : "否");
  212. },
  213. },
  214. {
  215. title: "创建时间",
  216. key: "crt_time",
  217. align: "center",
  218. resizable: true,width: 220,
  219. render: (h, params) => {
  220. const { row } = params;
  221. return h("span", {}, this.func.replaceDate(row.crt_time));
  222. },
  223. },
  224. {
  225. title: "操作",
  226. key: "code",
  227. align: "center",
  228. minWidth: 120,
  229. slot: "setSlot",
  230. },
  231. ],
  232. tableData: [],
  233. tableLoading: false,
  234. pageIndex: 1,
  235. pageSize: 10,
  236. total: 0,
  237. searchData: {
  238. title: "",
  239. code: "",
  240. contact: "",
  241. state: "",
  242. start_time: "",
  243. end_time: "",
  244. date: [],
  245. },
  246. suppliersTypeTitle: "",
  247. suppliersTypeId: "",
  248. };
  249. },
  250. // 生命周期 - 创建完成(可以访问当前this实例)
  251. created() {
  252. this.axios({
  253. method: "get",
  254. url: "/api/basic_supply_list",
  255. }).then((res) => {
  256. this.treeData[0].sub = res.data;
  257. });
  258. this.axios({
  259. method: "get",
  260. url: "/api/supply_contact",
  261. }).then((res) => {
  262. this.contactList = res.data;
  263. });
  264. },
  265. // 生命周期 - 挂载完成(可以访问DOM元素)
  266. mounted() {
  267. this.initData(this.searchData);
  268. },
  269. methods: {
  270. initData(row) {
  271. row.start_time = row.date[0]
  272. ? new Date(row.date[0]).getTime() / 1000
  273. : "";
  274. row.end_time = row.date[1] ? new Date(row.date[1]).getTime() / 1000 : "";
  275. this.tableLoading = true;
  276. this.axios({
  277. method: "get",
  278. url: "/api/supply_list",
  279. params: {
  280. ...row,
  281. page_index: this.pageIndex,
  282. page_size: this.pageSize,
  283. },
  284. }).then((res) => {
  285. this.tableLoading = false;
  286. this.total = res.data.total;
  287. this.tableData = res.data.data;
  288. });
  289. },
  290. handleSet(type, row, index) {
  291. // 2编辑 3删除
  292. switch (type) {
  293. case 2:
  294. this.handleGoPage(type, row.id);
  295. break;
  296. case 3:
  297. this.$Modal.confirm({
  298. title: "确认删除?",
  299. content: "此操作无法恢复,请确认!",
  300. onOk: () => {
  301. this.axios({
  302. method: "get",
  303. url: "/api/supply_del",
  304. params: {
  305. id: row.id,
  306. },
  307. }).then((res) => {
  308. this.$Message.success(res.msg);
  309. this.initData(this.searchData);
  310. })
  311. .catch((err) => {});
  312. },
  313. onCancel: () => {},
  314. });
  315. break;
  316. case 4:
  317. this.handleGoPage(type, row.id);
  318. break;
  319. }
  320. },
  321. append(data) {
  322. const children = data.children || [];
  323. children.push({
  324. code: this.form.code,
  325. title: this.form.title,
  326. expand: true,
  327. });
  328. this.$set(data, "children", children);
  329. },
  330. remove(root, node, data) {
  331. if (node.children && node.children.length > 0) {
  332. this.$Message.error("有子集时不可删除");
  333. } else {
  334. const parentKey = root.find((el) => el === node).parent;
  335. const parent = root.find((el) => el.nodeKey === parentKey).node;
  336. const index = parent.children.indexOf(data);
  337. parent.children.splice(index, 1);
  338. }
  339. },
  340. handleModalOk() {
  341. this.append(this.treeData[0]);
  342. },
  343. handleTreeSelect(arr, row) {
  344. console.log("row :>> ", row);
  345. this.searchData.type_id = row.id;
  346. this.suppliersTypeTitle = row.title;
  347. this.suppliersTypeId = row.id;
  348. this.initData(this.searchData);
  349. },
  350. changeSize(e) {
  351. this.pageSize = e;
  352. this.initData(this.searchData);
  353. },
  354. changePage(e) {
  355. this.pageIndex = e;
  356. this.initData(this.searchData);
  357. },
  358. handleGoPage(type, id) {
  359. if (type == 1 && this.suppliersTypeTitle == "") {
  360. this.$Message.warning("新增请先选择左侧供应商分类!");
  361. } else {
  362. this.$router.push({
  363. path: "/cms/BasicSettings/SuppliersManage/SippliersListEdit",
  364. query: {
  365. type,
  366. id,
  367. title: this.suppliersTypeTitle,
  368. basics_supply_id: this.suppliersTypeId,
  369. },
  370. });
  371. }
  372. },
  373. async exportData(){
  374. const res = await this.axios('/api/supply_export')
  375. if(res.code == 200){
  376. let url = `${this.$store.state.ip}/api/storage/${res.data.file}`
  377. location.href = url
  378. }
  379. }
  380. },
  381. // 监听属性 类似于data概念
  382. computed: {},
  383. // 监控data中的数据变化
  384. watch: {},
  385. beforeCreate() {}, // 生命周期 - 创建之前
  386. beforeMount() {}, // 生命周期 - 挂载之前
  387. beforeUpdate() {}, // 生命周期 - 更新之前
  388. updated() {}, // 生命周期 - 更新之后
  389. beforeDestroy() {}, // 生命周期 - 销毁之前
  390. destroyed() {}, // 生命周期 - 销毁完成
  391. activated() {}, // 如果页面有keep-alive缓存功能,这个函数会触发
  392. };
  393. </script>
  394. <style lang='scss' scoped>
  395. .content {
  396. width: 100%;
  397. display: flex;
  398. justify-content: space-between;
  399. padding-top: 30px;
  400. .content_left {
  401. width: 15%;
  402. height: 60vh;
  403. border-right: 1px solid #515a6e;
  404. }
  405. .content_right {
  406. width: 83%;
  407. .content_right_topform {
  408. /deep/.ivu-form {
  409. display: flex;
  410. justify-content: flex-start;
  411. flex-wrap: wrap;
  412. }
  413. /deep/.ivu-form-item {
  414. display: inline-block;
  415. width: 250px;
  416. }
  417. .content_right_topfrom_btn {
  418. display: flex;
  419. justify-content: flex-end;
  420. }
  421. }
  422. .content_right_content {
  423. border-top: 1px solid #f4f4f4;
  424. margin-top: 20px;
  425. padding-top: 20px;
  426. .content_right_content_btn {
  427. display: flex;
  428. justify-content: flex-end;
  429. margin-bottom: 20px;
  430. }
  431. .content_right_content_table {
  432. }
  433. .content_right_content_page {
  434. display: flex;
  435. justify-content: center;
  436. padding-top: 20px;
  437. }
  438. }
  439. }
  440. }
  441. .demo-tree-render {
  442. width: 100%;
  443. }
  444. </style>