add.js 3.6 KB

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