change.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel();
  5. import {
  6. TestVerify
  7. } from "../../utils/verify";
  8. const _Verify = new TestVerify();
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. fprodname: "", //产品名称
  15. fprodnum: "", //产品编码
  16. attinfos: [], //附件列表
  17. fintroduction: "", //产品说明
  18. ftag: [], //产品标签
  19. showSaleprod: "", //标签显示
  20. tagents_productid: 0, //识别产品ID
  21. checked: false, //开关控件
  22. fisonsale: 0, //是否上架
  23. throttle: false, //保存节流阀
  24. errTips: {
  25. fprodname: false,
  26. fprodnum: false,
  27. showSaleprod: false,
  28. }
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function (options) {
  34. if (options.data) {
  35. const data = JSON.parse(options.data)
  36. console.log(data)
  37. let attinfos = [];
  38. for (let i = 0; i < data.attinfos.length; i++) {
  39. let arr = {
  40. url: data.attinfos[i].fobsurl,
  41. ownerid: data.attinfos[i].ownerid,
  42. tattachmentid: data.attinfos[i].tattachmentid,
  43. ownertable: data.attinfos[i].ownertable,
  44. fdocument: data.attinfos[i].fdocument
  45. }
  46. attinfos.push(arr)
  47. };
  48. /* 是否上架 */
  49. const checked = (data.fisonsale == 1) ? true : false
  50. let showSaleprod = "",
  51. ftag = data.ftag
  52. /* 空标签转换为数组格式 */
  53. if (data.ftag == null || data.ftag == '') {
  54. ftag = []
  55. } else {
  56. /* 字符串数组转换数组 */
  57. for (var i = 0; i < ftag.length; i++) {
  58. showSaleprod += ftag[i] + ' ';
  59. }
  60. }
  61. /* 渲染数据 */
  62. this.setData({
  63. fprodname: data.fprodname, //产品名称
  64. fprodnum: data.fprodnum, //产品编码
  65. attinfos, //附件列表
  66. fintroduction: data.fintroduction, //产品说明
  67. fisonsale: data.fisonsale, //是否上架
  68. ftag: ftag, //产品标签
  69. tagents_productid: data.tagents_productid, //识别产品ID
  70. showSaleprod, // 显示标签
  71. checked, //是否上架
  72. });
  73. }
  74. },
  75. /**
  76. * 生命周期函数--监听页面初次渲染完成
  77. */
  78. onReady: function () {
  79. },
  80. /* 添加图片 */
  81. imageChange(data) {
  82. this.setData({
  83. attinfos: data.detail.fileList
  84. })
  85. },
  86. /* 上架开关 */
  87. switchChange() {
  88. const checked = !this.data.checked,
  89. fisonsale = (checked) ? 1 : 0;
  90. this.setData({
  91. checked,
  92. fisonsale
  93. });
  94. },
  95. /* 表单验证 */
  96. formVerify() {
  97. let errTips = this.data.errTips,
  98. verify = true;
  99. /* 验证产品名称 */
  100. if (!_Verify.required(this.data.fprodname)) {
  101. errTips.fprodname = true;
  102. verify = false;
  103. }
  104. /* 验证产品编码 */
  105. if (!_Verify.required(this.data.fprodnum)) {
  106. errTips.fprodnum = true;
  107. verify = false;
  108. }
  109. /* 验证附件列表 */
  110. if (!_Verify.required(this.data.attinfos, "请上传产品图片")) {
  111. errTips.fprodnum = true;
  112. }
  113. this.setData({
  114. errTips
  115. })
  116. return verify;
  117. },
  118. /* 提交 */
  119. submit() {
  120. if (!this.formVerify() || this.data.throttle) return;
  121. //请求参数
  122. _Http.basic({
  123. "accesstoken": wx.getStorageSync('userData').token,
  124. "classname": "customer.products.products",
  125. "method": "insertOrModifyProducts",
  126. "content": {
  127. "tagents_productid": this.data.tagents_productid,
  128. "fprodnum": this.data.fprodnum,
  129. "fprodname": this.data.fprodname,
  130. "fintroduction": this.data.fintroduction,
  131. "ftag": this.data.ftag,
  132. "fisonsale": this.data.fisonsale
  133. }
  134. }).then(res => {
  135. console.log(res)
  136. if (res.msg != "成功") return wx.showToast({
  137. title: res.data,
  138. icon: "none"
  139. });
  140. this.setData({
  141. throttle: true//设置节流阀
  142. });
  143. let content = {
  144. ownerid: res.data[0].tagents_productid,
  145. ownertable: "tagents_product",
  146. tattachmentid: 0
  147. };
  148. this.selectComponent("#UploadFiles").saveTheChanges(content);
  149. wx.showToast({
  150. title: '保存成功',
  151. })
  152. setTimeout(() => {
  153. wx.navigateBack({
  154. delta: 1,
  155. })
  156. }, 500)
  157. })
  158. },
  159. /* 获取焦点 */
  160. inputFocus(e) {
  161. const {
  162. name
  163. } = e.currentTarget.dataset;
  164. let errTips = this.data.errTips;
  165. errTips[name] = false;
  166. /* 经营类目提示框 */
  167. if (name == 'showSaleprod') {
  168. errTips[name] = true;
  169. }
  170. this.setData({
  171. errTips
  172. })
  173. },
  174. /* 失去焦点 */
  175. inputBlur(e) {
  176. const {
  177. name
  178. } = e.currentTarget.dataset;
  179. const {
  180. value
  181. } = e.detail;
  182. let errTips = this.data.errTips;
  183. if (value.trim() == "") errTips[name] = true;
  184. /* 经营类目提示框,字符串转化数组 */
  185. if (name == 'showSaleprod') {
  186. errTips[name] = false;
  187. const ftag = this.data.showSaleprod.split(" ");
  188. this.setData({
  189. ftag
  190. })
  191. };
  192. this.setData({
  193. errTips
  194. })
  195. },
  196. /**
  197. * 生命周期函数--监听页面显示
  198. */
  199. onShow: function () {
  200. },
  201. /**
  202. * 生命周期函数--监听页面隐藏
  203. */
  204. onHide: function () {
  205. },
  206. /**
  207. * 生命周期函数--监听页面卸载
  208. */
  209. onUnload: function () {},
  210. /**
  211. * 页面相关事件处理函数--监听用户下拉动作
  212. */
  213. onPullDownRefresh: function () {
  214. },
  215. /**
  216. * 页面上拉触底事件的处理函数
  217. */
  218. onReachBottom: function () {
  219. },
  220. /**
  221. * 用户点击右上角分享
  222. */
  223. onShareAppMessage: function () {
  224. }
  225. })