edit.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. {extend name="../../admin/view/main"}
  2. {block name='content'}
  3. <style>
  4. .layui-card-body{
  5. background: white;
  6. }
  7. #newForm{
  8. width: 80%;
  9. }
  10. .image{
  11. width: 100px;
  12. height: 100px;
  13. }
  14. .video{
  15. width: 200px;
  16. height: 200px;
  17. }
  18. .child-form{
  19. width: 500px;
  20. background: #f4f4f4;
  21. padding: 10px;
  22. display: inline-block;
  23. }
  24. </style>
  25. <div id="newForm">
  26. <el-form :model="form" label-width="140px" ref="form" size="medium">
  27. <el-form-item label="联系人" prop="real_name" :rules="{message:'此项必须',required:true}">
  28. <el-input v-model="form.real_name"></el-input>
  29. </el-form-item>
  30. <el-form-item label="联系电话" prop="mobile" :rules="{message:'此项必须',required:true}">
  31. <el-input v-model="form.mobile"></el-input>
  32. </el-form-item>
  33. <el-form-item label="生产技术标准" prop="standard_tech" :rules="{message:'此项必须',required:true}">
  34. <el-input v-model="form.standard_tech"></el-input>
  35. </el-form-item>
  36. <el-form-item label="生产验收标准" prop="standard_check" :rules="{message:'此项必须',required:true}">
  37. <el-input v-model="form.standard_check"></el-input>
  38. </el-form-item>
  39. <el-form-item label="商品信息:" prop="item" :rules="[{message:'此项必须',required:true},{type:'array',min:1,message:'需要商品信息'}]">
  40. <div><el-button @click="addItem">添加</el-button></div>
  41. <div v-for="(item,idx) in form.item" class="child-form">
  42. <i class="el-icon-delete" @click="deleteItem(idx)"></i>
  43. <el-form-item label="商品名称">
  44. <el-input v-model="item.name"></el-input>
  45. </el-form-item>
  46. <el-form-item label="规格">
  47. <el-input v-model="item.spec"></el-input>
  48. </el-form-item>
  49. <el-form-item label="数量">
  50. <el-input v-model="item.number"></el-input>
  51. </el-form-item>
  52. <!-- <el-form-item label="质量标准">-->
  53. <!-- <el-input v-model="item.standard"></el-input>-->
  54. <!-- </el-form-item>-->
  55. <!-- <el-form-item label="采购价">-->
  56. <!-- <el-input v-model="item.price"></el-input>-->
  57. <!-- </el-form-item>-->
  58. <el-form-item label="文件" prop="enclosure">
  59. <el-button @click="addFiles(null,item.enclosure)">增加</el-button>
  60. <div>
  61. <span v-for="(val,idx) in item.enclosure" :key="idx">
  62. <el-tag type="text" @close="item.enclosure.splice(idx,1)" closable>{{val.filename}}</el-tag>
  63. </span>
  64. </div>
  65. </el-form-item>
  66. </div>
  67. </el-form-item>
  68. <el-form-item label="图片视频" prop="files">
  69. <el-button @click="addFile('image')">增加图片/视频</el-button>
  70. <div>
  71. <div v-for="(item,idx) in form.images" :key="idx" style="display: inline-block;">
  72. <el-image v-if="item.type==='image'" :src="item.src" class="video"></el-image>
  73. <video controls v-else :src="item.src" class="video"></video>
  74. <a @click="form.images.splice(idx,1)">删除</a>
  75. </div>
  76. </div>
  77. </el-form-item>
  78. <el-form-item label="交货地址" :rules="{message:'此项必须',required:true}" prop="post_address">
  79. <el-input v-model="form.post_address"></el-input>
  80. </el-form-item>
  81. <el-form-item label="交货时间" :rules="{message:'此项必须',required:true}" prop="post_time">
  82. <el-date-picker type="datetime" v-model="form.post_time" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
  83. </el-form-item>
  84. <el-form-item>
  85. <el-button type="primary" @click="save" :loading="saving">保存</el-button>
  86. <el-button @click="history.back()">取消</el-button>
  87. </el-form-item>
  88. </el-form>
  89. <div style="display: none;">
  90. <button data-type="zip" data-file id="fileUpload"></button>
  91. </div>
  92. </div>
  93. <script>
  94. let editorContent;
  95. let vo={:json_encode($row?:null,256)};
  96. let audit=vo.audit
  97. if(audit===1){
  98. vo.audit=2
  99. }
  100. require(['ckeditor'], function () {
  101. });
  102. vo.item=vo.items
  103. new Vue({
  104. el:'#newForm',
  105. data:()=>({
  106. form:vo||{
  107. real_name:null,
  108. mobile:null,
  109. standard_tech:null,
  110. standard_check:null,
  111. item:[],
  112. images:[],
  113. },
  114. saving:false,
  115. }),
  116. methods:{
  117. addItem(){
  118. let that = this;
  119. that.form.item.push({
  120. name:null,
  121. spec:null,
  122. number:null,
  123. // standard:null,
  124. // price:null,
  125. enclosure:[]
  126. })
  127. },
  128. deleteItem (key) {
  129. this.form.item.splice(key, 1)
  130. },
  131. addFile(){
  132. $('#fileUpload').unbind('upload.done')
  133. $('#fileUpload').on('upload.done', (e,obj) => {
  134. let type=obj.file.type.split('/')[0]
  135. if(['image','video'].indexOf(type)===-1){
  136. this.$message.error('请上传正确的格式')
  137. return
  138. }
  139. console.log(this.form.images)
  140. this.form.images.push({
  141. type:type,
  142. src:obj.data.url
  143. })
  144. });
  145. $('#fileUpload').trigger('click')
  146. },
  147. addFiles(ext,form){
  148. $('#fileUpload').unbind('upload.done')
  149. $('#fileUpload').on('upload.done', (e,obj) => {
  150. if(ext && obj.file.type.indexOf(ext)===-1){
  151. this.$message.error('请上传正确的格式')
  152. return
  153. }
  154. // console.log(obj.file.name);
  155. // alert(obj.file.name);
  156. // console.log({fileurl:obj.data.url,filename:obj.data.url.split('/')[obj.data.url.split('/').length-1]})
  157. form.push({fileurl:obj.data.url,filename:obj.data.url.split('/')[obj.data.url.split('/').length-1]})
  158. });
  159. $('#fileUpload').trigger('click')
  160. },
  161. save(){
  162. let _this=this,
  163. form=this.form
  164. // form.item=form.item.map(item1=>{
  165. // item1.enclosure=item1.enclosure.map(item=>{
  166. // return {fileurl:item,filename:1235}
  167. // })
  168. // return item1
  169. // })
  170. console.log(form)
  171. this.$refs.form.validate(v=>{
  172. if(!v){
  173. return
  174. }
  175. $.ajax('{:sysuri()}',{
  176. data:form,
  177. type:'post',
  178. beforeSend(){
  179. _this.saving=true
  180. },
  181. success({code,info}){
  182. if(code){
  183. _this.$message.success('保存成功')
  184. window.history.back()
  185. }else{
  186. _this.$message.error(info)
  187. }
  188. },
  189. complete(){
  190. _this.saving=false
  191. }
  192. })
  193. })
  194. }
  195. }
  196. })
  197. </script>
  198. {/block}