addOrder.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. const _Http = getApp().globalData.http,
  2. {
  3. formatTime
  4. } = require("../../utils/getTime");
  5. let pageNumber = 1,
  6. pageTotal = 1,
  7. sys_payorderid = null,
  8. currency = require("../../utils/currency"),
  9. CNY = value => currency(value, {
  10. symbol: "¥",
  11. precision: 2
  12. }).format();
  13. Page({
  14. data: {
  15. users: [],
  16. remarks: "",
  17. showAmount: "¥0.00",
  18. isDelete: true
  19. },
  20. onLoad(options) {
  21. this.setData({
  22. sys_payinstructions: wx.getStorageSync('siteP').sys_payinstructions,
  23. sys_payincidence: 1,
  24. opUsers: options.users ? JSON.parse(options.users) : []
  25. })
  26. sys_payorderid = options.sys_payorderid;
  27. console.log(options)
  28. this.getVersions(options.vid || "");
  29. },
  30. /* 保存订单进度 */
  31. changeOrder() {
  32. _Http.basic({
  33. "classname": "system.payorder.payorder",
  34. "method": "insertUsers",
  35. "content": {
  36. "sys_site_systempartitionid": this.data.sys_site_systempartitionid,
  37. sys_payorderid,
  38. "remarks": this.data.remarks,
  39. "users": this.data.users.map(v => {
  40. let item = this.data.userList.find(s => {
  41. let id = this.data.sys_payincidence == 1 ? s.userid : s.sa_agentsid;
  42. return id == v
  43. })
  44. return {
  45. "isleader": item.isleader,
  46. "userid": item.userid,
  47. "sa_agentsid": item.sa_agentsid,
  48. "enddate": item.enddate[this.data.sys_site_systempartitionid] || ''
  49. }
  50. })
  51. }
  52. }).then(res => {
  53. console.log("修改订单信息", res)
  54. if (res.msg != '成功') return wx.showToast({
  55. title: res.msg,
  56. icon: "none",
  57. mask: true
  58. });
  59. this.setData({
  60. showAmount: CNY(res.data.amount),
  61. orderno: res.data.orderno
  62. })
  63. })
  64. },
  65. /* 更改备注 */
  66. onblur(e) {
  67. console.log(e)
  68. if (e.detail.value == this.data.remarks) return;
  69. this.setData({
  70. remarks: e.detail.value
  71. });
  72. this.changeOrder();
  73. },
  74. /* 获取版本 */
  75. getVersions(vid) {
  76. _Http.basic({
  77. "classname": "system.payorder.payorder",
  78. "method": "chooseSystemPartition",
  79. "content": {
  80. "pageNumber": 1,
  81. "pageSize": 9999,
  82. "where": {
  83. "condition": ""
  84. }
  85. }
  86. }).then(res => {
  87. console.log("版本列表", res)
  88. if (res.msg != '成功') {
  89. wx.showToast({
  90. title: res.msg,
  91. icon: "none",
  92. mask: true
  93. })
  94. setTimeout(() => {
  95. wx.navigateBack();
  96. }, 1000)
  97. return;
  98. };
  99. let sys_site_systempartitionid = res.data[0].sys_site_systempartitionid || '';
  100. if (vid && res.data.some(v => v.sys_site_systempartitionid == vid)) sys_site_systempartitionid = vid - 0;
  101. this.setData({
  102. versionsList: res.data,
  103. sys_site_systempartitionid
  104. })
  105. this.getUsers(true);
  106. })
  107. },
  108. /* 切换版本 */
  109. changeVer(e) {
  110. const {
  111. sys_site_systempartitionid
  112. } = e.currentTarget.dataset.item;
  113. if (this.data.sys_site_systempartitionid == sys_site_systempartitionid) return;
  114. this.setData({
  115. sys_site_systempartitionid
  116. });
  117. this.setUsers();
  118. },
  119. checkVer(e) {
  120. const {
  121. item
  122. } = e.currentTarget.dataset;
  123. this.selectComponent("#inventory").show(item.systemapp)
  124. },
  125. /* 获取可添加账号/主体 */
  126. getUsers(init = false) {
  127. if (init) {
  128. pageNumber = 1;
  129. pageTotal = 1;
  130. };
  131. if (pageNumber > pageTotal) return;
  132. _Http.basic({
  133. "classname": "system.payorder.payorder",
  134. "method": "chooseUsers",
  135. "content": {
  136. pageNumber,
  137. "pageSize": 99999,
  138. "where": {
  139. "condition": ""
  140. }
  141. }
  142. }).then(res => {
  143. console.log("用户列表", res)
  144. if (res.msg != '成功') {
  145. wx.showToast({
  146. title: res.msg,
  147. icon: "none",
  148. mask: true
  149. })
  150. setTimeout(() => {
  151. wx.navigateBack();
  152. }, 1000)
  153. return;
  154. };
  155. pageTotal = res.pageTotal;
  156. this.setData({
  157. userList: res.pageNumber == 1 ? res.data : this.data.userList.concat(res.data)
  158. })
  159. pageNumber = res.pageNumber + 1;
  160. this.setUsers(this.data.opUsers.filter(id => this.data.userList.some(v => id == v.userid)));
  161. // this.changeOrder();
  162. })
  163. },
  164. setUsers(users = []) {
  165. let list = this.data.userList,
  166. idname = this.data.sys_payincidence == 1 ? 'userid' : 'sa_agentsid'
  167. list.forEach(v => {
  168. let date = v.enddate[this.data.sys_site_systempartitionid];
  169. if (v.userid == wx.getStorageSync('userMsg').userid || v.isleader == 1) {
  170. if (date) {
  171. // if (formatTime(new Date(), '-').split(" ")[0] >= date) users.push(v[idname] + '');
  172. } else {
  173. if (!users.some(v => v == v[idname])) users.push(v[idname] + '');
  174. }
  175. }
  176. });
  177. this.setData({
  178. users
  179. });
  180. this.changeOrder();
  181. },
  182. onReachBottom() {
  183. // this.getUsers();
  184. },
  185. onChange(e) {
  186. const {
  187. id
  188. } = e.currentTarget.dataset;
  189. let users = this.data.users;
  190. if (users.some(v => v == id)) {
  191. users = users.filter(s => s != id)
  192. } else {
  193. users.push(id + "")
  194. }
  195. this.setData({
  196. users
  197. });
  198. this.changeOrder();
  199. },
  200. /* 支付 */
  201. payment() {
  202. let that = this;
  203. that.data.isDelete = false;
  204. wx.login({
  205. success: (s) => {
  206. _Http.basic({
  207. "classname": "system.payment.wechatpay",
  208. "method": "createWechatOrder",
  209. "content": {
  210. "orderno": that.data.orderno,
  211. "wechat_code": s.code,
  212. "trade_type": "JSAPI"
  213. }
  214. }).then(res => {
  215. console.log(res)
  216. wx.requestPayment({
  217. timeStamp: res.data.timeStamp,
  218. nonceStr: res.data.nonceStr,
  219. package: res.data.package,
  220. signType: res.data.signType,
  221. paySign: res.data.paySign,
  222. success() {
  223. wx.showToast({
  224. title: '支付成功',
  225. mask: true
  226. })
  227. },
  228. fail(err) {
  229. wx.showToast({
  230. title: '支付失败',
  231. icon: "error",
  232. mask: true
  233. })
  234. console.error(err)
  235. },
  236. complete(e) {
  237. console.log(e)
  238. setTimeout(() => {
  239. wx.redirectTo({
  240. url: '/pages/teams/order?id=' + sys_payorderid,
  241. })
  242. }, 1000)
  243. }
  244. })
  245. })
  246. },
  247. })
  248. },
  249. onUnload() {
  250. if (this.data.isDelete) _Http.basic({
  251. "classname": "system.payorder.payorder",
  252. "method": "delete",
  253. "content": {
  254. sys_payorderid
  255. }
  256. }).then(res => {
  257. console.log("删除订单", res)
  258. })
  259. }
  260. })