add.php 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. use common\helpers\AddonHelper;
  4. ComponentHelper::loadComponentView('form-diy-menus', AddonHelper::getAddonRootPath('SmartForm') . 'backend/views/components/formDiy');
  5. ComponentHelper::loadComponentView('form-diy-tool', AddonHelper::getAddonRootPath('SmartForm') . 'backend/views/components/formDiy');
  6. ComponentHelper::loadComponentView('form-diy-data', AddonHelper::getAddonRootPath('SmartForm') . 'backend/views/components/formDiy');
  7. ComponentHelper::loadComponentView('form-diy-model', AddonHelper::getAddonRootPath('SmartForm') . 'backend/views/components/formDiy');
  8. ?>
  9. <div id="app" class="u_box">
  10. <div class="nav">表单管理</div>
  11. <div style="height: 10px;"></div>
  12. <div class="body_box">
  13. <div class="diy_box">
  14. <form-diy-menus :list="menusList" @add-prev-item="addTool"></form-diy-menus>
  15. <div class="tool_yu_nbox">
  16. <div class="diy_tool_center_box">
  17. <form-diy-tool :tool-list="toolList" :tool-index="toolIndex" @change="diyToolChange"></form-diy-tool>
  18. </div>
  19. <!-- <div class="diy_tool_box">
  20. <div class="diy-phone">
  21. <div class="phone-body">
  22. <form-diy-tool :tool-list="toolList" :tool-index="toolIndex" @change="diyToolChange"></form-diy-tool>
  23. </div>
  24. </div>
  25. </div> -->
  26. </div>
  27. <form-diy-data :active-item="toolItem" @update="updateData"></form-diy-data>
  28. </div>
  29. <div class="dorm_diy_btn_box">
  30. <el-button size="small" @click="$historyGo(-1)">取消</el-button>
  31. <el-button size="small" style="margin-left: 30px;" type="primary" @click="save">保存</el-button>
  32. </div>
  33. </div>
  34. <el-dialog :visible.sync="saveModel" width="980px">
  35. <div class="phone_save_box">
  36. <div class="phone_model_w_box">
  37. <img src="resources/img/decorate/phone.png" class="pjone_bg_box">
  38. <div class="phone_form_body_box">
  39. <div class="phone_form_title_box">
  40. {{form.title || '自定义标题'}}
  41. </div>
  42. <div class="phone_form_body_mdg_box">
  43. <div class="phone_s_img_box" v-if="form.show_heard">
  44. <img :src="form.first_img" class="img_h_bx" />
  45. </div>
  46. <form-diy-model :tool-list="toolList"></form-diy-model>
  47. </div>
  48. <el-button class="phone_sub_btn">提 交</el-button>
  49. </div>
  50. </div>
  51. <div class="phone_form_data_box">
  52. <el-form :model="form" label-position="right" label-width="100">
  53. <div class="form_data_label_box">
  54. <div class="line_form_box"></div>
  55. <span class="form_data_label_text">基本信息</span>
  56. </div>
  57. <el-form-item label="表单标题:">
  58. <el-col :span="15">
  59. <el-input v-model="form.title" placeholder="请输入标题" size="small" :maxlength="10"></el-input>
  60. </el-col>
  61. </el-form-item>
  62. <el-form-item label="头部背景:">
  63. <div class="form_hearder_bg_box">
  64. <el-switch v-model="form.show_heard" :active-value="1" :inactive-value="0"></el-switch>
  65. <div class="form_upload_img_box" v-if="form.show_heard">
  66. <com-attachment :multiple="false" :max="1" type="images" @selected="coverPic">
  67. <div class="card-upload" v-if="!form.first_img">
  68. <i class="el-icon-plus"></i>
  69. </div>
  70. <img v-if="form.first_img" :src="form.first_img" class="avatar">
  71. </com-attachment>
  72. <p class="form_upload_img_p">图片大小不能超过2M</p>
  73. </div>
  74. </div>
  75. </el-form-item>
  76. <el-form-item label="可重复填写:">
  77. <div class="form_hearder_bg_box">
  78. <el-switch v-model="form.is_repeat" :active-value="1" :inactive-value="0"></el-switch>
  79. </div>
  80. <p style="color: red">仅限于在商品详情页面点击立即购买填变动完后且下单完成的情况</p>
  81. </el-form-item>
  82. <el-form-item label="截止日期:">
  83. <span>表单截止后,用户打开表单会提示此表单已结束哦</span>
  84. <div class="form_time_chose_box">
  85. <el-radio-group v-model="form.time_type">
  86. <el-radio :label="1">永久有效</el-radio>
  87. <el-radio :label="0">自定义时间</el-radio>
  88. </el-radio-group>
  89. <div v-if="form.time_type == 0">
  90. <el-date-picker v-model="form.date" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm:ss" size="small">
  91. </el-date-picker>
  92. </div>
  93. </div>
  94. </el-form-item>
  95. <div class="form_data_label_box">
  96. <div class="line_form_box"></div>
  97. <span class="form_data_label_text">表单填写后跳转设置</span>
  98. <el-switch v-model="form.link_status" :active-value="1" :inactive-value="0" style="margin-left: 10px;"></el-switch>
  99. </div>
  100. <el-form-item v-if="form.link_status">
  101. <el-radio-group v-model="form.jump_type">
  102. <el-radio :label="0">跳转链接</el-radio>
  103. <el-radio :label="1">跳转二维码</el-radio>
  104. <el-radio :label="2">原路返回</el-radio>
  105. </el-radio-group>
  106. <p>{{form.jump_type==2 ? '客户提交表单成功后原路返回':'客户提交表单成功后跳转此链接'}}</p>
  107. </el-form-item>
  108. <el-form-item v-if="form.link_status && !form.jump_type" style="margin-top: -20px;">
  109. <el-col :span="15">
  110. <el-input type="text" placeholder="请输入以http/https开头的网址" v-model="form.link" maxlength="100" show-word-limit size="small">
  111. </el-col>
  112. </el-form-item>
  113. <el-form-item v-if="form.link_status && form.jump_type ==1" style="margin-top: -20px;" label="上传二维码:">
  114. <div class="up_qcard_img_box">
  115. <com-attachment :multiple="false" :max="1" type="images" @selected="coverQcard">
  116. <div class="card-upload" v-if="!form.qcard_img">
  117. <i class="el-icon-plus"></i>
  118. </div>
  119. <img v-if="form.qcard_img" :src="form.qcard_img" class="avatar">
  120. </com-attachment>
  121. <p class="form_upload_img_p">二维码大小不能超过2M</p>
  122. </div>
  123. </el-form-item>
  124. </el-form>
  125. </div>
  126. </div>
  127. <span slot="footer" class="dialog-footer">
  128. <el-button @click="saveModel = false">取 消</el-button>
  129. <el-button type="primary" @click="submit">确 定</el-button>
  130. </span>
  131. </el-dialog>
  132. </div>
  133. <script>
  134. new Vue({
  135. el: '#app',
  136. data() {
  137. return {
  138. menusList: [{
  139. title: '组件',
  140. toolList: []
  141. }],
  142. toolList: [],
  143. toolIndex: -1,
  144. toolItem: {},
  145. saveModel: false,
  146. id: null,
  147. form: {
  148. id: null,
  149. title: '',
  150. show_heard: 0,
  151. first_img: '',
  152. time_type: 1,
  153. date: '',
  154. link_status: 0,
  155. jump_type: 1,
  156. link: '',
  157. qcard_img: '',
  158. is_repeat: 0,
  159. },
  160. is_export: 0,
  161. agree_on: 0,
  162. componentsText: {
  163. 'single-link-text': '单行文本',
  164. 'multi-text': '多行文本',
  165. 'id-card': '身份证号码',
  166. 'drow-box': '下拉框',
  167. 'checked-tool': '多选框',
  168. 'radio-tool': '单选框',
  169. 'upload-photo': '图片',
  170. 'date-tool': '日期',
  171. 'date-range': '日期范围',
  172. 'time-tool': '时间',
  173. 'time-range': '时间范围',
  174. 'city-chose': '城市',
  175. },
  176. }
  177. },
  178. created() {
  179. if (getQuery('template_id')) {
  180. this.id = getQuery('template_id');
  181. this.getEditInfo()
  182. }
  183. this.getToolMenus()
  184. },
  185. methods: {
  186. getSettingInfo() {
  187. request({
  188. params: {
  189. r: 'smart-form/setting/info'
  190. },
  191. method: 'GET',
  192. }).then(res => {
  193. console.log('oooooooppppppppppp')
  194. this.loading = false;
  195. if (res.data.code == 0) {
  196. if (res.data.data != null) {
  197. this.is_export = res.data.data.is_export
  198. this.agree_on = res.data.data.agree_on
  199. }
  200. } else {
  201. this.$message.error(res.data.msg);
  202. }
  203. })
  204. },
  205. async getEditInfo() {
  206. request({
  207. params: {
  208. r: 'smart-form/form/edit',
  209. template_id: this.id
  210. },
  211. method: 'GET',
  212. }).then(async e => {
  213. e.data.data.columns.forEach(item => {
  214. if (item.smart_form_components_code == "single-link-text") {
  215. this.toolList.push({
  216. type: 'single-link-text',
  217. title: item.title,
  218. placeholder: item.placeholder,
  219. required: item.required,
  220. tips: item.tips,
  221. components_id: item.smart_form_components_id,
  222. content_type: item.content_type,
  223. is_export: item.is_export
  224. })
  225. } else if (item.smart_form_components_code == "multi-text") {
  226. this.toolList.push({
  227. type: 'multi-text',
  228. title: item.title,
  229. placeholder: item.placeholder,
  230. required: item.required,
  231. tips: item.tips,
  232. components_id: item.smart_form_components_id
  233. })
  234. } else if (item.smart_form_components_code == "id-card") {
  235. this.toolList.push({
  236. type: 'id-card',
  237. title: item.title,
  238. required: item.required,
  239. tips: item.tips,
  240. components_id: item.smart_form_components_id
  241. })
  242. } else if (item.smart_form_components_code == "drow-box") {
  243. let option = []
  244. item.option.forEach(o => {
  245. option.push({
  246. title: o
  247. })
  248. })
  249. this.toolList.push({
  250. type: 'drow-box',
  251. title: item.title,
  252. required: item.required,
  253. chooseList: option,
  254. components_id: item.smart_form_components_id
  255. })
  256. } else if (item.smart_form_components_code == "checked-tool") {
  257. let option = []
  258. item.option.forEach(o => {
  259. option.push({
  260. title: o
  261. })
  262. })
  263. this.toolList.push({
  264. type: 'checked-tool',
  265. title: item.title,
  266. required: item.required,
  267. chooseList: option,
  268. components_id: item.smart_form_components_id
  269. })
  270. } else if (item.smart_form_components_code == "radio-tool") {
  271. let option = []
  272. item.option.forEach(o => {
  273. option.push({
  274. title: o
  275. })
  276. })
  277. this.toolList.push({
  278. type: 'radio-tool',
  279. title: item.title,
  280. required: item.required,
  281. chooseList: option,
  282. components_id: item.smart_form_components_id
  283. })
  284. } else if (item.smart_form_components_code == "upload-photo") {
  285. this.toolList.push({
  286. type: 'upload-photo',
  287. title: item.title,
  288. required: item.required,
  289. total: item.limit,
  290. components_id: item.smart_form_components_id
  291. })
  292. } else if (item.smart_form_components_code == "date-tool") {
  293. this.toolList.push({
  294. type: 'date-tool',
  295. title: item.title,
  296. required: item.required,
  297. date: item.default,
  298. show_now_day: item.show_now_start,
  299. is_show: item.show_default,
  300. tips: item.tips,
  301. components_id: item.smart_form_components_id
  302. })
  303. } else if (item.smart_form_components_code == "date-range") {
  304. this.toolList.push({
  305. type: 'date-range',
  306. title: item.title,
  307. startTitle: typeof item.tips == 'object' && item.tips.length ? item.tips[0] : '',
  308. endTitle: typeof item.tips == 'object' && item.tips.length && item.tips.length == 2 ? item.tips[1] : '',
  309. required: item.required,
  310. is_start_show: typeof item.show_default == 'object' && item.show_default.length ? item.show_default[0] : '',
  311. is_end_show: typeof item.show_default == 'object' && item.show_default.length && item.show_default.length == 2 ? item.show_default[1] : '',
  312. show_now_start: typeof item.show_now_start == 'object' && item.show_now_start.length ? item.show_now_start[0] : '',
  313. show_now_end: typeof item.show_now_start == 'object' && item.show_now_start.length && item.show_now_start.length == 2 ? item.show_now_start[1] : '',
  314. start_date: typeof item.default == 'object' && item.default.length ? item.default[0] : '',
  315. end_date: typeof item.default == 'object' && item.default.length && item.default.length == 2 ? item.default[1] : '',
  316. components_id: item.smart_form_components_id
  317. })
  318. } else if (item.smart_form_components_code == "time-tool") {
  319. this.toolList.push({
  320. type: 'time-tool',
  321. title: item.title,
  322. required: item.required,
  323. time: item.default,
  324. show_now_time: item.show_now_start,
  325. is_show: item.show_default,
  326. tips: item.tips,
  327. components_id: item.smart_form_components_id
  328. })
  329. } else if (item.smart_form_components_code == "time-range") {
  330. this.toolList.push({
  331. type: 'time-range',
  332. title: item.title,
  333. startTitle: typeof item.tips == 'object' && item.tips.length ? item.tips[0] : '',
  334. endTitle: typeof item.tips == 'object' && item.tips.length && item.tips.length == 2 ? item.tips[1] : '',
  335. required: item.required,
  336. is_start_show: typeof item.show_default == 'object' && item.show_default.length ? item.show_default[0] : '',
  337. is_end_show: typeof item.show_default == 'object' && item.show_default.length && item.show_default.length == 2 ? item.show_default[1] : '',
  338. show_now_start: typeof item.show_now_start == 'object' && item.show_now_start.length ? item.show_now_start[0] : '',
  339. show_now_end: typeof item.show_now_start == 'object' && item.show_now_start.length && item.show_now_start.length == 2 ? item.show_now_start[1] : '',
  340. start_time: typeof item.default == 'object' && item.default.length ? item.default[0] : '',
  341. end_time: typeof item.default == 'object' && item.default.length && item.default.length == 2 ? item.default[1] : '',
  342. components_id: item.smart_form_components_id
  343. })
  344. } else if (item.smart_form_components_code == "city-chose") {
  345. this.toolList.push({
  346. type: 'city-chose',
  347. title: item.title,
  348. required: item.required,
  349. city_type: item.default,
  350. components_id: item.smart_form_components_id
  351. })
  352. }
  353. })
  354. // console.log(e,1111111111111111)
  355. this.form.title = e.data.data.title
  356. this.form.first_img = e.data.data.header
  357. this.form.show_heard = e.data.data.show_header
  358. this.form.time_type = e.data.data.expire_time == -1 ? 1 : 0
  359. this.form.date = e.data.data.expire_time == -1 ? '' : await this.getDate(e.data.data.expire_time)
  360. // console.log( this.form.date,'date')
  361. this.form.jump_type = e.data.data.jump_type
  362. this.form.link_status = e.data.data.link_status
  363. this.form.qcard_img = e.data.data.jump_type == 0 ? '' : e.data.data.jump_link
  364. this.form.link = e.data.data.jump_type == 0 ? e.data.data.jump_link : ''
  365. this.form.id = e.data.data.id
  366. }).catch(e => {});
  367. },
  368. async getDate(time) {
  369. let date = new Date(time * 1000)
  370. let years = date.getFullYear()
  371. let mouth = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
  372. let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
  373. let hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  374. let secod = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  375. let min = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  376. return years + '-' + mouth + '-' + day + ' ' + hours + ':' + secod + ':' + min
  377. },
  378. addTool(item) {
  379. console.log(item)
  380. switch (item.type) {
  381. case 'single-link-text':
  382. this.toolList.push({
  383. type: 'single-link-text',
  384. title: '',
  385. placeholder: '',
  386. required: 1,
  387. tips: '',
  388. components_id: item.components_id,
  389. is_export: 0,
  390. content_type: 0
  391. })
  392. if (this.toolList.length == 1) {
  393. this.toolIndex = 0
  394. this.toolItem = {
  395. type: 'single-link-text',
  396. title: '',
  397. placeholder: '',
  398. required: 1,
  399. tips: '',
  400. components_id: item.components_id,
  401. is_export: 0,
  402. content_type: 0
  403. }
  404. }
  405. this.scrollToBottom()
  406. break;
  407. case 'multi-text':
  408. this.toolList.push({
  409. type: 'multi-text',
  410. title: '',
  411. placeholder: '',
  412. required: 1,
  413. tips: '',
  414. components_id: item.components_id
  415. })
  416. if (this.toolList.length == 1) {
  417. this.toolIndex = 0
  418. this.toolItem = {
  419. type: 'multi-text',
  420. title: '',
  421. placeholder: '',
  422. required: 1,
  423. tips: '',
  424. components_id: item.components_id
  425. }
  426. }
  427. this.scrollToBottom()
  428. break;
  429. case 'id-card':
  430. this.toolList.push({
  431. type: 'id-card',
  432. title: '',
  433. required: 1,
  434. tips: '',
  435. components_id: item.components_id
  436. })
  437. if (this.toolList.length == 1) {
  438. this.toolItem = {
  439. type: 'id-card',
  440. title: '',
  441. required: 1,
  442. tips: '',
  443. components_id: item.components_id
  444. }
  445. this.toolIndex = 0
  446. }
  447. this.scrollToBottom()
  448. break;
  449. case 'drow-box':
  450. this.toolList.push({
  451. type: 'drow-box',
  452. title: '',
  453. required: 1,
  454. chooseList: [{
  455. title: '选项一'
  456. }, {
  457. title: '选项二'
  458. }],
  459. components_id: item.components_id
  460. })
  461. if (this.toolList.length == 1) {
  462. this.toolItem = {
  463. type: 'drow-box',
  464. title: '',
  465. required: 1,
  466. chooseList: [{
  467. title: '选项一'
  468. }, {
  469. title: '选项二'
  470. }],
  471. components_id: item.components_id
  472. }
  473. this.toolIndex = 0
  474. }
  475. this.scrollToBottom()
  476. break;
  477. case 'checked-tool':
  478. this.toolList.push({
  479. type: 'checked-tool',
  480. title: '',
  481. required: 1,
  482. chooseList: [{
  483. title: '选项一'
  484. }, {
  485. title: '选项二'
  486. }],
  487. components_id: item.components_id
  488. })
  489. if (this.toolList.length == 1) {
  490. this.toolItem = {
  491. type: 'checked-tool',
  492. title: '',
  493. required: 1,
  494. chooseList: [{
  495. title: '选项一'
  496. }, {
  497. title: '选项二'
  498. }],
  499. components_id: item.components_id
  500. }
  501. this.toolIndex = 0
  502. }
  503. this.scrollToBottom()
  504. break;
  505. case 'radio-tool':
  506. this.toolList.push({
  507. type: 'radio-tool',
  508. title: '',
  509. required: 1,
  510. chooseList: [{
  511. title: '选项一'
  512. }, {
  513. title: '选项二'
  514. }],
  515. components_id: item.components_id
  516. })
  517. if (this.toolList.length == 1) {
  518. this.toolItem = {
  519. type: 'radio-tool',
  520. title: '',
  521. required: 1,
  522. chooseList: [{
  523. title: '选项一'
  524. }, {
  525. title: '选项二'
  526. }],
  527. components_id: item.components_id
  528. }
  529. this.toolIndex = 0
  530. }
  531. this.scrollToBottom()
  532. break;
  533. case 'upload-photo':
  534. this.toolList.push({
  535. type: 'upload-photo',
  536. title: '',
  537. required: 1,
  538. total: 3,
  539. components_id: item.components_id
  540. })
  541. if (this.toolList.length == 1) {
  542. this.toolItem = {
  543. type: 'upload-photo',
  544. title: '',
  545. required: 1,
  546. total: 3,
  547. components_id: item.components_id
  548. }
  549. this.toolIndex = 0
  550. }
  551. this.scrollToBottom()
  552. break;
  553. case 'date-tool':
  554. this.toolList.push({
  555. type: 'date-tool',
  556. title: '',
  557. required: 1,
  558. tips: '',
  559. is_show: 1,
  560. date: '',
  561. show_now_day: 1,
  562. components_id: item.components_id,
  563. extra_data: {
  564. is_enable_sms_notice: 0,
  565. sms_template_id: '',
  566. sms_template_content: '',
  567. sms_template_key: '',
  568. sms_template_name: '',
  569. send_at: '',
  570. send_day: '',
  571. vars: []
  572. }
  573. })
  574. if (this.toolList.length == 1) {
  575. this.toolItem = {
  576. type: 'date-tool',
  577. title: '',
  578. required: 1,
  579. tips: '',
  580. is_show: 1,
  581. date: '',
  582. show_now_day: 1,
  583. components_id: item.components_id,
  584. extra_data: {
  585. is_enable_sms_notice: 0,
  586. sms_template_id: '',
  587. sms_template_content: '',
  588. sms_template_key: '',
  589. sms_template_name: '',
  590. vars: []
  591. }
  592. }
  593. this.toolIndex = 0
  594. }
  595. this.scrollToBottom()
  596. break;
  597. case 'date-range':
  598. this.toolList.push({
  599. type: 'date-range',
  600. title: '',
  601. startTitle: '',
  602. endTitle: '',
  603. required: 1,
  604. is_start_show: 1,
  605. is_end_show: 1,
  606. show_now_start: 1,
  607. show_now_end: 1,
  608. start_date: '',
  609. end_date: '',
  610. components_id: item.components_id
  611. })
  612. if (this.toolList.length == 1) {
  613. this.toolItem = {
  614. type: 'date-range',
  615. title: '',
  616. startTitle: '',
  617. endTitle: '',
  618. required: 1,
  619. is_start_show: 1,
  620. is_end_show: 1,
  621. show_now_start: 1,
  622. show_now_end: 1,
  623. start_date: '',
  624. end_date: '',
  625. components_id: item.components_id
  626. }
  627. this.toolIndex = 0
  628. }
  629. this.scrollToBottom()
  630. break;
  631. case 'time-tool':
  632. this.toolList.push({
  633. type: 'time-tool',
  634. title: '',
  635. required: 1,
  636. tips: '',
  637. is_show: 1,
  638. time: '',
  639. show_now_time: 1,
  640. components_id: item.components_id
  641. })
  642. if (this.toolList.length == 1) {
  643. this.toolItem = {
  644. type: 'time-tool',
  645. title: '',
  646. required: 1,
  647. tips: '',
  648. is_show: 1,
  649. time: '',
  650. show_now_time: 1,
  651. components_id: item.components_id
  652. }
  653. this.toolIndex = 0
  654. }
  655. this.scrollToBottom()
  656. break;
  657. case 'time-range':
  658. this.toolList.push({
  659. type: 'time-range',
  660. title: '',
  661. startTitle: '',
  662. endTitle: '',
  663. required: 1,
  664. is_start_show: 1,
  665. is_end_show: 1,
  666. start_time: '',
  667. show_now_start: 1,
  668. show_now_end: 1,
  669. end_time: '',
  670. components_id: item.components_id
  671. })
  672. if (this.toolList.length == 1) {
  673. this.toolItem = {
  674. type: 'time-range',
  675. title: '',
  676. startTitle: '',
  677. endTitle: '',
  678. required: 1,
  679. is_start_show: 1,
  680. is_end_show: 1,
  681. start_time: '',
  682. show_now_start: 1,
  683. show_now_end: 1,
  684. end_time: '',
  685. components_id: item.components_id
  686. }
  687. this.toolIndex = 0
  688. }
  689. this.scrollToBottom()
  690. break;
  691. case 'city-chose':
  692. this.toolList.push({
  693. type: 'city-chose',
  694. title: '',
  695. required: 1,
  696. city_type: 1,
  697. components_id: item.components_id
  698. })
  699. if (this.toolList.length == 1) {
  700. this.toolItem = {
  701. type: 'city-chose',
  702. title: '',
  703. required: 1,
  704. city_type: 1,
  705. components_id: item.components_id
  706. }
  707. this.toolIndex = 0
  708. }
  709. this.scrollToBottom()
  710. break;
  711. }
  712. console.log(this.toolList, 'this.toolList')
  713. },
  714. coverPic(e) {
  715. this.form.first_img = e[0].url
  716. },
  717. coverQcard(e) {
  718. this.form.qcard_img = e[0].url
  719. },
  720. getToolMenus() {
  721. let that = this
  722. request({
  723. params: {
  724. r: 'smart-form/components/index',
  725. },
  726. method: 'GET',
  727. }).then(res => {
  728. console.log(res, '9090000')
  729. res.data.data.list.forEach(item => {
  730. that.menusList[0].toolList.push({
  731. type: item.code,
  732. components_id: item.id,
  733. img: _diy_img_prefix + item.icon,
  734. title: item.title
  735. })
  736. })
  737. })
  738. },
  739. // changeIndex(index){
  740. // this.toolIndex = index
  741. // },
  742. //滚动到底部
  743. scrollToBottom() {
  744. this.$nextTick(() => {
  745. let box = this.$el.querySelector(".diy_tool_center_box")
  746. box.scrollTop = box.scrollHeight
  747. })
  748. },
  749. //
  750. diyToolChange(e) {
  751. switch (e.type) {
  752. case 'change-index':
  753. this.toolIndex = e.index
  754. this.toolItem = {
  755. ...this.toolList[this.toolIndex]
  756. }
  757. break;
  758. case 'change-move':
  759. this.toolIndex = e.index
  760. this.toolList = e.list
  761. this.toolItem = {
  762. ...this.toolList[this.toolIndex]
  763. }
  764. break;
  765. case 'delete':
  766. this.toolList.splice(e.index, 1)
  767. this.toolIndex = this.toolIndex - 1 > 0 ? this.toolIndex - 1 : 0
  768. this.toolItem = {
  769. ...this.toolList[this.toolIndex]
  770. }
  771. break;
  772. case 'copy':
  773. this.toolList.splice(e.index, 0, e.item)
  774. break;
  775. }
  776. },
  777. updateData(e) {
  778. // console.log(JSON.stringify(this.toolList))
  779. this.toolItem = e
  780. this.toolList[this.toolIndex] = e
  781. this.toolList = JSON.parse(JSON.stringify((this.toolList)))
  782. },
  783. save() {
  784. console.log(this.toolList, 'hhhhhhhh');
  785. if (this.toolList.length <= 0) {
  786. this.$message.error(`请至少选择一个表单组件`);
  787. return;
  788. }
  789. for (let i = 0; i < this.toolList.length; i++) {
  790. if (this.toolList[i].title == '' || this.toolList[i].title == ' ') {
  791. this.$message.error(`请完善${this.componentsText[this.toolList[i].type]}组件的标题`);
  792. return;
  793. }
  794. }
  795. this.saveModel = true
  796. },
  797. submit() {
  798. let obj = {
  799. form: {
  800. ...this.form,
  801. },
  802. toolList: this.toolList
  803. }
  804. obj.form.date = obj.form.time_type == 1 ? -1 : obj.form.date
  805. obj.form.time_type = obj.form.time_type == 1 ? -1 : 0
  806. request({
  807. params: {
  808. r: this.id ? 'smart-form/form/edit' : 'smart-form/form/add',
  809. },
  810. method: 'post',
  811. data: {
  812. ...obj
  813. }
  814. }).then(res => {
  815. console.log(res)
  816. if (res.data.code == 0) {
  817. this.saveModel = false
  818. navigateTo({
  819. r: 'smart-form/form/index'
  820. })
  821. } else {
  822. this.$message.error(res.data.msg)
  823. }
  824. })
  825. }
  826. }
  827. })
  828. // 拦截页面卸载
  829. window.onbeforeunload = function(e) {
  830. var e = window.event || e;
  831. e.returnValue = ("确定离开当前页面吗?");
  832. }
  833. </script>
  834. <style scoped>
  835. .diy_tool_center_box {
  836. width: 100%;
  837. overflow-y: auto;
  838. height: 80vh;
  839. }
  840. .phone_sub_btn {
  841. border-radius: 0;
  842. width: 100%;
  843. height: 27px;
  844. font-size: 12px;
  845. color: #ffffff;
  846. background: #d9001b;
  847. line-height: 0.5;
  848. /* line-height: 27px; */
  849. }
  850. .phone_s_img_box {
  851. width: 100%;
  852. height: 144px;
  853. background: #aaa;
  854. }
  855. .img_h_bx {
  856. width: 100%;
  857. height: 100%;
  858. }
  859. .up_qcard_img_box {
  860. padding-top: 10px;
  861. box-sizing: border-box;
  862. display: flex;
  863. align-items: flex-start;
  864. flex-direction: column;
  865. justify-content: flex-start;
  866. }
  867. .form_time_chose_box {
  868. width: 100%;
  869. }
  870. .form_upload_img_p {
  871. font-size: 12px;
  872. color: #7f7f7f;
  873. margin-top: 20px;
  874. }
  875. .form_upload_img_box {
  876. padding-left: 60px;
  877. box-sizing: border-box;
  878. margin-top: 10px;
  879. }
  880. .avatar-uploader .el-upload {
  881. border: 1px dashed #d9d9d9;
  882. border-radius: 6px;
  883. cursor: pointer;
  884. position: relative;
  885. overflow: hidden;
  886. }
  887. .avatar-uploader .el-upload:hover {
  888. border-color: #409EFF;
  889. }
  890. .avatar-uploader-icon {
  891. font-size: 28px;
  892. color: #8c939d;
  893. width: 60px;
  894. height: 60px;
  895. line-height: 60px;
  896. text-align: center;
  897. }
  898. .avatar {
  899. width: 60px;
  900. height: 60px;
  901. display: block;
  902. }
  903. .form_hearder_bg_box {
  904. width: 100%;
  905. /* display: flex;
  906. align-items: flex-start;
  907. justify-content: flex-start;
  908. flex-direction: column; */
  909. }
  910. .form_data_label_text {
  911. font-size: 14px;
  912. color: #333;
  913. margin-left: 10px;
  914. }
  915. .form_data_label_box {
  916. width: 100%;
  917. display: flex;
  918. align-items: center;
  919. margin-bottom: 20px;
  920. }
  921. .line_form_box {
  922. width: 2px;
  923. height: 25px;
  924. background: #d9001b;
  925. }
  926. .phone_form_data_box {
  927. flex: 1;
  928. padding-left: 30px;
  929. padding-top: 20px;
  930. box-sizing: border-box;
  931. }
  932. .phone_form_body_mdg_box {
  933. flex: 1;
  934. width: 100%;
  935. overflow-y: auto;
  936. background: #ffffff;
  937. }
  938. .phone_form_title_box {
  939. width: 100%;
  940. height: 24px;
  941. background: #ffffff;
  942. font-size: 12px;
  943. color: #000;
  944. display: flex;
  945. align-items: center;
  946. justify-content: center;
  947. }
  948. .phone_form_body_box {
  949. width: 230px;
  950. height: 412px;
  951. overflow: hidden;
  952. display: flex;
  953. align-items: center;
  954. justify-content: flex-start;
  955. flex-direction: column;
  956. background: #f5f6f7;
  957. position: absolute;
  958. top: 59px;
  959. left: 15px;
  960. }
  961. .phone_save_box {
  962. width: 100%;
  963. display: flex;
  964. align-items: flex-start;
  965. justify-content: space-between;
  966. padding: 10px 20px;
  967. box-sizing: border-box;
  968. }
  969. .phone_model_w_box {
  970. width: 262px;
  971. height: 533px;
  972. position: relative;
  973. /* background: url('resources/img/decorate/phone.png')no-repeat;
  974. background-size: 100%; */
  975. }
  976. .pjone_bg_box {
  977. width: 100%;
  978. height: 100%;
  979. }
  980. .dorm_diy_btn_box {
  981. width: 100%;
  982. height: 50px;
  983. display: flex;
  984. align-items: center;
  985. justify-content: center;
  986. }
  987. .u_box {
  988. width: 100%;
  989. height: 100vh;
  990. display: flex;
  991. align-items: center;
  992. justify-content: center;
  993. flex-direction: column;
  994. }
  995. .nav {
  996. width: 100%;
  997. background: #ffffff;
  998. border-radius: 5px;
  999. padding: 26px 24px;
  1000. }
  1001. .body_box {
  1002. width: 100%;
  1003. flex: 1;
  1004. /* margin-top: 5px; */
  1005. background: #ffffff;
  1006. overflow: hidden;
  1007. overflow-y: auto;
  1008. }
  1009. .diy_box {
  1010. width: 100%;
  1011. display: flex;
  1012. align-items: center;
  1013. }
  1014. .diy_tool_box {
  1015. height: 100%;
  1016. overflow-y: auto;
  1017. }
  1018. .tool_yu_nbox {
  1019. flex: 1;
  1020. /* display: flex;
  1021. align-items: center;
  1022. justify-content: center; */
  1023. background: #fff;
  1024. height: 80vh;
  1025. overflow: hidden;
  1026. }
  1027. .diy-phone {
  1028. width: 410px;
  1029. border: 1px solid #bfbfbf;
  1030. border-radius: 4px;
  1031. background: #fafafa;
  1032. padding: 20px 12px;
  1033. position: relative;
  1034. }
  1035. .phone-body {
  1036. min-height: 650px;
  1037. width: 377px;
  1038. border: 1px solid #bfbfbf;
  1039. border-radius: 4px;
  1040. background: #f5f6f7;
  1041. position: relative;
  1042. }
  1043. </style>