index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. 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/process_route_index_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="handleAddProcessRequire"
  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,index}'>
  41. <div>
  42. <a style="margin:0 5px"
  43. @click="handleSet(row,index,1)">编辑</a>
  44. <a style="margin:0 5px;color:red"
  45. @click="handleSet(row,index,2)">删除</a>
  46. </div>
  47. </template>
  48. <Modal class-name="vertical-center-modal"
  49. :title="addPRInfo.PRId==''?'新增工艺要求':'编辑工艺要求'"
  50. v-model='showModal'
  51. :width="400">
  52. <div class="modal_div">
  53. <span>ID :</span> <Input v-model="addPRInfo.PRId"
  54. disabled
  55. placeholder="自动生成"
  56. style="width:200px" />
  57. </div>
  58. <div class="modal_div">
  59. <span>工艺要求 :</span> <Input v-model="addPRInfo.PRName"
  60. placeholder="请输入工艺要求"
  61. style="width:200px" />
  62. </div>
  63. <div class="modal-footer"
  64. slot="footer">
  65. <Button @click="showModal=false">取消</Button>
  66. <Button type="primary"
  67. @click="handlePRAddConfirm()">确认</Button>
  68. </div>
  69. </Modal>
  70. </FullPage>
  71. </div>
  72. </template>
  73. <script>
  74. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  75. // 例如:import 《组件名称》 from '《组件路径》';
  76. import { mapState } from 'vuex'
  77. export default {
  78. name: 'ProcessRequire',
  79. data () {
  80. // 这里存放数据
  81. return {
  82. list: [
  83. { title: '工艺要求', name: 'Input', value: '', serverName: 'title', placeholder: '请输入工艺要求' },
  84. ],
  85. tableColums: [
  86. { title: '序号', type: 'index', align: 'center', key: 'id', resizable:true,width: 200 },
  87. { title: '工艺要求', align: 'center', key: 'title', resizable:true,width: 1000 },
  88. { title: '操作', align: 'center', key: 'set', slot: 'set', fixed: 'right', minWidth: 80, fixed: 'right' },
  89. ],
  90. tableData: [],
  91. pageIndex: 1,
  92. total: 0,
  93. pageSize: 10,
  94. proxyObj: {},
  95. loading: false,
  96. headers: { 'Authorization': localStorage.getItem('token') },
  97. addPRInfo: {
  98. PRId: '',
  99. PRName: '',
  100. },
  101. showModal: false,
  102. }
  103. },
  104. // 生命周期 - 创建完成(可以访问当前this实例)
  105. created () {
  106. },
  107. // 生命周期 - 挂载完成(可以访问DOM元素)
  108. mounted () {
  109. },
  110. methods: {
  111. init (row) {
  112. this.pageIndex = 1;
  113. row.page_index = this.pageIndex
  114. row.page_size = this.pageSize;
  115. this.proxyObj = row
  116. this.getData(row)
  117. },
  118. getData (row) {
  119. this.loading = true;
  120. this.axios('/api/technological_requirement', { params: row }).then(res => {
  121. this.loading = false;
  122. // res.data.top.map(((v, i) => {
  123. // if (v.key == '颜色') { v.hover = 1 }
  124. // if (i == 0) {
  125. // v.fixed = 'left'
  126. // v.width = '100'
  127. // } else {
  128. // if (i == res.data.top.length - 1) {
  129. // v.fixed = 'right'
  130. // v.width = '150'
  131. // } else {
  132. // v.minWidth = 150
  133. // }
  134. // }
  135. // if (v.hover == 1) {
  136. // v.render = function (h, params) {
  137. // const { row } = params
  138. // return h('Tooltip', {
  139. // props: {
  140. // content: row[v.key],
  141. // placement: "top"
  142. // },
  143. // }, [
  144. // h('div', {
  145. // props: {},
  146. // style: {
  147. // width: '100px',
  148. // overflow: 'hidden',
  149. // whiteSpace: 'nowrap',
  150. // textOverflow: 'ellipsis'
  151. // }
  152. // }, row[v.key])
  153. // ])
  154. // }
  155. // }
  156. // }))
  157. this.tableData = res.data.data;
  158. this.total = res.data.total;
  159. })
  160. },
  161. changePage (e) {
  162. this.pageIndex = e;
  163. this.proxyObj.page_index = this.pageIndex;
  164. this.getData(this.proxyObj)
  165. },
  166. changeSize (e) {
  167. this.pageSize = e;
  168. this.proxyObj.page_size = this.pageSize;
  169. this.getData(this.proxyObj)
  170. },
  171. handleAddProcessRequire () {
  172. this.addPRInfo.PRId = ''
  173. this.addPRInfo.PRName = ''
  174. this.showModal = true
  175. },
  176. //1修改 2删除
  177. handleSet (row, index, type) {
  178. if (type == 1) {
  179. this.addPRInfo.PRId = row.id
  180. this.addPRInfo.PRName = row.title
  181. this.showModal = true
  182. } else if (type == 2) {
  183. //删除
  184. this.$Modal.confirm({
  185. title: '确认删除?',
  186. content: '此操作确认后不可恢复,请确认!',
  187. onOk: () => {
  188. this.axios({
  189. method: 'post',
  190. url: '/api/technological_requirement_del',
  191. data: {
  192. id: row.id
  193. }
  194. }).then((res) => {
  195. this.$Message.success(res.msg)
  196. this.getData(this.proxyObj)
  197. }).catch((err) => {
  198. });
  199. },
  200. onCancel: () => this.showModal = false
  201. })
  202. }
  203. },
  204. //新增
  205. handlePRAddConfirm () {
  206. let temp = {
  207. id: this.addPRInfo.PRId,
  208. title: this.addPRInfo.PRName
  209. }
  210. this.axios({
  211. method: 'post',
  212. url: '/api/technological_requirement_edit',
  213. data: temp
  214. }).then((res) => {
  215. this.$Message.success(res.msg)
  216. this.getData(this.proxyObj)
  217. this.showModal = false
  218. }).catch((err) => {
  219. });
  220. },
  221. async exportData () {
  222. const res = await this.axios('/api/process_require_export', { params: { ...this.proxyObj, page: 0 } })
  223. if (res.code == 200) {
  224. let url = `${this.$store.state.ip}/api/storage/${res.data.file}`
  225. location.href = url
  226. }
  227. },
  228. uploadSuccess (res) {
  229. if (res.code == 200) {
  230. this.$Message.success(res.msg || '上传成功')
  231. } else {
  232. this.$Message.warning(res.msg || '上传失败')
  233. }
  234. this.getData(this.proxyObj)
  235. },
  236. uploadError (err) {
  237. this.$Message.error(err.msg || '上传失败')
  238. }
  239. },
  240. // 监听属性 类似于data概念
  241. computed: {
  242. ...mapState(['persimissionData']),
  243. },
  244. // 监控data中的数据变化
  245. watch: {},
  246. beforeCreate () { }, // 生命周期 - 创建之前
  247. beforeMount () { }, // 生命周期 - 挂载之前
  248. beforeUpdate () { }, // 生命周期 - 更新之前
  249. updated () { }, // 生命周期 - 更新之后
  250. beforeDestroy () { }, // 生命周期 - 销毁之前
  251. destroyed () { }, // 生命周期 - 销毁完成
  252. activated () { }, // 如果页面有keep-alive缓存功能,这个函数会触发
  253. }
  254. </script>
  255. <style lang='scss' scoped>
  256. .modal_div {
  257. padding: 5px 20px;
  258. display: flex;
  259. justify-content: space-between;
  260. }
  261. </style>