change.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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: true, //开关控件
  22. fisonsale: 1, //是否上架
  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. /* 空标签转换为数组格式
  52. ftag = data.ftag
  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 that = this;
  89. wx.showModal({
  90. title: "提示",
  91. content: (this.data.checked) ? '是否确认下架该产品' : '是否确认上架该产品',
  92. success(res) {
  93. if (res.confirm) {
  94. const checked = !that.data.checked,
  95. fisonsale = (checked) ? 1 : 0;
  96. that.setData({
  97. checked,
  98. fisonsale
  99. });
  100. }
  101. }
  102. })
  103. },
  104. /* 表单验证 */
  105. formVerify() {
  106. let errTips = this.data.errTips,
  107. verify = true;
  108. /* 验证产品名称 */
  109. if (!_Verify.required(this.data.fprodname)) {
  110. errTips.fprodname = true;
  111. verify = false;
  112. }
  113. /* 验证产品编码 */
  114. if (!_Verify.required(this.data.fprodnum)) {
  115. errTips.fprodnum = true;
  116. verify = false;
  117. }
  118. /* 验证附件列表 */
  119. if (!_Verify.required(this.data.attinfos, "请上传产品图片")) {
  120. errTips.fprodnum = true;
  121. }
  122. this.setData({
  123. errTips
  124. })
  125. return verify;
  126. },
  127. /* 提交 */
  128. submit() {
  129. if (!this.formVerify() || this.data.throttle) return;
  130. //请求参数
  131. _Http.basic({
  132. "accesstoken": wx.getStorageSync('userData').token,
  133. "classname": "customer.products.products",
  134. "method": "insertOrModifyProducts",
  135. "content": {
  136. "tagents_productid": this.data.tagents_productid,
  137. "fprodnum": this.data.fprodnum,
  138. "fprodname": this.data.fprodname,
  139. "fintroduction": this.data.fintroduction,
  140. "ftag": this.data.ftag,
  141. "fisonsale": this.data.fisonsale
  142. }
  143. }).then(res => {
  144. console.log(res)
  145. if (res.msg != "成功") return wx.showToast({
  146. title: res.data,
  147. icon: "none"
  148. });
  149. this.setData({
  150. throttle: true //设置节流阀
  151. });
  152. let content = {
  153. ownerid: res.data[0].tagents_productid,
  154. ownertable: "tagents_product",
  155. tattachmentid: 0
  156. };
  157. this.selectComponent("#UploadFiles").saveTheChanges(content);
  158. wx.showToast({
  159. title: '保存成功',
  160. })
  161. setTimeout(() => {
  162. wx.navigateBack({
  163. delta: 1,
  164. })
  165. }, 500)
  166. })
  167. },
  168. /* 获取焦点 */
  169. inputFocus(e) {
  170. const {
  171. name
  172. } = e.currentTarget.dataset;
  173. let errTips = this.data.errTips;
  174. errTips[name] = false;
  175. /* 经营类目提示框 */
  176. if (name == 'showSaleprod') {
  177. errTips[name] = true;
  178. }
  179. this.setData({
  180. errTips
  181. })
  182. },
  183. /* 失去焦点 */
  184. inputBlur(e) {
  185. const {
  186. name
  187. } = e.currentTarget.dataset;
  188. const {
  189. value
  190. } = e.detail;
  191. let errTips = this.data.errTips;
  192. if (value.trim() == "") errTips[name] = true;
  193. /* 经营类目提示框,字符串转化数组 */
  194. if (name == 'showSaleprod') {
  195. errTips[name] = false;
  196. const ftag = this.data.showSaleprod.split(" ");
  197. this.setData({
  198. ftag
  199. })
  200. };
  201. this.setData({
  202. errTips
  203. })
  204. },
  205. /**
  206. * 生命周期函数--监听页面显示
  207. */
  208. onShow: function () {
  209. },
  210. /**
  211. * 生命周期函数--监听页面隐藏
  212. */
  213. onHide: function () {
  214. },
  215. /**
  216. * 生命周期函数--监听页面卸载
  217. */
  218. onUnload: function () {},
  219. /**
  220. * 页面相关事件处理函数--监听用户下拉动作
  221. */
  222. onPullDownRefresh: function () {
  223. },
  224. /**
  225. * 页面上拉触底事件的处理函数
  226. */
  227. onReachBottom: function () {
  228. },
  229. /**
  230. * 用户点击右上角分享
  231. */
  232. onShareAppMessage: function () {
  233. }
  234. })