selectcanvas.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <uv-toast ref="toast"></uv-toast>
  3. <view class="">
  4. <navbar :title="$t('calculate_BMI')" size="48" :backtext="$t('back')" color="#fff"></navbar>
  5. </view>
  6. <view class="app_content">
  7. <view class='titlearea'>
  8. <text class='title_2'>{{$t('selectcanvas_text1')}}</text>
  9. <text class='title_member'>{{$t('report_user')}}:{{selectuser.membername}}</text>
  10. <text class='title_desstr' decode='true'>{{$t('selectcanvas_text2')}}</text>
  11. <!-- <text class='title_desstr' decode='true'>{{$t('selectcanvas_text3')}}</text> -->
  12. </view>
  13. <view class="info_div">
  14. <view class="text_div">
  15. <!-- <text class="title1">BMI:</text> -->
  16. <text class="title1">{{$t("bmi_text")}}:</text>
  17. <text class="text">{{bmi}}</text>
  18. </view>
  19. </view>
  20. <view class="info_div">
  21. <view class="text_div">
  22. <text class="title3">{{$t('height')}}:</text>
  23. <text class="text">&nbsp;{{heightvalue}}</text>
  24. <text class="title2">&nbsp;CM</text>
  25. </view>
  26. <!-- <view class="mybtn" @click="setheight">{{$t('select')}}</view> -->
  27. <view class="showdiv" id="showdiv" :style="{height:style.canvasHeight}">
  28. <scroll-view style="width:100%;height: 100%;"
  29. :scroll-x="true" @scroll="scroll1" :scroll-left="scroll_left_1" :show-scrollbar="false">
  30. <canvas :style="{width:style.canvasWidth_1,height:style.canvasHeight}"
  31. canvas-id="canvas_ruler" id="canvas_ruler" :width="canvasWidth_1">
  32. </canvas>
  33. </scroll-view>
  34. <canvas :style="{width:style.screenWidth_1,height:style.canvasHeight}"
  35. canvas-id="canvas-cursor" id="canvas-cursor">
  36. </canvas>
  37. </view>
  38. </view>
  39. <view class="info_div">
  40. <view class="text_div">
  41. <text class="title3">{{$t('weight')}}:</text>
  42. <text class="text">&nbsp;{{weightvalue}}</text>
  43. <text class="title2">&nbsp;KG</text>
  44. </view>
  45. <!-- <view class="mybtn" @click="setweight">{{$t('select')}}</view> -->
  46. <view class="showdiv" id="showdiv" :style="{height:style.canvasHeight}">
  47. <scroll-view style="width:100%;height: 100%;"
  48. :scroll-x="true" @scroll="scroll2" :scroll-left="scroll_left_2" :show-scrollbar="false">
  49. <canvas :style="{width:style.canvasWidth_2,height:style.canvasHeight}"
  50. canvas-id="canvas_ruler_2" id="canvas_ruler_2" :width="canvasWidth_2">
  51. </canvas>
  52. </scroll-view>
  53. <canvas :style="{width:style.screenWidth_2,height:style.canvasHeight}"
  54. canvas-id="canvas-cursor_2" id="canvas-cursor_2">
  55. </canvas>
  56. </view>
  57. </view>
  58. <!-- <view class="">
  59. <uv-picker ref="picker" :columns="columns" @change="change" keyName="label" :showToolbar="false" fontSize="25px"></uv-picker>
  60. </view> -->
  61. <view class="donext_div">
  62. <uv-button type="primary" :text="$t('next_step')" @click="donext" :customStyle="selectbutton2" :customTextStyle="selectbutton3"></uv-button>
  63. </view>
  64. <view>
  65. <uv-popup ref="popup" mode="bottom" @maskClick="maskClick">
  66. <view class="over_percent_div">
  67. <view class="content">
  68. <uv-text :text="$t('show_info_text1')" align="center" size="25"></uv-text>
  69. <uv-text :text="over_percent" type="success" bold="true" align="center" size="30"></uv-text>
  70. <uv-text :text="$t('show_info_text2')" align="center" size="25"></uv-text>
  71. </view>
  72. </view>
  73. </uv-popup>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import {tohome,tostemlistnext} from "/common/js/common.js"
  79. import {subanswerbyuserid} from "/common/api/scale.js"
  80. import {querybmipercentage} from "/common/api/health.js"
  81. import {drawruler,getCanvasConfig,getcursorvalue,setcursorvalue,getscrollleft} from "@/common/js/slider_ruler.js"
  82. export default{
  83. data(){
  84. return {
  85. columns:[],
  86. userinfo:{},
  87. selectuser:{},
  88. scaleid:0,
  89. srid:0,
  90. sindex:0,
  91. heightvalue:170,
  92. weightvalue:50,
  93. minheight:90,
  94. maxheight:210,
  95. minweight:35,
  96. maxweight:125,
  97. selecttype:"height",
  98. selectbutton2:{
  99. fontSize:'30px',
  100. width:'500rpx',
  101. background:'#3f73b3',
  102. border:"0px",
  103. },
  104. selectbutton3:{
  105. fontSize:"20px",
  106. fontWeight:"bold",
  107. letterSpacing: "0.5em",
  108. },
  109. over_percent:"11%",
  110. timer:false,
  111. canvasHeight:80,
  112. canvasWidth_1:1000,
  113. canvasWidth_2:1000,
  114. scroll_left_1:0,
  115. scroll_left_2:0,
  116. }
  117. },
  118. methods:{
  119. init(){
  120. this.userinfo = uni.getStorageSync("userinfo")
  121. this.selectuser = uni.getStorageSync("selectuser")
  122. },
  123. setheight(){
  124. this.columns = this.heightlist
  125. this.$refs.picker.open();
  126. let index = this.heightvalue-this.minheight
  127. this.$refs.picker.setIndexs([index],true)
  128. this.selecttype="height"
  129. },
  130. setweight(){
  131. this.columns = this.weightlist
  132. this.$refs.picker.open();
  133. let index = (this.weightvalue-this.minweight)*2
  134. this.$refs.picker.setIndexs([index],true)
  135. this.selecttype="weight"
  136. },
  137. change(e){
  138. let value = e.value[0].value
  139. switch(this.selecttype){
  140. case "height":
  141. this.heightvalue = value
  142. break;
  143. case "weight":
  144. this.weightvalue = value
  145. break;
  146. }
  147. },
  148. donext(){
  149. var usrBMI = {
  150. userid: this.userinfo.id,
  151. fmemberid:this.selectuser.fmemberid,
  152. stemid: 2,
  153. answertype: 0,
  154. answervalue: this.bmi,
  155. }
  156. var userheight = {
  157. userid: this.userinfo.id,
  158. fmemberid:this.selectuser.fmemberid,
  159. stemid: 27,
  160. answertype: 0,
  161. answervalue: this.heightvalue,
  162. }
  163. var userweight = {
  164. userid: this.userinfo.id,
  165. fmemberid:this.selectuser.fmemberid,
  166. stemid: 28,
  167. answertype: 0,
  168. answervalue: this.weightvalue,
  169. }
  170. let answer =[]
  171. answer.push(usrBMI)
  172. answer.push(userheight)
  173. answer.push(userweight)
  174. let data={
  175. userid:this.userinfo.id,
  176. fmemberid:this.selectuser.fmemberid,
  177. srid: this.srid,
  178. scaleid: this.scaleid,
  179. }
  180. subanswerbyuserid(answer,data).then(res=>{
  181. res = res.data
  182. if(0==res.code){
  183. this.$refs.toast.show({
  184. type: 'error',
  185. message: res.errmsg
  186. })
  187. return false
  188. }
  189. if(200==res.code){
  190. uni.setStorage({
  191. key: 'srid',
  192. data: res.resultData,
  193. });
  194. querybmipercentage(this.bmi).then(res=>{
  195. res = res.data
  196. if(0==res.code){
  197. this.$refs.toast.show({
  198. type: 'error',
  199. message: res.errmsg
  200. })
  201. return false
  202. }
  203. if(200==res.code){
  204. this.over_percent = res.resultData+"%"
  205. this.showinfo()
  206. let that = this
  207. this.timer = setTimeout(function(){
  208. that.closeinfo()
  209. console.log(123)
  210. tostemlistnext(that.sindex,1)
  211. }, 3000);
  212. }
  213. })
  214. }
  215. })
  216. },
  217. showinfo(){
  218. this.$refs.popup.open();
  219. },
  220. closeinfo(){
  221. this.$refs.popup.close();
  222. },
  223. maskClick(){
  224. clearTimeout(this.timer)
  225. this.$refs.popup.close();
  226. tostemlistnext(this.sindex,1)
  227. },
  228. drawruler1(){
  229. let param ={
  230. canvasid:'canvas_ruler',
  231. canvascursorid:'canvas-cursor',
  232. minvalue:this.minheight,
  233. maxvalue:this.maxheight,
  234. interval:1,
  235. defaultvalue:this.heightvalue,
  236. precision:0
  237. }
  238. drawruler(param)
  239. this.heightvalue=getcursorvalue()
  240. this.canvasHeight=getCanvasConfig().canvasHeight
  241. this.canvasWidth_1=getCanvasConfig().canvasWidth
  242. this.screenWidth = getCanvasConfig().screenWidth;
  243. this.scroll_left_1 = getscrollleft()
  244. // this.scroll_left = this.canvasWidth/2-this.screenWidth/2
  245. },
  246. scroll1(e){
  247. this.heightvalue = setcursorvalue(e.detail.scrollLeft,this.minheight);
  248. },
  249. drawruler2(){
  250. let param ={
  251. canvasid:'canvas_ruler_2',
  252. canvascursorid:'canvas-cursor_2',
  253. minvalue:this.minweight,
  254. maxvalue:this.maxweight,
  255. interval:1,
  256. defaultvalue:this.weightvalue,
  257. precision:0
  258. }
  259. drawruler(param)
  260. this.weightvalue=getcursorvalue()
  261. this.canvasHeight=getCanvasConfig().canvasHeight
  262. this.canvasWidth_2=getCanvasConfig().canvasWidth
  263. this.screenWidth = getCanvasConfig().screenWidth;
  264. this.scroll_left_2 = getscrollleft()
  265. // this.scroll_left = this.canvasWidth/2-this.screenWidth/2
  266. },
  267. scroll2(e){
  268. this.weightvalue = setcursorvalue(e.detail.scrollLeft);
  269. }
  270. },
  271. mounted() {
  272. uni.setNavigationBarTitle({
  273. title: this.$t('calculate_BMI')
  274. });
  275. this.init()
  276. },
  277. computed:{
  278. bmi(){
  279. var value = (this.weightvalue / ((this.heightvalue / 100) * (this.heightvalue / 100))).toFixed(1)
  280. return value
  281. },
  282. heightlist(){
  283. let list = []
  284. for (var i = this.minheight; i <= this.maxheight; i++) {
  285. let item = {
  286. label:i,
  287. value:i
  288. }
  289. list.push(item)
  290. }
  291. return [list]
  292. },
  293. weightlist(){
  294. let list = []
  295. for (var i = this.minweight; i <= this.maxweight; i+=0.5) {
  296. let item = {
  297. label:i,
  298. value:i
  299. }
  300. list.push(item)
  301. }
  302. return [list]
  303. },
  304. style(){
  305. let value ={
  306. canvasHeight:this.canvasHeight+"px",
  307. canvasWidth_1:this.canvasWidth_1+"px",
  308. canvasWidth_2:this.canvasWidth_2+"px",
  309. screenWidth:this.screenWidth+"px"
  310. }
  311. return value
  312. },
  313. },
  314. onLoad: function (option) {
  315. this.scaleid=option.scaleid
  316. this.srid=option.srid
  317. this.sindex = option.sindex
  318. },
  319. onBackPress:function(option){
  320. tohome()
  321. return true
  322. },
  323. onReady(){
  324. this.drawruler1()
  325. this.drawruler2()
  326. }
  327. }
  328. </script>
  329. <style scoped>
  330. .titlearea{
  331. height:400rpx;
  332. display:flex;
  333. flex-direction:column;
  334. justify-content: center;
  335. align-items:center;
  336. margin-bottom: 30px;
  337. font-size: 13px;
  338. }
  339. .title_2{
  340. margin-top:15rpx;
  341. font-size:36rpx;
  342. font-weight:400;
  343. color:#666666
  344. }
  345. .title_member{
  346. margin-top:30rpx;
  347. font-size:36rpx;
  348. font-weight:400;
  349. color:#648EB8;
  350. }
  351. .title_desstr{
  352. width:700rpx;
  353. margin-left:25rpx;
  354. margin-top:30rpx;
  355. font-size:36rpx;
  356. font-weight:400;
  357. color:#9C9C9C;
  358. }
  359. .info_div:first{
  360. margin-top: 10px;
  361. }
  362. .info_div{
  363. display: flex;
  364. flex-direction: column;
  365. align-items: center;
  366. margin-bottom: 20px;
  367. gap: 5px;
  368. }
  369. .info_div .text_div{
  370. text-align: center;
  371. letter-spacing: "0.5em";
  372. }
  373. .title1{
  374. color: gray;
  375. font-size: 30px;
  376. }
  377. .text{
  378. color: #0000CD;
  379. font-size: 30px;
  380. }
  381. .title2{
  382. color: gray;
  383. font-size: 15px;
  384. }
  385. .title3{
  386. color: gray;
  387. font-size: 20px;
  388. }
  389. .mybtn{
  390. width: 50%;
  391. letter-spacing: 10px;
  392. }
  393. .over_percent_div{
  394. width: 100%;
  395. height: 600rpx;
  396. display: flex;
  397. flex-direction: column;
  398. align-items: center;
  399. justify-content: center;
  400. }
  401. .over_percent_div .content{
  402. width: 80%;
  403. display: flex;
  404. flex-direction: column;
  405. align-items: center;
  406. gap: 20px;
  407. justify-content: center;
  408. }
  409. .canvasview{
  410. position:relative;
  411. }
  412. .showdiv{
  413. position: relative;
  414. width: 100%;
  415. }
  416. .showdiv #canvas_ruler{
  417. position: absolute;
  418. top: 0;
  419. left: 0;
  420. z-index: 0;
  421. }
  422. .showdiv #canvas-cursor{
  423. position: absolute;
  424. top: 0;
  425. left: 0;
  426. z-index: 100;
  427. pointer-events:none;
  428. }
  429. .showdiv #canvas_ruler_2{
  430. position: absolute;
  431. top: 0;
  432. left: 0;
  433. z-index: 0;
  434. }
  435. .showdiv #canvas-cursor_2{
  436. position: absolute;
  437. top: 0;
  438. left: 0;
  439. z-index: 100;
  440. pointer-events:none;
  441. }
  442. </style>