shenNext.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. // StepPage/pages/lin/lin.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. productList:[{
  8. basic_material_id: "",basic_material_name: "",code: "",mark: "",material_id: "",name: "",number: "",size: "",price:'',total_price:'',unit:''}],
  9. chooseIndex:'',
  10. materialList:[],
  11. searchRList:[],
  12. searchCList:[],
  13. searchRValue:'',
  14. roll_film_number_arr:[],
  15. set_status:""
  16. },
  17. onSearchC(event){
  18. let arr = this.data.materialList.filter(v=>v.code.indexOf(event.detail)!=-1);
  19. this.setData({
  20. searchCList:arr
  21. })
  22. },
  23. onSearchR(event){
  24. let arr = this.data.materialList.filter(v=>v.name.indexOf(event.detail)!=-1);
  25. this.setData({
  26. searchRList:arr
  27. })
  28. },
  29. onChooseC(data){
  30. this.setData({
  31. c_show:true,
  32. searchCList:this.data.materialList,
  33. chooseIndex:data.target.dataset.index
  34. })
  35. },
  36. onChooseR(data){
  37. this.setData({
  38. r_show:true,
  39. searchRList:this.data.materialList,
  40. chooseIndex:data.target.dataset.index
  41. })
  42. },
  43. handleCancelR(){
  44. this.setData({
  45. r_show:false
  46. })
  47. },
  48. handleCancelC(){
  49. this.setData({
  50. c_show:false,
  51. })
  52. },
  53. handleChooseR(item){
  54. let arr = this.data.productList;
  55. arr[this.data.chooseIndex].basic_material_name = item.target.dataset.item.basic_material_name;
  56. arr[this.data.chooseIndex].basic_material_id = item.target.dataset.item.material_id;
  57. arr[this.data.chooseIndex].code = item.target.dataset.item.code;
  58. arr[this.data.chooseIndex].material_id = item.target.dataset.item.id;
  59. arr[this.data.chooseIndex].name = item.target.dataset.item.name;
  60. arr[this.data.chooseIndex].size = item.target.dataset.item.size;
  61. arr[this.data.chooseIndex].price = item.target.dataset.item.price;
  62. arr[this.data.chooseIndex].unit = item.target.dataset.item.unit;
  63. arr[this.data.chooseIndex].total_price = '';
  64. arr[this.data.chooseIndex].number = '';
  65. this.setData({
  66. searchRValue:'',
  67. r_show:false,
  68. productList:arr,
  69. c_show:false,
  70. searchCValue:''
  71. })
  72. },
  73. handleChangePrice(e){
  74. let arr = this.data.productList;
  75. if(isNaN(e.detail.value*1)){
  76. arr[e.target.dataset.index].price = '';
  77. this.setData({
  78. productList:arr
  79. })
  80. return wx.showToast({
  81. icon:'error',
  82. title: '请输入数字',
  83. })
  84. }
  85. arr[e.target.dataset.index].price = e.detail.value;
  86. arr[e.target.dataset.index].total_price = (e.detail.value*1*(arr[e.target.dataset.index].number?arr[e.target.dataset.index].number*1:0)).toFixed(2);
  87. this.setData({
  88. productList:arr
  89. })
  90. },
  91. handleChangeTotalPrice(e){
  92. let arr = this.data.productList;
  93. if(isNaN(e.detail.value*1)){
  94. arr[e.target.dataset.index].total_price = '';
  95. arr[e.target.dataset.index].number = '';
  96. this.setData({
  97. productList:arr
  98. })
  99. return wx.showToast({
  100. icon:'error',
  101. title: '请输入数字',
  102. })
  103. }
  104. arr[e.target.dataset.index].total_price = e.detail.value;
  105. arr[e.target.dataset.index].number =arr[e.target.dataset.index].price*1? (e.detail.value*1/arr[e.target.dataset.index].price*1).toFixed(2):0;
  106. this.setData({
  107. productList:arr
  108. })
  109. },
  110. handleChangeMark(e){
  111. let arr = this.data.productList;
  112. arr[e.target.dataset.index].mark = e.detail.value;
  113. this.setData({
  114. productList:arr
  115. })
  116. },
  117. handleChangeNumber(e){
  118. let arr = this.data.productList;
  119. if(isNaN(e.detail.value*1)){
  120. arr[e.target.dataset.index].number = '';
  121. this.setData({
  122. productList:arr
  123. })
  124. return wx.showToast({
  125. icon:'error',
  126. title: '请输入数字',
  127. })
  128. }
  129. arr[e.target.dataset.index].number = e.detail.value;
  130. arr[e.target.dataset.index].total_price = (e.detail.value*1*(arr[e.target.dataset.index].price?arr[e.target.dataset.index].price*1:0)).toFixed(2);
  131. this.setData({
  132. productList:arr
  133. })
  134. },
  135. handleAddItem(data){
  136. let arr = this.data.productList;
  137. let index = data.target.dataset.index;
  138. arr.splice(index+1,0,{basic_material_id: "",basic_material_name: "",code: "",mark: "",material_id: "",name: "",number: "",size: "",price:'',total_price:'',unit:''})
  139. this.setData({
  140. productList : arr
  141. })
  142. },
  143. handleDeleteItem(data){
  144. let arr = this.data.productList;
  145. let index = data.target.dataset.index;
  146. if(arr.length === 1 ){
  147. arr = [
  148. {basic_material_id: "",basic_material_name: "",code: "",mark: "",material_id: "",name: "",number: "",size: "",price:'',total_price:'',unit:''}
  149. ]
  150. }else{
  151. arr.splice(index,1);
  152. }
  153. this.setData({
  154. productList:arr
  155. })
  156. },
  157. handleReturn(){
  158. wx.navigateBack({
  159. delta:1
  160. })
  161. },
  162. handleBack(){
  163. let app = getApp();
  164. app.globalData={
  165. stepData:[],
  166. openID:app.globalData.openID,
  167. url:'https://zhapi.qingyaokeji.com/'
  168. }
  169. wx.navigateBack({
  170. delta:3
  171. })
  172. },
  173. handleNext(){
  174. const app = getApp();
  175. let data = {
  176. address:app.globalData.address,
  177. area:app.globalData.area,
  178. mark:app.globalData.mark,
  179. regional_manager:app.globalData.regional_manager,
  180. sub:this.data.productList,
  181. openid:app.globalData.openID
  182. }
  183. if(this.data.set_status){
  184. data.order_number = app.globalData.detailData.order_number
  185. console.log(data);
  186. wx.p.request({
  187. method:'post',
  188. url:`${app.globalData.url}wx/materialChargeEdit`,
  189. data
  190. }).then(res=>{
  191. if(res.data.code==200){
  192. wx.showToast({
  193. title: res.data.msg,
  194. })
  195. app.globalData={
  196. stepData:[],
  197. openID:app.globalData.openID,
  198. url:'https://zhapi.qingyaokeji.com/'
  199. }
  200. wx.navigateBack({
  201. delta:3
  202. })
  203. }
  204. })
  205. }else{
  206. wx.p.request({
  207. method:'post',
  208. url:`${app.globalData.url}wx/materialChargeAdd`,
  209. data
  210. }).then(res=>{
  211. if(res.data.code==200){
  212. wx.showToast({
  213. title: res.data.msg,
  214. })
  215. app.globalData={
  216. stepData:[],
  217. openID:app.globalData.openID,
  218. url:'https://zhapi.qingyaokeji.com/'
  219. }
  220. wx.navigateBack({
  221. delta:3
  222. })
  223. }
  224. })
  225. }
  226. },
  227. /**
  228. * 生命周期函数--监听页面加载
  229. */
  230. onLoad(options) {
  231. const app = getApp();
  232. const openid = app.globalData.openID;
  233. //获取卷膜型号
  234. wx.p.request({
  235. url: `${app.globalData.url}wx/materialList`,
  236. method:'POST',
  237. data:{
  238. openid
  239. }
  240. }).then(res=>{
  241. if(res.data.code==200){
  242. this.setData({
  243. materialList:res.data.data.data,
  244. })
  245. }
  246. })
  247. if(app.globalData.set_status){
  248. this.setData({
  249. productList:app.globalData.detailData.sub,
  250. set_status:app.globalData.set_status
  251. })
  252. }else{
  253. this.setData({
  254. set_status:''
  255. })
  256. }
  257. console.log(app.globalData)
  258. },
  259. /**
  260. * 生命周期函数--监听页面初次渲染完成
  261. */
  262. onReady() {
  263. },
  264. /**
  265. * 生命周期函数--监听页面显示
  266. */
  267. onShow() {
  268. },
  269. /**
  270. * 生命周期函数--监听页面隐藏
  271. */
  272. onHide() {
  273. },
  274. /**
  275. * 生命周期函数--监听页面卸载
  276. */
  277. onUnload() {
  278. },
  279. /**
  280. * 页面相关事件处理函数--监听用户下拉动作
  281. */
  282. onPullDownRefresh() {
  283. },
  284. /**
  285. * 页面上拉触底事件的处理函数
  286. */
  287. onReachBottom() {
  288. },
  289. /**
  290. * 用户点击右上角分享
  291. */
  292. onShareAppMessage() {
  293. }
  294. })