Commit b41bb96d authored by huai.li's avatar huai.li

修改留言模块请求方式

parent 55179ae6
......@@ -7,11 +7,7 @@ let config = {
ajaxOption: {
method: dev ? 'GET' : 'POST',
dataType: 'json',
contentType: 'application/json'
// xhrFields: {
// withCredentials: true
// }
// contentType: 'application/x-www-form-urlencoded; charset=UTF-8'
contentType: 'application/x-www-form-urlencoded; charset=UTF-8'
},
token: {
......@@ -47,12 +43,12 @@ let setUrlK = (o) => {
})
return params
}
export function requestAPI (option, data) {
// let params = { data: JSON.stringify(data) }
return ajax.requestAPI(option, data)
}
// export function requestAPI (option, data) {
// let params = { data: JSON.stringify(data) }
// return ajax.requestAPI(option, params)
// }
export function requestWithJsonAPI (option, data) {
export function requestAPI (option, data) {
let _option = Object.assign({}, option)
if (dev && data) {
_option.url += setUrlK(data)
......
......@@ -39,20 +39,20 @@
<div class="commentText">
<div class="comment-title">
{{ item.created_by }} {{ item.created_at }}
<a href="#" class="addcomment">
<a href="#" class="addcomment" @click.prevent="showSecondText(item.id.toString())">
<i class="fa fa-fw fa-commenting-o pull-right"></i>
</a>
<a href="#" class="removecomment">
<a href="#" class="removecomment" @click.prevent="del(item.id)">
<i class="fa fa-fw fa-trash-o pull-right"></i>
</a>
</div>
<div class="date sub-text">
{{ item.description }}
<form class="form-inline form-comment" role="form">
<form class="form-inline form-comment" role="form" v-show="secondTextBool[item.id.toString()]">
<div class="input-group">
<input type="text" class="form-control form-control-sm comment-input" placeholder="">
<input type="text" v-model="secondArrayText[item.id.toString()]" class="form-control form-control-sm comment-input" placeholder="">
<span class="input-group-btn">
<el-button size="mini" @click.prevent="send">回复</el-button>
<el-button size="mini" @click.prevent="recover(item.id)">回复</el-button>
</span>
</div>
</form>
......@@ -65,8 +65,8 @@
<div class="commentText">
<div class="comment-title">
{{ sItem.created_by }} {{ sItem.created_at }}
<a href="#" class="addcomment">
<i class="fa fa-fw fa-commenting-o pull-right"></i>
<a href="#" class="removecomment" @click.prevent="del(sItem.id)">
<i class="fa fa-fw fa-trash-o pull-right"></i>
</a>
</div>
<div class="date sub-text">
......@@ -87,21 +87,25 @@
</template>
<script>
import {
requestWithJsonAPI,
requestAPI,
api
} from '@/lib/commonMixin'
import { setModule } from '@/lib/viewHelper'
export default {
data () {
return {
is: false,
sendText: '',
secondTextBool: {},
secondArrayText: {},
model: {},
result: {}
}
},
props: {
lmTemplate: Array
lmTemplate: Array,
type: Number
},
mounted () {
......@@ -120,29 +124,70 @@ export default {
}
},
showSecondText (id) {
Object.keys(this.secondTextBool).forEach(item => {
this.secondTextBool[item] = false
})
this.secondTextBool[id] = true
},
send () {
requestWithJsonAPI(api.saveNewComment)
if (this.sendText.trim() === '') {
this.$message.warning('请输入留言')
return
}
let params = {}
params.object_id = this.model.id
params.object_type = this.type
params.description = this.sendText
let _params = Object.assign({}, setModule(params, 'Comments'))
requestAPI(api.saveNewComment, _params)
.then((res) => {
this.sendText = ''
this.init()
})
},
recover (id) {
if (this.secondArrayText[id.toString()].trim() === '') {
this.$message.warning('请输入留言')
return
}
let params = {}
params.object_id = this.model.id
params.object_type = this.type
params.description = this.secondArrayText[id.toString()].trim()
params.parent = id
let _params = Object.assign({}, setModule(params, 'Comments'))
requestAPI(api.saveNewComment, _params)
.then((res) => {
console.log(res)
this.secondTextBool = {}
this.secondArrayText = {}
this.init()
})
},
del () {
requestWithJsonAPI(api.deleteComment)
del (id) {
let params = { id }
requestAPI(api.deleteComment, params)
.then((res) => {
console.log(res)
this.init()
})
},
init () {
let vm = this
let params = {
object_type: 9,
object_id: 7578
object_type: this.type,
object_id: this.model.id
}
requestWithJsonAPI(api.getCommentList, params)
requestAPI(api.getCommentList, params)
.then((res) => {
res.list.forEach(item => {
vm.$set(this.secondTextBool, item.id.toString(), false)
vm.$set(this.secondArrayText, item.id.toString(), '')
})
this.result = res
console.log(res)
})
}
}
......
......@@ -32,7 +32,8 @@
</Pagenation>
<leave-message
ref="leaveMessage"
:lmTemplate="lmTemplate">
:lmTemplate="lmTemplate"
:type="9">
</leave-message>
</div>
</div>
......@@ -48,7 +49,7 @@ import ScheduleModal from '../schedule/scheduleModal'
import LeaveMessage from '../common/leaveMessage'
import Pagenation from './schedulePagenation'
import {
requestWithJsonAPI,
requestAPI,
api
} from '@/lib/commonMixin'
export default {
......@@ -141,7 +142,7 @@ export default {
},
getFilter () {
requestWithJsonAPI(api.getScheduleFilter).then(res => {
requestAPI(api.getScheduleFilter).then(res => {
this.filter = res
})
},
......@@ -164,7 +165,7 @@ export default {
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
requestWithJsonAPI(api.deleteSchedule)
requestAPI(api.deleteSchedule)
.then((res) => {
console.log(res)
})
......@@ -174,7 +175,7 @@ export default {
},
getScheduleList () {
requestWithJsonAPI(api.getScheduleList)
requestAPI(api.getScheduleList)
.then((res) => {
const {
list = [],
......
......@@ -21,3 +21,20 @@ export function removeEmptyMemberArray (arr) {
})
return newArr
}
export let setModule = (obj, key) => {
let ob = {}
Object.keys(obj).forEach((item) => {
if (Array.isArray(obj[item])) {
obj[item].forEach(arr => {
if (arr.key === 'new') {
ob[key + '[' + item + '][' + arr.key + '][]'] = arr.name
} else {
ob[key + '[' + item + '][' + arr.key + ']'] = arr.name
}
})
} else {
ob[key + '[' + item + ']'] = obj[item]
}
})
return ob
}
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