create.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <template>
  2. <div>
  3. <!--头部标题-->
  4. <div class="i-layout-page-header">
  5. <PageHeader class="product_tabs" hidden-breadcrumb>
  6. <div slot="title" class="acea-row row-middle">
  7. <router-link :to="{ path: `${roterPre}/marketing/short_video/index` }">
  8. <div class="font-sm after-line">
  9. <span class="iconfont iconfanhui"></span>
  10. <span class="pl10">返回</span>
  11. </div>
  12. </router-link>
  13. <span v-text="$route.params.id ? '编辑短视频' : '添加短视频'" class="mr20 ml16"></span>
  14. </div>
  15. </PageHeader>
  16. </div>
  17. <Card :bordered="false" dis-hover class="ivu-mt mb79">
  18. <!-- Tab栏切换 -->
  19. <div class="new_tab">
  20. <Tabs v-model="currentTab">
  21. <TabPane
  22. :label="item.name"
  23. :name="item.type"
  24. v-for="(item, index) in headeNum"
  25. :key="index"
  26. />
  27. </Tabs>
  28. </div>
  29. <div class="Button" v-if="currentTab === '2'">
  30. <Button type="primary" class="bnt mr15" @click="addGoods">添加商品</Button>
  31. <Tooltip content="本页至少选中一项" :disabled="!!formSelection.length">
  32. <Button
  33. class="bnt mr15"
  34. :disabled="!formSelection.length"
  35. @click="batchDel"
  36. >批量删除</Button
  37. >
  38. </Tooltip>
  39. </div>
  40. <Form
  41. class="formValidate mt20"
  42. ref="formValidate"
  43. :rules="ruleValidate"
  44. :model="formValidate"
  45. :label-width="labelWidth"
  46. :label-position="labelPosition"
  47. @submit.native.prevent
  48. >
  49. <Row :gutter="24" type="flex" v-show="currentTab === '1'">
  50. <Col span="24">
  51. <FormItem label="视频简介:" prop="desc">
  52. <Input
  53. v-model="formValidate.desc"
  54. type="textarea"
  55. :rows="3"
  56. placeholder="请输入视频简介"
  57. maxlength="220"
  58. show-word-limit
  59. v-width="'50%'"
  60. />
  61. </FormItem>
  62. </Col>
  63. <Col span="24">
  64. <FormItem label="上传视频:" prop="video_url">
  65. <Button @click="modalPicTap('video')">上传视频</Button>
  66. <div class="tips">建议时长:9~30秒,视频宽高比9:16(不建议本地储存)</div>
  67. <div class="iview-video-style" v-if="formValidate.video_url">
  68. <video
  69. class="video-style"
  70. :src="formValidate.video_url"
  71. controls="controls"
  72. >
  73. </video>
  74. <div class="mark"></div>
  75. <Icon
  76. type="ios-trash-outline"
  77. class="iconv"
  78. @click="delVideo"
  79. />
  80. </div>
  81. </FormItem>
  82. </Col>
  83. <Col span="24">
  84. <FormItem label="封面图:" prop="image">
  85. <div class="pictrueBox">
  86. <div class="pictrue" v-if="formValidate.image">
  87. <img v-lazy="formValidate.image" />
  88. <Button
  89. shape="circle"
  90. icon="md-close"
  91. @click.native="handleRemove"
  92. class="btndel"
  93. ></Button>
  94. </div>
  95. <div class="upLoad acea-row row-center-wrapper" @click="modalPicTap('image')" v-else>
  96. <Input v-model="formValidate.image" class="input-display"></Input>
  97. <Icon type="ios-add" size="26" />
  98. </div>
  99. </div>
  100. <div class="tips">建议尺寸:226 * 300px</div>
  101. </FormItem>
  102. </Col>
  103. <Col span="24">
  104. <FormItem label="排序:">
  105. <InputNumber
  106. v-model="formValidate.sort"
  107. :min="0"
  108. :max="99999999"
  109. v-width="'50%'"
  110. ></InputNumber>
  111. </FormItem>
  112. </Col>
  113. </Row>
  114. <div v-show="currentTab === '2'">
  115. <Table
  116. :columns="columns"
  117. :data="tableData"
  118. @on-selection-change="selectChange"
  119. highlight-row
  120. no-userFrom-text="暂无数据"
  121. no-filtered-userFrom-text="暂无筛选结果"
  122. class="ivu-mt"
  123. >
  124. <template slot-scope="{ row }" slot="info">
  125. <div class="imgPic acea-row row-middle">
  126. <viewer>
  127. <div class="pictrue"><img v-lazy="row.image" /></div>
  128. </viewer>
  129. <div class="info">
  130. <Tooltip max-width="200" placement="bottom" transfer>
  131. <span class="line2">{{ row.store_name }}{{row.suk}}</span>
  132. <p slot="content">{{ row.store_name }}{{row.suk}}</p>
  133. </Tooltip>
  134. </div>
  135. </div>
  136. </template>
  137. <template slot-scope="{ row, index }" slot="action">
  138. <a @click="del(row)">删除</a>
  139. </template>
  140. </Table>
  141. </div>
  142. </Form>
  143. </Card>
  144. <Card :bordered="false" dis-hover class="fixed-card" :style="{left: `${!menuCollapse?'200px':isMobile?'0':'80px'}`}">
  145. <Form>
  146. <FormItem>
  147. <Button
  148. v-if="currentTab !== '1'"
  149. @click="upTab"
  150. style="margin-right:10px"
  151. >上一步</Button>
  152. <Button
  153. type="primary"
  154. class="submission"
  155. v-if="currentTab !== '2'"
  156. @click="downTab('formValidate')"
  157. >下一步</Button
  158. >
  159. <Button
  160. v-else
  161. type="primary"
  162. class="submission"
  163. @click="handleSubmit('formValidate')"
  164. >保存</Button
  165. >
  166. </FormItem>
  167. </Form>
  168. </Card>
  169. <Modal
  170. v-model="modalPic"
  171. width="960px"
  172. scrollable
  173. footer-hide
  174. closable
  175. title="上传商品图"
  176. :mask-closable="false"
  177. :z-index="1"
  178. >
  179. <uploadPictures
  180. :isChoice="isChoice"
  181. @getPic="getPic"
  182. :gridBtn="gridBtn"
  183. :gridPic="gridPic"
  184. v-if="modalPic"
  185. ></uploadPictures>
  186. </Modal>
  187. <Modal v-model="modals" title="商品列表" footerHide class="paymentFooter" scrollable width="900" @on-cancel="cancel">
  188. <goods-list ref="goodslist" :ischeckbox="true" :isdiy="true" @getProductId="getProductId" v-if="modals"></goods-list>
  189. </Modal>
  190. </div>
  191. </template>
  192. <script>
  193. import { mapState } from "vuex";
  194. import uploadPictures from "@/components/uploadPictures";
  195. import { videoInfo, videoSave } from "@/api/marketing";
  196. import goodsList from '@/components/goodsList';
  197. import Setting from "@/setting";
  198. export default {
  199. name: "create",
  200. components:{
  201. uploadPictures,
  202. goodsList
  203. },
  204. data() {
  205. const validateImage = (rule, value, callback) =>{
  206. if(!value){
  207. return callback(new Error('请上传视频封面图'))
  208. }else{
  209. callback();
  210. }
  211. };
  212. const validateVideo = (rule, value, callback) => {
  213. if(!value){
  214. return callback(new Error('请上传视频'))
  215. }else{
  216. callback();
  217. }
  218. };
  219. return {
  220. roterPre: Setting.roterPre,
  221. currentTab: "1",
  222. modals:false,
  223. gridBtn: {
  224. xl: 4,
  225. lg: 8,
  226. md: 8,
  227. sm: 8,
  228. xs: 8,
  229. },
  230. gridPic: {
  231. xl: 6,
  232. lg: 8,
  233. md: 12,
  234. sm: 12,
  235. xs: 12,
  236. },
  237. headeNum: [
  238. { type: "1", name: "基础设置" },
  239. { type: "2", name: "关联商品" }
  240. ],
  241. formValidate:{
  242. desc:'',
  243. image:'',
  244. sort:0,
  245. video_url:'',
  246. product_id:[]
  247. },
  248. modalPic: false,
  249. isChoice: "单选",
  250. ruleValidate: {
  251. desc: [
  252. { required: true, message: '请输入视频简介', trigger: 'blur' }
  253. ],
  254. video_url: [
  255. {
  256. required: true,
  257. message: "请上传视频",
  258. validator: validateVideo,
  259. trigger: "change",
  260. }
  261. ],
  262. image: [
  263. {
  264. required: true,
  265. validator: validateImage,
  266. trigger: 'change',
  267. }
  268. ]
  269. },
  270. columns: [
  271. {
  272. type: 'selection',
  273. width: 60,
  274. align: 'center'
  275. },
  276. {
  277. title: "商品信息",
  278. slot: "info",
  279. minWidth: 180,
  280. },
  281. {
  282. title: "商品分类",
  283. key: "cate_name",
  284. minWidth: 180,
  285. },
  286. {
  287. title: "售价",
  288. key: "price",
  289. minWidth: 180,
  290. },
  291. {
  292. title: "库存",
  293. key: "stock",
  294. minWidth: 180,
  295. },
  296. {
  297. title: "操作",
  298. slot: "action",
  299. fixed: "right",
  300. width: 100,
  301. }
  302. ],
  303. tableData:[],
  304. id:0,
  305. formSelection:[],
  306. typeTit:''
  307. };
  308. },
  309. computed: {
  310. ...mapState("admin/layout", ["isMobile","menuCollapse"]),
  311. labelWidth() {
  312. return this.isMobile ? undefined : 90;
  313. },
  314. labelPosition() {
  315. return this.isMobile ? "top" : "right";
  316. }
  317. },
  318. created() {
  319. this.id = this.$route.params.id || 0;
  320. if(this.id){
  321. this.getInfo();
  322. }
  323. },
  324. methods: {
  325. delVideo(){
  326. let that = this;
  327. that.$set(that.formValidate, "video_url", "");
  328. this.$refs.formValidate.validateField('video_url');
  329. },
  330. del(row){
  331. this.tableData.forEach((item,index)=>{
  332. if(row.id === item.id){
  333. return this.tableData.splice(index, 1)
  334. }
  335. })
  336. },
  337. batchDel(){
  338. for(var i=0;i<this.formSelection.length;i++){
  339. for(var j=0;j<this.tableData.length;j++){
  340. if(this.tableData[j].id===this.formSelection[i].id){
  341. this.tableData.splice(j,1);
  342. j--;
  343. }
  344. }
  345. }
  346. },
  347. selectChange(data){
  348. this.formSelection = data;
  349. },
  350. addGoods(){
  351. this.modals = true;
  352. },
  353. cancel () {
  354. this.modals = false;
  355. },
  356. //对象数组去重;
  357. unique(arr) {
  358. const res = new Map();
  359. return arr.filter((arr) => !res.has(arr.id) && res.set(arr.id, 1))
  360. },
  361. getProductId (data) {
  362. this.modals = false;
  363. let list = this.tableData.concat(data);
  364. this.tableData = this.unique(list);
  365. },
  366. //视频详情
  367. getInfo(){
  368. videoInfo(this.id).then(res=>{
  369. this.formValidate = res.data;
  370. this.tableData = res.data.productInfo;
  371. }).catch(err=>{
  372. this.$Message.error(err.msg)
  373. })
  374. },
  375. upTab(){
  376. this.currentTab = '1';
  377. },
  378. downTab(name){
  379. this.$refs[name].validate((valid) => {
  380. if (valid) {
  381. this.currentTab = '2';
  382. }else{
  383. this.$Message.warning("请完善数据");
  384. }
  385. })
  386. },
  387. //保存视频
  388. handleSubmit(name){
  389. this.$refs[name].validate((valid) => {
  390. if (valid) {
  391. let product_id = [];
  392. this.tableData.forEach(item=>{
  393. product_id.push(item.id)
  394. });
  395. this.formValidate.product_id = product_id;
  396. videoSave(this.formValidate,this.id).then(res=>{
  397. this.$router.push({ path: `${this.roterPre}/marketing/short_video/index` });
  398. this.$Message.success(res.msg)
  399. }).catch(err=>{
  400. this.$Message.error(err.msg)
  401. })
  402. }else{
  403. this.$Message.warning("请完善数据");
  404. }
  405. })
  406. },
  407. // 点击商品图
  408. modalPicTap(type) {
  409. this.typeTit = type;
  410. this.modalPic = true;
  411. },
  412. // 获取单张图片信息
  413. getPic(pc) {
  414. this.modalPic = false;
  415. if(this.typeTit == 'image'){
  416. this.formValidate.image = pc.att_dir;
  417. this.$refs.formValidate.validateField('image');
  418. }else{
  419. this.formValidate.video_url = pc.att_dir;
  420. this.$refs.formValidate.validateField('video_url');
  421. }
  422. },
  423. handleRemove() {
  424. this.formValidate.image = '';
  425. this.$refs.formValidate.validateField('image');
  426. },
  427. }
  428. };
  429. </script>
  430. <style scoped lang="less">
  431. .pictrueBox {
  432. display: inline-block;
  433. .upLoad {
  434. width: 58px;
  435. height: 58px;
  436. line-height: 58px;
  437. border: 1px dotted rgba(0, 0, 0, 0.1);
  438. border-radius: 4px;
  439. background: rgba(0, 0, 0, 0.02);
  440. cursor: pointer;
  441. .input-display {
  442. display: none
  443. }
  444. }
  445. .pictrue {
  446. width: 60px;
  447. height: 60px;
  448. border: 1px dotted rgba(0, 0, 0, 0.1);
  449. margin-right: 15px;
  450. margin-bottom: 10px;
  451. display: inline-block;
  452. position: relative;
  453. cursor: pointer;
  454. img {
  455. width: 100%;
  456. height: 100%;
  457. }
  458. .btndel {
  459. position: absolute;
  460. z-index: 1;
  461. width: 20px !important;
  462. height: 20px !important;
  463. left: 46px;
  464. top: -4px;
  465. }
  466. }
  467. }
  468. .tips{
  469. font-size: 12px;
  470. font-weight: 400;
  471. color: #ccc;
  472. }
  473. .imgPic{
  474. .info{
  475. width: 60%;
  476. margin-left: 10px;
  477. }
  478. .pictrue{
  479. height: 36px;
  480. margin: 7px 3px 0 3px;
  481. img{
  482. height: 100%;
  483. display: block;
  484. }
  485. }
  486. }
  487. .iview-video-style {
  488. width: 40%;
  489. height: 180px;
  490. border-radius: 10px;
  491. background-color: #707070;
  492. margin-top: 10px;
  493. position: relative;
  494. overflow: hidden;
  495. .video-style {
  496. width: 100%;
  497. height: 100% !important;
  498. border-radius: 10px;
  499. }
  500. .iconv{
  501. color: #fff;
  502. line-height: 180px;
  503. width: 50px;
  504. height: 50px;
  505. display: inherit;
  506. font-size: 26px;
  507. position: absolute;
  508. top: -74px;
  509. left: 50%;
  510. margin-left: -25px;
  511. }
  512. .mark{
  513. position: absolute;
  514. width: 100%;
  515. height: 30px;
  516. top: 0;
  517. background-color: rgba(0, 0, 0, 0.5);
  518. text-align: center;
  519. }
  520. }
  521. .fixed-card {
  522. position: fixed;
  523. right: 0;
  524. bottom: 0;
  525. left: 200px;
  526. z-index: 20;
  527. box-shadow: 0 -1px 2px rgb(240, 240, 240);
  528. /deep/ .ivu-card-body {
  529. padding: 15px 16px 14px;
  530. }
  531. .ivu-form-item {
  532. margin-bottom: 0!important;
  533. }
  534. /deep/ .ivu-form-item-content {
  535. margin-right: 124px;
  536. text-align: center;
  537. }
  538. .ivu-btn {
  539. height: 36px;
  540. padding: 0 20px;
  541. }
  542. }
  543. </style>