edit.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <style>
  2. .form-body {
  3. padding: 20px;
  4. background-color: #fff;
  5. margin-bottom: 20px;
  6. padding-right: 20%;
  7. min-width: 900px;
  8. }
  9. .form-body .el-form-item {
  10. padding-right: 50%;
  11. min-width: 850px;
  12. }
  13. .form-button {
  14. margin: 0;
  15. }
  16. .form-button .el-form-item__content {
  17. margin-left: 0 !important;
  18. }
  19. .button-item {
  20. padding: 9px 25px;
  21. }
  22. /*批量上传图片*/
  23. .pic-url-remark {
  24. font-size: 13px;
  25. color: #c9c9c9;
  26. margin-bottom: 12px;
  27. }
  28. .add-image-btn {
  29. width: 100px;
  30. height: 100px;
  31. color: #419EFB;
  32. border: 1px solid #e2e2e2;
  33. cursor: pointer;
  34. }
  35. .del-btn-pro{
  36. position: absolute;
  37. top: 28%;
  38. left: 57px;
  39. }
  40. .del-btn{
  41. position: absolute;
  42. top: -4%;
  43. right: -4%;
  44. }
  45. </style>
  46. <?php
  47. use common\helpers\ComponentHelper;
  48. ComponentHelper::loadComponentView('com-dialog-select');
  49. ComponentHelper::loadComponentView('com-image');
  50. ?>
  51. <div id="app" v-cloak>
  52. <el-card v-loading="cardLoading" shadow="never" style="border:0;min-width: 1000px;" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  53. <div slot="header">
  54. <el-breadcrumb separator="/">
  55. <el-breadcrumb-item><span style="color: #409EFF;cursor: pointer" @click="$navigate({r:'material/default/index'})">素材中心</span>
  56. </el-breadcrumb-item>
  57. <el-breadcrumb-item>{{editTitle}}</el-breadcrumb-item>
  58. </el-breadcrumb>
  59. </div>
  60. <div class="form-body">
  61. <el-form :model="ruleForm" :rules="rules" size="small" ref="ruleForm" label-width="150px">
  62. <el-row>
  63. <el-col :span="24">
  64. <el-form-item label="选择分类" prop="cate_id">
  65. <div style="display: flex">
  66. <el-cascader
  67. v-model="selectCate"
  68. :options="materilCateList"
  69. :props="cascadeProps"
  70. @change="handleChange"
  71. ></el-cascader>
  72. <el-button class="el-button--primary2" style="padding: 9px 15px!important; float: left;" type="primary" @click="addgsForm()" size="small">新增分类
  73. </el-button>
  74. </div>
  75. </el-form-item>
  76. <el-form-item label="素材文案" prop="describe">
  77. <el-input type="textarea" placeholder="请输入素材文案" style="width: 400px;" v-model="ruleForm.describe"></el-input>
  78. </el-form-item>
  79. <el-form-item label="虚拟下载次数" prop="virtual_download_num">
  80. <el-input type="nember" v-model.number="ruleForm.virtual_download_num" maxlength="6" oninput="value=value.replace(/^\.+|[^\d.]/g,'')" style="width: 160px;" placeholder="虚拟下载次数"></el-input>
  81. 次
  82. </el-form-item>
  83. <el-form-item label="是否展示" prop="status">
  84. <el-switch v-model="ruleForm.status" :active-value="1" :inactive-value="0">
  85. </el-switch>
  86. </el-form-item>
  87. <el-form-item label="上传类型" prop="download_type" required>
  88. <el-radio-group v-model="ruleForm.download_type">
  89. <el-radio :label="1">图文</el-radio>
  90. <el-radio :label="2">短视频</el-radio>
  91. <el-radio :label="3">文本</el-radio>
  92. </el-radio-group>
  93. </el-form-item>
  94. <!-- 图文-->
  95. <el-form-item v-if="ruleForm.download_type == 1" prop="pic_url_img" :rules="ruleForm.pic_url&&ruleForm.pic_url.length > 0 ?rules.pic_url_img:[{required: true, message: '请选择图片', trigger: 'change'}]" class="com-goods">
  96. <template slot="label">
  97. <span>上传素材</span>
  98. <el-tooltip effect="dark" placement="top" content="第一张图片为封面图">
  99. <i class="el-icon-info"></i>
  100. </el-tooltip>
  101. </template>
  102. <div class="pic-url-remark">
  103. 第一张图片为缩略图,其它图片为轮播图,建议像素750*750,可拖拽使其改变顺序,最多支持上传9张
  104. </div>
  105. <div flex="dir:left">
  106. <template v-if="ruleForm.pic_url&&(ruleForm.pic_url.length > 0) && (ruleForm.download_type == 1)">
  107. <div v-for="(item,index) in ruleForm.pic_url" :key="index" style="margin-right: 20px;position: relative;cursor: move;">
  108. <com-attachment @selected="updatePicUrl" :params="{'currentIndex': index}">
  109. <com-image mode="aspectFill" width="100px" height='100px' :src="item.pic_url">
  110. </com-image>
  111. </com-attachment>
  112. <el-button class="del-btn" size="mini" type="danger" icon="el-icon-close" circle @click="delPic(index)"></el-button>
  113. </div>
  114. </template>
  115. <template v-if="ruleForm.pic_url&&ruleForm.pic_url.length < 9">
  116. <com-attachment style="margin-bottom: 10px;" :multiple="true" :max="9" @selected="picUrl">
  117. <el-tooltip class="item" effect="dark" content="建议尺寸:750 * 750" placement="top">
  118. <div flex="main:center cross:center" class="add-image-btn">
  119. + 添加图片
  120. </div>
  121. </el-tooltip>
  122. </com-attachment>
  123. </template>
  124. </div>
  125. </el-form-item>
  126. <!-- 短视频-->
  127. <el-form-item v-if="ruleForm.download_type == 2" label="商品视频" prop="video_url" :rules="ruleForm.video_url ?rules.video_url:[{required: true, message: '请选择视频', trigger: 'change'}]">
  128. <el-input v-model="ruleForm.video_url" placeholder="请输入视频原地址或选择上传视频">
  129. <template slot="append">
  130. <com-attachment :multiple="false" :max="1" @selected="videoUrl" type="videos">
  131. <el-tooltip class="item" effect="dark" content="支持格式mp4;支持编码H.264;" placement="top">
  132. <el-button size="mini">添加视频</el-button>
  133. </el-tooltip>
  134. </com-attachment>
  135. </template>
  136. </el-input>
  137. <a class="box-grow-0" type="primary" style="font-size:12px" title="播放视频" v-if="ruleForm.thumb_url" :underline="false" target="_blank" :href="ruleForm.video_url">
  138. <com-image v-model="ruleForm.thumb_url" mode="aspectFill" width='80px' height='80px' style="margin-top: 10px;" :src="ruleForm.thumb_url"></com-image>
  139. </a>
  140. <com-attachment v-model="ruleForm.thumb_url" @selected="thumbUrl" :multiple="false" :max="1">
  141. <el-tooltip class="item" effect="dark" content="建议尺寸:420 * 336" placement="top">
  142. <el-button size="mini">修改封面</el-button>
  143. </el-tooltip>
  144. </com-attachment>
  145. </el-form-item>
  146. <el-form-item label="关联商品">
  147. <el-radio-group v-model="ruleForm.associated_good">
  148. <com-dialog-select :multiple="false" @selected="goodsSelect" title="商品选择">
  149. <el-button type="text">选择商品</el-button>
  150. </com-dialog-select>
  151. </el-radio-group>
  152. </el-form-item>
  153. <el-form-item v-if="ruleForm.goods_id" prop="goods_id">
  154. <template>
  155. <div style="color: #ff4544;">最多可关联1个商品</div>
  156. <div style="max-height: 300px;overflow-y: auto">
  157. <el-table :data="ruleForm.goods_list" :show-header="false" border>
  158. <el-table-column label="">
  159. <template slot-scope="scope">
  160. <div flex>
  161. <div style="padding-right: 10px;flex-grow: 0">
  162. <com-image mode="aspectFill" :src="scope.row.cover_pic"></com-image>
  163. </div>
  164. <div style="flex-grow: 1;">
  165. <com-ellipsis :line="2">{{scope.row.name}}</com-ellipsis>
  166. <p style="color: red;">¥ {{scope.row.price}}</p>
  167. </div>
  168. <div style="flex-grow: 0;">
  169. <el-button @click="deleteGoods(scope.$index)" type="text" circle size="mini">
  170. 删除
  171. </el-button>
  172. </div>
  173. </div>
  174. </template>
  175. </el-table-column>
  176. </el-table>
  177. </div>
  178. </template>
  179. </el-form-item>
  180. </el-col>
  181. </el-row>
  182. <!-- 弹框添加分类开始-->
  183. <el-dialog :title="addFormTitle" width="30%" :visible.sync="dialogAddgsVisible" @close="closeDialogAddgsVisible" :modal-append-to-body="false">
  184. <el-form :model="addForm" ref="addForm" :rules="addRule" :inline="true" @submit.native.prevent label-width="100px">
  185. <el-form-item label="分类名称" prop="name">
  186. <el-input v-model="addForm.name" placeholder="请填写标题"></el-input>
  187. </el-form-item>
  188. </el-form>
  189. <span slot="footer" class="dialog-footer">
  190. <el-button @click="dialogAddgsVisible = false">取 消</el-button>
  191. <el-button type="primary" :loading="btnLoading" @click="saveAddForm('addForm')">确 定</el-button>
  192. </span>
  193. </el-dialog>
  194. <!-- 弹框添加分类结束-->
  195. </el-form>
  196. </div>
  197. <el-button class="button-item" :loading="btnLoading" type="primary" @click="store('ruleForm')" size="small">保存
  198. </el-button>
  199. </el-card>
  200. </div>
  201. <script>
  202. const app = new Vue({
  203. el: '#app',
  204. data() {
  205. var validatePass = (rule, value, callback) => {
  206. var reg = /^[\u4e00-\u9fa5\w]+$/;
  207. if (reg.test(value)) {
  208. callback();
  209. }else{
  210. callback(new Error('不能含有特殊字符'));
  211. }
  212. };
  213. return {
  214. btnLoading: false,
  215. cardLoading: false,
  216. editTitle: '创建素材',
  217. ruleForm: {
  218. user_avatar_url: '',
  219. download_type: 1,
  220. pic_url: [],
  221. user_id:0,
  222. associated_good: [],
  223. goods_list: [],
  224. video_url: '',
  225. thumb_url: '',
  226. goods_id:'',
  227. // 短视频设置
  228. is_alone: 0, //是否独立
  229. video_share_type: "1", //默认选中百分比
  230. percentage: 0, //默认0%
  231. fixed_value: 0, //默认固定金额0
  232. virtual_download_num: 0,
  233. },
  234. rules: {
  235. user_avatar_url: [{
  236. required: true,
  237. message: '请选择头像',
  238. trigger: 'change'
  239. }, ],
  240. // cate_id: [{
  241. // required: true,
  242. // message: '请你选择分类',
  243. // trigger: 'change'
  244. // }, ],
  245. describe: [{
  246. required: true,
  247. message: '请输入方案',
  248. trigger: 'change'
  249. },
  250. {
  251. //validator:validatePass,
  252. trigger: 'blur'
  253. },
  254. ],
  255. material_type_id: [{
  256. required: true,
  257. message: '请选择分类',
  258. trigger: 'change'
  259. }, ],
  260. // pic_url_img: [
  261. // {required: true, message: '请选择图片', trigger: 'change'},
  262. // ],
  263. // video_url: [
  264. // {required: true, message: '请选择视频', trigger: 'change'},
  265. // ],
  266. },
  267. materilCateList:[],
  268. //弹框配置
  269. addForm: {
  270. id: '',
  271. name: '',
  272. status: 1,
  273. },
  274. addRule: {
  275. name: [{
  276. required: true,
  277. message: '请填写分类名称',
  278. trigger: 'change'
  279. },
  280. {
  281. max: 8,
  282. message: '最大长度为8个字符',
  283. trigger: 'blur'
  284. }
  285. ],
  286. },
  287. ptypeList: [{
  288. key: "0",
  289. value: "成功"
  290. },
  291. {
  292. key: "1",
  293. value: "失败"
  294. },
  295. ],
  296. addFormTitle: "",
  297. dialogAddgsVisible: false,
  298. dataList: [],
  299. // 对话框显示与否
  300. dialogVisible: false,
  301. dataloading: false,
  302. addGroupVisible: false,
  303. cascadeProps: {
  304. checkStrictly: true,
  305. value: 'value',
  306. label: 'label',
  307. children: 'children'
  308. },
  309. selectCate: [],
  310. };
  311. },
  312. methods: {
  313. store(formName) {
  314. this.$refs[formName].validate((valid) => {
  315. if (!this.ruleForm.cate_id) {
  316. this.$message.error('请您选择分类');
  317. return false;
  318. }
  319. let self = this;
  320. if (valid) {
  321. self.btnLoading = true;
  322. request({
  323. params: {
  324. r: 'material/default/edit',
  325. },
  326. method: 'post',
  327. data: self.ruleForm,
  328. }).then(e => {
  329. self.btnLoading = false;
  330. if (e.data.code == 0) {
  331. navigateTo({
  332. r: 'material/default/index',
  333. })
  334. } else {
  335. console.log(e,888);
  336. self.$message.error(e.data.msg);
  337. }
  338. }).catch(e => {
  339. console.log(e.data,e.data.msg,888);
  340. self.$message.error(e.data.msg);
  341. self.btnLoading = false;
  342. });
  343. } else {
  344. console.log('error submit!!');
  345. return false;
  346. }
  347. });
  348. },
  349. getDetail() {
  350. if (!getQuery('id')) return;
  351. let self = this;
  352. //self.cardLoading = true;
  353. request({
  354. params: {
  355. r: 'material/default/edit',
  356. id: getQuery('id')
  357. },
  358. method: 'get',
  359. }).then(e => {
  360. self.cardLoading = false;
  361. if (e.data.code == 0) {
  362. var detailData = e.data.data.detail;
  363. if(detailData){
  364. self.ruleForm = detailData;
  365. if (detailData.goods_id) {
  366. self.ruleForm.goods_list = [];
  367. detailData.goods['name'] = detailData.goods['goods_name'];
  368. self.ruleForm.goods_list.push(detailData.goods);
  369. self.ruleForm.goods_id = detailData.goods_id;
  370. } else {
  371. self.ruleForm.goods_list = [];
  372. self.ruleForm.goods_id = '';
  373. }
  374. this.initSelectCate(self.ruleForm.cate_id, self.ruleForm.second_cate_id);
  375. }
  376. } else {
  377. self.$message.error(e.data.msg);
  378. }
  379. }).catch(e => {
  380. console.log(e);
  381. });
  382. },
  383. /**
  384. * 获取分类
  385. */
  386. getCateList() {
  387. request({
  388. params: {
  389. r: 'material/default/get-cate-list',
  390. },
  391. method: 'get',
  392. }).then(e => {
  393. this.cardLoading = true
  394. if (e.data.code == 0) {
  395. this.materilCateList = e.data.data
  396. this.cardLoading = false
  397. }
  398. })
  399. },
  400. updatePicUrl(e, params) {
  401. this.ruleForm.pic_url[params.currentIndex].id = e[0].id;
  402. this.ruleForm.pic_url[params.currentIndex].pic_url = e[0].url;
  403. this.$forceUpdate();
  404. },
  405. thumbUrl(e) {
  406. if (e.length) {
  407. this.ruleForm.thumb_url = e[0].url;
  408. this.$refs.ruleForm.validateField('thumb_url');
  409. }
  410. this.$forceUpdate();
  411. },
  412. delPic(index) {
  413. this.ruleForm.pic_url.splice(index, 1)
  414. },
  415. // 轮播图
  416. picUrl(e) {
  417. if (e.length) {
  418. let self = this;
  419. e.forEach(function(item, index) {
  420. if (self.ruleForm.pic_url.length >= 9) {
  421. return;
  422. }
  423. self.ruleForm.pic_url.push({
  424. id: item.id,
  425. pic_url: item.url
  426. });
  427. });
  428. }
  429. },
  430. goodsSelect(param) {
  431. this.ruleForm.goods_id = param.id;
  432. this.ruleForm.goods_list.push({
  433. id: param.id,
  434. name: param.goods_name,
  435. price: param.price,
  436. cover_pic: param.cover_pic,
  437. });
  438. console.log(this.ruleForm.goods_id,this.ruleForm.goods_list,999999999999);
  439. },
  440. deleteGoods(index) {
  441. this.ruleForm.goods_list.splice(index, 1);
  442. this.ruleForm.goods_id = '';
  443. },
  444. // 商品视频
  445. videoUrl(e) {
  446. if (e.length) {
  447. this.ruleForm.video_url = e[0].url;
  448. this.ruleForm.thumb_url = e[0].thumb_url;
  449. }
  450. console.log('视频');
  451. console.log(e[0]);
  452. console.log(this.ruleForm);
  453. this.$forceUpdate();
  454. },
  455. // 短视频设置单选按钮
  456. shareTypeChange(e) {
  457. if (e == 0) {
  458. this.ruleForm.percentage = 0;
  459. } else {
  460. this.ruleForm.fixed_value = 0;
  461. }
  462. },
  463. // 4.0 短视频设置
  464. videoSetting() {
  465. let self = this;
  466. let postData = {
  467. goods_id: self.goods_id,
  468. video_share_type: self.ruleForm.video_share_type,
  469. percentage: self.ruleForm.percentage,
  470. fixed_value: self.ruleForm.fixed_value,
  471. is_alone: self.ruleForm.is_alone,
  472. }
  473. request({
  474. params: {
  475. r: 'plugin/short_video/mall/goods/goods-setting',
  476. },
  477. method: 'post',
  478. data: postData
  479. }).then(e => {
  480. self.loading = false;
  481. if (e.data.code == 0) {
  482. self.$message.success(e.data.msg);
  483. } else {
  484. self.$message.error(e.data.msg);
  485. }
  486. }).catch(e => {
  487. console.log(e);
  488. });
  489. },
  490. // 4.1 获取短视频设置
  491. videoLoadData() {
  492. let self = this;
  493. self.loading = true;
  494. request({
  495. params: {
  496. r: 'plugin/short_video/mall/goods/goods-setting',
  497. goods_id: self.goods_id,
  498. },
  499. method: 'get',
  500. data: {}
  501. }).then(e => {
  502. self.loading = false;
  503. if (e.data.code == 0) {
  504. // self.form = e.data.data.setting;
  505. self.ruleForm.is_alone = e.data.data.is_alone;
  506. self.ruleForm.video_share_type = e.data.data.video_share_type;
  507. self.ruleForm.percentage = e.data.data.percentage;
  508. self.ruleForm.fixed_value = e.data.data.fixed_value;
  509. } else {
  510. self.$message.error(e.data.msg);
  511. }
  512. }).catch(e => {
  513. console.log(e);
  514. });
  515. },
  516. /**
  517. *点击新增按钮,弹出新增模态框
  518. * @param
  519. */
  520. addgsForm() {
  521. this.dialogAddgsVisible = true;
  522. this.title = "新增分类"
  523. },
  524. /**
  525. *关闭或取消模态框,清空值
  526. * @param
  527. */
  528. closeDialogAddgsVisible() {
  529. this.$refs.addForm.resetFields(); //element封装的方法,清空模态框的值
  530. this.addFormTitle = "" //初始化title的值
  531. this.addForm = { //初始化addForm中的值
  532. name: "",
  533. }
  534. },
  535. /**
  536. *更新新数据
  537. * @param
  538. */
  539. saveAddForm(formName) {
  540. this.$refs[formName].validate((valid) => {
  541. let self = this;
  542. if (valid) {
  543. this.postData({name : self.addForm.name});
  544. } else {
  545. console.log('error submit!!');
  546. return false;
  547. }
  548. });
  549. },
  550. postData(data){
  551. let self = this;
  552. self.btnLoading = true;
  553. request({
  554. params: {
  555. r: 'material/cate/edit',
  556. },
  557. method: 'post',
  558. data:data,
  559. }).then(e => {
  560. this.dialogAddgsVisible = false;
  561. this.btnLoading = false;
  562. if (e.data.code == 0) {
  563. this.getDetail();
  564. } else {
  565. self.$message.error(e.data.msg);
  566. }
  567. }).catch(e => {
  568. console.log(e);
  569. });
  570. },
  571. updateView(e) {
  572. this.$forceUpdate()
  573. },
  574. handleChange(value) {
  575. if (value && value.length >= 2) {
  576. this.ruleForm.cate_id = value[0];
  577. this.ruleForm.second_cate_id = value[1];
  578. } else if (value && value.length === 1) {
  579. // 如果只选择了一级分类
  580. this.ruleForm.cate_id = value[0];
  581. this.ruleForm.second_cate_id = 0; // 或空字符串''
  582. } else {
  583. // 清空选择的情况
  584. this.ruleForm.cate_id = null;
  585. this.ruleForm.second_cate_id = 0;
  586. }
  587. console.log('当前表单值:', this.ruleForm);
  588. },
  589. initSelectCate(cate_id, second_cate_id) {
  590. this.selectCate = [];
  591. this.selectCate.push(cate_id);
  592. if (second_cate_id > 0) {
  593. this.selectCate.push(second_cate_id);
  594. }
  595. }
  596. },
  597. mounted: function() {
  598. if (getQuery('id')) {
  599. this.editTitle = '编辑素材';
  600. this.getDetail();
  601. }
  602. this.getCateList()
  603. this.getDetail();
  604. }
  605. });
  606. </script>