mixin.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. import { CtableClass, WtableClass } from '@/utils/CtableClass'
  2. import { clone, Vuehttp } from '@/utils/tools'
  3. import {formatDate} from "@/utils/date"
  4. export const AddressMode = {
  5. data() {
  6. return {
  7. IslookOrUpdate: 'update',
  8. chooseItem: {}, // 当前已选择的对象
  9. currentPage: 1,
  10. swtichType: '公司地址'// 当前是公司地址还是收货地址
  11. }
  12. },
  13. computed: {
  14. headArr() {
  15. return ['联系人', '联系地址', '联系电话', '操作', '']
  16. },
  17. StyleWidth() {
  18. return [180, 524, 170, 164, 124]
  19. },
  20. controlArray() {
  21. return [['编辑', 'updateItem'],['删除', 'deteleItem']]
  22. },
  23. swtichText() {
  24. return ['公司地址', '仓储地址']
  25. },
  26. getServerOrclient() { //当前是客户中心还是服务商中心
  27. return this.$route.path.indexOf('clientPage') > -1 ? 'client' : 'server'
  28. },
  29. getHttpResource() {
  30. // 后台取回来的数据源
  31. return this.$store.state.address.Addresslist.data.content.content
  32. },
  33. totalElements() {
  34. return this.$store.state.address.Addresslist.data.content.totalElements
  35. },
  36. tableData() {
  37. return CtableClass(this.getHttpResource, ['name', ['地址','detailAddress','area'], 'telephone', '操作', ['设为默认', 'num']] )
  38. },
  39. getAddressType() {
  40. return this.getServerOrclient === 'client' ?
  41. (this.swtichType === '公司地址' ? 101 : 104) : (this.swtichType === '公司地址' ? 100 : 104)
  42. },
  43. AlertTitle() {
  44. return this.IslookOrUpdate === 'add' ? '新增公司地址' : (this.IslookOrUpdate === 'update' ? '修改公司地址' : '查看公司地址')
  45. }
  46. },
  47. methods: {
  48. deteleItem(index) {
  49. // 删除事件需要重新走 刷新数据的方法
  50. let item = clone(this.getHttpResource[index])
  51. this.$confirm('此操作将永久删除该条信息, 是否继续?', '提示', {
  52. confirmButtonText: '确定',
  53. cancelButtonText: '取消',
  54. type: 'warning'
  55. }).then(() => {
  56. this.$http.delete(`/common/address/id?id=${item.id}`).then(res => {
  57. if (res.data.code !== 1) {
  58. this.$message.error(res.data.message)
  59. } else {
  60. this.$message({
  61. message: '删除成功',
  62. type: 'success'
  63. })
  64. this.handleCurrentChange(1)
  65. }
  66. })
  67. }).catch(() => {
  68. });
  69. },
  70. updateItem(index) {
  71. this.IslookOrUpdate = 'update'
  72. this.chooseItem = clone(this.getHttpResource[index])
  73. this.$refs.addressAlert.show(this.chooseItem)
  74. },
  75. setAutoFn(index) {
  76. // 设置事件需要重新走 刷新数据的方法
  77. let id = this.getHttpResource[index].id
  78. Vuehttp({ id: id }, '/common/address/default').then(res => {
  79. if (res.data.code !== 1) {
  80. this.$message.error(res.data.message)
  81. } else {
  82. this.$message({
  83. message: '设置成功',
  84. type: 'success'
  85. })
  86. this.handleCurrentChange(1)
  87. }
  88. })
  89. },
  90. // 切换视图
  91. swtichClick(index) {
  92. this.swtichType = this.swtichText[index]
  93. this.handleCurrentChange(1)
  94. },
  95. addAddress() {
  96. this.IslookOrUpdate = 'add'
  97. this.chooseItem = {
  98. name: '',
  99. telephone: '',
  100. detailAddress: '',
  101. araa: '',
  102. num: 0
  103. }
  104. this.$refs.addressAlert.show(this.chooseItem)
  105. },
  106. clickTwo(index) {
  107. this.IslookOrUpdate = 'look'
  108. this.chooseItem = clone(this.getHttpResource[index])
  109. this.$refs.addressAlert.show(this.chooseItem)
  110. },
  111. handleCurrentChange(page) {
  112. this.currentPage = page
  113. this.$store.dispatch('address/getAddressList', {page: this.currentPage, count: 10, type: this.getAddressType})
  114. },
  115. // 关闭编辑查看弹窗
  116. closeAlert(_tp, item) {
  117. if (_tp === 'save') {
  118. let params
  119. let url = this.IslookOrUpdate === 'add' ? '/common/address/persist' : '/common/address/update'
  120. if (this.IslookOrUpdate === 'add') {
  121. params = {
  122. params: {
  123. area: item.area,
  124. telephone: item.telephone,
  125. name: item.name,
  126. detailAddress: item.detailAddress,
  127. },
  128. type: this.getAddressType,
  129. isDefault: item.num === 1
  130. }
  131. } else {
  132. params = {
  133. json: JSON.stringify(item),
  134. isDefault: item.num === 1
  135. }
  136. }
  137. Vuehttp(params,url).then(res => {
  138. if (res.data.code !== 1) {
  139. this.$message.error(res.data.message)
  140. } else {
  141. this.$refs.addressAlert.hide()
  142. this.handleCurrentChange(1)
  143. }
  144. })
  145. } else {
  146. this.$refs.addressAlert.hide()
  147. }
  148. }
  149. }
  150. }
  151. export const DocumentsMode = {
  152. layout: 'default',
  153. middleware: 'authenticated',
  154. data () {
  155. return {
  156. clickData: '',
  157. hasMultiple: true,
  158. selectData: [],
  159. isDialogTitle: false,
  160. dialogInfo: '',
  161. isDialog: false,
  162. pageParams: {
  163. page: 1,
  164. count: 10,
  165. },
  166. pickerOptions: {
  167. shortcuts: [{
  168. text: '最近一周',
  169. onClick(picker) {
  170. const end = new Date();
  171. const start = new Date();
  172. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  173. picker.$emit('pick', [start, end]);
  174. }
  175. }, {
  176. text: '最近一个月',
  177. onClick(picker) {
  178. const end = new Date();
  179. const start = new Date();
  180. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
  181. picker.$emit('pick', [start, end]);
  182. }
  183. }, {
  184. text: '最近三个月',
  185. onClick(picker) {
  186. const end = new Date();
  187. const start = new Date();
  188. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
  189. picker.$emit('pick', [start, end]);
  190. }
  191. }],
  192. disabledDate (time) {
  193. // 大于等于今天
  194. return time.getTime() >= Date.now()
  195. }
  196. },
  197. searchKey: '',
  198. dataTime: [],
  199. files: {},
  200. selectedArr: [] // 选中的数据
  201. }
  202. },
  203. computed: {
  204. thead () {
  205. return this.urlLink.route === 'clientPage' ? [
  206. {id: 'checkbox', name: '全选', width:60, type: 'string'},
  207. {id: 'csid', name: '系统编号', width:120, type: 'string'},
  208. {id: 'applyTime', name: '报关日期', width:165, type: 'date'},
  209. {id: 'commissionCompany', name: '委托公司', width:142, type: 'string'},
  210. {id: 'status', name: '状态', width:80, type: 'string'},
  211. {id: 'csid1', name: '进出口岸', width:95, type: 'string'},
  212. {id: 'totalAmount', name: '总件数', width:105, type: 'string'},
  213. {id: 'totalGrossWeight', name: '总毛重', width:98, type: 'string'},
  214. {id: 'currency', name: '币种', width:70, type: 'string'},
  215. {id: 'totalPrice', name: '总金额', width:106, type: 'string'},
  216. {id: 'csid2', name: '对账', width:115, type: 'string'}] : [
  217. {id: 'checkbox', name: '全选', width:60, type: 'string'},
  218. {id: 'csid', name: '系统编号', width:120, type: 'string'},
  219. {id: 'applyTime', name: '报关日期', width:165, type: 'date'},
  220. {id: 'commissionCompanySimplify', name: '委托公司', width:142, type: 'string'},
  221. {id: 'status', name: '状态', width:80, type: 'string'},
  222. {id: 'csid1', name: '进出口岸', width:95, type: 'string'},
  223. {id: 'totalAmount', name: '总件数', width:105, type: 'string'},
  224. {id: 'totalGrossWeight', name: '总毛重', width:98, type: 'string'},
  225. {id: 'currency', name: '币种', width:70, type: 'string'},
  226. {id: 'totalPrice', name: '总金额', width:106, type: 'string'},
  227. {id: 'csid2', name: '对账', width:115, type: 'string'}]
  228. },
  229. sheetList () {
  230. return this.urlLink.route === 'clientPage' ? this.$store.state.clientSheet.list.data.content : this.$store.state.severSheet.list.data.content
  231. },
  232. data () {
  233. return WtableClass(JSON.parse(JSON.stringify(this.sheetList.content)), this.thead)
  234. },
  235. urlLink () {
  236. if (this.$route.path.indexOf('clientPage') > -1) {
  237. return {getData: 'loadClientSheetInfo', route: 'clientPage'}
  238. } else {
  239. return {getData: 'loadSeverSheetInfo', route: 'severPage'}
  240. }
  241. },
  242. selectId () {
  243. let ids = []
  244. this.selectData.forEach((value) => {
  245. ids.push(value.id)
  246. })
  247. return ids ? ids.join('-') : ''
  248. }
  249. },
  250. methods: {
  251. // 时间格式化
  252. formatDate (type) {
  253. return formatDate(new Date(type), 'yyyy-MM-dd hh:mm:ss')
  254. },
  255. // 添加文件
  256. upload (e, type) {
  257. this.files[type] = e
  258. },
  259. // 删除选择文件
  260. closeFile (e, type) {
  261. delete this.files[type]
  262. },
  263. // 分页调整数据
  264. pageEvent (type) {
  265. this.pageParams.page = type
  266. let params = {}
  267. params.page = type
  268. params.count = this.pageParams.count
  269. if (this.searchKey) {
  270. params.keyword = this.searchKey
  271. }
  272. if (this.dataTime) {
  273. params.startTime = this.dataTime[0]
  274. params.endTime = this.dataTime[1]
  275. }
  276. this.$store.dispatch(this.urlLink.getData, params)
  277. },
  278. // 搜索
  279. searchClick () {
  280. this.pageEvent(1)
  281. },
  282. // 表格选中数据
  283. clickEvent (type) {
  284. this.clickData = type
  285. },
  286. // 表格选中是否有多选
  287. multipleEvent (type, list) {
  288. this.hasMultiple = type
  289. this.selectData = list
  290. if (this.urlLink.route !== 'clientPage') {
  291. this.selectedArr = list
  292. }
  293. },
  294. // 新增
  295. addEvent () {
  296. this.$router.push('/' + this.urlLink.route +'/entrustApply')
  297. },
  298. // 编辑
  299. editEvent () {
  300. if (this.hasMultiple) {
  301. this.$message({
  302. message: '请选择一条信息!',
  303. type: 'error'
  304. })
  305. } else {
  306. this.$router.push('/' + this.urlLink.route +'/entrustApply?id=' + this.clickData.id)
  307. }
  308. },
  309. //导入事件
  310. importClick () {
  311. this.isDialog = true
  312. this.dialogInfo = '导入'
  313. },
  314. // 供应商导入事件
  315. materialImportClick () {
  316. if (this.selectData.length === 0) {
  317. this.$message({
  318. message: '至少选择一条信息!',
  319. type: 'error'
  320. })
  321. } else {
  322. this.isDialog = true
  323. this.dialogInfo = '供应商导入'
  324. }
  325. },
  326. // 导入文件保存
  327. saveEvent () {
  328. if (this.dialogInfo === '导入') {
  329. this.bomSave()
  330. }
  331. if (this.dialogInfo === '供应商导入') {
  332. this.materialImport()
  333. }
  334. },
  335. // 确认弹窗的关闭
  336. closeTitle () {
  337. this.isDialogTitle = false
  338. this.dialogInfo = ''
  339. },
  340. // 确认弹窗确认操作
  341. enterInfo () {
  342. if (this.dialogInfo === '删除') {
  343. this.deleteEvent()
  344. } else if (this.dialogInfo === '作废') {
  345. this.cancellationEvent()
  346. }
  347. },
  348. // 删除点击弹窗
  349. deleteClick () {
  350. if (this.selectData.length === 0) {
  351. this.$message({
  352. message: '至少选择一条信息!',
  353. type: 'error'
  354. })
  355. } else {
  356. this.isDialogTitle = true
  357. this.dialogInfo = '删除'
  358. }
  359. },
  360. // 删除处理事件
  361. deleteEvent () {
  362. let params = new FormData()
  363. params.append('ids', this.selectId)
  364. let config = {
  365. headers: {'Content-Type': 'multipart/form-data'}
  366. }
  367. this.$http.post('/CommissionSheet/delete', params, config)
  368. .then(res => {
  369. this.closeTitle()
  370. if (res.data.success) {
  371. this.$message({
  372. message: res.data.message,
  373. type: 'success'
  374. })
  375. this.searchClick()
  376. } else {
  377. this.$message({
  378. message: res.data.message,
  379. type: 'error'
  380. })
  381. }
  382. })
  383. },
  384. // 查看
  385. lookEvent () {
  386. if (this.hasMultiple) {
  387. this.$message({
  388. message: '请选择一条信息!',
  389. type: 'error'
  390. })
  391. } else {
  392. this.lookEventDbl(this.clickData)
  393. }
  394. },
  395. // 作废点击弹窗
  396. cancellationClick () {
  397. if (this.selectData.length === 0) {
  398. this.$message({
  399. message: '至少选择一条信息!',
  400. type: 'error'
  401. })
  402. } else {
  403. this.isDialogTitle = true
  404. this.dialogInfo = '作废'
  405. }
  406. },
  407. // 作废
  408. cancellationEvent () {
  409. let params = new FormData()
  410. params.append('ids', this.selectId)
  411. let config = {
  412. headers: {'Content-Type': 'multipart/form-data'}
  413. }
  414. this.$http.post('/CommissionSheet/abandoned', params, config)
  415. .then(res => {
  416. this.closeTitle()
  417. if (res.data.success) {
  418. this.$message({
  419. message: res.data.message,
  420. type: 'success'
  421. })
  422. this.searchClick()
  423. } else {
  424. this.$message({
  425. message: res.data.message,
  426. type: 'error'
  427. })
  428. }
  429. })
  430. },
  431. // 导出委托单
  432. exportEntrust () {
  433. if (this.selectData.length === 0) {
  434. this.$message({
  435. message: '至少选择一条信息!',
  436. type: 'error'
  437. })
  438. } else {
  439. window.location.href = '/CommissionSheet/batchDown?ids=' + this.selectId
  440. }
  441. },
  442. // 复制
  443. copyEvent () {
  444. if (this.selectData.length === 0) {
  445. this.$message({
  446. message: '至少选择一条信息!',
  447. type: 'error'
  448. })
  449. } else {
  450. let params = new FormData()
  451. params.append('ids', this.selectId)
  452. let config = {
  453. headers: {'Content-Type': 'multipart/form-data'}
  454. }
  455. this.$http.post('/CommissionSheet/copy', params, config)
  456. .then(res => {
  457. if (res.data.success) {
  458. this.$message({
  459. message: '复制信息成功!',
  460. type: 'success'
  461. })
  462. this.searchClick()
  463. } else {
  464. this.$message({
  465. message: res.data.message,
  466. type: 'error'
  467. })
  468. }
  469. })
  470. }
  471. },
  472. // 供应商资料导入
  473. materialImport () {
  474. let params = new FormData()
  475. params.append('ids', this.selectId)
  476. for (let i in this.files) {
  477. if (i !== 'sheet') {
  478. params.append(i, this.files[i])
  479. }
  480. }
  481. let config = {
  482. headers: {'Content-Type': 'multipart/form-data'}
  483. }
  484. this.$http.post('/CommissionSheet/facilitator/upload', params, config)
  485. .then(res => {
  486. if (res.data.success) {
  487. this.isDialog = false
  488. this.$message({
  489. message: '供应商资料导入成功!',
  490. type: 'success'
  491. })
  492. this.searchClick()
  493. } else {
  494. this.$message({
  495. message: res.data.message,
  496. type: 'error'
  497. })
  498. }
  499. })
  500. .catch(()=> {
  501. this.$message({
  502. message: '请检查网络是否正常!',
  503. type: 'error'
  504. })
  505. })
  506. },
  507. // 表格双击事件
  508. lookEventDbl (type) {
  509. this.$router.push('/' + this.urlLink.route +'/' + type.id)
  510. },
  511. // 下载模板信息
  512. downBom () {
  513. window.location.href = '/CommissionSheet/template'
  514. },
  515. // 清除选中文件
  516. closeFile (e, type) {
  517. delete this.files[type]
  518. },
  519. // bom取消
  520. closebom () {
  521. this.isDialog = false
  522. this.dialogInfo = ''
  523. if (this.$refs.sheetUpload) {
  524. this.$refs.sheetUpload.closeClick()
  525. }
  526. this.$refs.contactUpload.closeClick()
  527. this.$refs.billUpload.closeClick()
  528. this.$refs.packagelistUpload.closeClick()
  529. },
  530. // bom表单文件导入
  531. bomSave () {
  532. if (!this.files.sheet) {
  533. this.$message({
  534. message: '委托报关单为必选择项,请选择文件!',
  535. type: 'error'
  536. })
  537. } else {
  538. let params = new FormData()
  539. for (let i in this.files) {
  540. params.append(i, this.files[i])
  541. }
  542. let config = {
  543. headers: {'Content-Type': 'multipart/form-data'}
  544. }
  545. let _this = this
  546. this.$http.post('/CommissionSheet/upload', params, config)
  547. .then(res => {
  548. if (res.data.code === 1) {
  549. this.isDialog = false
  550. this.$message({
  551. message: '信息保存成功!',
  552. type: 'success'
  553. })
  554. this.$store.dispatch(this.urlLink.getData, {count: 10, page: 1})
  555. } else if (res.data.code === 4) {
  556. this.$message({
  557. message: '信息保存成功,但信息不符合逻辑,需要再次修改!',
  558. type: 'error'
  559. })
  560. setTimeout(() => {
  561. _this.$router.push('/' + this.urlLink.route + '/entrustApply?id=' + res.data.content.id)
  562. }, 300)
  563. } else {
  564. this.$message({
  565. message: res.data.message,
  566. type: 'error'
  567. })
  568. }
  569. })
  570. .catch(() => {
  571. this.$message({
  572. message: '请检查网络是否正常!',
  573. type: 'error'
  574. })
  575. })
  576. }
  577. }
  578. }
  579. }