change.js 7.6 KB

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