index.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. "isdefault": 1
  177. }
  178. }
  179. }],
  180. content = {
  181. sa_orderid: 0,
  182. rec_contactsid: 0,
  183. pay_enterpriseid: 0,
  184. sa_contractid: 0,
  185. sa_projectid: 0,
  186. sa_accountclassid: 0,
  187. "sa_brandid": 0, //品牌ID
  188. "type": '标准订单', //订单类型
  189. "tradefield": '默认', //必选
  190. sys_enterpriseid
  191. };
  192. Promise.all(queryList.map(v => _Http.basic(v))).then(res1 => {
  193. res1.forEach((v, index) => {
  194. if (queryList[index].id == 20221013160602) {
  195. if (v.code == 1) {
  196. try {
  197. let item = v.data.find(s => s.isdefault);
  198. if (!item && v.data.length) item = v.data[0];
  199. content.sys_enterprise_financeid = item.sys_enterprise_financeid;
  200. content.invoicename = item.enterprisename;
  201. content.invoicetaxno = item.taxno;
  202. content.invoiceaddress = item.address;
  203. content.finance = item;
  204. } catch (error) {
  205. console.log("获取开票方式错误", error)
  206. console.log("开票方式数据", v.data)
  207. }
  208. }
  209. } else if (queryList[index].id == 20221008134803) {
  210. if (v.code == 1) {
  211. try {
  212. let item = v.data.find(v => v.accountname == '现金账户');
  213. if (!item && v.data.length) item = v.data[0];
  214. content.sa_accountclassid = item.sa_accountclassid;
  215. } catch (error) {
  216. console.log("账户错误", error)
  217. console.log("账户数据", v.data)
  218. }
  219. }
  220. } else {
  221. // 收货地址
  222. if (v.code == 1) {
  223. try {
  224. let item = v.data.find(s => s.isdefault);
  225. if (!item && v.data.length) item = v.data[0];
  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. } catch (error) {
  236. console.log("地址错误", error)
  237. console.log("地址数据", v.data)
  238. }
  239. }
  240. }
  241. })
  242. this.handleAdd(content)
  243. })
  244. })
  245. },
  246. handleAdd(content) {
  247. wx.showModal({
  248. title: '提示',
  249. content: `是否确定创建订单`,
  250. complete: ({
  251. confirm
  252. }) => {
  253. if (confirm) _Http.basic({
  254. "id": 20221108111402,
  255. content
  256. }).then(res => {
  257. console.log(`创建标准订单`, res);
  258. wx.showToast({
  259. title: res.msg != '成功' ? res.msg : '创建成功',
  260. icon: "none",
  261. mask: true
  262. });
  263. if (res.msg == '成功') setTimeout(() => {
  264. wx.navigateTo({
  265. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  266. });
  267. }, 500)
  268. })
  269. }
  270. })
  271. }
  272. })