index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <view class="question-detail-page">
  3. <van-sticky v-if="!id">
  4. <view class="" @click="goSearch">
  5. <van-search :value="key_word" shape="round" :placeholder="type==='question' ? '提问内容' : '评论内容'" disabled />
  6. </view>
  7. <van-tabs v-if="type=='question'" id="tabs" :active="status" title-active-color="#3385FF" color="#3385FF" @change="typeChange" >
  8. <template v-if="tabs.length">
  9. <van-tab :title="item.label" :name="item.key" v-for="item in tabs" :key="item.key"></van-tab>
  10. </template>
  11. </van-tabs>
  12. </van-sticky>
  13. <!-- list -->
  14. <view class="list-cont">
  15. <question-item
  16. v-for="item in list"
  17. :key="item.CommunityQuestionId"
  18. :item="item"
  19. :status="status"
  20. :type="type"
  21. :select_users="select_users"
  22. @open_picker="openPicker"
  23. @del="delHandle"
  24. @edit="editHandle"
  25. @hot="setHotHandle"
  26. />
  27. </view>
  28. <van-empty description="暂无数据" :image="require('@/static/empty.png')" v-if="finished&&list.length===0"/>
  29. <!-- 研究员选择弹窗 -->
  30. <pickerThreeColumn
  31. :data="researcherList"
  32. v-if="researcherList.length"
  33. :visible="isShowrsPicker"
  34. :default_picker_val="default_picker_val"
  35. @cancel="cancelPicker"
  36. @ensure="confirmPicker"
  37. />
  38. <!-- 编辑框 -->
  39. <van-popup :show="showEditPicker" bind:close="onClose">
  40. <view class="edit-cont">
  41. <view class="editor-wrapper">
  42. <textarea
  43. v-model="edit_item.QuestionContent"
  44. placeholder="请输入提问内容"
  45. :show-confirm-bar="false"
  46. :cursor-spacing="20"
  47. class="editor"
  48. />
  49. </view>
  50. <view style="height:40rpx;padding:10rpx 34rpx;font-size:24rpx;color:#999">
  51. <text style="float:left">注:限制28个字</text>
  52. <text style="float:right">超出字数:<text style="color:#ff0000">{{edit_item.QuestionContent.length>28?edit_item.QuestionContent.length-28:0}}</text>字</text>
  53. </view>
  54. <view class="edit-bottom">
  55. <view class="cancel-color" @click="showEditPicker=false">取消</view>
  56. <view class="blue-color" @click="editQuestionHandle">确定</view>
  57. </view>
  58. </view>
  59. </van-popup>
  60. </view>
  61. </template>
  62. <script>
  63. import * as $api from '@/api/question/index.js';
  64. import questionItem from '../components/questionItem.vue'
  65. import pickerThreeColumn from '../components/pickerThreeColumn.vue'
  66. export default {
  67. data() {
  68. return {
  69. id: '',//消息列表进入带的id
  70. type:'',//页面类型 question comment
  71. key_word: '',
  72. status: 1,
  73. tabs: [],
  74. page_no: 1,
  75. pageSize: 10,
  76. list:[],
  77. finished: false,
  78. researcherList: [],
  79. isShowrsPicker: false,
  80. select_item: {},
  81. default_picker_val:[],
  82. showEditPicker: false,//编辑弹窗
  83. edit_item:{}
  84. };
  85. },
  86. components: { questionItem,pickerThreeColumn },
  87. onLoad(options) {
  88. this.initState(options)
  89. // 搜索返回
  90. uni.$on('questionListUpdate',({key_word})=>{
  91. this.key_word = key_word;
  92. this.tabs = [];
  93. this.status = -1;
  94. this.page_no = 1;
  95. this.getList()
  96. })
  97. },
  98. onUnload() {
  99. uni.$off('questionListUpdate')
  100. },
  101. onShow() {
  102. if(!this.id&&this.type==='question'){
  103. this.$nextTick(()=>{
  104. this.selectComponent('#tabs').resize();// 解决初始渲染 vant tab 底部条
  105. })
  106. }
  107. },
  108. onPullDownRefresh() {
  109. this.page_no=1
  110. this.finished=false
  111. this.list=[]
  112. this.getList()
  113. setTimeout(()=>{
  114. uni.stopPullDownRefresh()
  115. },1500)
  116. },
  117. onReachBottom() {
  118. if(this.finished) return
  119. this.page_no++
  120. this.getList()
  121. },
  122. methods: {
  123. /* 待分配研究员列表 */
  124. async getResearcherList() {
  125. const { code,data } = await $api.apiRsList();
  126. if(code !== 200) return
  127. data && data.forEach(_ => {
  128. _.children = _.tags || [];
  129. _.label = _.classify_name;
  130. _.tags.forEach(_sub => {
  131. _sub.children = _sub.researcher_list;
  132. _sub.label = _sub.tag_name
  133. _sub.researcher_list.forEach(_ths => {
  134. _ths.label = _ths.admin_name
  135. })
  136. })
  137. })
  138. this.researcherList = data;
  139. },
  140. async getList() {
  141. const params = {
  142. Keyword: this.key_word || '',
  143. CurrentIndex: this.page_no,
  144. PageSize: this.pageSize
  145. }
  146. const {code,data} = this.type==='question'
  147. ? await $api.apiQuestionList({...params,ReplyStatus: this.status,
  148. CommunityQuestionId: Number(this.id) || '',})
  149. : await $api.apiCommentList({...params,Source:1,HotStatus: this.status,CommunityQuestionCommentId: Number(this.id)});
  150. if(code !== 200) return
  151. this.finished = this.page_no >= data.Paging.Pages;
  152. this.list = this.page_no === 1 ? (data.List || []) : this.list.concat(data.List);
  153. },
  154. /* 改变类型 */
  155. typeChange({ detail }) {
  156. this.status=detail.name
  157. this.page_no=1
  158. this.list=[]
  159. this.getList()
  160. },
  161. /* 搜索 */
  162. goSearch() {
  163. uni.navigateTo({
  164. url: `/pages-approve/search/index?type=question`,
  165. })
  166. },
  167. // 删除
  168. delHandle(id) {
  169. let index = this.type === 'question' ? this.list.findIndex(_ => _.CommunityQuestionId === id) : this.list.findIndex(_ => _.CommunityQuestionCommentId === id);
  170. this.list.splice(index,1)
  171. },
  172. /* 设置精选*/
  173. setHotHandle(id) {
  174. let index = this.list.findIndex(_ => _.CommunityQuestionCommentId === id);
  175. if(this.status === -1) {
  176. this.list[index].IsHot = this.list[index].IsHot ? 0 : 1
  177. }else {
  178. this.list.splice(index,1)
  179. }
  180. },
  181. /* 修改问题 */
  182. editHandle(item) {
  183. this.edit_item = JSON.parse(JSON.stringify(item));
  184. this.showEditPicker = true;
  185. },
  186. /* 修改问题*/
  187. async editQuestionHandle() {
  188. const { CommunityQuestionId,QuestionContent } = this.edit_item;
  189. if(QuestionContent.length > 28) return uni.showToast({
  190. title: '字数超限,请修改问题后重试',
  191. icon: 'none'
  192. })
  193. const {code,data} = await $api.apiEditQuestion({
  194. QuestionId: CommunityQuestionId,
  195. QuestionContent
  196. })
  197. if( code !== 200) return
  198. uni.showToast({title: '修改成功'})
  199. this.showEditPicker = false;
  200. let obj = this.list.find(_ => _.CommunityQuestionId === CommunityQuestionId);
  201. obj.QuestionContent = QuestionContent;
  202. console.log(obj)
  203. },
  204. // 打开弹窗
  205. openPicker(id) {
  206. this.select_item = this.list.find(_ => _.CommunityQuestionId === id);
  207. this.default_picker_val = this.select_item.select_users ? this.select_item.select_users.val : [];
  208. this.isShowrsPicker = true;
  209. },
  210. cancelPicker() {
  211. this.isShowrsPicker = false;
  212. },
  213. /* 确认*/
  214. confirmPicker(val) {
  215. console.log(val)
  216. let data = this.researcherList;
  217. if(data[val[0]].children.length && data[val[0]].children[val[1]].children.length) {
  218. let select_users = {
  219. val,
  220. first_id: data[val[0]].tag_id,
  221. second_id: data[val[0]].children[val[1]].tag_id,
  222. user_id: data[val[0]].children[val[1]].children[val[2]].admin_id,
  223. user_name: data[val[0]].children[val[1]].children[val[2]].admin_name
  224. }
  225. if(this.select_item.select_users) this.select_item.select_users = select_users
  226. else this.$set(this.select_item,'select_users',select_users)
  227. }
  228. },
  229. /* init*/
  230. initState({ type,id }) {
  231. const titleMap = {
  232. 'question': '问答管理',
  233. 'comment': '评论管理'
  234. }
  235. const tabMap = {
  236. 'question': [
  237. // {
  238. // label: '待分配',
  239. // key: 1
  240. // },
  241. {
  242. label: '待回答',
  243. key: 2
  244. },
  245. {
  246. label: '已回答',
  247. key: 3
  248. },
  249. {
  250. label: '已终止',
  251. key: 4
  252. },
  253. ],
  254. 'comment': [
  255. {
  256. label: '全部',
  257. key: -1
  258. },
  259. {
  260. label: '已精选',
  261. key: 1
  262. },
  263. {
  264. label: '未精选',
  265. key: 0
  266. },
  267. ]
  268. }
  269. this.type = type;
  270. this.id = id;
  271. this.tabs = id ? [] : tabMap[type];
  272. this.status = this.tabs.length ? this.tabs[0].key : -1;
  273. type === 'question' && this.getResearcherList();
  274. this.getList();
  275. uni.setNavigationBarTitle({
  276. title: titleMap[type]
  277. });
  278. }
  279. }
  280. }
  281. </script>
  282. <style lang="scss" scoped>
  283. .blue-color {
  284. color: #3385FF;
  285. }
  286. .cancel-color {
  287. color: #999;
  288. }
  289. .list-cont {
  290. padding: 40rpx 20rpx;
  291. }
  292. .edit-cont {
  293. .editor-wrapper {
  294. padding: 40rpx 34rpx 0;
  295. }
  296. .editor {
  297. height: 300rpx;
  298. border: 1px solid #EAEAEA;
  299. border-radius: 4px;
  300. padding: 20rpx;
  301. }
  302. .edit-bottom {
  303. border-top: 1px solid #EAEAEA;
  304. display: flex;
  305. align-items: center;
  306. margin-top: 30rpx;
  307. view {
  308. flex: 1;
  309. padding: 30rpx 0;
  310. text-align: center;
  311. font-size: 30rpx;
  312. border-right: 1px solid #EAEAEA;
  313. &:last-child {
  314. border: none;
  315. }
  316. }
  317. }
  318. }
  319. </style>