SippliersList.vue 12 KB

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