add.js 5.1 KB

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