index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div>
  3. <FullPage :title='$route.query.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. style="display:flex;">
  16. <Upload name='your_file'
  17. :show-upload-list='false'
  18. :headers='headers'
  19. :on-error='uploadError'
  20. :on-success='uploadSuccess'
  21. :action="$store.state.ip+'/api/material_import'">
  22. <Button type="success"
  23. ghost
  24. icon='md-exit'
  25. style="margin-right:10px;">批量导入</Button>
  26. </Upload>
  27. <Button @click="exportData"
  28. type="warning"
  29. ghost
  30. icon='md-return-left'
  31. style="margin-right:10px;">批量导出</Button>
  32. <Button @click="goDetial(1)"
  33. type="primary"
  34. ghost
  35. icon='md-add'>新增物料</Button>
  36. </div>
  37. <div slot='navButton'>
  38. </div>
  39. <template slot='set'
  40. slot-scope='{row}'>
  41. <div class="table-set">
  42. <svg style="font-size:20px"
  43. color='#3764FF'
  44. @click="goDetial(4,row)"
  45. class="icon icon-nav"
  46. aria-hidden="true">
  47. <use xlink:href="#iconcopy-01"></use>
  48. </svg>
  49. <svg style="font-size:20px"
  50. color='#3764FF'
  51. @click="goDetial(2,row)"
  52. class="icon icon-nav"
  53. aria-hidden="true">
  54. <use xlink:href="#iconbianji"></use>
  55. </svg>
  56. <svg style="font-size:20px"
  57. color='green'
  58. @click="goDetial(3,row)"
  59. class="icon icon-nav"
  60. aria-hidden="true">
  61. <use xlink:href="#iconxiangqing"></use>
  62. </svg>
  63. <svg @click="delItems(row)"
  64. class="icon icon-nav"
  65. style="font-size:20px"
  66. color='red'
  67. aria-hidden="true">
  68. <use xlink:href="#iconshanchu"></use>
  69. </svg>
  70. </div>
  71. </template>
  72. </FullPage>
  73. </div>
  74. </template>
  75. <script>
  76. export default {
  77. data () {
  78. return {
  79. list: [
  80. { title: '物料', name: 'Input', serverName: 'title', placeholder: '请输入物料', value: '' }
  81. ],
  82. tableColums: [
  83. { title: '序号', type: 'index', align: 'center', key: '', fixed: 'left', width: '100' },
  84. { title: '材料分类名称', align: 'center', key: 'm_title', minWidth: 150 },
  85. { title: '物料名称', align: 'center', key: 'title', minWidth: 150 },
  86. { title: '单位', align: 'center', key: 'unit', minWidth: 100 },
  87. { title: '厚', align: 'center', key: 'high', minWidth: 100 },
  88. { title: '描述', align: 'center', key: 'remark', minWidth: 200 },
  89. { title: '操作', align: 'center', slot: 'set', fixed: 'right', width: '150' },
  90. ],
  91. tableData: [],
  92. pageIndex: 1,
  93. total: 0,
  94. pageSize: 10,
  95. loading: false,
  96. proxyObj: {},
  97. headers: { 'Authorization': localStorage.getItem('token') },
  98. materialList: [],
  99. basic_type_id: ''
  100. }
  101. },
  102. watch: {
  103. $route (to) {
  104. this.proxyObj.type_id = to.query.id;
  105. this.proxyObj.title = ''
  106. this.list[0].value = ''
  107. this.getData(this.proxyObj)
  108. //
  109. let tempArr = this.$store.state.navgationData[7].sub
  110. let id = this.$route.query.id
  111. tempArr.forEach(element => {
  112. if (element.id == id) {
  113. this.basic_type_id = element.sub_type_id
  114. }
  115. });
  116. if (this.basic_type_id == 4 || this.basic_type_id == 5 || this.basic_type_id == 6) {
  117. this.tableColums = [
  118. { title: '序号', type: 'index', align: 'center', key: '', fixed: 'left', width: '100' },
  119. { title: '材料分类名称', align: 'center', key: 'm_title', minWidth: 150 },
  120. { title: '物料名称', align: 'center', key: 'title', minWidth: 150 },
  121. { title: '单位', align: 'center', key: 'unit', minWidth: 100 },
  122. { title: '描述', align: 'center', key: 'remark', minWidth: 200 },
  123. { title: '操作', align: 'center', slot: 'set', fixed: 'right', width: '150' },
  124. ]
  125. } else {
  126. this.tableColums = [
  127. { title: '序号', type: 'index', align: 'center', key: '', fixed: 'left', width: '100' },
  128. { title: '材料分类名称', align: 'center', key: 'm_title', minWidth: 150 },
  129. { title: '物料名称', align: 'center', key: 'title', minWidth: 150 },
  130. { title: '单位', align: 'center', key: 'unit', minWidth: 100 },
  131. { title: '厚', align: 'center', key: 'high', minWidth: 100 },
  132. { title: '描述', align: 'center', key: 'remark', minWidth: 200 },
  133. { title: '操作', align: 'center', slot: 'set', fixed: 'right', width: '150' },
  134. ]
  135. }
  136. }
  137. },
  138. mounted () {
  139. },
  140. methods: {
  141. init (row) {
  142. this.pageIndex = 1
  143. row.page_index = this.pageIndex;
  144. row.page_size = this.pageSize;
  145. row.type_id = this.$route.query.id;
  146. this.proxyObj = row
  147. this.getData(row)
  148. },
  149. getData (row) {
  150. this.loading = true;
  151. this.axios('/api/material', { params: row }).then(res => {
  152. this.loading = false;
  153. this.tableData = res.data.data;
  154. this.total = res.data.total;
  155. })
  156. },
  157. changePage (e) {
  158. this.pageIndex = e;
  159. this.proxyObj.page_index = this.pageIndex;
  160. this.getData(this.proxyObj)
  161. },
  162. changeSize (e) {
  163. this.pageSize = e;
  164. this.proxyObj.page_size = this.pageSize;
  165. this.getData(this.proxyObj)
  166. },
  167. goDetial (n, row) {// n = 1 新增 2 编辑 3 查看
  168. let id = row ? row.id : ''
  169. this.$router.push({
  170. path: `/cms/materialmannage/edit`,
  171. query: {
  172. id: id,
  173. type: n,
  174. back_id: this.$route.query.id
  175. }
  176. })
  177. },
  178. delItems (row) {
  179. this.confirmDelete({
  180. content: '确认删除么?',
  181. then: () => {
  182. this.axios.post('/api/material', { id: row.id, state: 0, op: 'edit' }).then(res => {
  183. if (res.code == 200) {
  184. this.$Message.success(res.msg)
  185. this.getData(this.proxyObj)
  186. }
  187. })
  188. }
  189. })
  190. },
  191. async exportData () {
  192. const res = await this.axios('/api/material_export', { params: { ...this.proxyObj } })
  193. if (res.code == 200) {
  194. let url = `${this.$store.state.ip}/api/storage/${res.data.file}`
  195. location.href = url
  196. }
  197. },
  198. uploadSuccess (res) {
  199. if (res.code == 200) {
  200. this.$Message.success(res.msg || '上传成功')
  201. } else {
  202. this.$Message.warning(res.msg || '上传失败')
  203. }
  204. this.getData(this.proxyObj)
  205. },
  206. uploadError (err) {
  207. this.$Message.error(err || '上传失败')
  208. }
  209. }
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. </style>