index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div>
  3. <FullPage
  4. :title="title"
  5. :list="list"
  6. @init="init"
  7. :loading="loading"
  8. @searchData="init"
  9. @changePage="changePage"
  10. @changeSize="changeSize"
  11. :tableColums="tableColums"
  12. :tableData="tableData"
  13. :pageIndex="pageIndex"
  14. :total="total"
  15. >
  16. <div slot="titleButton" style="display:flex">
  17. <Button type="success" ghost icon='ios-download-outline' style="margin-right:10px;" @click='exportData()'>导出</Button>
  18. <Button
  19. v-if="persimissionData['新增'] || persimissionData.all"
  20. @click="addItems"
  21. type="primary"
  22. ghost
  23. icon="md-add"
  24. >新增{{ title }}</Button
  25. >
  26. </div>
  27. <div slot="navButton"></div>
  28. <template slot="set" slot-scope="{ row }">
  29. <div class="table-set">
  30. <svg
  31. v-if="persimissionData['编辑'] || persimissionData.all"
  32. style="font-size:20px"
  33. color="#3764FF"
  34. @click="addItems(row)"
  35. class="icon icon-nav"
  36. aria-hidden="true"
  37. >
  38. <use xlink:href="#iconbianji"></use>
  39. </svg>
  40. <svg
  41. v-if="persimissionData['删除'] || persimissionData.all"
  42. @click="delItems(row)"
  43. class="icon icon-nav"
  44. style="font-size:20px"
  45. color="red"
  46. aria-hidden="true"
  47. >
  48. <use xlink:href="#iconshanchu"></use>
  49. </svg>
  50. </div>
  51. </template>
  52. <div>
  53. <Modal
  54. class-name="vertical-center-modal"
  55. :title="showType == 1 ? '新增' + title : '编辑' + title"
  56. v-model="showModal"
  57. :width="480"
  58. @on-visible-change="vivibleModal"
  59. >
  60. <Form :label-width="90">
  61. <FormItem label="ID:">
  62. <Input disabled placeholder="ID自动生成" v-model="classInfo.id" />
  63. </FormItem>
  64. <span v-if="repeatFlag" style="color:red;margin-left:8px;"
  65. >以下属性重复</span
  66. >
  67. <FormItem label="属性名称:">
  68. <div v-if="showType == 1">
  69. <div
  70. class="item-attr"
  71. v-for="(item, index) of attribute"
  72. :key="index"
  73. >
  74. <Input
  75. :placeholder="'请输入' + title + '名称'"
  76. v-model="item.title"
  77. />
  78. <Icon
  79. @click="add(attribute)"
  80. style="'margin:0 10px"
  81. color="#32C800"
  82. size="20"
  83. type="ios-add-circle"
  84. />
  85. <Icon
  86. v-if="attribute.length != 1"
  87. @click="remove(attribute, index)"
  88. style="'margin:0 10px"
  89. color="#FF5E5C"
  90. size="20"
  91. type="md-remove-circle"
  92. />
  93. <!-- <Icon @click="addAttr(index)" style="'margin:0 10px" :color='index == attribute.length-1 ? "#32C800" : "#FF5E5C"' size='20' :type="index == attribute.length-1 ? 'ios-add-circle' : 'md-remove-circle'" /> -->
  94. </div>
  95. </div>
  96. <Input
  97. v-if="showType == 2"
  98. :placeholder="'请输入' + title + '名称'"
  99. v-model="classInfo.title"
  100. />
  101. </FormItem>
  102. <FormItem label="属性分类:">
  103. <Input
  104. placeholder="请输入属性分类"
  105. v-model="classInfo.type_title"
  106. />
  107. </FormItem>
  108. </Form>
  109. <div slot="footer" class="modal-footer">
  110. <Button @click="showModal = false">取消</Button>
  111. <Button type="primary" @click="postInfo">确定</Button>
  112. </div>
  113. </Modal>
  114. </div>
  115. </FullPage>
  116. </div>
  117. </template>
  118. <script>
  119. import { mapState } from "vuex";
  120. export default {
  121. data() {
  122. return {
  123. list: [
  124. {
  125. title: `颜色名称`,
  126. name: "Input",
  127. value: "",
  128. serverName: "title",
  129. placeholder: `请输入颜色名称`,
  130. },
  131. ],
  132. tableColums: [
  133. {
  134. title: "序号",
  135. type: "index",
  136. align: "center",
  137. key: "id",
  138. resizable:true,
  139. width: 150,
  140. },
  141. { title: `颜色`, align: "center", key: "title" ,resizable:true, width: 600},
  142. { title: `分类`, align: "center", key: "type_title" ,resizable:true, width: 600},
  143. { title: "操作", align: "center", slot: "set", minWidth: 150 },
  144. ],
  145. tableData: [],
  146. pageIndex: 1,
  147. total: 0,
  148. pageSize: 10,
  149. showModal: false,
  150. showType: 1,
  151. classInfo: {},
  152. attribute: [{ title: "" }],
  153. title: "",
  154. id: null,
  155. proxyObj: {},
  156. loading: false,
  157. repeatFlag: false,
  158. };
  159. },
  160. mounted() {
  161. this.title = this.$route.query.title;
  162. if (this.$route.query.id) {
  163. this.proxyObj.id = this.$route.query.id;
  164. this.list[0].title = `${this.title}名称`;
  165. this.list[0].placeholder = `请输入${this.title}名称`;
  166. this.tableColums[1].title = this.title;
  167. this.getData(this.proxyObj);
  168. }
  169. },
  170. computed: {
  171. ...mapState(["persimissionData"]),
  172. },
  173. watch: {
  174. $route(to) {
  175. this.title = to.query.title;
  176. this.id = to.query.id;
  177. this.proxyObj.id = this.id;
  178. this.list[0].title = `${this.title}名称`;
  179. this.list[0].value = "";
  180. this.list[0].placeholder = `请输入${this.title}名称`;
  181. this.tableColums[1].title = this.title;
  182. this.proxyObj.title = "";
  183. this.getData(this.proxyObj);
  184. this.classInfo.id = this.id;
  185. },
  186. },
  187. methods: {
  188. init(row) {
  189. this.pageIndex = 1;
  190. row.page_index = this.pageIndex;
  191. row.page_size = this.pageSize;
  192. this.proxyObj = row;
  193. this.proxyObj.id = this.$route.query.id;
  194. this.getData(this.proxyObj);
  195. },
  196. addItems(obj) {
  197. this.showModal = true;
  198. this.repeatFlag = false
  199. if (obj.id) {
  200. this.showType = 2;
  201. this.classInfo.id = obj.id;
  202. this.classInfo.type_title = obj.type_title;
  203. this.classInfo.title = obj.title;
  204. } else {
  205. //新增
  206. this.showType = 1;
  207. }
  208. },
  209. changePage(e) {
  210. this.pageIndex = e;
  211. this.proxyObj.page_index = this.pageIndex;
  212. this.getData(this.proxyObj);
  213. },
  214. changeSize(e) {
  215. this.pageSize = e;
  216. this.proxyObj.page_size = this.pageSize;
  217. this.getData(this.proxyObj);
  218. },
  219. vivibleModal(e) {
  220. // if (!e) {
  221. // this.showType == 1 ? this.attribute = [{ title: '' }] : this.classInfo = {}
  222. // this.repeatFlag = false
  223. // this.getData(this.proxyObj)
  224. // }
  225. },
  226. exportData(){
  227. let url ='';
  228. if(this.$route.query.id==1){
  229. url = '/api/process_material_export';
  230. }
  231. if(this.$route.query.id==2){
  232. url = "/api/process_finish_export";
  233. }
  234. if(this.$route.query.id==3){
  235. url = "/api/process_ship_export";
  236. }
  237. this.axios.get(url,{params:{id:this.$route.query.id}}).then(res=>{
  238. if(res.code == 200){
  239. let url = `${this.$store.state.ip}/api/storage/${res.data.file}`
  240. location.href = url
  241. }
  242. })
  243. },
  244. postInfo() {
  245. let post_url, post_data;
  246. if (this.showType == 1) {
  247. post_url = "/api/properties_add";
  248. let result = [];
  249. this.attribute.map((v) => result.push(v.title));
  250. post_data = {
  251. id: this.$route.query.id,
  252. title: result.join(","),
  253. type_title:this.classInfo.type_title
  254. };
  255. } else {
  256. post_url = "/api/properties_edit";
  257. post_data = this.classInfo;
  258. }
  259. this.axios.post(post_url, post_data).then((res) => {
  260. if (res.code == 200) {
  261. this.$Message.success(res.msg);
  262. this.showModal = false;
  263. this.getData(this.proxyObj);
  264. this.classInfo.id = "";
  265. this.classInfo.type_title = "";
  266. this.classInfo.title = "";
  267. this.attribute = [{ title: "" }];
  268. } else {
  269. if (Array.isArray(res.data)) {
  270. this.repeatFlag = true;
  271. let result = [];
  272. res.data.map((v) => {
  273. let obj = {};
  274. v ? (obj.title = v) : "";
  275. obj.title ? result.push(obj) : "";
  276. });
  277. this.attribute = result;
  278. this.getData(this.proxyObj);
  279. }
  280. }
  281. });
  282. },
  283. addAttr(n) {
  284. n == this.attribute.length - 1
  285. ? this.attribute.push({ title: "" })
  286. : this.attribute.splice(n, 1);
  287. },
  288. add(array) {
  289. array.push({ title: "" });
  290. },
  291. remove(array, n) {
  292. array.splice(n, 1);
  293. },
  294. getData(row) {
  295. this.loading = true;
  296. this.axios("/api/properties_index", { params: row }).then((res) => {
  297. this.loading = false;
  298. this.tableData = res.data.data;
  299. this.total = res.data.total;
  300. });
  301. },
  302. delItems(row) {
  303. this.confirmDelete({
  304. content: "确认删除么?",
  305. then: () => {
  306. this.axios
  307. .post("/api/properties_del", { id: row.id, state: 0 })
  308. .then((res) => {
  309. if (res.code == 200) {
  310. this.$Message.success(res.msg);
  311. this.getData(this.proxyObj);
  312. }
  313. });
  314. },
  315. });
  316. },
  317. },
  318. };
  319. </script>
  320. <style lang="scss" scoped>
  321. .nav {
  322. display: flex;
  323. justify-content: space-between;
  324. align-items: center;
  325. }
  326. .item-attr {
  327. display: flex;
  328. align-items: center;
  329. margin-bottom: 10px;
  330. }
  331. </style>