index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <div>
  3. <FullPage title='附加项目档案列表'
  4. :list='list'
  5. @init='init'
  6. :loading='loading'
  7. @searchData='searchData'
  8. @changePage='changePage'
  9. @changeSize='changeSize'
  10. :tableColums='tableColums'
  11. :tableData='tableData'
  12. :page_index='page_index'
  13. :total='total'>
  14. <div slot='titleButton'>
  15. <Upload style="display:inline"
  16. 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/parts_classify'">
  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="handleSet({},-1,1)"
  33. type='primary'
  34. style="margin-right:10px;">新增</Button>
  35. </div>
  36. <template slot='set'
  37. slot-scope='{row,index}'>
  38. <div class="table-set">
  39. <a style="margin:0 5px"
  40. @click="handleSet(row,index,2)">编辑</a>
  41. <!-- <a style="margin:0 5px"
  42. @click="handleSet(row,index,3)">查看</a> -->
  43. <a style="margin:0 5px"
  44. @click="handleSet(row,index,4)">删除</a>
  45. </div>
  46. </template>
  47. </FullPage>
  48. <Modal v-model="showModal"
  49. :title="type==1?'新增附加项目':type==2?'编辑附加项目':'查看附加项目'"
  50. @on-ok="handleFormConfirm"
  51. @on-cancel="showModal = false">
  52. <Form ref="editForm"
  53. :label-width="150"
  54. :model="editForm">
  55. <FormItem label='ID:'>
  56. <Input type="text"
  57. style="width:250px"
  58. readonly
  59. v-model="editForm.id"
  60. placeholder="自动生成">
  61. </Input>
  62. </FormItem>
  63. <FormItem label="附加项目名称:">
  64. <Input type="text"
  65. style="width:250px"
  66. v-model="editForm.title"
  67. placeholder="请输入附加项目名称">
  68. </Input>
  69. </FormItem>
  70. <FormItem label="数量:">
  71. <Input type="text"
  72. style="width:250px"
  73. v-model="editForm.num"
  74. placeholder="请输入数量">
  75. </Input>
  76. </FormItem>
  77. <FormItem label="单价:">
  78. <Input type="text"
  79. style="width:250px"
  80. v-model="editForm.price"
  81. placeholder="请输入单价">
  82. </Input>
  83. </FormItem>
  84. </Form>
  85. </Modal>
  86. </div>
  87. </template>
  88. <script>
  89. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  90. // 例如:import 《组件名称》 from '《组件路径》';
  91. export default {
  92. name: 'AdditionalProjectIndex',
  93. components: {
  94. },
  95. props: {},
  96. // import引入的组件需要注入到对象中才能使用
  97. data () {
  98. // 这里存放数据
  99. return {
  100. list: [
  101. { title: '附加项目名称', name: 'Input', value: '', serverName: 'title', placeholder: '请输入附加项目名称' },
  102. ],
  103. loading: false,
  104. headers: { 'Authorization': localStorage.getItem('token') },
  105. tableData: [],
  106. page_index: 1,
  107. total: 0,
  108. page_size: 10,
  109. proxyObj: {},
  110. tableColums: [
  111. { title: '序号', type: 'index', key: '', align: 'center', width: 80 },
  112. { title: '附加项目名称', key: 'title', align: 'center', tooltip: true, minWidth: 140 },
  113. { title: '数量', key: 'num', align: 'center', tooltip: true, minWidth: 140 },
  114. { title: '单价', key: 'price', align: 'center', tooltip: true, minWidth: 140 },
  115. { title: '操作', key: '', align: 'center', slot: 'set', width: 200 },
  116. ],
  117. tableData: [],
  118. type: null,
  119. showModal: false,
  120. editForm: {},
  121. }
  122. },
  123. // 生命周期 - 创建完成(可以访问当前this实例)
  124. created () {
  125. },
  126. // 生命周期 - 挂载完成(可以访问DOM元素)
  127. mounted () {
  128. },
  129. methods: {
  130. init (row) {
  131. this.proxyObj = row
  132. this.axios.get('/api/project_ext_list', {
  133. params: {
  134. page_index: this.page_index,
  135. page_size: this.page_size,
  136. ...row
  137. }
  138. }).then(res => {
  139. if (res.code == 200) {
  140. this.total = res.data.total
  141. this.tableData = res.data.data
  142. }
  143. }).catch(err => { console.error(err); })
  144. },
  145. searchData (row) {
  146. this.page_index = 1;
  147. this.init(row)
  148. },
  149. handleFormConfirm () {
  150. this.axios({
  151. method: 'post',
  152. url: '/api/project_ext_edit',
  153. data: {
  154. ...this.editForm
  155. }
  156. }).then((res) => {
  157. this.$Message.success(res.msg)
  158. this.init(this.proxyObj)
  159. this.editForm = { id: null, title: null, num: null, price: null }
  160. }).catch((err) => { });
  161. },
  162. handleSet (row, index, type) {
  163. this.type = type
  164. this.editForm = JSON.parse(JSON.stringify(row))
  165. // 1新增 2编辑 3查看 4删除
  166. switch (type) {
  167. case 1:
  168. case 2:
  169. this.showModal = true
  170. break;
  171. case 3:
  172. break;
  173. case 4:
  174. this.$Modal.confirm({
  175. title: '确认删除?',
  176. content: '此操作无法恢复,请确认!',
  177. onOk: () => {
  178. this.axios({
  179. method: 'post',
  180. url: '/api/project_ext_del',
  181. data: {
  182. id: row.id
  183. }
  184. }).then((res) => {
  185. this.$Message.success(res.msg)
  186. this.init(this.proxyObj)
  187. }).catch((err) => { });
  188. },
  189. onCancel: () => { }
  190. })
  191. break;
  192. default:
  193. break;
  194. }
  195. },
  196. changePage (e) {
  197. this.page_index = e;
  198. this.init(this.proxyObj)
  199. },
  200. changeSize (e) {
  201. this.page_size = e;
  202. this.init(this.proxyObj)
  203. },
  204. uploadSuccess (res) {
  205. if (res.code == 200) {
  206. this.$Message.success(res.msg || '上传成功')
  207. } else {
  208. this.$Message.warning(res.msg || '上传失败')
  209. }
  210. this.getData(this.proxyObj)
  211. },
  212. uploadError (err) {
  213. this.$Message.error(err.msg || '上传失败')
  214. },
  215. async exportData () {
  216. const res = await this.axios('/api/project_ext_export')
  217. if (res.code == 200) {
  218. let url = `${this.$store.state.ip}/api/storage/${res.data.file}`
  219. location.href = url
  220. }
  221. },
  222. },
  223. // 监听属性 类似于data概念
  224. computed: {},
  225. // 监控data中的数据变化
  226. watch: {},
  227. beforeCreate () { }, // 生命周期 - 创建之前
  228. beforeMount () { }, // 生命周期 - 挂载之前
  229. beforeUpdate () { }, // 生命周期 - 更新之前
  230. updated () { }, // 生命周期 - 更新之后
  231. beforeDestroy () { }, // 生命周期 - 销毁之前
  232. destroyed () { }, // 生命周期 - 销毁完成
  233. activated () { }, // 如果页面有keep-alive缓存功能,这个函数会触发
  234. }
  235. </script>
  236. <style lang='scss' scoped>
  237. </style>