add.js 5.8 KB

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