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

修改留言模块请求方式

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