alteration.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. loading: false,
  5. disabled: true,
  6. showAll: false,
  7. selectedProducts: [],
  8. sa_orderid: null,
  9. today: '',
  10. form: [{
  11. label: "服务类型",
  12. error: false,
  13. errMsg: "",
  14. hint: "",
  15. type: "radio",
  16. value: "",
  17. radioList: [],
  18. valueName: "typeclass", //绑定的字段名称
  19. required: true, //必填
  20. checking: `base`,
  21. }, {
  22. label: "原因描写",
  23. error: false,
  24. errMsg: "",
  25. type: "textarea",
  26. value: "",
  27. placeholder: "请填写",
  28. valueName: "remarks",
  29. required: true,
  30. checking: "base"
  31. }]
  32. },
  33. onLoad(options) {
  34. // 设置今天的日期,用于日期选择器的start值
  35. const today = new Date();
  36. const year = today.getFullYear();
  37. const month = String(today.getMonth() + 1).padStart(2, '0');
  38. const day = String(today.getDate()).padStart(2, '0');
  39. const todayStr = `${year}-${month}-${day}`;
  40. this.setData({
  41. sa_orderid: options.id,
  42. today: todayStr
  43. });
  44. this.getDetail();
  45. getApp().globalData.Language.getLanguagePackage(this, '订单变更申请');
  46. const form = this.data.form;
  47. _Http.basic({
  48. "classname": "sysmanage.develop.optiontype.optiontype",
  49. "method": "optiontypeselect",
  50. "content": {
  51. "pageNumber": 1,
  52. "pageSize": 1000,
  53. "typename": "orderchangereason",
  54. },
  55. }).then(res => {
  56. console.log("变更类型", res)
  57. if (res.code == 1) {
  58. let data = form.find(v => v.valueName == 'typeclass');
  59. data.radioList = res.data.map(v => {
  60. return {
  61. id: v.value,
  62. name: v.value,
  63. }
  64. });;
  65. data.value = data.value || data.radioList[0].id;
  66. this.setData({
  67. form
  68. })
  69. }
  70. })
  71. },
  72. getDetail() {
  73. // 从详情页面获取选中的商品
  74. let pages = getCurrentPages();
  75. let detailPage = pages.find(v => v.__route__ == 'packageA/orderForm/detail');
  76. this.setData({
  77. selectedProducts: detailPage.data.selectedProducts || []
  78. });
  79. if (this.data.selectedProducts.length == 0) {
  80. wx.showToast({
  81. title: '请先选择要变更的商品',
  82. icon: 'none'
  83. });
  84. setTimeout(() => {
  85. wx.navigateBack();
  86. }, 1000);
  87. }
  88. },
  89. onConfirm({
  90. detail
  91. }) {
  92. this.setData({
  93. disabled: detail
  94. })
  95. },
  96. /* 处理变更数量 */
  97. onChangeValue(e) {
  98. const {
  99. index
  100. } = e.currentTarget.dataset;
  101. const value = e.detail.value;
  102. let selectedProducts = [...this.data.selectedProducts];
  103. selectedProducts[index].newvalue = value;
  104. this.setData({
  105. selectedProducts
  106. });
  107. },
  108. /* 处理变更交期 */
  109. onChangeDate(e) {
  110. const {
  111. index
  112. } = e.currentTarget.dataset;
  113. const value = e.detail.value;
  114. let selectedProducts = [...this.data.selectedProducts];
  115. selectedProducts[index].newdeliverydate = value;
  116. this.setData({
  117. selectedProducts
  118. });
  119. },
  120. /* 取消按钮点击事件 */
  121. cancel() {
  122. wx.showModal({
  123. title: '提示',
  124. content: '确定要取消订单变更申请吗?',
  125. cancelText: '取消',
  126. confirmText: '确定',
  127. success: (res) => {
  128. if (res.confirm) {
  129. wx.navigateBack();
  130. }
  131. }
  132. });
  133. },
  134. /* 提交按钮点击事件 */
  135. submit() {
  136. // 二次确认
  137. wx.showModal({
  138. title: '提示',
  139. content: '确定要提交订单变更申请吗?',
  140. cancelText: '取消',
  141. confirmText: '确定',
  142. success: (res) => {
  143. if (res.confirm) {
  144. this.doSubmit();
  145. }
  146. }
  147. });
  148. },
  149. /* 执行提交操作 */
  150. doSubmit() {
  151. // 提交申请
  152. this.setData({
  153. loading: true,
  154. disabled: true
  155. });
  156. // 构建itemifnos数组
  157. let itemifnos = this.data.selectedProducts.map(item => {
  158. return {
  159. sa_orderitemsid: item.sa_orderitemsid,
  160. itemid: item.itemid,
  161. newvalue: item.newvalue || item.qty,
  162. newdeliverydate: item.newdeliverydate || item.deliverydate || ''
  163. };
  164. });
  165. _Http.basic({
  166. "id": "2026033114502902",
  167. "content": {
  168. sa_orderid: this.data.sa_orderid,
  169. type: "",
  170. ...this.selectComponent("#Form").submit(),
  171. itemifnos
  172. }
  173. }).then(res => {
  174. console.log('提交订单变更申请', res);
  175. this.setData({
  176. loading: false,
  177. disabled: false
  178. });
  179. if (res.code == '1') {
  180. // 获取详情页面实例
  181. let pages = getCurrentPages();
  182. let detailPage = pages.find(v => v.__route__ == 'packageA/orderForm/detail');
  183. if (detailPage) {
  184. // 调用详情页面的getDetail方法更新数据
  185. detailPage.getDetail(false, false);
  186. }
  187. // 先返回详情页面,在回调中显示提示
  188. wx.navigateBack({
  189. success: () => {
  190. // 显示提交成功的提示
  191. wx.showToast({
  192. title: '提交成功',
  193. icon: 'success'
  194. });
  195. }
  196. });
  197. } else {
  198. wx.showToast({
  199. title: res.msg,
  200. icon: 'none'
  201. });
  202. }
  203. }).catch(err => {
  204. console.error('提交订单变更申请失败', err);
  205. this.setData({
  206. loading: false,
  207. disabled: false
  208. });
  209. wx.showToast({
  210. title: '提交失败,请重试',
  211. icon: 'none'
  212. });
  213. });
  214. }
  215. })