index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. const _Http = getApp().globalData.http;
  2. import currency from "../../utils/currency";
  3. let content = null;
  4. Page({
  5. data: {
  6. isInsert: false,
  7. CustomBar: getApp().globalData.CustomBar,
  8. privacyFieldC: [],
  9. },
  10. onLoad(options) {
  11. if (wx.getStorageSync('auth').worderform.options.some(v => v == 'insert')) this.setData({
  12. isInsert: true
  13. })
  14. content = {
  15. nocache: true,
  16. "isExport": 0,
  17. "pageNumber": 1,
  18. "pageTotal": 1,
  19. "where": {
  20. "condition": "",
  21. type: '标准订单',
  22. tablefilter: {}
  23. }
  24. };
  25. this.getList()
  26. try {
  27. let privacyFieldC = wx.getStorageSync('auth').worderform.forms.list.formcols.map(v => v.title);
  28. this.setData({
  29. privacyFieldC
  30. })
  31. console.log("privacyFieldC", privacyFieldC)
  32. } catch (error) {
  33. console.error(error)
  34. }
  35. },
  36. /* 获取产品 */
  37. getList(init = false) {
  38. if (init.detail != undefined) init = init.detail;
  39. if (init) content.pageNumber = 1;
  40. if (content.pageNumber > content.pageTotal) return;
  41. this.setListHeight();
  42. _Http.basic({
  43. "id": 20221224180302,
  44. content
  45. }).then(res => {
  46. console.log("订单列表", res)
  47. this.selectComponent('#ListBox').RefreshToComplete();
  48. /* 格式化价格 */
  49. if (res.data.length != 0) res.data = res.data.map(v => {
  50. v.defaultamount = currency(v.defaultamount, {
  51. symbol: "¥",
  52. precision: 2
  53. }).format();
  54. return v
  55. })
  56. content.pageNumber = res.pageNumber + 1
  57. content.pageTotal = res.pageTotal
  58. this.setData({
  59. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  60. total: res.total,
  61. amount: currency(res.tips.amount, {
  62. symbol: "¥",
  63. precision: 2
  64. }).format()
  65. })
  66. })
  67. },
  68. /* 更新列表 */
  69. updateList() {
  70. let params = JSON.parse(JSON.stringify(content));
  71. params.pageSize = (params.pageNumber - 1) * params.pageSize;
  72. params.pageNumber = 1;
  73. _Http.basic({
  74. "id": 20221224180302,
  75. content: params
  76. }).then(res => {
  77. console.log("订单列表", res)
  78. if (res.msg != '成功') return;
  79. /* 格式化价格 */
  80. if (res.data.length != 0) res.data = res.data.map(v => {
  81. v.defaultamount = currency(v.defaultamount, {
  82. symbol: "¥",
  83. precision: 2
  84. }).format();
  85. return v
  86. })
  87. this.setData({
  88. list: res.data,
  89. total: res.total,
  90. amount: currency(res.tips.amount, {
  91. symbol: "¥",
  92. precision: 2
  93. }).format()
  94. })
  95. })
  96. },
  97. /* 切换tabs */
  98. tabsChange(e) {
  99. let status = "";
  100. switch (e.detail.title) {
  101. case '全部':
  102. status = "";
  103. break;
  104. case '待确认':
  105. status = "交期待确认";
  106. break;
  107. default:
  108. status = e.detail.title
  109. break;
  110. }
  111. content.where.tablefilter.status = status;
  112. content.where.status = status;
  113. this.getList(true);
  114. },
  115. /* 搜索 */
  116. onSearch({
  117. detail
  118. }) {
  119. content.where.condition = detail;
  120. this.getList(true)
  121. },
  122. /* 设置页面高度 */
  123. setListHeight() {
  124. this.selectComponent("#ListBox").setHeight(".header", this);
  125. },
  126. showModal(e) {
  127. this.setData({
  128. modalName: e.currentTarget.dataset.target
  129. })
  130. },
  131. hideModal(e) {
  132. this.setData({
  133. modalName: null
  134. })
  135. },
  136. createOrder() {
  137. _Http.basic({
  138. "classname": "common.usercenter.usercenter",
  139. "method": "queryUserMsg",
  140. "content": {},
  141. }).then(res => {
  142. console.log("获取经销商数据", res)
  143. if (res.code != 1) return wx.showToast({
  144. title: res.msg,
  145. icon: "none"
  146. })
  147. let sys_enterpriseid = res.data.hr.sys_enterpriseid;
  148. let queryList = [{
  149. "id": 20221008134803,
  150. "version": 1,
  151. "content": {
  152. "pageNumber": 1,
  153. "pageTotal": 1,
  154. "pageSize": 9999,
  155. "where": {
  156. "condition": "",
  157. "isused": 1,
  158. "isnotspecialfund": 0,
  159. },
  160. }
  161. }, {
  162. "id": "20221013160602",
  163. "content": {
  164. sys_enterpriseid,
  165. "where": {
  166. "tablefilter": {}
  167. }
  168. }
  169. }, {
  170. "id": "20221009155803",
  171. "content": {
  172. sys_enterpriseid,
  173. "pageSize": 1000,
  174. "where": {
  175. "workaddress": 1
  176. }
  177. }
  178. }],
  179. content = {
  180. sa_orderid: 0,
  181. rec_contactsid: 0,
  182. pay_enterpriseid: 0,
  183. sa_contractid: 0,
  184. sa_projectid: 0,
  185. sa_accountclassid: 0,
  186. "sa_brandid": 0, //品牌ID
  187. "type": '标准订单', //订单类型
  188. "tradefield": '默认', //必选
  189. sys_enterpriseid
  190. };
  191. Promise.all(queryList.map(v => _Http.basic(v))).then(res1 => {
  192. res1.forEach((v, index) => {
  193. if (queryList[index].id == 20221013160602) {
  194. if (v.code == 1) {
  195. try {
  196. let item = v.data.find(s => s.isdefault);
  197. if (!item && v.data.length) item = v.data[0];
  198. content.sys_enterprise_financeid = item.sys_enterprise_financeid;
  199. content.invoicename = item.enterprisename;
  200. content.invoicetaxno = item.taxno;
  201. content.invoiceaddress = item.address;
  202. content.finance = item;
  203. } catch (error) {
  204. console.log("获取开票方式错误", error)
  205. console.log("开票方式数据", v.data)
  206. }
  207. }
  208. } else if (queryList[index].id == 20221008134803) {
  209. if (v.code == 1) {
  210. try {
  211. let item = v.data.find(v => v.accountname == '现金账户');
  212. if (!item && v.data.length) item = v.data[0];
  213. content.sa_accountclassid = item.sa_accountclassid;
  214. } catch (error) {
  215. console.log("账户错误", error)
  216. console.log("账户数据", v.data)
  217. }
  218. }
  219. } else {
  220. // 收货地址
  221. if (v.code == 1) {
  222. let list = v.data.filter(v => v.type == '收货')
  223. let item = list.find(s => s.isdefault);
  224. if (!item && list.length) item = list[0];
  225. if (!item) return;
  226. content.contact = item.name;
  227. content.name = item.name;
  228. content.phonenumber = item.phonenumber;
  229. content.province = item.province;
  230. content.city = item.city;
  231. content.county = item.county;
  232. content.address = item.address;
  233. content.rec_contactsid = item.contactsid;
  234. content.contacts = item;
  235. }
  236. }
  237. })
  238. if (!content.invoicename) return wx.showModal({
  239. title: "提示",
  240. content: "开票信息不完整:请联系总部公司补充开票信息",
  241. showCancel: false
  242. })
  243. if (!content.contact) return wx.showModal({
  244. title: "提示",
  245. content: "收货信息不完整:请联系总部公司补充收货信息",
  246. showCancel: false
  247. })
  248. this.handleAdd(content)
  249. })
  250. })
  251. },
  252. handleAdd(content) {
  253. wx.showModal({
  254. title: '提示',
  255. content: `是否确定创建订单`,
  256. complete: ({
  257. confirm
  258. }) => {
  259. if (confirm) _Http.basic({
  260. "id": 20221108111402,
  261. content
  262. }).then(res => {
  263. console.log(`创建标准订单`, res);
  264. wx.showToast({
  265. title: res.msg != '成功' ? res.msg : '创建成功',
  266. icon: "none",
  267. mask: true
  268. });
  269. if (res.msg == '成功') setTimeout(() => {
  270. wx.navigateTo({
  271. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  272. });
  273. }, 500)
  274. })
  275. }
  276. })
  277. }
  278. })