serviceSupply.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. const app = getApp()
  2. const util = require("../../utils/jmsUtil.js");
  3. const api = require('../../api/jms.js');
  4. import moment from 'moment'
  5. Page({
  6. data: {
  7. bookno:'',
  8. showPicker:false,
  9. currentItem:'',
  10. supplyList:[{itemName:'',number:1,price:0,difTotalPrice:0}],
  11. columns:[],
  12. typeList:[],
  13. totalAmount:0,
  14. orderSkillList:[],
  15. diffId:0,
  16. skillId:'',
  17. skillName:''
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. if(options.bookno){
  24. this.setData({
  25. bookno:options.bookno
  26. });
  27. this.getSupplyTypeList();
  28. }
  29. if(options.id){
  30. this.setData({
  31. diffId:options.id
  32. });
  33. this.getDiffOrderDetail();
  34. }
  35. },
  36. getDiffOrderDetail(){
  37. wx.showLoading({
  38. title: '加载中...',
  39. });
  40. util.request(api.getDiffDetail, {
  41. diffOrderId:this.data.diffId
  42. }, 'GET').then(res => {
  43. wx.hideLoading();
  44. if (res.errno === 0) {
  45. this.setData({
  46. orderInfo:res.data,
  47. supplyList:res.data.itemList,
  48. totalAmount:res.data.difTotalPrice,
  49. bookno:res.data.bookDetailId,
  50. skillId:res.data.skillId,
  51. skillName:res.data.skillName,
  52. });
  53. this.getSupplyTypeList();
  54. }
  55. }).catch(err => {
  56. wx.hideLoading();
  57. });
  58. },
  59. getSupplyTypeList(){
  60. wx.showLoading({
  61. title: '加载中...',
  62. });
  63. util.request(api.getDiffTypeList, {
  64. bookDetailId:this.data.bookno
  65. }, 'GET').then(res => {
  66. wx.hideLoading();
  67. if (res.errno === 0) {
  68. let list=res.data.diffList;
  69. list=list.map(item=>{return item.itemName});
  70. this.setData({
  71. typeList:res.data.diffList,
  72. orderSkillList:res.data.orderSkillList,
  73. columns:list
  74. });
  75. }
  76. }).catch(err => {
  77. wx.hideLoading();
  78. });
  79. },
  80. /**
  81. * 生命周期函数--监听页面初次渲染完成
  82. */
  83. onReady: function () {
  84. },
  85. minusNum(e){
  86. let index=e.currentTarget.dataset.index;
  87. let num=e.currentTarget.dataset.num;
  88. let price=e.currentTarget.dataset.price;
  89. if(num<=1){
  90. wx.showToast({
  91. title: '数量不能再少了',
  92. icon: 'none',
  93. duration: 3000
  94. });
  95. return false;
  96. }else{
  97. let item1='supplyList['+index+']'+'.number';
  98. let item2='supplyList['+index+']'+'.difTotalPrice';
  99. this.setData({
  100. [item1]:num-1,
  101. [item2]:Number((num-1)*price).toFixed(2)
  102. });
  103. }
  104. let total=0;
  105. this.data.supplyList.forEach(item=>{
  106. total+=Number(item.difTotalPrice);
  107. });
  108. total=Number(total).toFixed(2);
  109. this.setData({
  110. totalAmount:total
  111. });
  112. },
  113. addNum(e){
  114. let index=e.currentTarget.dataset.index;
  115. let num=e.currentTarget.dataset.num;
  116. let price=e.currentTarget.dataset.price;
  117. let item1='supplyList['+index+']'+'.number';
  118. let item2='supplyList['+index+']'+'.difTotalPrice';
  119. this.setData({
  120. [item1]:num+1,
  121. [item2]:Number((num+1)*price).toFixed(2)
  122. });
  123. let total=0;
  124. this.data.supplyList.forEach(item=>{
  125. total+=Number(item.difTotalPrice);
  126. });
  127. total=total.toFixed(2);
  128. this.setData({
  129. totalAmount:total
  130. });
  131. },
  132. delItem(e){
  133. let index=e.currentTarget.dataset.index;
  134. let supplyList=this.data.supplyList;
  135. supplyList.splice(index, 1);
  136. this.setData({
  137. supplyList: supplyList
  138. });
  139. },
  140. addItem(){
  141. this.setData({
  142. supplyList: this.data.supplyList.concat({itemName:'',number:1,price:0,difTotalPrice:0}),
  143. })
  144. },
  145. pickerCancel(){
  146. this.setData({
  147. showPicker:false
  148. });
  149. },
  150. showTypePicker(e){
  151. let index=e.currentTarget.dataset.index;
  152. this.setData({
  153. currentItem:index,
  154. showPicker:true
  155. })
  156. },
  157. pickerConfirm(e){
  158. let value=e.detail.value;
  159. let index=e.detail.index;
  160. let item='supplyList['+this.data.currentItem+']';
  161. let item1='supplyList['+this.data.currentItem+']'+'.itemName';
  162. let item2='supplyList['+this.data.currentItem+']'+'.price';
  163. let item3='supplyList['+this.data.currentItem+']'+'.difTotalPrice';
  164. this.setData({
  165. // [item]:{itemName:this.data.typeList[index].itemName,
  166. // },
  167. [item1]:value,
  168. [item2]:this.data.typeList[index].price,
  169. [item3]:Number((this.data.typeList[index].price)*(this.data.supplyList[this.data.currentItem].number)).toFixed(2),
  170. showPicker:false,
  171. });
  172. let total=0;
  173. this.data.supplyList.forEach(item=>{
  174. total+=Number(item.difTotalPrice);
  175. console.log(total);
  176. });
  177. total=total.toFixed(2);
  178. this.setData({
  179. totalAmount:total
  180. });
  181. },
  182. createOrder(){
  183. let isValid=this.data.supplyList.every(item=>{return item.itemName!=''});
  184. if(isValid){
  185. wx.showLoading({
  186. title: '加载中...',
  187. });
  188. util.request(api.createDiffOrder, {
  189. bookDetailId:this.data.bookno,
  190. diffId:this.data.diffId,
  191. diffList:this.data.supplyList,
  192. skillId:this.data.skillId,
  193. skillName:this.data.skillName
  194. }, 'POST').then(res => {
  195. wx.hideLoading();
  196. if (res.errno === 0) {
  197. app.globalData.diffId=res.data.diffOrder.id;
  198. app.globalData.diffOrder=res.data.diffOrder;
  199. app.globalData.diffItem=res.data.diffItem;
  200. wx.navigateTo({
  201. url: '/pages/supplyOrder/supplyOrder',
  202. });
  203. }else{
  204. wx.showToast({
  205. title: res.errmsg,
  206. icon: 'none',
  207. });
  208. }
  209. }).catch(err => {
  210. wx.hideLoading();
  211. });
  212. }else{
  213. wx.showToast({
  214. title: '补差项内容不能为空',
  215. icon:'none'
  216. })
  217. }
  218. },
  219. handleOptionChange:function(e){
  220. console.log(e);
  221. let skillId=e.detail.value;
  222. let name='';
  223. this.data.orderSkillList.forEach(f=>{
  224. if(f.skillId==skillId){
  225. name=f.skillName;
  226. }
  227. })
  228. this.setData({
  229. skillId:skillId,
  230. skillName:name
  231. })
  232. },
  233. /**
  234. * 生命周期函数--监听页面显示
  235. */
  236. onShow: function () {
  237. this.setData({
  238. diffId:app.globalData.diffId
  239. });
  240. },
  241. onHide: function () {
  242. },
  243. onUnload: function () {
  244. },
  245. /**
  246. * 页面相关事件处理函数--监听用户下拉动作
  247. */
  248. onPullDownRefresh: function () {
  249. },
  250. /**
  251. * 页面上拉触底事件的处理函数
  252. */
  253. onReachBottom: function () {
  254. },
  255. /**
  256. * 用户点击右上角分享
  257. */
  258. onShareAppMessage: function () {
  259. },
  260. })