add.js 5.9 KB

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