addRoadShowQuestion.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <view class="add-roadshow-question-page">
  3. <van-field
  4. :value="industry"
  5. is-link
  6. readonly
  7. clickable
  8. name="picker"
  9. label="客户行业"
  10. placeholder="选择客户行业"
  11. @click.native="showSelectIndustry = true"
  12. />
  13. <van-field
  14. :value="type"
  15. is-link
  16. readonly
  17. clickable
  18. name="picker"
  19. label="客户类型"
  20. placeholder="选择客户类型"
  21. @click.native="showSelectType = true"
  22. />
  23. <view class="list-wrap">
  24. <view class="list-item" v-for="item,index in list" :key="index">
  25. <van-field
  26. :value="item.question"
  27. placeholder="请输入内容"
  28. clearable
  29. :error-message="item.questionErrorMessage"
  30. @change="bindInputHandle('question',index, $event)"
  31. >
  32. <view class="label-box" slot="label">
  33. <image
  34. class="del-icon"
  35. src="../static/del.png"
  36. mode="aspectFit|aspectFill|widthFix"
  37. v-if="list.length>2"
  38. @click="handleDelItem(index)"
  39. />
  40. <view style="flex: 1;">{{ 'Q'+(index+1) }}</view>
  41. </view>
  42. </van-field>
  43. <van-field
  44. type="textarea"
  45. :value="item.answer"
  46. :label="'A'+(index+1)"
  47. placeholder="请输入内容"
  48. :autosize="{
  49. minHeight:80
  50. }"
  51. clearable
  52. :error-message="item.answerErrorMessage"
  53. @change="bindInputHandle('answer',index, $event)"
  54. >
  55. <view class="label-box" slot="label">
  56. <view>{{ 'A'+(index+1) }}</view>
  57. </view>
  58. </van-field>
  59. </view>
  60. </view>
  61. <view class="add-btn" @click="handleAddItem">
  62. <image class="icon" src="../static/add.png" mode="aspectFit|aspectFill|widthFix" lazy-load="false" binderror="" bindload="" />
  63. <view>添加更多</view>
  64. </view>
  65. <view class="fix-bottom-wrap btns-wrap flex">
  66. <button class="refuse-btn" @click="handleActions('cancel')">取消</button>
  67. <button class="pass-btn" @click="handleActions('accept')">提交</button>
  68. </view>
  69. <!-- 选择客户行业 -->
  70. <van-popup
  71. :show="showSelectIndustry"
  72. position="bottom">
  73. <van-picker
  74. show-toolbar
  75. title="客户行业"
  76. :columns="industryOpts"
  77. @confirm="confirmSelectIndustry"
  78. @cancel="showSelectIndustry = false"
  79. />
  80. </van-popup>
  81. <!-- 选择客户类型 -->
  82. <van-popup
  83. :show="showSelectType"
  84. position="bottom">
  85. <van-picker
  86. show-toolbar
  87. title="客户类型"
  88. :columns="customTypeOpts"
  89. @confirm="confirmSelectType"
  90. @cancel="showSelectType = false"
  91. />
  92. </van-popup>
  93. </view>
  94. </template>
  95. <script>
  96. import { roadShowQuestionAdd } from '@/api/roadshow/index.js'
  97. export default {
  98. data () {
  99. return {
  100. industryOpts:[
  101. {
  102. value:'黑色',
  103. text:'黑色'
  104. },
  105. {
  106. value:'有色',
  107. text:'有色'
  108. },
  109. {
  110. value:'能化',
  111. text:'能化'
  112. },
  113. {
  114. value:'综合',
  115. text:'综合'
  116. },
  117. {
  118. value:'金融',
  119. text:'金融'
  120. },
  121. {
  122. value:'农产品',
  123. text:'农产品'
  124. }
  125. ],
  126. customTypeOpts:[
  127. {
  128. value:'上游',
  129. text:'上游'
  130. },
  131. {
  132. value:'中游',
  133. text:'中游',
  134. },
  135. {
  136. value:'下游',
  137. text:'下游',
  138. },
  139. {
  140. value:'投资',
  141. text:'投资',
  142. }
  143. ],
  144. RsCalendarResearcherId:0,
  145. RsCalendarId:0,
  146. industry:'',
  147. showSelectIndustry:false,
  148. type:'',
  149. showSelectType:false,
  150. list:[
  151. {
  152. question:'',
  153. answer:'',
  154. questionErrorMessage:'',
  155. answerErrorMessage:'',
  156. },
  157. {
  158. question:'',
  159. answer:'',
  160. questionErrorMessage:'',
  161. answerErrorMessage:'',
  162. }
  163. ]
  164. }
  165. },
  166. onLoad(opt){
  167. this.getOpenerEventChannel().on('data', (data)=> {
  168. uni.setNavigationBarTitle({
  169. title:data.companyName+'客户问答',
  170. });
  171. this.RsCalendarId=data.RsCalendarId
  172. this.RsCalendarResearcherId=data.RsCalendarResearcherId
  173. })
  174. },
  175. methods: {
  176. handleActions(type){
  177. if(type==='cancel'){
  178. uni.navigateBack({
  179. delta: 1
  180. });
  181. return
  182. }
  183. if(!this.industry){
  184. uni.showToast({
  185. title: '选择客户行业',
  186. icon: 'none',
  187. });
  188. return
  189. }
  190. if(!this.type){
  191. uni.showToast({
  192. title: '选择客户类型',
  193. icon: 'none',
  194. });
  195. return
  196. }
  197. let hasError = false;
  198. let qArr=[]
  199. this.list.forEach(item => {
  200. // 检查问题是否为空
  201. if (!item.question) {
  202. item.questionErrorMessage = '请输入内容';
  203. hasError = true;
  204. } else {
  205. item.questionErrorMessage = '';
  206. }
  207. // 检查答案是否为空或长度不足
  208. if (!item.answer) {
  209. item.answerErrorMessage = '请输入内容';
  210. hasError = true;
  211. } else if (item.answer.length < 30) {
  212. item.answerErrorMessage = '字数不少于30字';
  213. hasError = true;
  214. } else {
  215. item.answerErrorMessage = '';
  216. }
  217. qArr.push({
  218. QuestionContent:item.question,
  219. ReplyContent:item.answer
  220. })
  221. });
  222. if (hasError) {
  223. uni.showToast({
  224. title: '请检查问答内容是否填完整',
  225. icon: 'none',
  226. });
  227. return;
  228. }
  229. uni.showModal({
  230. title: '提示',
  231. content: '客户问答只能提交一次,确认提交吗? ',
  232. success: async (modalres) =>{
  233. if (modalres.confirm) {
  234. console.log('用户点击确定');
  235. const res=await roadShowQuestionAdd({
  236. RsCalendarId:this.RsCalendarId,
  237. RsCalendarResearcherId:this.RsCalendarResearcherId,
  238. CompanyIndustry:this.industry,
  239. CompanyClassify:this.type,
  240. QuestionList:qArr
  241. })
  242. if(res.code===200){
  243. uni.showToast({
  244. title:'提交成功',
  245. icon:'success'
  246. })
  247. setTimeout(() => {
  248. this.handleActions('cancel')
  249. }, 1000);
  250. }
  251. } else if (modalres.cancel) {
  252. console.log('用户点击取消');
  253. }
  254. }
  255. });
  256. },
  257. confirmSelectIndustry(e){
  258. this.industry=e.detail.value.value
  259. this.showSelectIndustry=false
  260. },
  261. confirmSelectType(e){
  262. this.type=e.detail.value.value
  263. this.showSelectType=false
  264. },
  265. handleDelItem(index){
  266. this.list.splice(index,1)
  267. },
  268. handleAddItem(){
  269. this.list.push({
  270. question:'',
  271. answer:'',
  272. questionErrorMessage:'',
  273. answerErrorMessage:'',
  274. })
  275. },
  276. bindInputHandle(type,index,e){
  277. this.list[index][type]=e.detail
  278. }
  279. },
  280. }
  281. </script>
  282. <style lang="scss">
  283. .add-roadshow-question-page{
  284. .van-field__label{
  285. text-align: right;
  286. color: #333;
  287. width: 120rpx !important;
  288. }
  289. }
  290. </style>
  291. <style lang="scss" scoped>
  292. .add-roadshow-question-page{
  293. padding-top: 20rpx;
  294. padding-bottom: 200rpx;
  295. .list-wrap{
  296. .list-item{
  297. margin-top: 10rpx;
  298. .label-box{
  299. display: flex;
  300. justify-content: space-between;
  301. text-align: right;
  302. align-items: center;
  303. width: 120rpx;
  304. }
  305. .del-icon{
  306. width: 36rpx;
  307. height: 36rpx;
  308. }
  309. }
  310. }
  311. .add-btn{
  312. background-color: #fff;
  313. height: 85rpx;
  314. margin-top: 20rpx;
  315. padding: 0 var(--cell-horizontal-padding,16px);
  316. display: flex;
  317. align-items: center;
  318. color: $uni-color-primary;
  319. .icon{
  320. width: 34rpx;
  321. height: 34rpx;
  322. margin-right: 10rpx;
  323. }
  324. }
  325. .btns-wrap {
  326. justify-content: center;
  327. button {
  328. width: 260rpx;
  329. height: 70rpx;
  330. border-radius: 28px;
  331. border: none;
  332. margin: 0 15px;
  333. font-size: 15px;
  334. color: #fff;
  335. line-height: 70rpx;
  336. }
  337. .pass-btn {
  338. background-color: $uni-color-primary;
  339. }
  340. .refuse-btn {
  341. background-color: transparent;
  342. border: 1px solid $uni-color-primary;
  343. color: $uni-color-primary;
  344. }
  345. }
  346. }
  347. </style>