selectage.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <uv-toast ref="toast"></uv-toast>
  3. <view class='titlearea'>
  4. <text class='title_2'>{{$t('selectage_test1')}}</text>
  5. <text class='title_member'>{{$t('report_user')}}:{{selectuser.membername}}</text>
  6. <text class='title_desstr' decode='true'>{{$t('selectage_test2')}}</text>
  7. </view>
  8. <view class="agevalue">
  9. <view class="">
  10. {{$t('select_age')}}:
  11. <text class='strage' v-show="viewage<=29">29{{$t("select_age_3")}}</text>
  12. <text class='strage' v-show="viewage>29&&viewage<70">{{viewage}}{{$t("select_age_1")}}</text>
  13. <text class='strage' v-show="viewage>=70">70{{$t("select_age_2")}}</text>
  14. </view>
  15. <!-- <uv-button type="primary" :plain="true" :text="$t('select')" @click="showselectage" :customStyle="selectbutton1" :customTextStyle="selectbutton3"></uv-button> -->
  16. </view>
  17. <!-- <view class="">
  18. <uv-picker ref="picker" :columns="columns" @confirm="confirm" @change="change" keyName="label" :showToolbar="false" fontSize="25px"></uv-picker>
  19. </view> -->
  20. <view class="showdiv" id="showdiv" :style="{height:style.canvasHeight}">
  21. <scroll-view style="width:100%;height: 100%;"
  22. :scroll-x="true" @scroll="scroll" :scroll-left="scroll_left" :show-scrollbar="false">
  23. <canvas :style="{width:style.canvasWidth,height:style.canvasHeight}"
  24. canvas-id="canvas_ruler" id="canvas_ruler" :width="canvasWidth">
  25. </canvas>
  26. </scroll-view>
  27. <canvas :style="{width:style.screenWidth,height:style.canvasHeight}"
  28. canvas-id="canvas-cursor" id="canvas-cursor">
  29. </canvas>
  30. </view>
  31. <view class="donext_div">
  32. <uv-button type="primary" :text="$t('next_step')" @click="donext" :customStyle="selectbutton2" :customTextStyle="selectbutton3"></uv-button>
  33. </view>
  34. </template>
  35. <script>
  36. import {subanswerbyuserid} from "/common/api/scale.js"
  37. import {tohome,tostemlistnext} from "/common/js/common.js"
  38. import {drawruler,getCanvasConfig,getcursorvalue,setcursorvalue,getscrollleft} from "@/common/js/slider_ruler.js"
  39. export default {
  40. data() {
  41. return {
  42. minage:18,
  43. maxage:80,
  44. userinfo:{},
  45. selectuser:{},
  46. viewage:35,
  47. selectbutton1:{
  48. fontSize:'30px',
  49. width:'500rpx',
  50. borderColor:"#648EB8",
  51. color:"#648EB8",
  52. },
  53. selectbutton2:{
  54. fontSize:'30px',
  55. width:'500rpx',
  56. background:'#648EB8',
  57. border:"0px",
  58. },
  59. selectbutton3:{
  60. fontSize:"20px",
  61. fontWeight:"bold",
  62. letterSpacing: "0.5em",
  63. },
  64. scaleid:0,
  65. srid:0,
  66. sindex:0,
  67. stemid:1,
  68. answertype:0,
  69. canvasHeight:80,
  70. canvasWidth:1000,
  71. scroll_left:0,
  72. }
  73. },
  74. computed:{
  75. columns(){
  76. let list = []
  77. for (var i = this.minage; i <= this.maxage; i++) {
  78. let label=i+this.$t('select_age_1');
  79. if(i<=this.minage){
  80. label=i+this.$t('select_age_3');
  81. }
  82. if(i>=this.maxage){
  83. label=i+this.$t('select_age_2');
  84. }
  85. let item = {
  86. label:label,
  87. value:i
  88. }
  89. list.push(item)
  90. }
  91. return [list]
  92. },
  93. style(){
  94. let value ={
  95. canvasHeight:this.canvasHeight+"px",
  96. canvasWidth:this.canvasWidth+"px",
  97. screenWidth:this.screenWidth+"px"
  98. }
  99. return value
  100. },
  101. },
  102. methods: {
  103. init(){
  104. this.userinfo = uni.getStorageSync("userinfo")
  105. this.selectuser = uni.getStorageSync("selectuser")
  106. //this.getScreenSize()
  107. },
  108. showselectage(){
  109. this.$refs.picker.open();
  110. let index = this.viewage-this.minage
  111. this.$refs.picker.setIndexs([index],true)
  112. },
  113. confirm(e){
  114. let value = e.value[0].value
  115. this.viewage = value
  116. },
  117. change(e){
  118. let value = e.value[0].value
  119. this.viewage = value
  120. },
  121. donext(){
  122. let answer={
  123. userid:this.userinfo.id,
  124. fmemberid:this.selectuser.fmemberid,
  125. stemid:this.stemid,
  126. answertype:this.answertype,
  127. answervalue:this.viewage
  128. }
  129. let data={
  130. userid:this.userinfo.id,
  131. fmemberid:this.selectuser.fmemberid,
  132. srid: this.srid,
  133. scaleid: this.scaleid,
  134. }
  135. subanswerbyuserid(answer,data).then(res=>{
  136. res = res.data
  137. if(0==res.code){
  138. this.$refs.toast.show({
  139. type: 'error',
  140. message: res.errmsg
  141. })
  142. return false
  143. }
  144. if(200==res.code){
  145. uni.setStorage({
  146. key: 'srid',
  147. data: res.resultData,
  148. });
  149. tostemlistnext(this.sindex,1)
  150. }
  151. })
  152. //tostemlistnext(this.sindex+1)
  153. },
  154. drawruler(){
  155. let param ={
  156. canvasid:'canvas_ruler',
  157. canvascursorid:'canvas-cursor',
  158. minvalue:this.minage,
  159. maxvalue:this.maxage,
  160. interval:1,
  161. defaultvalue:this.viewage,
  162. precision:0
  163. }
  164. drawruler(param)
  165. this.viewage=getcursorvalue()
  166. this.canvasHeight=getCanvasConfig().canvasHeight
  167. this.canvasWidth=getCanvasConfig().canvasWidth
  168. this.screenWidth = getCanvasConfig().screenWidth;
  169. this.scroll_left = getscrollleft()
  170. // this.scroll_left = this.canvasWidth/2-this.screenWidth/2
  171. },
  172. scroll(e){
  173. this.viewage = setcursorvalue(e.detail.scrollLeft);
  174. }
  175. },
  176. mounted() {
  177. uni.setNavigationBarTitle({
  178. title: this.$t('select_age')
  179. });
  180. this.init()
  181. },
  182. onLoad: function (option) {
  183. this.scaleid=option.scaleid
  184. this.srid=option.srid
  185. this.sindex = option.sindex
  186. },
  187. onBackPress:function(option){
  188. tohome()
  189. return true
  190. },
  191. onReady(){
  192. this.drawruler()
  193. // this.drowtest()
  194. }
  195. }
  196. </script>
  197. <style scoped>
  198. .titlearea{
  199. height:400rpx;
  200. display:flex;
  201. flex-direction:column;
  202. justify-content: center;
  203. align-items:center;
  204. }
  205. .title_2{
  206. margin-top:15rpx;
  207. font-size:36rpx;
  208. font-weight:400;
  209. color:#666666
  210. }
  211. .title_member{
  212. margin-top:30rpx;
  213. font-size:36rpx;
  214. font-weight:400;
  215. color:#648EB8;
  216. }
  217. .title_desstr{
  218. width:700rpx;
  219. margin-left:25rpx;
  220. margin-top:30rpx;
  221. font-size:36rpx;
  222. font-weight:400;
  223. color:#9C9C9C;
  224. }
  225. .agevalue {
  226. color: #0000FF;
  227. font-size: 50rpx;
  228. text-align: center;
  229. line-height: 90rpx;
  230. display: flex;
  231. align-items: center;
  232. flex-direction: column;
  233. }
  234. .canvasview{
  235. position:relative;
  236. }
  237. .showdiv{
  238. position: relative;
  239. width: 100%;
  240. }
  241. .showdiv #canvas_ruler{
  242. position: absolute;
  243. top: 0;
  244. left: 0;
  245. z-index: 0;
  246. }
  247. .showdiv #canvas-cursor{
  248. position: absolute;
  249. top: 0;
  250. left: 0;
  251. z-index: 100;
  252. pointer-events:none;
  253. }
  254. </style>