add.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. cancelText: getApp().globalData.Language.getMapText('取消'),
  93. confirmText: getApp().globalData.Language.getMapText('确定'),
  94. title: getApp().globalData.Language.getMapText('提示'),
  95. content: getApp().globalData.Language.getMapText('您还未选择经销商!是否立即前往'),
  96. complete: (res) => {
  97. if (res.confirm) that.selectAgency()
  98. }
  99. })
  100. return;
  101. };
  102. if (this.data.loading) return;
  103. this.setData({
  104. loading: true
  105. })
  106. _Http.basic({
  107. "id": 20221108111402,
  108. content: {
  109. sa_orderid: 0,
  110. sa_accountclassid: 0,
  111. rec_contactsid: 0,
  112. pay_enterpriseid: 0,
  113. sa_contractid: this.data.sa_contractid,
  114. sa_projectid: this.data.sa_projectid,
  115. "sa_brandid": this.data.sa_brandid, //品牌ID
  116. "type": this.data.type, //订单类型
  117. "tradefield": this.data.tradefield, //必选
  118. sys_enterpriseid: this.data.agency.sys_enterpriseid
  119. }
  120. }).then(res => {
  121. this.setData({
  122. loading: false
  123. })
  124. console.log("创建标准订单", res);
  125. wx.showToast({
  126. title: res.code != '1' ? res.msg : getApp().globalData.Language.getMapText('创建成功'),
  127. icon: "none",
  128. mask: true
  129. });
  130. if (res.code == '1') setTimeout(() => {
  131. wx.redirectTo({
  132. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  133. });
  134. let page = getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/index');
  135. if (page) page.getList(true);
  136. }, 500)
  137. })
  138. },
  139. /* 业务员逻辑 ↓ */
  140. selectAgency() {
  141. wx.navigateTo({
  142. url: `/select/agent/index?params=${JSON.stringify({
  143. "id": 20230219195002,
  144. "content": {
  145. nocache:true,
  146. "ismanage": "0",
  147. "where": {
  148. "condition": ""
  149. }
  150. }
  151. })}&radio=true`,
  152. })
  153. getApp().globalData.handleSelect = this.setAgency.bind(this);
  154. },
  155. /* 设置经销商 */
  156. setAgency({
  157. item
  158. }) {
  159. let that = this;
  160. wx.showModal({
  161. cancelText: getApp().globalData.Language.getMapText('取消'),
  162. confirmText: getApp().globalData.Language.getMapText('确定'),
  163. title: getApp().globalData.Language.getMapText('提示'),
  164. content: getApp().globalData.Language.joint([{
  165. t: 1,
  166. v: '是否确定选择'
  167. }, {
  168. v: item.enterprisename,
  169. f: "“",
  170. r: '”'
  171. }, {
  172. t: 1,
  173. v: '作为指定经销商',
  174. r: '?'
  175. }]),
  176. complete: (res) => {
  177. if (res.confirm) {
  178. that.setData({
  179. agency: item
  180. })
  181. that.getBrand(item.sys_enterpriseid)
  182. that.getDomain(item.sys_enterpriseid)
  183. wx.navigateBack()
  184. }
  185. }
  186. })
  187. }
  188. })