add.js 7.7 KB

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