index.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. isDisabled: false, //是否禁用
  15. butText: "保存", //按钮文字
  16. popups: false, //弹出层控制
  17. /* */
  18. fbrand: "", //品牌名称
  19. attinfos: [], // 图片列表
  20. coverAttinfos: [], //品牌展示图
  21. isLogo: [], //用于判断是否上传logo
  22. saleprodclass: [], //经营类目
  23. showSaleprodclass: "", //显示经营类目
  24. fcontact: "", //联系人
  25. fphonenumber: "", //联系方式
  26. fagentname: "", //商户名称
  27. fintroduction: "", //商户介绍
  28. faddress: "", //地址
  29. fdutyparagraph: "", //统一社会代码
  30. requestType: "普通修改", //请求类型
  31. /* */
  32. errTips: {
  33. fbrand: false,
  34. attinfos: false,
  35. saleprodclass: false,
  36. fcontact: false,
  37. fphonenumber: false,
  38. fagentname: false,
  39. fintroduction: false,
  40. faddress: false,
  41. }
  42. },
  43. /**
  44. * 生命周期函数--监听页面加载
  45. */
  46. onLoad: function (options) {
  47. // 判断主子账号 是否禁用
  48. this.setData({
  49. isDisabled: (wx.getStorageSync('userData').fisadministrator == 1) ? false : true
  50. });
  51. //判断进入方式
  52. if (options.data == null) {
  53. console.log("注册进入")
  54. this.setData({
  55. requestType: "商户认证"
  56. })
  57. } else if (options.data == 1) {
  58. wx.showToast({
  59. title: '商户信息审核中',
  60. icon: 'none',
  61. duration: 5000
  62. });
  63. this.setData({
  64. requestType: "商户认证",
  65. isDisabled: true
  66. })
  67. } else {
  68. console.log("商户进入");
  69. const data = JSON.parse(options.data);
  70. console.log(data)
  71. this.returnData(data)
  72. }
  73. },
  74. /* 添加图片 */
  75. imageChange(data) {
  76. this.setData({
  77. attinfos: data.detail.fileList
  78. })
  79. },
  80. coverImageChange(data) {
  81. this.setData({
  82. coverAttinfos: data.detail.fileList
  83. })
  84. },
  85. /* 选择类目回调 */
  86. saleprodChange(arr) {
  87. let detail = arr.detail,
  88. showSaleprodclass = "";
  89. for (let i = 0; i < detail.length; i++) {
  90. showSaleprodclass += (detail[i] + ',');
  91. };
  92. this.setData({
  93. popups: false,
  94. saleprodclass: detail,
  95. showSaleprodclass: showSaleprodclass.slice(0, showSaleprodclass.length - 1)
  96. })
  97. },
  98. /* 返回数据 */
  99. returnData(data) {
  100. var attinfos = [],
  101. coverAttinfos = [];
  102. // 格式化图片
  103. for (let i = 0; i < data.attinfos.length; i++) {
  104. const Data = {
  105. url: data.attinfos[i].fobsurl,
  106. ownerid: data.attinfos[i].ownerid,
  107. tattachmentid: data.attinfos[i].tattachmentid,
  108. ownertable: data.attinfos[i].ownertable,
  109. fdocument: data.attinfos[i].fdocument
  110. };
  111. (data.attinfos[i].ftype == "brandlogo") ? attinfos.unshift(Data): coverAttinfos.unshift(Data);
  112. }
  113. //格式化经营类目
  114. if (data.saleprodclass.length >= 1) {
  115. this.saleprodChange({
  116. detail: data.saleprodclass
  117. })
  118. }
  119. this.setData({
  120. fbrand: data.fbrand,
  121. saleprodclass: data.saleprodclass,
  122. fcontact: data.fcontact,
  123. fphonenumber: data.fphonenumber,
  124. fintroduction: data.fintroduction,
  125. fagentname: data.fagentname,
  126. faddress: data.faddress,
  127. fdutyparagraph: data.fdutyparagraph,
  128. attinfos,
  129. coverAttinfos
  130. })
  131. },
  132. /* 提交数据 */
  133. submit() {
  134. if (!this.formVerify()) return wx.showToast({
  135. title: '请检查表单内容',
  136. icon: "error"
  137. });
  138. if (this.data.attinfos.length < 1) return wx.showToast({
  139. title: '请上传品牌LOGO!',
  140. icon: "none"
  141. });
  142. if (this.data.coverAttinfos.length < 1) return wx.showToast({
  143. title: '请上传品牌展示图!',
  144. icon: "none"
  145. });
  146. const that = this;
  147. if (this.data.requestType == '普通修改') {
  148. wx.showModal({
  149. title: '提示',
  150. content: "是否确认修改商户信息",
  151. success: (res => {
  152. if (res.confirm) {
  153. that.requestToSend();
  154. };
  155. })
  156. })
  157. } else {
  158. that.requestToSend();
  159. }
  160. },
  161. /* 发送请求 */
  162. requestToSend() {
  163. _Http.basic({
  164. "accesstoken": wx.getStorageSync('userData').token,
  165. "classname": "customer.tagents.tagents",
  166. "method": "modify_enterpriseAgent",
  167. "content": {
  168. "ftype": this.data.requestType,
  169. "data": [{
  170. "fbrand": this.data.fbrand,
  171. "saleprodclass": this.data.saleprodclass,
  172. "fcontact": this.data.fcontact,
  173. "fphonenumber": this.data.fphonenumber,
  174. "fagentname": this.data.fagentname,
  175. "fintroduction": this.data.fintroduction,
  176. "faddress": this.data.faddress,
  177. "fdutyparagraph": this.data.fdutyparagraph,
  178. }]
  179. }
  180. }).then(res => {
  181. if (res.msg != '成功') return wx.showToast({
  182. title: res.data,
  183. })
  184. wx.showToast({
  185. title: '提交成功',
  186. });
  187. setTimeout(() => {
  188. wx.navigateBack({
  189. delta: 1,
  190. })
  191. }, 500)
  192. })
  193. },
  194. /* 表单验证 */
  195. formVerify() {
  196. let errTips = this.data.errTips,
  197. verify = true;
  198. /* 验证品牌名 */
  199. if (!_Verify.required(this.data.fbrand)) {
  200. errTips.fbrand = true;
  201. verify = false;
  202. }
  203. /* 验证经营类目 */
  204. if (!_Verify.required(this.data.showSaleprodclass)) {
  205. errTips.saleprodclass = true;
  206. verify = false;
  207. }
  208. /* 验证联系人 */
  209. if (!_Verify.required(this.data.fcontact)) {
  210. errTips.fcontact = true;
  211. verify = false;
  212. }
  213. /* 验证联系方式 */
  214. if (!_Verify.phoneNumber(this.data.fphonenumber)) {
  215. errTips.fphonenumber = true;
  216. verify = false;
  217. }
  218. /* 验证商户名称 */
  219. if (!_Verify.required(this.data.fagentname)) {
  220. errTips.fagentname = true;
  221. verify = false;
  222. }
  223. /* 验证商户介绍 */
  224. if (!_Verify.required(this.data.fintroduction)) {
  225. errTips.fintroduction = true;
  226. verify = false;
  227. }
  228. /* 验证地址 */
  229. if (!_Verify.required(this.data.faddress)) {
  230. errTips.faddress = true;
  231. verify = false;
  232. }
  233. this.setData({
  234. errTips
  235. })
  236. return verify;
  237. },
  238. /* 弹出层 */
  239. showPop() {
  240. if (this.data.isDisabled) return;
  241. this.setData({
  242. popups: !this.data.popups
  243. })
  244. },
  245. /* 获取焦点 */
  246. inputFocus(e) {
  247. const {
  248. name
  249. } = e.currentTarget.dataset;
  250. let errTips = this.data.errTips;
  251. errTips[name] = false;
  252. this.setData({
  253. errTips
  254. })
  255. },
  256. /* 失去焦点 */
  257. inputBlur(e) {
  258. const {
  259. name
  260. } = e.currentTarget.dataset;
  261. const {
  262. value
  263. } = e.detail;
  264. let errTips = this.data.errTips;
  265. /* 联系方式验证 */
  266. if (name == 'fphonenumber') {
  267. if (!_Verify.phoneNumber(this.data.fphonenumber, true)) errTips[name] = true;
  268. }
  269. if (value.trim() == "") {
  270. errTips[name] = true;
  271. }
  272. this.setData({
  273. errTips
  274. })
  275. },
  276. /**
  277. * 生命周期函数--监听页面初次渲染完成
  278. */
  279. onReady: function () {
  280. },
  281. /**
  282. * 生命周期函数--监听页面显示
  283. */
  284. onShow: function () {
  285. },
  286. /**
  287. * 生命周期函数--监听页面隐藏
  288. */
  289. onHide: function () {
  290. },
  291. /**
  292. * 生命周期函数--监听页面卸载
  293. */
  294. onUnload: function () {
  295. },
  296. /**
  297. * 页面相关事件处理函数--监听用户下拉动作
  298. */
  299. onPullDownRefresh: function () {
  300. },
  301. /**
  302. * 页面上拉触底事件的处理函数
  303. */
  304. onReachBottom: function () {
  305. },
  306. /**
  307. * 用户点击右上角分享
  308. */
  309. onShareAppMessage: function () {
  310. }
  311. })