setcombine.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. },
  7. onLoad: function (options) {
  8. var unitid = options.id;
  9. this.setData({
  10. Height: common.getSystemHeight(),
  11. UnitID: unitid,
  12. });
  13. this.init();
  14. },
  15. init: function () {
  16. var that = this;
  17. server.getData('GetHanziWordListByUnitID?UnitID=' + this.data.UnitID + "&UserID=" + app.globalData.userInfo.UserID, function (data) {
  18. if (data) {
  19. that.setData({
  20. List: data,
  21. })
  22. }
  23. });
  24. },
  25. changeSelected: function (e) {
  26. var id = e.currentTarget.dataset.id;
  27. var name = e.currentTarget.dataset.name;
  28. for (var i = 0; i < this.data.List.length; i++) {
  29. if (this.data.List[i].ID == id) {
  30. for (var j = 0; j < this.data.List[i].CombineWords.length; j++) {
  31. var item = this.data.List[i].CombineWords[j];
  32. if (item.name == name) {
  33. if (item.css == "")
  34. item.css = "selected";
  35. else
  36. item.css = "";
  37. break;
  38. }
  39. }
  40. }
  41. }
  42. this.setData({
  43. List: this.data.List,
  44. })
  45. },
  46. save: function () {
  47. var result=[];
  48. for (var i = 0; i < this.data.List.length; i++) {
  49. var word=[];
  50. for (var j = 0; j < this.data.List[i].CombineWords.length; j++) {
  51. var item = this.data.List[i].CombineWords[j];
  52. if (item.css == "selected"){
  53. word.push(item.name);
  54. }
  55. }
  56. this.data.List[i].CombineWords=word.join(",");
  57. result.push(this.data.List[i]);
  58. }
  59. var UnitCustom = wx.getStorageSync("UnitCustom");
  60. if (UnitCustom){
  61. var b=false;
  62. for(var i=0;i<UnitCustom.length;i++){
  63. if (UnitCustom[i].ID==this.data.UnitID){
  64. UnitCustom[i].List=result;
  65. b=true;
  66. break;
  67. }
  68. }
  69. if (!b){
  70. UnitCustom.push({
  71. ID:this.data.UnitID,
  72. List:result,
  73. })
  74. }
  75. }
  76. else{
  77. UnitCustom=[];
  78. UnitCustom.push({
  79. ID: this.data.UnitID,
  80. List: result,
  81. })
  82. }
  83. wx.setStorageSync("UnitCustom", UnitCustom);
  84. server.postData('AddHanziCustom',{
  85. UserID: app.globalData.userInfo.UserID,
  86. UnitID: this.data.UnitID,
  87. UnitCustom: JSON.stringify(result),
  88. }, function (data) {});
  89. app.globalData.IsSaveCustom=true;
  90. wx.navigateBack({
  91. delta: 1
  92. });
  93. },
  94. })