index.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. //引入网络请求
  2. import {
  3. ApiModel
  4. } from "../../utils/api.js"
  5. //引入文本校验
  6. import {
  7. TestVerify
  8. } from "../../utils/verify"
  9. const _Verify = new TestVerify()
  10. const _Http = new ApiModel()
  11. Page({
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. brandName: "", //品牌名称
  17. classify: "", //经营类目
  18. contact: "", //联系人
  19. telephone: "", //电话号
  20. companyName: "", //公司名称
  21. companyIntroduce: "", //公司介绍
  22. companyAddress: "", //公司地址
  23. userCode: "", //统一社会编码
  24. fileList: "", //logo
  25. //必填项状态 是否红色字体
  26. ErrRed: {
  27. brandNameErrRed: false, //品牌名
  28. logoErrRed: false, //logo
  29. classifyErrRed: false, //经营类目
  30. contactErrRed: false, //联系人
  31. telephoneErrRed: false, //联系方式
  32. },
  33. logoErrTips: "", //logo格式/大小错误提示
  34. telephoneErrTitle: "", //手机号错误提示
  35. tagentsid: "", //上传图片使用
  36. },
  37. /**
  38. * 生命周期函数--监听页面加载
  39. */
  40. onLoad: function (options) {
  41. /* 查询商户信息 */
  42. _Http.basic({
  43. "accesstoken": wx.getStorageSync('token'),
  44. "classname": "customer.tagents.tagents",
  45. "method": "query_enterpriseAgentsMain",
  46. "content": {}
  47. }).then(s => {
  48. if (s.msg != "成功") return;
  49. this.setData({
  50. tagentsid: s.data[0].tagentsid
  51. })
  52. })
  53. },
  54. /* 必填项,获得焦点更新状态 */
  55. isInputFocus(e) {
  56. let data = this.data.ErrRed;
  57. data[e.currentTarget.dataset.name] = false;
  58. this.setData({
  59. ErrRed: data
  60. })
  61. },
  62. /* 必填项,失去焦点更新状态 */
  63. isInputBlur(e) {
  64. let data = this.data.ErrRed;
  65. data[e.currentTarget.dataset.name] = true;
  66. this.setData({
  67. ErrRed: data
  68. })
  69. },
  70. //联系方式失去焦点校验
  71. inputTelephoneBlur(e) {
  72. if (!_Verify.phoneNumber(this.data.telephone)) {
  73. let data = this.data.ErrRed;
  74. data[e.currentTarget.dataset.name] = true;
  75. this.setData({
  76. telephoneErrTitle: "手机号格式错误",
  77. ErrRed: data
  78. })
  79. return
  80. }
  81. this.setData({
  82. telephoneErrTitle: "",
  83. })
  84. },
  85. /* 上传图片 */
  86. afterRead(event) {
  87. // 初始化数据
  88. this.setData({
  89. logoErrTips: ""
  90. })
  91. var that = this
  92. const {
  93. file
  94. } = event.detail;
  95. var index = file.url.lastIndexOf(".");
  96. var ext = file.url.substr(index + 1);
  97. const fileName = file.url.split('/'),
  98. name = fileName[fileName.length - 1];
  99. //验证文件格式大小
  100. const Uploader = _Verify.verifyUploader({
  101. file
  102. });
  103. if (Uploader == "发送请求") {
  104. wx.getFileSystemManager().readFile({
  105. filePath: file.url,
  106. // encoding:'utf-8',
  107. success: result => {
  108. //返回临时文件路径
  109. const fileData = result.data
  110. _Http.basic({
  111. "accesstoken": wx.getStorageSync('token'),
  112. "classname": "system.system.docManage",
  113. "method": "getFileName",
  114. "content": {
  115. "filename": name,
  116. "filetype": ext,
  117. "ownertable": "tagents",
  118. "ownerid": that.data.tagentsid,
  119. "ftype": "brandlogo"
  120. }
  121. }).then(res => {
  122. that.uploadFile(res, fileData)
  123. }).catch(err => {
  124. console.log(err)
  125. })
  126. },
  127. fail: console.error
  128. })
  129. } else {
  130. this.setData({
  131. logoErrTips: Uploader
  132. })
  133. }
  134. },
  135. /* 上传成功反馈 */
  136. uploadFile(res, data) {
  137. var that = this
  138. wx.request({
  139. url: res.data.obsuploadurl,
  140. method: "PUT",
  141. data: data,
  142. header: {
  143. 'content-type': 'application/octet-stream' // 默认值
  144. },
  145. success() {
  146. _Http.basic({
  147. "accesstoken": wx.getStorageSync('token'),
  148. "classname": "system.system.docManage",
  149. "method": "uploadSuccsess",
  150. "content": {
  151. "obsfilename": res.data.obsfilename
  152. }
  153. }).then(res => {
  154. if (res.msg != "成功") return;
  155. const fileList = [{
  156. url: res.data[0].fobsurl,
  157. tattachmentid: res.data[0].tattachmentid
  158. }]
  159. that.setData({
  160. fileList
  161. })
  162. }).catch(err => {
  163. console.log(err)
  164. })
  165. }
  166. })
  167. },
  168. /* 删除logo */
  169. logoDelete() {
  170. _Http.basic({
  171. "accesstoken": wx.getStorageSync('token'),
  172. "classname": "system.system.docManage",
  173. "method": "deleteDoc",
  174. "content": {
  175. "ownertable": "tagents",
  176. "ownerid": this.data.tagentsid,
  177. "tattachmentid": this.data.fileList.tattachmentid
  178. }
  179. }).then(s => {
  180. console.log(s)
  181. if (s.msg != "成功") return;
  182. this.setData({
  183. fileList: "",
  184. })
  185. })
  186. },
  187. /* 必填项目检测 */
  188. inputCertain() {
  189. let ErrRed = this.data.ErrRed,
  190. state = true;
  191. /* 品牌名 */
  192. if (!_Verify.required(this.data.brandName)) {
  193. ErrRed.brandNameErrRed = true;
  194. state = false;
  195. };
  196. /* logo */
  197. if (this.data.fileList == '') {
  198. this.setData({
  199. logoErrTips: "品牌Logo还未上传"
  200. })
  201. state = false;
  202. };
  203. /* 经营类目 */
  204. if (!_Verify.required(this.data.classify)) {
  205. ErrRed.classifyErrRed = true;
  206. state = false;
  207. };
  208. /* 联系人 */
  209. if (!_Verify.required(this.data.contact)) {
  210. ErrRed.contactErrRed = true;
  211. state = false;
  212. };
  213. /* 电话号 */
  214. if (!_Verify.phoneNumber(this.data.telephone)) {
  215. ErrRed.telephoneErrRed = true;
  216. state = false;
  217. };
  218. this.setData({
  219. ErrRed
  220. });
  221. return state;
  222. },
  223. /* 立即创建--完善设置商户信息 */
  224. setUserMsg() {
  225. //必填项,校验
  226. if (!this.inputCertain()) return;
  227. console.log(!this.inputCertain())
  228. _Http.basic({
  229. "accesstoken": wx.getStorageSync('token'),
  230. "classname": "customer.tagents.tagents",
  231. "method": "modify_enterpriseAgent",
  232. "content": {
  233. "ftype": "商户认证",
  234. "data": [{
  235. "fagentnum": this.data.companyName,
  236. "fbrand": this.data.brandName,
  237. "fcontact": this.data.contact,
  238. "fphonenumber": this.data.telephone,
  239. "faddress": this.data.companyAddress,
  240. "fdutyparagraph": this.data.userCode,
  241. "fintroduction": this.data.companyIntroduce,
  242. "saleprodclass": this.data.classify
  243. }]
  244. }
  245. }).then(s => {
  246. if (s.msg != "成功") return;
  247. this.toHomePage();
  248. })
  249. },
  250. /* 跳过 */
  251. toHomePage() {
  252. wx.reLaunch({
  253. url: '/pages/tabbarPage/Home/index'
  254. })
  255. },
  256. /**
  257. * 生命周期函数--监听页面初次渲染完成
  258. */
  259. onReady: function () {
  260. },
  261. /**
  262. * 生命周期函数--监听页面显示
  263. */
  264. onShow: function () {
  265. },
  266. /**
  267. * 生命周期函数--监听页面隐藏
  268. */
  269. onHide: function () {
  270. },
  271. /**
  272. * 生命周期函数--监听页面卸载
  273. */
  274. onUnload: function () {
  275. },
  276. /**
  277. * 页面相关事件处理函数--监听用户下拉动作
  278. */
  279. onPullDownRefresh: function () {
  280. },
  281. /**
  282. * 页面上拉触底事件的处理函数
  283. */
  284. onReachBottom: function () {
  285. },
  286. /**
  287. * 用户点击右上角分享
  288. */
  289. onShareAppMessage: function () {
  290. }
  291. })