listdemo.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div>
  3. <FullPage title='客户列表'
  4. :list='set_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/material_import'">
  22. <Button type="success"
  23. ghost
  24. icon='md-exit'
  25. style="margin-right:10px;">导入</Button>
  26. </Upload>
  27. <Button @click="handleSet({},-1,1)"
  28. type='primary'
  29. style="margin-right:10px;">新增</Button>
  30. </div>
  31. <template slot='set'
  32. slot-scope='{row,index}'>
  33. <div class="table-set">
  34. <a style="margin:0 5px"
  35. @click="handleSet(row,index,2)">编辑</a>
  36. <a style="margin:0 5px"
  37. @click="handleSet(row,index,3)">查看</a>
  38. <a style="margin:0 5px"
  39. @click="handleSet(row,index,4)">删除</a>
  40. </div>
  41. </template>
  42. </FullPage>
  43. </div>
  44. </template>
  45. <script>
  46. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  47. // 例如:import 《组件名称》 from '《组件路径》';
  48. export default {
  49. name: 'AdditionalProjectIndex',
  50. components: {
  51. },
  52. props: {},
  53. // import引入的组件需要注入到对象中才能使用
  54. data () {
  55. // 这里存放数据
  56. return {
  57. loading: false,
  58. tableData: [],
  59. page_index: 1,
  60. total: 0,
  61. page_size: 10,
  62. headers: { 'Authorization': localStorage.getItem('token') },
  63. proxyObj: {},
  64. tableColums: [
  65. { title: '序号', type: 'index', key: '', align: 'center', width: 80 },
  66. { title: '客户编码', key: 'code', align: 'center', tooltip: true, minWidth: 140 },
  67. { title: '客户名称', key: 'title', align: 'center', tooltip: true, minWidth: 140 },
  68. { title: '折扣率', key: 'fax', align: 'center', tooltip: true, minWidth: 140 },
  69. {
  70. title: '专营业务员', key: 'service_id', align: 'center', tooltip: true, minWidth: 140,
  71. render: (h, params) => {
  72. const { row } = params
  73. let text
  74. this.userList.forEach(element => {
  75. (element.id == row.service_id) && (text = element.nickname)
  76. });
  77. return h('span', {}, text)
  78. }
  79. },
  80. {
  81. title: '超标方案', key: 'plan_title', align: 'center', tooltip: true, minWidth: 140,
  82. // render: (h, params) => {
  83. // const { row } = params
  84. // let text
  85. // this.overStandardList.forEach(element => {
  86. // (element.id == row.overdraft_plan_id) && (text = element.title)
  87. // });
  88. // return h('span', {}, text)
  89. // }
  90. },
  91. // {
  92. // title: '是否启用', key: 'lock', align: 'center', tooltip: true, minWidth: 140,
  93. // render: (h, params) => {
  94. // return h('span', {}, params.row.lock ? '是' : '否')
  95. // }
  96. // },
  97. {
  98. title: '创建时间', key: 'crt_time', align: 'center', tooltip: true, minWidth: 140,
  99. render: (h, params) => {
  100. return h('span', {}, this.func.replaceDate(params.row.crt_time))
  101. }
  102. },
  103. { title: '操作', key: '', align: 'center', slot: 'set', width: 200 },
  104. ],
  105. tableData: [],
  106. type: null,
  107. userList: [],
  108. overStandardList: []
  109. }
  110. },
  111. // 生命周期 - 创建完成(可以访问当前this实例)
  112. created () {
  113. // 获取用户列表
  114. this.axios({ method: 'get', url: '/api/user', }).then((res) => { this.userList = res.data.data }).catch((err) => { });
  115. // 获取超标方案
  116. this.axios({ method: 'get', url: '/api/overdraft_list', }).then((res) => { this.overStandardList = res.data.data }).catch((err) => { });
  117. },
  118. // 生命周期 - 挂载完成(可以访问DOM元素)
  119. mounted () {
  120. },
  121. methods: {
  122. init (row) {
  123. this.proxyObj = row
  124. this.axios.get('/api/custom_list', {
  125. params: {
  126. page_index: this.page_index,
  127. page_size: this.page_size,
  128. ...row
  129. }
  130. }).then(res => {
  131. console.log(res)
  132. if (res.code == 200) {
  133. this.total = res.data.total
  134. this.tableData = res.data.data
  135. }
  136. }).catch(err => { console.error(err); })
  137. },
  138. searchData () {
  139. this.page_index = 1;
  140. this.init(this.proxyObj)
  141. },
  142. handleSet (row, index, type) {
  143. this.type = type
  144. // 1新增 2编辑 3查看 4删除
  145. switch (type) {
  146. case 1:
  147. case 2:
  148. case 3:
  149. this.$router.push({
  150. path: '/cms/BasicSettings/CustomerFiles/detail',
  151. query: {
  152. type,
  153. id: row.id,
  154. }
  155. })
  156. break;
  157. case 4:
  158. this.$Modal.confirm({
  159. title: '确认删除?',
  160. content: '此操作无法恢复,请确认!',
  161. onOk: () => {
  162. this.axios({
  163. method: 'post',
  164. url: '/api/custom_del',
  165. data: {
  166. id: row.id
  167. }
  168. }).then((res) => {
  169. this.$Message.success(res.msg)
  170. this.init(this.proxyObj)
  171. }).catch((err) => { });
  172. },
  173. onCancel: () => { }
  174. })
  175. break;
  176. default:
  177. break;
  178. }
  179. },
  180. changePage (e) {
  181. this.page_index = e;
  182. this.init(this.proxyObj)
  183. },
  184. changeSize (e) {
  185. this.page_size = e;
  186. this.init(this.proxyObj)
  187. },
  188. uploadSuccess (res) {
  189. if (res.code == 200) {
  190. this.$Message.success(res.msg || '上传成功')
  191. } else {
  192. this.$Message.warning(res.msg || '上传失败')
  193. }
  194. this.getData(this.proxyObj)
  195. },
  196. uploadError (err) {
  197. this.$Message.error(err.msg || '上传失败')
  198. },
  199. async exportData () {
  200. const res = await this.axios('/api/parts_classify_export', { params: { ...this.proxyObj } })
  201. if (res.code == 200) {
  202. let url = `${this.$store.state.ip}/api/storage/${res.data.file}`
  203. location.href = url
  204. }
  205. },
  206. },
  207. // 监听属性 类似于data概念
  208. computed: {
  209. set_list () {
  210. return [
  211. { title: '客户编码', name: 'Input', value: '', serverName: 'code', placeholder: '请输入客户编码' },
  212. { title: '客户名称', name: 'Input', value: '', serverName: 'title', placeholder: '请输入客户名称' },
  213. { title: '专营业务员', name: 'Select', value: '', placeholder: '请选择专营业务员', serverName: 'service_id', optionValue: 'id', optionName: 'nickname', option: this.userList },
  214. { title: '超标方案', name: 'Select', value: '', placeholder: '请选择超标方案', serverName: 'plan_id', optionValue: 'id', optionName: 'title', option: this.overStandardList },
  215. // { title: '是否启用', name: 'Select', value: '', placeholder: '请选择是否启用', serverName: 'lock', option: [{ label: '是', vlaue: 1 }, { label: '否', value: 0 }] },
  216. { title: '创建时间', start_server: 'start_time', end_server: 'end_time', start_value: '', end_value: '', isDate: true, start_placeholder: '开始日期', end_placeholder: '结束日期' },
  217. ]
  218. }
  219. },
  220. // 监控data中的数据变化
  221. watch: {},
  222. beforeCreate () { }, // 生命周期 - 创建之前
  223. beforeMount () { }, // 生命周期 - 挂载之前
  224. beforeUpdate () { }, // 生命周期 - 更新之前
  225. updated () { }, // 生命周期 - 更新之后
  226. beforeDestroy () { }, // 生命周期 - 销毁之前
  227. destroyed () { }, // 生命周期 - 销毁完成
  228. activated () { }, // 如果页面有keep-alive缓存功能,这个函数会触发
  229. }
  230. </script>
  231. <style lang='scss' scoped>
  232. </style>