index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. typemx:"合同借用",
  84. "where": {
  85. "condition": ""
  86. }
  87. }
  88. })}&radio=false`
  89. })
  90. getApp().globalData.handleSelect = this.handleCreated.bind(this);
  91. } else {
  92. if (this.data.userrole == '业务员') {
  93. wx.navigateTo({
  94. url: `/select/agent/index?params=${JSON.stringify({
  95. "id": 20220920083901,
  96. "content": {
  97. nocache:true,
  98. "where": {
  99. "condition": "",
  100. "type":9,
  101. }
  102. }
  103. })}&radio=true`,
  104. })
  105. getApp().globalData.handleSelect = this.handleSingle.bind(this);
  106. } else {
  107. _Http.basic({
  108. "id": 20230116092702,
  109. "content": {
  110. "sa_orderid": 0
  111. }
  112. }).then(res => {
  113. console.log("按个", res)
  114. if (res.msg != '成功') return wx.showToast({
  115. title: res.msg,
  116. icon: "none"
  117. });
  118. wx.navigateTo({
  119. url: '/packageA/borrow/detail?id=' + res.data.sa_orderid,
  120. })
  121. })
  122. }
  123. }
  124. },
  125. handleSingle({
  126. item
  127. }) {
  128. wx.showModal({
  129. title: '提示',
  130. content: `是否确定选择"${item.enterprisename}"创建工具借用单?`,
  131. complete: (res) => {
  132. if (res.confirm) _Http.basic({
  133. "id": 20230116092702,
  134. "content": {
  135. "sa_orderid": 0,
  136. sys_enterpriseid: item.sys_enterpriseid
  137. }
  138. }).then(res => {
  139. console.log("按个", res)
  140. if (res.msg != '成功') return wx.showToast({
  141. title: res.msg,
  142. icon: "none"
  143. });
  144. wx.redirectTo({
  145. url: '/packageA/borrow/detail?id=' + res.data.sa_orderid,
  146. })
  147. })
  148. }
  149. })
  150. },
  151. handleCreated(e) {
  152. wx.showModal({
  153. title: '提示',
  154. content: `是否确认选择“${e.item.title}”创建借用单`,
  155. complete: ({
  156. confirm
  157. }) => {
  158. if (confirm) _Http.basic({
  159. "id": 20230116092702,
  160. "content": {
  161. "sa_contractid": e.id[0],
  162. "sa_orderid": 0
  163. }
  164. }).then(res => {
  165. console.log("按套", res)
  166. if (res.msg != '成功') return wx.showToast({
  167. title: res.msg,
  168. icon: "none"
  169. });
  170. _Http.basic({
  171. "id": 20230116142602,
  172. "content": {
  173. "sa_orderid": res.data.sa_orderid,
  174. "sys_enterpriseid": res.data.sys_enterpriseid,
  175. "sa_contractid": e.id[0]
  176. }
  177. }, false).then(s => {
  178. console.log("复制合同商品", s)
  179. wx.redirectTo({
  180. url: '/packageA/borrow/detail?id=' + res.data.sa_orderid,
  181. })
  182. })
  183. })
  184. }
  185. })
  186. },
  187. onCancel() {
  188. this.setData({
  189. createShow: false
  190. })
  191. },
  192. /* 搜索 */
  193. onSearch({
  194. detail
  195. }) {
  196. this.setData({
  197. "content.where.condition": detail
  198. });
  199. this.getList(true)
  200. },
  201. /* 切换tabs */
  202. tabsChange(e) {
  203. let status = "";
  204. switch (e.detail.title) {
  205. case '全部':
  206. status = "";
  207. break;
  208. case '待确认':
  209. status = "交期待确认";
  210. break;
  211. default:
  212. status = e.detail.title
  213. break;
  214. }
  215. this.setData({
  216. active: status
  217. });
  218. this.getList(true);
  219. },
  220. onReady() {
  221. this.setListHeight()
  222. },
  223. /* 设置页面高度 */
  224. setListHeight() {
  225. this.selectComponent("#ListBox").setHeight(".total", this);
  226. },
  227. })