add.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. agency: {
  5. sys_enterpriseid: 0
  6. },
  7. skeletonShow: false,
  8. loading: false,
  9. sa_brandid: null,
  10. tradefield: null,
  11. sa_accountclassid: 0,
  12. brandList: [],
  13. domainList: [],
  14. type: "标准订单",
  15. },
  16. /* 切换订单类型 */
  17. onSelectType(e) {
  18. this.setData({
  19. type: e.currentTarget.dataset.name
  20. })
  21. this.getAccList();
  22. },
  23. onLoad(options) {
  24. this.getOrderList()
  25. this.setData({
  26. type: options.type || '标准订单',
  27. sa_projectid: options.sa_projectid || 0,
  28. sa_contractid: options.sa_contractid || 0,
  29. userrole: wx.getStorageSync('userrole')
  30. })
  31. if (this.data.userrole == '经销商') {
  32. this.getBrand();
  33. this.getDomain();
  34. };
  35. let domainrelatedaccounts = wx.getStorageSync('domainrelatedaccounts');
  36. if (domainrelatedaccounts.length) {
  37. this.setData({
  38. domainrelatedaccounts
  39. })
  40. } else {
  41. _Http.basic({
  42. "classname": "sysmanage.develop.optiontype.optiontype",
  43. "method": "optiontypeselect",
  44. "content": {
  45. "pageNumber": 1,
  46. "pageSize": 9999,
  47. "typename": "domainrelatedaccounts"
  48. }
  49. }).then(res => {
  50. console.log("查询领域对应列表", res)
  51. if (res.msg == '成功' && res.data.length) {
  52. domainrelatedaccounts = res.data;
  53. wx.setStorageSync('domainrelatedaccounts', domainrelatedaccounts)
  54. this.setData({
  55. domainrelatedaccounts
  56. })
  57. }
  58. })
  59. }
  60. console.log(domainrelatedaccounts)
  61. },
  62. /* 获取品牌 */
  63. getBrand(id) {
  64. let content = {
  65. nocache: true,
  66. "pageSize": 999,
  67. }
  68. if (id) content.sys_enterpriseid = id;
  69. _Http.basic({
  70. "id": 20220924163702,
  71. content
  72. }).then(res => {
  73. console.log("查询品牌", res)
  74. if (res.data.length) this.setData({
  75. brandList: res.data,
  76. sa_brandid: res.data[0].sa_brandid
  77. });
  78. })
  79. },
  80. /* 获取orderList */
  81. getOrderList() {
  82. _Http.basic({
  83. "classname": "sysmanage.develop.optiontype.optiontype",
  84. "method": "optiontypeselect",
  85. "content": {
  86. "typename": "ordertype"
  87. }
  88. }).then(res => {
  89. console.log("订单类型", res)
  90. let orderList = [];
  91. try {
  92. orderList = res.data.map(v => v.value);
  93. } catch (error) {
  94. }
  95. if (orderList.length == 0) orderList.push("标准订单")
  96. this.setData({
  97. orderList,
  98. type: orderList[0]
  99. })
  100. })
  101. },
  102. /* 选择品牌 */
  103. onSelectBrand(e) {
  104. let {
  105. item
  106. } = e.currentTarget.dataset;
  107. if (this.data.sa_brandid == item.sa_brandid) return;
  108. this.setData({
  109. sa_brandid: item.sa_brandid
  110. })
  111. },
  112. /* 获取领域 */
  113. getDomain(id) {
  114. let content = {
  115. nocache: true,
  116. "pageNumber": 1,
  117. "pageSize": 99999,
  118. "where": {
  119. "condition": ""
  120. }
  121. };
  122. if (id) content.sys_enterpriseid = id;
  123. _Http.basic({
  124. "id": 20221223141802,
  125. content
  126. }).then(res => {
  127. console.log("获取领域", res)
  128. if (res.data.length) this.setData({
  129. domainList: res.data,
  130. tradefield: res.data[0].tradefield,
  131. skeletonShow: false
  132. });
  133. this.getAccList();
  134. })
  135. },
  136. /* 选择领域 */
  137. onSelect(e) {
  138. let {
  139. item
  140. } = e.currentTarget.dataset;
  141. if (this.data.tradefield == item.tradefield) return;
  142. this.setData({
  143. tradefield: item.tradefield
  144. })
  145. this.getAccList();
  146. },
  147. onSelectAcc(e) {
  148. let {
  149. item
  150. } = e.currentTarget.dataset;
  151. console.log(item)
  152. this.setData({
  153. sa_accountclassid: item.sa_accountclassid
  154. })
  155. },
  156. getAccList() {
  157. this.setData({
  158. optionalAccount: [],
  159. sa_accountclassid: 0
  160. })
  161. if (['标准订单', '特殊订单'].includes(this.data.type || '标准订单')) {
  162. let tradefield = this.data.domainrelatedaccounts.find(v => v.value == this.data.tradefield);
  163. if (tradefield) _Http.basic({
  164. "id": 20221008134803,
  165. "version": 1,
  166. "content": {
  167. "pageNumber": 1,
  168. "pageTotal": 1,
  169. "pageSize": 9999,
  170. "where": {
  171. "condition": "",
  172. "isused": 1,
  173. "isnotspecialfund": this.data.type == '标准订单' ? 0 : 1, //是否专用
  174. },
  175. }
  176. }).then(res => {
  177. console.log("账户列表", res)
  178. let list = res.data.filter(v => tradefield.subvalues.some(s => s == v.sa_accountclassid))
  179. if (res.msg == '成功') this.setData({
  180. optionalAccount: list,
  181. sa_accountclassid: list.length ? list[0].sa_accountclassid : 0
  182. })
  183. })
  184. }
  185. },
  186. submit() {
  187. if (this.data.userrole == '业务员' && !this.data.agency.sys_enterpriseid) {
  188. let that = this;
  189. wx.showModal({
  190. title: '提示',
  191. content: '您还未选择经销商!是否立即前往',
  192. complete: (res) => {
  193. if (res.confirm) that.selectAgency()
  194. }
  195. })
  196. return;
  197. };
  198. if (this.data.loading) return;
  199. this.setData({
  200. loading: true
  201. })
  202. // sa_accountclassid: 0,
  203. _Http.basic({
  204. "id": 20221108111402,
  205. content: {
  206. sa_orderid: 0,
  207. rec_contactsid: 0,
  208. pay_enterpriseid: 0,
  209. sa_contractid: this.data.sa_contractid,
  210. sa_projectid: this.data.sa_projectid,
  211. "sa_brandid": this.data.sa_brandid, //品牌ID
  212. "type": this.data.type, //订单类型
  213. "tradefield": this.data.tradefield, //必选
  214. sys_enterpriseid: this.data.agency.sys_enterpriseid,
  215. sa_accountclassid: this.data.sa_accountclassid
  216. }
  217. }).then(res => {
  218. this.setData({
  219. loading: false
  220. })
  221. console.log("创建" + this.data.type, res);
  222. wx.showToast({
  223. title: res.msg != '成功' ? res.msg || '创建失败' : '创建成功',
  224. icon: "none",
  225. mask: true
  226. });
  227. if (res.msg == '成功') setTimeout(() => {
  228. wx.redirectTo({
  229. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  230. });
  231. }, 500)
  232. })
  233. },
  234. /* 业务员逻辑 ↓ */
  235. selectAgency() {
  236. wx.navigateTo({
  237. url: `/select/agent/index?params=${JSON.stringify({
  238. "id": 20230219195002,
  239. "content": {
  240. nocache:true,
  241. "ismanage": "0",
  242. "where": {
  243. "condition": ""
  244. }
  245. }
  246. })}&radio=true`,
  247. })
  248. getApp().globalData.handleSelect = this.setAgency.bind(this);
  249. },
  250. /* 设置经销商 */
  251. setAgency({
  252. item
  253. }) {
  254. let that = this;
  255. wx.showModal({
  256. title: '提示',
  257. content: `是否确定选择"${item.enterprisename}"作为指定经销商?`,
  258. complete: (res) => {
  259. if (res.confirm) {
  260. that.setData({
  261. agency: item
  262. })
  263. that.getBrand(item.sys_enterpriseid)
  264. that.getDomain(item.sys_enterpriseid)
  265. wx.navigateBack()
  266. }
  267. }
  268. })
  269. }
  270. })