serviceSupply.js 6.1 KB

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