index.vue 10 KB

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