GoodsConsult.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <home-base :show="false"><view style="position: absolute;top:0;right:0;left:0;bottom:0" class="scroll-view-wrapper div container">
  3. <view class="div common-header-wrap">
  4. <view class="status-holder"></view>
  5. <view :style="'height:'+navHeight+'px'"></view>
  6. <view class="common-header-holder"></view>
  7. <view class="common-header-fixed">
  8. <title-header />
  9. <uni-nav-bar title="商品咨询" class="common-header" left-icon="back" @clickLeft="goBack()">
  10. </uni-nav-bar>
  11. </view>
  12. </view>
  13. <view class="div consult-form">
  14. <view class="div" @click="showPopup('typeVisible')">
  15. <flex-line :is-link="true" :show-border="true"><text class="span line-name">咨询类型</text><text class="span" slot="right">{{type_name}}</text></flex-line>
  16. </view>
  17. <flex-line class="field-line" :show-border="true"><text class="span field-name">咨询内容</text><view class="div field-line-right" slot="right"><input class="field-input" type="textarea" v-model="content" /></view></flex-line>
  18. <!-- <flex-line v-if="config.captcha_status_goodsqa" class="field-line" :show-border="true"><text class="span field-name">验证码</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="pictureCode" /><image mode="aspectFit" @click="changePictureCode" :src="pictureCodeUrl" class="img countdown" ></view></flex-line> -->
  19. <view class="div pt-10 pb-10"><view class="div common-btn ds-button-large" @click="submit">保存</view></view>
  20. </view>
  21. <uni-popup background-color="#fff" ref="typeVisible" type="right" >
  22. <view :style="'width:'+screenWidth+'px'" class="common-popup-wrapper">
  23. <view class="div common-header-wrap">
  24. <view :style="'height:'+navHeight+'px'"></view>
  25. <view class="common-header-holder"></view>
  26. <view class="common-header-fixed">
  27. <title-header />
  28. <uni-nav-bar title="咨询类型" class="common-header" left-icon="back" @clickLeft="hidePopup('typeVisible')">
  29. </uni-nav-bar>
  30. </view>
  31. </view>
  32. <view class="div common-popup-content">
  33. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" scroll-y="true">
  34. <radio-group class="radio-wrapper" @change="radioChange">
  35. <view class="radio-item" v-for="(item, index) in type_options" :key="index">
  36. <radio :value="item.value" :checked="type_id==item.value" />
  37. <text>{{item.label}}</text>
  38. </view>
  39. </radio-group>
  40. </scroll-view>
  41. </view>
  42. </view>
  43. </uni-popup>
  44. <view class="scroll-view div" style="position:relative">
  45. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" class="div" @scrolltolower="loadMore" scroll-y="true">
  46. <view class="div consult-list" v-if="consult_list && consult_list.length">
  47. <view class="div consult-item" v-for="(item, index) in consult_list" :key="index">
  48. <view class="div consult-info">
  49. <view class="div p-info">
  50. <view class="div explain">{{consultType[item.consulttype_id].consulttype_name}}<text class="span right">{{ $moment.unix(item.consult_addtime).format('YYYY年MM月DD日') }}</text></view>
  51. <view class="div name">{{item.consult_content}}</view>
  52. <view class="div replay" v-if="item.consult_reply">{{item.consult_reply}}</view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <empty-record v-else-if="consult_list && !consult_list.length"></empty-record>
  58. </scroll-view>
  59. </view>
  60. </view></home-base>
  61. </template>
  62. <script>
  63. import {getFontSize} from '@/util/common'
  64. import TitleHeader from '../../TitleHeader'
  65. import HomeBase from '../HomeBase'
  66. import { mapState, mapMutations, mapActions } from 'vuex'
  67. import EmptyRecord from '../../EmptyRecord'
  68. import { getGoodsConsult, addGoodsConsult } from '../../../api/homegoodsdetail'
  69. import { checkPictureCaptcha } from '../../../api/common'
  70. import flexLine from '../../flexLine'
  71. import { env } from '../../../static/config'
  72. export default {
  73. name:'HomeGoodsConsult',
  74. data(){
  75. return {
  76. navHeight: 0,
  77. screenWidth:0,
  78. goods_id: 0,
  79. pictureCode: '',
  80. pictureCodeUrl: '',
  81. content: '',
  82. type_name: '',
  83. type_id: '',
  84. type_options: [],
  85. params: { 'page': 0, 'per_page': 10 },
  86. consult_list: false,
  87. pictureCodeValid: false,
  88. loading: false, // 是否加载更多
  89. isMore: true // 是否有更多
  90. }
  91. },
  92. components:{
  93. TitleHeader,
  94. HomeBase,
  95. flexLine,
  96. EmptyRecord
  97. },
  98. computed:{
  99. fontSize(){
  100. return getFontSize()
  101. },
  102. ...mapState({
  103. token: state => state.member.token,
  104. consultType: state => state.goodsdetail.consultType,
  105. config: state => state.config.config
  106. })
  107. },
  108. mounted(){
  109. // #ifdef MP-WEIXIN
  110. this.navHeight = uni.getMenuButtonBoundingClientRect().top
  111. // #endif
  112. this.screenWidth=uni.getSystemInfoSync().screenWidth
  113. // this.changePictureCode()
  114. },
  115. onLoad: function (option) {
  116. this.goods_id=option.goods_id
  117. this.fetchConfig()
  118. if (!this.goods_id) {
  119. uni.showToast({icon:'none',title: '参数错误'})
  120. uni.navigateBack({delta:1})
  121. }
  122. let temp = this.consultType
  123. for (var i in temp) {
  124. if (!this.type_id) {
  125. this.type_id = temp[i].consulttype_id + ''
  126. }
  127. this.type_options.push({
  128. label: temp[i].consulttype_name,
  129. value: temp[i].consulttype_id + ''
  130. })
  131. }
  132. this.loadMore()
  133. },
  134. watch: {
  135. pictureCode: function (val) {
  136. if (val.length >= 4) {
  137. this.pictureCodeWait = true
  138. checkPictureCaptcha(val).then(
  139. response => {
  140. this.pictureCodeWait = false
  141. this.pictureCodeValid = true
  142. },
  143. error => {
  144. this.pictureCodeWait = false
  145. uni.showToast({icon:'none',title: error.message})
  146. }
  147. )
  148. }
  149. },
  150. type_id: function (type_id) {
  151. this.type_name = this.consultType[type_id].consulttype_name
  152. this.hidePopup('typeVisible')
  153. }
  154. },
  155. methods:{
  156. radioChange(e){
  157. this.type_id=e.detail.value
  158. },
  159. showPopup(id){
  160. this.$refs[id].open()
  161. },
  162. hidePopup(id){
  163. this.$refs[id].close()
  164. },
  165. goBack(){uni.navigateBack({delta:1})},
  166. ...mapActions({
  167. fetchConfig: 'fetchConfig'
  168. }),
  169. submit () {
  170. if (!this.content) {
  171. uni.showToast({icon:'none',title: '请先输入咨询内容'})
  172. return
  173. }
  174. addGoodsConsult(this.goods_id, this.type_id, this.content, this.token).then(res => {
  175. uni.showToast({icon:'none',title: res.message})
  176. this.content = ''
  177. this.pictureCode = ''
  178. this.params = { 'page': 0, 'per_page': 10 }
  179. this.consult_list = false
  180. this.loading = false
  181. this.isMore = true
  182. this.loadMore()
  183. }).catch(function (error) {
  184. uni.showToast({icon:'none',title: error.message})
  185. })
  186. },
  187. changePictureCode () {
  188. this.pictureCodeUrl = env.API_HOST + '/Seccode/makecode?r=' + Math.random()
  189. },
  190. loadMore () {
  191. this.loading = true
  192. this.params.page = ++this.params.page
  193. if (this.isMore) {
  194. this.loading = false
  195. this.getConsultList(true)
  196. }
  197. },
  198. getConsultList () {
  199. uni.showLoading({ title: '加载中' })
  200. getGoodsConsult(this.params, this.goods_id).then(res => {
  201. uni.hideLoading()
  202. if (res.result.hasmore) {
  203. this.isMore = true
  204. } else {
  205. this.isMore = false
  206. }
  207. let temp = res.result.consult_list
  208. if (temp) {
  209. if (!this.consult_list) {
  210. this.consult_list = temp
  211. } else {
  212. this.consult_list = this.consult_list.concat(temp)
  213. }
  214. }
  215. }).catch(function (error) {
  216. uni.hideLoading()
  217. uni.showToast({icon:'none',title: error.message})
  218. })
  219. }
  220. }
  221. }
  222. </script>
  223. <style scoped lang="scss">
  224. .scroll-view-wrapper{display: flex;flex-direction: column;}
  225. .scroll-view{flex:1}
  226. .consult-form{background: #fff;padding:0 $pageSpace;box-shadow: 0px 4px 4px #f7f7f7;}
  227. .consult-list{background: #fff;padding:0 $pageSpace;}
  228. .consult-item{background:#fff;border-bottom:1px dashed #eee;}
  229. .consult-info{padding:.5rem 0;display: flex}
  230. .consult-info .p-info{flex:1;}
  231. .consult-info .p-info .name{font-size:$subFontSize;color:$primaryColor;}
  232. .consult-info .p-info .explain{font-size:$subFontSize;margin-bottom:.5rem}
  233. .consult-info .p-info .explain .right{float:right;color:gray}
  234. .consult-info .p-info .replay{font-size:$subFontSize;padding-top:.5rem;color:$descTextColor}
  235. .countdown{width: auto;height: 1.75rem;min-width: 4rem;}
  236. .radio-wrapper{
  237. display: block;
  238. padding: 0 $pageSpace;
  239. .radio-item{
  240. padding:.5rem 0;
  241. border-bottom: 1px dashed #f5f5f5;
  242. }
  243. }
  244. </style>