PageRenderTime 62ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 1ms

/StaffSoftwareQuery/Scripts/crm.js

https://gitlab.com/daniel0422/timesheet
JavaScript | 165 lines | 150 code | 9 blank | 6 comment | 0 complexity | 2f5477d468059d52bf4a4234855bf131 MD5 | raw file
  1. //requirejs paths methond: 路徑別名功能,減少重複輸入
  2. requirejs.config({
  3. baseUrl: "../../bower_components/",
  4. paths: {
  5. 'vue': ['validator/vendor/vue-0.11.1'],
  6. 'validator': ['validator/validator'],
  7. "jquery": ['jquery/dist/jquery.min'],
  8. "core": ["jqueryui/ui/core"],
  9. "datepicker": ["jqueryui/ui/datepicker"]
  10. }
  11. });
  12. //define(id?, dependencies?, factory);
  13. define(["vue", "validator", "jquery", "datepicker"], function (Vue, validator, $) {
  14. Vue.debug = true;
  15. Vue.use(validator);
  16. Vue.directive('datepicker', {
  17. bind: function () {
  18. var vm = this.vm;
  19. var key = this.expression;
  20. $(this.el).datepicker({
  21. dateFormat: "yy/mm/dd",
  22. onSelect: function (date) {
  23. vm.$set(key, date);
  24. }
  25. });
  26. },
  27. update: function (val) {
  28. $(this.el).datepicker('setDate', val);
  29. }
  30. });
  31. /* Dress list component. */
  32. Vue.component("member-list", {
  33. template: "#memberlist-template",
  34. data: function () {
  35. return {
  36. members: null,
  37. searchText: "",
  38. icountMembers: 0,
  39. selectedMemberID: "",
  40. }
  41. },
  42. compiled: function () {
  43. this.fetchData();
  44. this.$watch('searchText', function () {
  45. console.log(this._children);
  46. this.icountMembers = this._children.length;
  47. });
  48. },
  49. methods: {
  50. fetchData: function () {
  51. var self = this;
  52. $.post(host("Member/GetList"), {}, function (rs) {
  53. self.members = rs.members;
  54. self.icountMembers = self.members.length;
  55. self.$emit("list-loaded");
  56. });
  57. },
  58. clickAddNewDress: function () {
  59. main.editMode = true;
  60. main.isDetail = true;
  61. this.$parent.$.refMemberForm.AddNewMember();
  62. },
  63. getOneMember: function (e) {
  64. main.editMode = false;
  65. var self = this;
  66. var raw = e.targetVM._raw;
  67. var gid = raw.GID; //Pass to parent...
  68. this.selectedMemberID = gid;
  69. main.MemberID = gid;
  70. main.isDetail = true;
  71. this.$parent.$.refMemberForm.MemberID = gid;
  72. //console.log("list", gid, this.selectedMemberID, "|", this.$parent.$);
  73. }
  74. }
  75. });
  76. Vue.component("member-form", {
  77. template: "#member-form-template",
  78. //replace: true, // cache view...
  79. data: function(){
  80. return {
  81. Member: { GID: "", CallName: "", Mate: "", Email: "", TEL: "", Mobile: "", Address: "", WeddingDate: "", EngageDate: "", InsertDate: "", UpdateTime: "", Birthday: "", Note: "" },
  82. editMode: false,
  83. MemberID: "",
  84. isDetail:false
  85. }
  86. },
  87. created: function () {
  88. this.$watch("MemberID", function () {
  89. var gid = main.MemberID;
  90. this.fetchData();
  91. });
  92. },
  93. methods: {
  94. fetchData: function () {
  95. var self = this;
  96. $.post(host("Member/GetOneMember"), { gid: main.MemberID }, function (rs) {
  97. var f = self.Member;
  98. f.GID = rs.GID;
  99. f.CallName = rs.CallName;
  100. f.Email = rs.Email;
  101. f.Address = rs.Address;
  102. f.TEL = rs.TEL;
  103. f.Note=rs.Note;
  104. f.Mobile = rs.Mobile; console.log(rs);
  105. f.WeddingDate = rs.WeddingDate;
  106. f.EngageDate = rs.EngageDate;
  107. f.InsertDate = rs.InsertDate;
  108. f.UpdateTime = rs.UpdateTime;
  109. f.Birthday = rs.Birthday;
  110. });
  111. },
  112. hideDetail: function () {
  113. main.isDetail = false;
  114. },
  115. AddNewMember: function () {
  116. console.log('addnew');
  117. this.editMode=true;
  118. this.Member = { GID: "", CallName: "", Mate: "", Email: "", TEL: "", Mobile: "", Address: "", WeddingDate: "", EngageDate: "", InsertDate: "", UpdateTime: "", Birthday: "", Note: "" };
  119. },
  120. clickEdit: function () {
  121. this.editMode = true;
  122. },
  123. clickSave: function (e) {
  124. e.preventDefault();
  125. var self = this;
  126. $.post(host("Member/SaveMember"), this.Member, function (rs) {
  127. self.fetchData();
  128. self.editMode = false;
  129. self.$parent.$.refMemberlist.fetchData();
  130. });
  131. },
  132. clickCancel: function () {
  133. this.editMode = false;
  134. }
  135. }
  136. });
  137. var main = new Vue({
  138. el: "#main",
  139. data: {
  140. editMode: false,
  141. MemberID: "",
  142. isDetail: false
  143. },
  144. created: function () {
  145. this.$watch("MemberID", function () {
  146. //console.log("main", this.MemberID);
  147. })
  148. },
  149. filters: {
  150. formatDate: function (v) { return ToJavaScriptDate(v); },
  151. formatDateTime: function (v) { return ToJavaScriptDateTime(v); }
  152. },
  153. methods: {
  154. }
  155. });
  156. });