com-form.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <?php defined('YII_ENV') or exit('Access Denied'); ?>
  2. <style>
  3. .com-form .options {
  4. background-color: #F3F5F6;
  5. padding: 15px !important;
  6. margin-right: 40px;
  7. min-width: 180px;
  8. }
  9. .com-form .options .options-item:first-of-type {
  10. margin-top: 0
  11. }
  12. .com-form .options .options-item {
  13. height: 32px;
  14. line-height: 32px;
  15. margin-top: 10px;
  16. background-color: #fff;
  17. cursor: pointer;
  18. display: flex;
  19. justify-content: center;
  20. }
  21. .com-form .options .options-item img {
  22. margin: 9px 5px 9px 0;
  23. display: block;
  24. float: left;
  25. height: 14px;
  26. width: 14px;
  27. }
  28. .com-form .form-item .el-form-item__label {
  29. width: 100px !important;
  30. }
  31. .com-form .form-item .el-form-item__content {
  32. margin-left: 100px !important;
  33. width: 60% !important;
  34. position: relative;
  35. }
  36. .com-form .outline {
  37. position: absolute;
  38. right: -30px;
  39. top: 0;
  40. line-height: 32px;
  41. height: 32px;
  42. color: #F56E6E;
  43. cursor: pointer;
  44. font-size: 22px;
  45. }
  46. .com-form .form-item {
  47. background-color: #fff;
  48. padding: 22px;
  49. position: relative;
  50. cursor: move;
  51. }
  52. .com-form .delete-btn {
  53. position: absolute;
  54. top: 20px;
  55. right: 20px;
  56. }
  57. .com-form .required {
  58. width: 80px;
  59. height: 32px;
  60. }
  61. .com-form .required.active {
  62. border: 1px solid #3399FF;
  63. color: #3399FF;
  64. }
  65. .com-form .name {
  66. display: inline-block;
  67. margin-left: 20px;
  68. width: 80px;
  69. height: 32px;
  70. line-height: 30px;
  71. text-align: center;
  72. background-color: #F4F4F5;
  73. color: #909399;
  74. border: 1px solid #E0E0E3;
  75. border-radius: 3px;
  76. font-size: 12px;
  77. }
  78. .com-form .form-item .el-form-item {
  79. margin-bottom: 22px;
  80. }
  81. .com-form .top {
  82. height:15px;
  83. background:#F3F5F6;
  84. width:calc(100% - 40px);
  85. }
  86. </style>
  87. <template id="com-form">
  88. <el-row class="com-form">
  89. <el-col class="options" :span="3">
  90. <div class="options-item" @click="handleChange(item)" v-for="item in options">
  91. <div style="width: 50%">
  92. <img :src="item.img" alt="">{{item.label}}
  93. </div>
  94. </div>
  95. </el-col>
  96. <el-col :span="15">
  97. <div v-if="list && list.length" class="top"></div>
  98. <draggable v-model="list" @update='update'>
  99. <div style="padding: 0 15px 15px !important;" class="options" v-for="(item,index) in list">
  100. <el-form @submit.native.prevent :model="item" :rules="form_rules" ref="form" class="form-item">
  101. <el-button size="small" class="delete-btn" circle type="text" @click="formDestroy(index)">
  102. <el-tooltip class="item" effect="dark" content="删除" placement="top">
  103. <img src="resources/img/mall/del.png" alt="">
  104. </el-tooltip>
  105. </el-button>
  106. <div style="margin-bottom: 15px;">
  107. <el-button size="small" @click="toggle(item)" plain class="required active"
  108. v-if="item.is_required">必填
  109. </el-button>
  110. <el-button size="small" @click="toggle(item)" plain v-else class="required">非必填
  111. </el-button>
  112. <div class="name">{{item.key_name}}</div>
  113. </div>
  114. <el-form-item prop="key_name">
  115. <template slot='label'>
  116. <span>名称</span>
  117. <el-tooltip effect="dark" content="名称建议不超过4个字"
  118. placement="top">
  119. <i class="el-icon-info"></i>
  120. </el-tooltip>
  121. </template>
  122. <el-input size="small" v-model="item.name" placeholder="请输入名称"></el-input>
  123. </el-form-item>
  124. <el-form-item label="默认值" v-if="item.key === 'date'">
  125. <el-date-picker
  126. size="small"
  127. value-format="yyyy-MM-dd"
  128. v-model="item.default"
  129. type="date"
  130. placeholder="选择日期">
  131. </el-date-picker>
  132. </el-form-item>
  133. <el-form-item label="日期区间" v-if="item.key === 'date' && is_date_range">
  134. <el-date-picker
  135. size="small"
  136. value-format="yyyy-MM-dd"
  137. v-model="item.range"
  138. @change="timeSet(item)"
  139. type="daterange"
  140. range-separator="至"
  141. start-placeholder="开始日期"
  142. end-placeholder="结束日期">
  143. </el-date-picker>
  144. </el-form-item>
  145. <el-form-item label="默认值" v-if="item.key === 'time'">
  146. <el-time-picker
  147. value-format="HH:mm"
  148. range-separator=":"
  149. size="small"
  150. v-model="item.default"
  151. placeholder="选择时间">
  152. </el-time-picker>
  153. </el-form-item>
  154. <el-form-item label="时间区间" v-if="item.key === 'time' && is_time_range">
  155. <el-time-picker
  156. size="small"
  157. value-format="HH:mm"
  158. is-range
  159. v-model="item.range"
  160. @change="timeSet(item)"
  161. range-separator="至"
  162. start-placeholder="开始时间"
  163. end-placeholder="结束时间">
  164. </el-time-picker>
  165. </el-form-item>
  166. <el-form-item label="默认值" v-if="item.key === 'text'">
  167. <el-input size="small" v-model="item.default" placeholder="默认值"></el-input>
  168. </el-form-item>
  169. <el-form-item label="提示语" v-if="item.key === 'text'">
  170. <el-input size="small" v-model="item.hint" placeholder="提示语"></el-input>
  171. </el-form-item>
  172. <el-form-item label="默认值" v-if="item.key === 'textarea'">
  173. <el-input size="small" :rows="1"
  174. type="textarea"
  175. v-model="item.default"
  176. placeholder="默认值">
  177. </el-input>
  178. </el-form-item>
  179. <el-form-item label="提示语" v-if="item.key === 'textarea'">
  180. <el-input size="small" :rows="1"
  181. type="textarea"
  182. v-model="item.hint"
  183. placeholder="提示语">
  184. </el-input>
  185. </el-form-item>
  186. <el-form-item label="多选选项" v-if="item.key === 'checkbox'"
  187. v-for="(check,index) in item.list" :key="index">
  188. <el-input size="small" v-model="check.label"
  189. placeholder="选项名称">
  190. </el-input>
  191. <i @click="lose(item,index)"
  192. class="el-icon-remove-outline outline"></i>
  193. </el-form-item>
  194. <el-form-item label="单选选项" v-if="item.key === 'radio'"
  195. v-for="(check,index) in item.list" :key="index">
  196. <el-input size="small" v-model="check.label"
  197. placeholder="选项名称">
  198. </el-input>
  199. <i @click="lose(item,index)"
  200. class="el-icon-remove-outline outline"></i>
  201. </el-form-item>
  202. <el-form-item class="img-type" label="图片类型"
  203. v-if="item.key === 'img_upload'">
  204. <el-radio v-for="(check,index) in item.list"
  205. :key="item.index"
  206. v-model="item.img_type"
  207. :label="check.value">
  208. {{check.label}}
  209. </el-radio>
  210. </el-form-item>
  211. <el-form-item style="margin-bottom: 0"
  212. v-if="item.key === 'checkbox' || item.key === 'radio'">
  213. <el-button type="text" @click="add(item)">
  214. <i class="el-icon-plus">新增选项</i>
  215. </el-button>
  216. </el-form-item>
  217. </el-form>
  218. </div>
  219. </draggable>
  220. </el-col>
  221. </el-row>
  222. </template>
  223. <script src="<?= Yii::$app->request->baseUrl ?>/resources/unpkg/vuedraggable@2.18.1/dist/vuedraggable.umd.min.js"></script>
  224. <script>
  225. Vue.component('com-form', {
  226. template: '#com-form',
  227. props: {
  228. value: {
  229. type: Array
  230. },
  231. is_mch: {
  232. type: Boolean,
  233. default: false
  234. },
  235. is_date_range: {
  236. type: Boolean,
  237. default: false,
  238. },
  239. is_time_range: {
  240. type: Boolean,
  241. default: false,
  242. }
  243. },
  244. data() {
  245. return {
  246. list: [],
  247. options: [
  248. {
  249. value: 'text',
  250. label: '单行文本',
  251. img: 'resources/img/mall/order-form/text.png'
  252. },
  253. {
  254. value: 'textarea',
  255. label: '多行文本',
  256. img: 'resources/img/mall/order-form/textarea.png'
  257. },
  258. {
  259. value: 'date',
  260. label: '日期选择',
  261. img: 'resources/img/mall/order-form/date.png'
  262. },
  263. {
  264. value: 'time',
  265. label: '时间选择',
  266. img: 'resources/img/mall/order-form/time.png'
  267. },
  268. {
  269. value: 'radio',
  270. label: '单选',
  271. img: 'resources/img/mall/order-form/radio.png',
  272. children: [
  273. {
  274. value: 1,
  275. label: '1个',
  276. },
  277. {
  278. value: 2,
  279. label: '2个',
  280. },
  281. {
  282. value: 3,
  283. label: '3个',
  284. },
  285. ]
  286. },
  287. {
  288. value: 'checkbox',
  289. label: '多选',
  290. img: 'resources/img/mall/order-form/checkbox.png',
  291. children: [
  292. {
  293. value: 1,
  294. label: '1个',
  295. },
  296. {
  297. value: 2,
  298. label: '2个',
  299. },
  300. {
  301. value: 3,
  302. label: '3个',
  303. },
  304. ]
  305. },
  306. {
  307. value: 'img_upload',
  308. label: '图片上传',
  309. img: 'resources/img/mall/order-form/img_upload.png'
  310. },
  311. ],
  312. form_rules: {
  313. key_name: [
  314. {required: true, message: '请输入名称', trigger: 'change'},
  315. ],
  316. },
  317. };
  318. },
  319. mounted() {
  320. this.list = this.value;
  321. },
  322. methods: {
  323. timeSet(e) {
  324. e.min = e.range[0];
  325. e.max = e.range[1];
  326. },
  327. update() {
  328. this.$emit('update:value', this.list)
  329. },
  330. toggle(row) {
  331. row.is_required = row.is_required ? 0 : 1;
  332. },
  333. lose(row, index) {
  334. row.list.splice(index, 1)
  335. },
  336. add(row) {
  337. row.list.push({
  338. label: "",
  339. value: "false"
  340. })
  341. },
  342. // 添加表单
  343. handleChange(item) {
  344. let self = this;
  345. let value = {
  346. key: item.value,
  347. key_name: item.label,
  348. name: '',
  349. is_required: 0,
  350. }
  351. if (item.value == 'checkbox' || item.value == 'radio') {
  352. value.list = [{
  353. label: "",
  354. value: "false"
  355. }]
  356. }
  357. if (item.value == 'img_upload' && this.is_mch) {
  358. value.img_type = '1',
  359. value.list = [
  360. {
  361. label: "普通图片",
  362. value: '1'
  363. },
  364. {
  365. label: "身份证",
  366. value: '2'
  367. },
  368. {
  369. label: "营业执照",
  370. value: '3'
  371. },
  372. ]
  373. } else if (item.value == 'img_upload' && !this.is_mch) {
  374. value.img_type = '1',
  375. value.list = [
  376. {
  377. label: "普通图片",
  378. value: '1'
  379. }
  380. ]
  381. }
  382. this.list.push(value)
  383. this.$emit('update:value', this.list)
  384. },
  385. // 删除表单
  386. formDestroy(index) {
  387. this.value.splice(index, 1);
  388. this.$emit('update:value', this.list)
  389. }
  390. }
  391. });
  392. </script>