SippliersList.vue 12 KB

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