Commit 3d979067 authored by daywrite's avatar daywrite

费用报销新建编辑成功

parent 22065a4e
import ScheduleApi from './apis/schedule.js'
import ReimburrsementApi from './apis/reimbursement.js'
const usingJSONP = process.env.NODE_ENV !== 'production'
const API_HOST = process.env.API_HOST
const API_PORT = process.env.API_PORT
const JANUS_HOST = process.env.JANUS_HOST
const JANUS_PORT = process.env.JANUS_PORT
const option = {
tokenKey: '__token__',
sessionExpiredCode: 401,
loginUrl: '/logout.php',
host: API_HOST,
port: API_PORT,
hostJanus: JANUS_HOST,
portJanus: JANUS_PORT,
baseUrl: '',
ajax: {
method: usingJSONP ? 'GET' : 'POST',
dataType: 'json',
getQuery: usingJSONP ? '?duplextrans' : '',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8'
}
}
let apis = {}
apis = Object.assign(apis, ScheduleApi)
apis = Object.assign(apis, ReimburrsementApi)
export default {
option,
...apis
}
......@@ -16,5 +16,8 @@ export default {
},
saveEditReim: {
url: '/vue/reimbursement/save-edit'
},
deleteReim: {
url: '/vue/reimbursement/delete'
}
}
......@@ -20,6 +20,8 @@
size="small"
v-model="model.occurrence_at"
type="datetime"
value-format="yyyy-MM-dd HH:mm:ss"
@change="occurrenceAtChange"
placeholder="选择日期时间">
</el-date-picker>
</el-form-item>
......@@ -28,6 +30,8 @@
size="small"
v-model="model.settle_accounts_at"
type="datetime"
value-format="yyyy-MM-dd HH:mm:ss"
@change="settleAccountsAtChange"
placeholder="选择日期时间">
</el-date-picker>
</el-form-item>
......@@ -147,6 +151,14 @@ export default {
},
methods: {
occurrenceAtChange (val) {
this.model.occurrence_at = val
},
settleAccountsAtChange (val) {
this.model.settle_accounts_at = val
},
getProjectArray (id) {
requestAPI(api.searchProjectByClientId, {
client_id: id
......
......@@ -38,6 +38,7 @@ export default {
client_name: '', // 客户
form_reimbursementVerifyRels: [],
form_reimbursementCarbonCopyRels: [],
settle_accounts_by: '',
description: '',
project_id: '',
attachmentFiles: []
......@@ -47,7 +48,15 @@ export default {
methods: {
show (model) {
model && UTIL.flatten(this.model, model)
if (model) {
UTIL.flatten(this.model, model)
this.model.form_type = model.type.id
this.model.form_costType = model.costType.id
this.model.client_name = model.client.name
this.model.form_reimbursementVerifyRels = model.reimbursementVerifyRels.map(item => item.user_id)
this.model.form_reimbursementCarbonCopyRels = model.reimbursementCarbonCopyRels.map(item => item.user_id)
this.model.settle_accounts_by = model.settleAccountsBy.id
}
this.$refs.sidePopup.show()
},
......@@ -69,7 +78,7 @@ export default {
console.log(_params)
requestAPI(Object.assign(_apiUrl, { method: 'POST' }), _params)
.then((res) => {
this.$refs.scheduleSidePopup.close()
this.$refs.sidePopup.close()
this.$message.success('操作成功')
})
}
......
......@@ -167,6 +167,14 @@ export default {
this.getFilter()
},
_reload () {
let params = this.setParams({
...this.form,
page: this.pagenation.thispage
}, {})
this.getList(params)
},
timeSearchForm (search) {
let params = this.setParams({
...this.form,
......@@ -230,8 +238,9 @@ export default {
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
requestAPI(api.deleteSchedule, { id })
requestAPI(api.deleteReim, { id })
.then((res) => {
this._reload()
this.$message.success('删除成功')
})
}).catch(() => {
......
// request
export { requestAPI, requestWithJsonAPI } from '../ajax'
export { requestOAPI } from './request'
export { requestJanusAPI } from '../ajax-janus'
export { default as api } from '@/api'
export { default as UTIL } from './util'
import api from '../api'
import api from '../api_old'
import $ from 'jquery'
import Cookie from 'browser-cookie'
// import Cookie from 'browser-cookie'
let globalOpt = api.option
const SESSION_EXPIRED_CODE = globalOpt.sessionExpiredCode
const SUCCESS_CODE = 200
const SUCCESS_CODE = 2000
const HTTP_PROTOCOL = /^http[s]?:\/\//
// const usingJSONP = false
const usingJSONP = process.env.NODE_ENV !== 'production'
function normalizeUrl (url, query, option) {
if (HTTP_PROTOCOL.test(url)) return url
......@@ -23,7 +24,6 @@ function normalizeUrl (url, query, option) {
fullUrl += url
if (Object.keys(query).length > 0) {
fullUrl += '?' + $.param(query)
console.log(fullUrl)
}
return fullUrl
......@@ -32,6 +32,7 @@ function normalizeUrl (url, query, option) {
function mergeAjaxOption (...options) {
let option1 = options.shift()
let option2 = options.shift()
console.log(option1, option2)
let query = {...option1.query, ...option2.query}
let data = {...option1.data, ...option2.data}
let headers = {...option1.headers, ...option2.headers}
......@@ -62,13 +63,13 @@ export function request (option) {
resolve(res.result)
} else {
// 如果不执行 reject,可能加载中动画不被关闭
reject(res.result, xhr, null)
reject(res, xhr, null)
if (res.msg) {
// 先让界面变化
setTimeout(function () {
window.alert(res.msg)
}, 300)
// setTimeout(function () {
// window.alert(res.msg)
// }, 300)
}
}
}, function (xhr, status, error) {
......@@ -93,13 +94,13 @@ export function request (option) {
})
}
function getTokenFromCookie () {
let cookie = new Cookie()
return cookie.get('vup_token')
}
// function getTokenFromCookie () {
// let cookie = new Cookie()
// return cookie.get('vup_token')
// }
let isSessionExpired = false
export function requestAPI (api, option = {}) {
export function requestOAPI (api, option = {}) {
// 第一个请求会放过期提示用户登录后,避免之后的其他请求再次弹消息
if (isSessionExpired) {
window.location.href = globalOpt.loginUrl
......@@ -107,7 +108,13 @@ export function requestAPI (api, option = {}) {
resolve({})
})
}
let setUrlK = (ojson) => {
let params = ''
Object.keys(ojson).forEach(item => {
params += '&' + encodeURIComponent(item) + '=' + ojson[item]
})
return params
}
// merge option
let ajaxOption = mergeAjaxOption(
globalOpt.ajax, // global
......@@ -116,11 +123,17 @@ export function requestAPI (api, option = {}) {
)
ajaxOption.url = normalizeUrl(ajaxOption.url, ajaxOption.query, globalOpt)
delete ajaxOption.query
if (usingJSONP) {
ajaxOption.url = ajaxOption.url + ajaxOption.getQuery
if (ajaxOption.data) {
ajaxOption.url += setUrlK(ajaxOption.data)
delete ajaxOption.data
}
}
// ajaxOption.contentType = 'application/json'
// ajaxOption.dataType = 'json'
// ajaxOption.data = JSON.stringify(ajaxOption.data)
ajaxOption.data = {data: JSON.stringify(ajaxOption.data)}
// ajaxOption.data = {data: JSON.stringify(ajaxOption.data)}
// stringify object member of data
let data = ajaxOption.data
......@@ -132,20 +145,20 @@ export function requestAPI (api, option = {}) {
}
// check is session expired
let token = getTokenFromCookie()
if (!token && process.env.NODE_ENV === 'production') {
console.info('token expired')
isSessionExpired = true
window.alert('登录超时,请重新登录!')
window.location.href = globalOpt.loginUrl
return new Promise(function (resolve, reject) {
resolve({})
})
}
// let token = getTokenFromCookie()
// if (!token && process.env.NODE_ENV === 'production') {
// console.info('token expired')
// isSessionExpired = true
// window.alert('登录超时,请重新登录!')
// window.location.href = globalOpt.loginUrl
// return new Promise(function (resolve, reject) {
// resolve({})
// })
// }
// append token to header
let headers = ajaxOption.headers || (ajaxOption.headers = {})
headers['X-Token'] = token
// let headers = ajaxOption.headers || (ajaxOption.headers = {})
// headers['X-Token'] = token
return request(ajaxOption)
}
......@@ -21,12 +21,24 @@ export function removeEmptyMemberArray (arr) {
})
return newArr
}
export let setModule = (obj, key) => {
export let setModule = (obj, key, options) => {
let ob = {}
console.log(options)
Object.keys(obj).forEach((item) => {
// ob[key + '[' + item + ']'] = obj[item]
if (Array.isArray(obj[item])) {
ob[key + '[' + item + ']'] = obj[item]
let opt = options && options.find(i => key + '[' + item + ']' === i.key)
console.log(opt)
obj[item].forEach((arr, index) => {
if (arr.key) {
if (arr.key === 'new') {
ob[key + '[' + item + '][' + arr.key + '][]'] = arr.name
} else {
ob[key + '[' + item + '][' + arr.key + ']'] = arr.name
}
} else {
ob[key + '[' + item + '][' + index + ']'] = arr
}
})
} else {
ob[key + '[' + item + ']'] = obj[item]
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment