checkdesigner.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // miniprogram/checkdesigner/checkdesigner.js
  2. const utils = require("../../utils/http");
  3. const util = require("../../utils/util");
  4. const app = getApp();
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. multiple: {
  11. type: Boolean,
  12. value: true
  13. },
  14. filterable: {
  15. type: Boolean,
  16. value: false
  17. },
  18. title: {
  19. type: String,
  20. value: "请选择人员"
  21. },
  22. type: {
  23. type: String,
  24. value: "1"
  25. },
  26. showSelect: {
  27. type: Boolean,
  28. value: true
  29. }
  30. },
  31. /**
  32. * 组件的初始数据
  33. */
  34. data: {
  35. showTime: true,
  36. result: [],
  37. itemStr: "",
  38. pid: "",
  39. searchVal: "",
  40. item: {},
  41. itemArr: [],
  42. departArr: {},
  43. departmentObj: {}
  44. },
  45. lifetimes: {
  46. attached: function () {
  47. // 在组件实例进入页面节点树时执行
  48. this.getDepart();
  49. },
  50. detached: function () {
  51. // 在组件实例被从页面节点树移除时执行
  52. },
  53. },
  54. /**
  55. * 组件的方法列表
  56. */
  57. methods: {
  58. doneFunc: function() {},
  59. closeComponent: function() {
  60. this.triggerEvent('close');
  61. },
  62. onChange: function (e) {
  63. let itemArr = []
  64. e.detail.forEach(v => {
  65. let textStr = v.split('$');
  66. itemArr.push({name: textStr[0],id: textStr[1]});
  67. })
  68. this.setData({
  69. result: e.detail,
  70. itemArr: itemArr
  71. });
  72. },
  73. onRadioChange: function(e) {
  74. let textStr = e.detail.split('$');
  75. let itemObj = {name: textStr[0],id: textStr[1]}
  76. this.setData({
  77. itemStr: e.detail,
  78. item: itemObj,
  79. });
  80. },
  81. onInputChange: function(e) {
  82. this.setData({
  83. searchVal: e.detail
  84. })
  85. },
  86. onSearch: function() {
  87. this.getDepart();
  88. },
  89. getDepart: function () {
  90. const that = this;
  91. let apiUrl = "";
  92. let dataObj = {};
  93. if (this.data.type == '1') {
  94. apiUrl = 'api/crm_customer/get_setting';
  95. dataObj = {
  96. name: that.data.searchVal
  97. };
  98. } else if (this.data.type == '2') {
  99. apiUrl = "api/designer/list";
  100. dataObj = {
  101. keyword: that.data.searchVal,
  102. org_type: 1
  103. };
  104. }
  105. utils.$post({
  106. url: app.globalData.webUrl + apiUrl,
  107. header: {
  108. 'Authorization': 'bearer ' + app.globalData.token
  109. },
  110. data: dataObj,
  111. success: function (res) {
  112. if (res.data.code == 0) {
  113. if (that.data.type == '1') {
  114. that.setData({
  115. departArr: res.data.data.employees,
  116. departmentObj: res.data.data.employees
  117. })
  118. }
  119. if (that.data.type == '2') {
  120. that.setData({
  121. departArr: res.data.data,
  122. departmentObj: res.data.data
  123. })
  124. }
  125. }
  126. }
  127. })
  128. },
  129. nextDepart: function (e) {
  130. let item = e.currentTarget.dataset.item;
  131. if (item.designer_num == 0) {
  132. wx.showToast({
  133. title: '此部门人数为0,不能选择!',
  134. icon: "none",
  135. duration: 1500
  136. })
  137. return;
  138. }
  139. this.setData({
  140. pid: item.pid,
  141. departmentObj: item,
  142. showTime: false
  143. })
  144. setTimeout(() => {
  145. this.setData({
  146. showTime: true,
  147. })
  148. },800)
  149. },
  150. lastStepFuc: function () {
  151. if (this.data.pid == 0) {
  152. this.setData({
  153. pid: null,
  154. departmentObj: this.data.departArr,
  155. showTime: false
  156. })
  157. setTimeout(() => {
  158. this.setData({
  159. showTime: true,
  160. })
  161. },600)
  162. } else {
  163. this.getlastItemFunc(this.data.departArr);
  164. }
  165. },
  166. getlastItemFunc: function (obj) {
  167. let itemObj = {};
  168. if (obj.child_org && obj.child_org.length) {
  169. obj.child_org.forEach(item => {
  170. if (item.id == this.data.pid) {
  171. this.setData({
  172. departmentObj: item,
  173. pid: item.pid,
  174. showTime: false
  175. })
  176. setTimeout(() => {
  177. this.setData({
  178. showTime: true,
  179. })
  180. },600)
  181. return;
  182. }
  183. if (item.child_org && item.child_org.length) {
  184. this.getlastItemFunc(item)
  185. }
  186. if (this.data.departArr.child_org.length && (this.data.departArr.child_org[0].pid == this.data.pid)) {
  187. this.setData({
  188. pid: null,
  189. departmentObj: this.data.departArr,
  190. showTime: false
  191. })
  192. setTimeout(() => {
  193. this.setData({
  194. showTime: true,
  195. })
  196. },600)
  197. }
  198. })
  199. }
  200. },
  201. submitDataFunc: function () {
  202. if (this.data.multiple) {
  203. this.triggerEvent('submit',this.data.itemArr);
  204. } else {
  205. this.triggerEvent('submit',this.data.item);
  206. }
  207. }
  208. }
  209. })