take.js 10 KB

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