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