index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. const _Http = getApp().globalData.http;
  2. import currency from "../../utils/currency";
  3. Page({
  4. data: {
  5. loading: true,
  6. active: "新建",
  7. "content": {
  8. nocache: true,
  9. "pageNumber": 1,
  10. "pageTotal": 1,
  11. "pageSize": 20,
  12. "isManage": 0, //默认是1,表示管理端,0表示非管理端,根据用户类型自动区分业务员还是经销商
  13. "isExport": 0,
  14. total: 0,
  15. "where": {
  16. "condition": "",
  17. },
  18. sort: []
  19. },
  20. createShow: false,
  21. types: [{
  22. name: "按借用合同借用"
  23. }, {
  24. name: "单个借用"
  25. }]
  26. },
  27. onLoad(options) {
  28. this.getList(true)
  29. this.setData({
  30. userrole: wx.getStorageSync('userrole')
  31. })
  32. },
  33. getList(init = false) {
  34. if (init.detail != undefined) init = init.detail;
  35. let content = this.data.content;
  36. if (init) content.pageNumber = 1;
  37. if (content.pageNumber > content.pageTotal) return;
  38. content.where.status = this.data.active;
  39. _Http.basic({
  40. "id": 20230114105002,
  41. "version": 1,
  42. content
  43. }).then(res => {
  44. console.log("工具借用列表", res)
  45. this.selectComponent('#ListBox').RefreshToComplete();
  46. res.data = res.data.map(v => {
  47. v.amount = currency(v.amount, {
  48. symbol: "¥",
  49. precision: 2
  50. }).format()
  51. return v
  52. })
  53. this.setData({
  54. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  55. "content.pageNumber": res.pageNumber + 1,
  56. "content.pageTotal": res.pageTotal,
  57. "content.sort": res.sort,
  58. "content.total": res.total,
  59. loading: false
  60. })
  61. })
  62. },
  63. /* 去新增 */
  64. openAction() {
  65. this.setData({
  66. createShow: true
  67. })
  68. },
  69. createBor({
  70. detail
  71. }) {
  72. this.onCancel();
  73. if (detail.name == '按借用合同借用') {
  74. wx.navigateTo({
  75. url: `/select/contract/index?params=${JSON.stringify({
  76. "id": 20230114092502,
  77. "content": {
  78. nocache: true,
  79. "pageNumber": 1,
  80. "pageTotal": 1,
  81. "total": null,
  82. "pageSize": 20,
  83. "where": {
  84. "condition": ""
  85. }
  86. }
  87. })}&radio=false`
  88. })
  89. getApp().globalData.handleSelect = this.handleCreated.bind(this);
  90. } else {
  91. if (this.data.userrole == '业务员') {
  92. wx.navigateTo({
  93. url: `/select/agent/index?params=${JSON.stringify({
  94. "id": 20220920083901,
  95. "content": {
  96. nocache:true,
  97. "where": {
  98. "condition": "",
  99. "type":9,
  100. }
  101. }
  102. })}&radio=true`,
  103. })
  104. getApp().globalData.handleSelect = this.handleSingle.bind(this);
  105. } else {
  106. _Http.basic({
  107. "id": 20230116092702,
  108. "content": {
  109. "sa_orderid": 0
  110. }
  111. }).then(res => {
  112. console.log("按个", res)
  113. if (res.msg != '成功') return wx.showToast({
  114. title: res.msg,
  115. icon: "none"
  116. });
  117. wx.navigateTo({
  118. url: '/packageA/borrow/detail?id=' + res.data.sa_orderid,
  119. })
  120. })
  121. }
  122. }
  123. },
  124. handleSingle({
  125. item
  126. }) {
  127. wx.showModal({
  128. title: '提示',
  129. content: `是否确定选择"${item.enterprisename}"创建工具借用单?`,
  130. complete: (res) => {
  131. if (res.confirm) _Http.basic({
  132. "id": 20230116092702,
  133. "content": {
  134. "sa_orderid": 0,
  135. sys_enterpriseid: item.sys_enterpriseid
  136. }
  137. }).then(res => {
  138. console.log("按个", res)
  139. if (res.msg != '成功') return wx.showToast({
  140. title: res.msg,
  141. icon: "none"
  142. });
  143. wx.redirectTo({
  144. url: '/packageA/borrow/detail?id=' + res.data.sa_orderid,
  145. })
  146. })
  147. }
  148. })
  149. },
  150. handleCreated(e) {
  151. wx.showModal({
  152. title: '提示',
  153. content: `是否确认选择“${e.item.title}”创建借用单`,
  154. complete: ({
  155. confirm
  156. }) => {
  157. if (confirm) _Http.basic({
  158. "id": 20230116092702,
  159. "content": {
  160. "sa_contractid": e.id[0],
  161. "sa_orderid": 0
  162. }
  163. }).then(res => {
  164. console.log("按套", res)
  165. if (res.msg != '成功') return wx.showToast({
  166. title: res.msg,
  167. icon: "none"
  168. });
  169. _Http.basic({
  170. "id": 20230116142602,
  171. "content": {
  172. "sa_orderid": res.data.sa_orderid,
  173. "sys_enterpriseid": res.data.sys_enterpriseid,
  174. "sa_contractid": e.id[0]
  175. }
  176. }, false).then(s => {
  177. console.log("复制合同商品", s)
  178. wx.redirectTo({
  179. url: '/packageA/borrow/detail?id=' + res.data.sa_orderid,
  180. })
  181. })
  182. })
  183. }
  184. })
  185. },
  186. onCancel() {
  187. this.setData({
  188. createShow: false
  189. })
  190. },
  191. /* 搜索 */
  192. onSearch({
  193. detail
  194. }) {
  195. this.setData({
  196. "content.where.condition": detail
  197. });
  198. this.getList(true)
  199. },
  200. /* 切换tabs */
  201. tabsChange(e) {
  202. let status = "";
  203. switch (e.detail.title) {
  204. case '全部':
  205. status = "";
  206. break;
  207. case '待确认':
  208. status = "交期待确认";
  209. break;
  210. default:
  211. status = e.detail.title
  212. break;
  213. }
  214. this.setData({
  215. active: status
  216. });
  217. this.getList(true);
  218. },
  219. onReady() {
  220. this.setListHeight()
  221. },
  222. /* 设置页面高度 */
  223. setListHeight() {
  224. this.selectComponent("#ListBox").setHeight(".total", this);
  225. },
  226. })