take.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. const util = require("../../../utils/util.js");
  2. import * as echarts from '../../../components/ec-canvas/echarts.js';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. childs:[],
  7. activity:[],
  8. actives: [],
  9. childIndex : 0,
  10. index : 0,
  11. ec: {
  12. lazyLoad: true // 延迟加载
  13. },
  14. months : [],
  15. info : [],
  16. datas : {
  17. dtype: 0,
  18. dayType: 1,
  19. monthIndex:0,
  20. deadline: ""
  21. },
  22. scrollLeft : 0,
  23. npsOptons: {},
  24. npsStatus: false,//nps组件是否显示
  25. isGet: true,
  26. edition:2, //1--旧版本 2--新版本
  27. },
  28. onShow() {
  29. let that = this;
  30. if (this.data.isGet) {
  31. if (getCurrentPages().length == 1) {
  32. // var getLocation = util.promise();
  33. // getLocation.then(function (value) {
  34. that.getChild();
  35. that.setData({ currentPages: getCurrentPages().length })
  36. // }, function (error) {
  37. // });
  38. } else {
  39. that.getChild();
  40. }
  41. }
  42. },
  43. // 折线图绘制
  44. chartInit(type,idname,dataX,dataY){
  45. this.data.info.xarr=dataX;
  46. if (util.isObjEmpty(this.data.info.xarr)) return false;
  47. let columns = [], that = this;
  48. for (let i in this.data.info.xarr){
  49. columns.push({
  50. value: this.data.info.xarr[i],
  51. textStyle: {
  52. color: '#908f90'
  53. }
  54. });
  55. }
  56. this.selectComponent(idname).init((canvas, width, height) => {
  57. // 初始化图表
  58. var Chart = echarts.init(canvas, null, {
  59. width: width,
  60. height: height
  61. });
  62. Chart.clear();
  63. let options = {
  64. xAxis: {
  65. type: 'category',
  66. axisLine: {
  67. show: false
  68. },
  69. axisTick: {
  70. show: false
  71. },
  72. axisLabel: {
  73. interval:0,
  74. rotate: dataX.length>6?40:0
  75. },
  76. data: columns
  77. },
  78. yAxis: {
  79. show: true,
  80. type: 'value'
  81. },
  82. grid: {
  83. left: '0',
  84. right: '0',
  85. bottom: '10%'
  86. },
  87. series: [{
  88. name:"喝水",
  89. type: 'line',
  90. // barWidth: 38,
  91. stack: '总量',
  92. label: {
  93. show: true,
  94. position: 'top',
  95. formatter: idname=='#mychart'?'{c}瓶':'{c}度',
  96. color: '#ee3a43'
  97. },
  98. itemStyle: {
  99. color:'#ffccd3'
  100. },
  101. data: dataY
  102. }]
  103. };
  104. if(type == 0){
  105. options.grid = {
  106. left: '8%',
  107. right: '5%',
  108. bottom: '40%'
  109. };
  110. options.dataZoom = [{
  111. type:'inside',
  112. start: 0,
  113. end: 100
  114. },{
  115. type: 'slider',
  116. showDetail:false,
  117. showDataShadow:true,
  118. handleStyle:{
  119. borderColor:'#ee3a43',
  120. borderWidth:0
  121. },
  122. backgroundColor:'#fff0f3',
  123. handleSize:'60%',
  124. // handleIcon:'path://M30.9,53.2c-14.1,0-25.6-11.5-25.6-25.6S16.8,2,30.9,2C45,2,56.4,13.5,56.4,27.6S45,53.2,30.9,53.2z'
  125. }];
  126. }
  127. Chart.setOption(options);
  128. return Chart;
  129. });
  130. },
  131. selectImage(e) {
  132. this.setData({ isGet: e.detail.isGet });
  133. },
  134. close(e) {//关闭nps
  135. this.setData({ npsStatus: false });
  136. },
  137. getChild(){
  138. let that = this;
  139. util.ajax({
  140. func: "user/childs",
  141. load: false
  142. }, function (res) {
  143. if (res.code == 0) {
  144. that.setData({ childs : res.data });
  145. if(!util.isObjEmpty(that.data.childs)){
  146. that.getActivity();
  147. wx.setNavigationBarTitle({
  148. title: that.data.childs[that.data.childIndex].name
  149. });
  150. }
  151. }
  152. });
  153. },
  154. getActivity(){
  155. let that = this;
  156. util.ajax({
  157. func: "daily/activity_list",
  158. data: {"idcard": that.data.childs[that.data.childIndex].cardNo, "cardType": that.data.childs[that.data.childIndex].cardType},
  159. load: false
  160. }, function (res) {
  161. if (res.code == 0) {
  162. that.setData({ activity: res.data });
  163. that.jsonDataArr();
  164. that.getDate();
  165. }else
  166. util.showTips(res.reason);
  167. });
  168. },
  169. jsonDataArr() {
  170. let self = this, arr = [];
  171. for (var i = 0; i < self.data.activity.length; i++) {
  172. arr.push(self.data.activity[i].sname + " " + self.data.activity[i].pstitle);
  173. // arr.push(self.data.activity[i].text)
  174. }
  175. this.setData({ actives: arr });
  176. },
  177. getInfo(){
  178. let that = this,sendData = {},deadlineStart='',deadlineEnd='';
  179. if (that.data.datas.dtype==1&&that.data.months.length>0) {
  180. deadlineStart = util.formatDate(util.formatUnixtimestamp(that.data.months[0].value), "MM月dd日", false);
  181. deadlineEnd = util.formatDate(util.formatUnixtimestamp(that.data.months[that.data.months.length-1].value), "dd日", false);
  182. }
  183. sendData['teamId'] = that.data.activity[that.data.index].teamId || '';
  184. sendData['dtype'] = that.data.datas.dtype;
  185. sendData['sid'] = that.data.activity[that.data.index].sid;
  186. sendData['childId']= that.data.activity[that.data.index].childId;
  187. sendData['deadline'] = that.data.datas.deadline;
  188. sendData['summary'] = 1;
  189. util.ajax({
  190. func: that.data.datas.dtype == 1 ? "v2/daily/summary/info" : "v2/daily/info", //v2/daily/summary/info ——总结记录 v2/daily/info ——每日记录
  191. data: sendData
  192. },function(res){
  193. if(res.code == 0){
  194. if (res.data) {
  195. if(that.data.datas.dtype == 0 && res.data.id){
  196. res.data.deadlineText = util.formatDate(res.data.deadline, "MM月dd日", false);
  197. res.data.remark = res.data.fight == 0 && res.data.hurt == 0 && res.data.illness == 0 ? '活动中和小朋友和睦相处,身体无受伤并没有不适情况' + res.data.remark : res.data.remark;
  198. res.data.score = res.data.score.toFixed(1);
  199. }
  200. if (that.data.datas.dtype == 1) {
  201. if (!res.data.versionNum || res.data.versionNum==2) {
  202. let dateArr=[];
  203. if (res.data.xdeadlineArr && res.data.xdeadlineArr.length>0) {
  204. res.data.xdeadlineArr.forEach(el => {
  205. let arr = el.split('-')
  206. dateArr.push(arr[1]+'-'+arr[2])
  207. });
  208. }
  209. setTimeout(() => {
  210. if (res.data.ydrinkArr.length>0) {
  211. that.chartInit(dateArr.length>4?0:1,'#mychart',dateArr,res.data.ydrinkArr)
  212. }
  213. if (res.data.ytemperatureArr.length>0) {
  214. that.chartInit(dateArr.length>4?0:1,'#mychart1',dateArr,res.data.ytemperatureArr)
  215. }
  216. }, 500);
  217. }
  218. res.data.deadlineStart = deadlineStart;
  219. res.data.deadlineEnd = deadlineEnd;
  220. }
  221. }
  222. that.setData({ info : res.data,edition:res.data? (res.data.versionNum || 2):2});
  223. }else{
  224. util.showTips(res.reason);
  225. }
  226. });
  227. },
  228. getDate(){
  229. let that = this, months = [];
  230. if (!util.isObjEmpty(that.data.activity[that.data.index])){
  231. that.data.datas.dayType = that.data.activity[that.data.index].single;
  232. if (that.data.activity[that.data.index].single == 1) {
  233. if (that.data.activity[that.data.index].start != undefined) {
  234. that.data.datas.deadline = util.formatDate(util.formatUnixtimestamp(that.data.activity[that.data.index].start.time), "yyyy-MM-dd", false);
  235. }else{
  236. that.data.datas.deadline = "";
  237. }
  238. } else {
  239. if (that.data.activity[that.data.index].start != undefined && that.data.activity[that.data.index].end != undefined) {
  240. months = util.formatMonth(that.data.activity[that.data.index].start.time, that.data.activity[that.data.index].end.time);
  241. that.data.datas.monthIndex = 0;
  242. for (let i in months){
  243. if(months[i].active == 1){
  244. that.data.datas.monthIndex = i;
  245. }
  246. }
  247. that.data.datas.deadline = months[that.data.datas.monthIndex].value;
  248. }else{
  249. that.data.datas.deadline = "";
  250. }
  251. }
  252. that.setData({
  253. months: months,
  254. datas: that.data.datas
  255. });
  256. if (!util.isEmpty(that.data.datas.deadline)) that.getInfo();
  257. }
  258. },
  259. bindPickerChange(e){
  260. this.data.datas.dtype = 0;
  261. this.data.datas.dayType = 1;
  262. this.data.datas.deadline = "";
  263. this.data.datas.monthIndex = 0;
  264. this.setData({ childIndex: e.detail.value, index: 0, datas: this.data.datas, scrollLeft: 0, info: {}, months:[] });
  265. wx.setNavigationBarTitle({
  266. title: this.data.childs[this.data.childIndex].name
  267. })
  268. this.getActivity();
  269. },
  270. bindPickerActivity(e){
  271. this.data.datas.dtype = 0;
  272. this.data.datas.dayType = 1;
  273. this.data.datas.deadline = "";
  274. this.data.datas.monthIndex = 0;
  275. this.setData({ index: e.detail.value, datas: this.data.datas, scrollLeft: 0 });
  276. this.getDate();
  277. },
  278. copy(e){
  279. let self = this, s_type = e.currentTarget.dataset.type, data = "";
  280. switch (s_type){
  281. case "remark":
  282. data = self.data.info.remark;
  283. break;
  284. case "expression":
  285. data = self.data.info.expression;
  286. break;
  287. case "s_remark":
  288. data = self.data.info.s_remark || "";
  289. break;
  290. case "s_expression":
  291. for (let i in self.data.info.expressionList) {
  292. data += self.data.info.expressionList[i].deadline + ":" + self.data.info.expressionList[i].expression+"\n";
  293. }
  294. if (self.data.info.s_expression) data += "总结:" + self.data.info.s_expression;
  295. break;
  296. }
  297. wx.setClipboardData({
  298. data: data,
  299. success: function (res) {
  300. wx.showToast({
  301. title: '复制成功',
  302. icon: 'none'
  303. });
  304. }
  305. });
  306. },
  307. showTab(e){
  308. let data = e.currentTarget.dataset;
  309. this.data.datas.dtype = data.dtype;
  310. this.data.datas.deadline = data.deadline;
  311. this.data.datas.monthIndex = data.monthindex;
  312. this.setData({ datas: this.data.datas, scrollLeft: e.currentTarget.offsetLeft });
  313. this.getInfo();
  314. },
  315. onShareAppMessage() {
  316. return {
  317. title: '儿童参加活动的生活记录',
  318. path: '/pages/account/take/take'
  319. }
  320. }
  321. })