add.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. brandList: [],
  12. domainList: [],
  13. type: "标准订单",
  14. },
  15. onLoad(options) {
  16. this.setData({
  17. type: options.type || '标准订单',
  18. sa_projectid: options.sa_projectid || 0,
  19. sa_contractid: options.sa_contractid || 0,
  20. userrole: wx.getStorageSync('userrole')
  21. })
  22. if (this.data.userrole == '经销商') {
  23. this.getBrand();
  24. this.getDomain();
  25. }
  26. },
  27. /* 获取品牌 */
  28. getBrand(id) {
  29. let content = {
  30. nocache: true,
  31. "pageSize": 999,
  32. }
  33. if (id) content.sys_enterpriseid = id;
  34. _Http.basic({
  35. "id": 20220924163702,
  36. content
  37. }).then(res => {
  38. console.log("查询品牌", res)
  39. if (res.data.length) this.setData({
  40. brandList: res.data,
  41. sa_brandid: res.data[0].sa_brandid
  42. });
  43. })
  44. },
  45. /* 选择品牌 */
  46. onSelectBrand(e) {
  47. let {
  48. item
  49. } = e.currentTarget.dataset;
  50. if (this.data.sa_brandid == item.sa_brandid) return;
  51. this.setData({
  52. sa_brandid: item.sa_brandid
  53. })
  54. },
  55. /* 获取领域 */
  56. getDomain(id) {
  57. let content = {
  58. nocache: true,
  59. "pageNumber": 1,
  60. "pageSize": 99999,
  61. "where": {
  62. "condition": ""
  63. }
  64. };
  65. if (id) content.sys_enterpriseid = id;
  66. _Http.basic({
  67. "id": 20221223141802,
  68. content
  69. }).then(res => {
  70. console.log("获取领域", res)
  71. if (res.data.length) this.setData({
  72. domainList: res.data,
  73. tradefield: res.data[0].tradefield,
  74. skeletonShow: false
  75. });
  76. })
  77. },
  78. /* 选择领域 */
  79. onSelect(e) {
  80. let {
  81. item
  82. } = e.currentTarget.dataset;
  83. if (this.data.tradefield == item.tradefield) return;
  84. this.setData({
  85. tradefield: item.tradefield
  86. })
  87. },
  88. submit() {
  89. if (this.data.userrole == '业务员' && !this.data.agency.sys_enterpriseid) {
  90. let that = this;
  91. wx.showModal({
  92. title: '提示',
  93. content: '您还未选择经销商!是否立即前往',
  94. complete: (res) => {
  95. if (res.confirm) that.selectAgency()
  96. }
  97. })
  98. return;
  99. };
  100. if (this.data.loading) return;
  101. this.setData({
  102. loading: true
  103. })
  104. _Http.basic({
  105. "id": 20221108111402,
  106. content: {
  107. sa_orderid: 0,
  108. sa_accountclassid: 0,
  109. rec_contactsid: 0,
  110. pay_enterpriseid: 0,
  111. sa_contractid: this.data.sa_contractid,
  112. sa_projectid: this.data.sa_projectid,
  113. "sa_brandid": this.data.sa_brandid, //品牌ID
  114. "type": this.data.type, //订单类型
  115. "tradefield": this.data.tradefield, //必选
  116. sys_enterpriseid: this.data.agency.sys_enterpriseid
  117. }
  118. }).then(res => {
  119. this.setData({
  120. loading: false
  121. })
  122. console.log("创建标准订单", res);
  123. wx.showToast({
  124. title: res.msg != '成功' ? res.msg : '创建成功',
  125. icon: "none",
  126. mask: true
  127. });
  128. if (res.msg == '成功') setTimeout(() => {
  129. wx.redirectTo({
  130. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  131. });
  132. let page = getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/index');
  133. if (page) page.getList(true);
  134. }, 500)
  135. })
  136. },
  137. /* 业务员逻辑 ↓ */
  138. selectAgency() {
  139. wx.navigateTo({
  140. url: `/select/agent/index?params=${JSON.stringify({
  141. "id": 20230219195002,
  142. "content": {
  143. nocache:true,
  144. "ismanage": "0",
  145. "where": {
  146. "condition": ""
  147. }
  148. }
  149. })}&radio=true`,
  150. })
  151. getApp().globalData.handleSelect = this.setAgency.bind(this);
  152. },
  153. /* 设置经销商 */
  154. setAgency({
  155. item
  156. }) {
  157. let that = this;
  158. wx.showModal({
  159. title: '提示',
  160. content: `是否确定选择"${item.enterprisename}"作为指定经销商?`,
  161. complete: (res) => {
  162. if (res.confirm) {
  163. that.setData({
  164. agency: item
  165. })
  166. that.getBrand(item.sys_enterpriseid)
  167. that.getDomain(item.sys_enterpriseid)
  168. wx.navigateBack()
  169. }
  170. }
  171. })
  172. }
  173. })