Materialfield.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <div>
  3. <FullPage title='物料分类字段'
  4. :list='list'
  5. @init='init'
  6. :loading='loading'
  7. @searchData='init'
  8. @changePage='changePage'
  9. @changeSize='changeSize'
  10. :tableColums='tableColums'
  11. :tableData='tableData'
  12. :pageIndex='pageIndex'
  13. :total='total'>
  14. <div slot='titleButton'>
  15. <Button type="primary"
  16. ghost
  17. icon='md-add'
  18. @click="addItems(classInfo)">新增物料分类</Button>
  19. </div>
  20. <div slot='navButton'>
  21. </div>
  22. <template slot="basicTypeSet"
  23. slot-scope="{row}">
  24. <span v-show="row.type_id==item.id"
  25. v-for="item in materialTypeList"
  26. :key="item.id">
  27. {{item.title}}
  28. </span>
  29. </template>
  30. <template slot='set'
  31. slot-scope='{row}'>
  32. <div class="table-set">
  33. <svg style="font-size:20px"
  34. color='#3764FF'
  35. @click="addItems(row)"
  36. class="icon icon-nav"
  37. aria-hidden="true">
  38. <use xlink:href="#iconbianji"></use>
  39. </svg>
  40. <svg @click="delItems(row)"
  41. class="icon icon-nav"
  42. style="font-size:20px"
  43. color='red'
  44. aria-hidden="true">
  45. <use xlink:href="#iconshanchu"></use>
  46. </svg>
  47. </div>
  48. </template>
  49. <div>
  50. <Modal class-name="vertical-center-modal"
  51. :title="showType == 1 ? '新增物料分类': '编辑物料分类'"
  52. v-model="showModal"
  53. :width="480"
  54. @on-visible-change='vivibleModal'>
  55. <Form :label-width="90">
  56. <FormItem label="物料分类:">
  57. <Input placeholder=""
  58. v-model="classInfo.title" />
  59. </FormItem>
  60. <FormItem label="所属分类:">
  61. <Select v-model="classInfo.type_id">
  62. <Option v-for="(item) of materialTypeList"
  63. :key="item.id"
  64. :value="item.id"
  65. :label="item.title"></Option>
  66. </Select>
  67. </FormItem>
  68. <FormItem label="子分类:">
  69. <Select v-model="classInfo.sub_type">
  70. <Option :value=0
  71. label="无"></Option>
  72. <Option :value=1
  73. label="胶水"></Option>
  74. <Option :value=2
  75. label="包材"></Option>
  76. </Select>
  77. </FormItem>
  78. </Form>
  79. <div class="modal-footer"
  80. slot='footer'>
  81. <Button @click='showModal = false'>取消</Button>
  82. <Button type="primary"
  83. @click="postInfo">确定</Button>
  84. </div>
  85. </Modal>
  86. </div>
  87. </FullPage>
  88. </div>
  89. </template>
  90. <script>
  91. import { mapActions, mapState } from 'vuex'
  92. export default {
  93. data () {
  94. return {
  95. list: [
  96. { title: '物料分类名称', name: 'Input', value: '', serverName: 'title', placeholder: '请输入物料分类名称' },
  97. ],
  98. tableColums: [
  99. { title: '序号', type: 'index', align: 'center', key: 'id', width: '100' },
  100. { title: '物料分类', align: 'center', key: 'title' },
  101. { title: '物料所属分类', align: 'center', key: 'title', slot: 'basicTypeSet' },
  102. { title: '操作', align: 'center', slot: 'set', width: '150' },
  103. ],
  104. tableData: [],
  105. pageIndex: 1,
  106. total: 0,
  107. pageSize: 10,
  108. showModal: false,
  109. showType: 1,
  110. classInfo: {
  111. type_id: '',
  112. title: '',
  113. sub_type: ''
  114. },
  115. proxyObj: {},
  116. loading: false,
  117. attribute: [{ title: '' }],
  118. repeatFlag: false,
  119. materialTypeList: []
  120. }
  121. },
  122. mounted () {
  123. this.initData()
  124. },
  125. methods: {
  126. ...mapActions(['undata_navData']),
  127. initData () {
  128. //加载所属分类
  129. this.axios({
  130. method: 'get',
  131. url: '/api/basics_material_type',
  132. }).then((res) => {
  133. this.materialTypeList = res.data
  134. }).catch((err) => {
  135. });
  136. },
  137. init (row) {
  138. this.pageIndex = 1
  139. row.page_index = this.pageIndex;
  140. row.page_size = this.pageSize;
  141. this.proxyObj = row;
  142. this.getData(row)
  143. },
  144. getData (row) {
  145. this.loading = true;
  146. this.axios('/api/basics_material_index', { params: row }).then(res => {
  147. this.loading = false;
  148. this.tableData = res.data.data;
  149. this.total = res.data.total;
  150. // this.undata_navData()/////
  151. })
  152. },
  153. changePage (e) {
  154. this.pageIndex = e;
  155. this.proxyObj.page_index = e;
  156. this.getData(this.proxyObj)
  157. },
  158. changeSize (e) {
  159. this.pageSize = e;
  160. this.proxyObj.page_size = this.pageSize;
  161. this.getData(this.proxyObj)
  162. },
  163. addItems (obj) {
  164. this.showModal = true;
  165. if (obj.id) {
  166. this.showType = 2
  167. this.classInfo.id = obj.id;
  168. this.classInfo.title = obj.title;
  169. this.classInfo.type_id = obj.type_id;
  170. this.classInfo.sub_type = obj.sub_type_id
  171. } else {
  172. //新增
  173. this.showType = 1
  174. this.classInfo.id = obj.id;
  175. this.classInfo.title = obj.title;
  176. this.classInfo.type_id = obj.type_id;
  177. }
  178. },
  179. delItems (row) {
  180. this.confirmDelete({
  181. content: '确认删除么?',
  182. then: () => {
  183. this.axios.post('/api/basics_material_del', { id: row.id, state: 0 }).then(res => {
  184. if (res.code == 200) {
  185. this.$Message.success(res.msg)
  186. this.getData(this.proxyObj)
  187. this.undata_navData()
  188. }
  189. })
  190. }
  191. })
  192. },
  193. vivibleModal (e) {
  194. if (!e) {
  195. this.classInfo = {
  196. id: '',
  197. title: ''
  198. }
  199. this.attribute = [{ title: '' }]
  200. this.repeatFlag = false;
  201. }
  202. },
  203. add (array) {
  204. array.push({ title: '' })
  205. },
  206. remove (array, n) { array.splice(n, 1) },
  207. postInfo () {
  208. let postData = {}, post_url = '';
  209. if (this.showType == 1) {
  210. post_url = '/api/basics_material_add';
  211. let result = []
  212. this.attribute.map(v => result.push(v.title))
  213. // postData = {
  214. // id: this.classInfo.id,
  215. // title: result.join(',')
  216. // }
  217. postData = this.classInfo;
  218. } else {
  219. post_url = '/api/basics_material_edit'
  220. postData = this.classInfo;
  221. }
  222. this.axios.post(post_url, postData).then(res => {
  223. if (res.code == 200) {
  224. this.$Message.success(res.msg)
  225. this.getData(this.proxyObj)
  226. this.undata_navData()
  227. this.showModal = false;
  228. } else {
  229. if (Array.isArray(res.data)) {
  230. this.repeatFlag = true
  231. let result = []
  232. res.data.map(v => {
  233. let obj = {};
  234. v ? obj.title = v : ''
  235. obj.title ? result.push(obj) : ''
  236. })
  237. this.attribute = result;
  238. this.getData(this.proxyObj)
  239. this.undata_navData()
  240. }
  241. }
  242. })
  243. }
  244. }
  245. }
  246. </script>
  247. <style lang="scss" scoped>
  248. .item-attr {
  249. display: flex;
  250. align-items: center;
  251. margin-bottom: 10px;
  252. }
  253. </style>