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