replace.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. <template>
  2. <view class="">
  3. <view class="header">
  4. <image src="../../static/images/skm_fn_bg.png" mode="aspectFill" class="bg-img"></image>
  5. <view class="info-block flex-row-between">
  6. <view class="info">
  7. <view class="title">智能替换</view>
  8. <view class="desc">请上传高质量原图图片,以便更好的识别替换</view>
  9. </view>
  10. </view>
  11. </view>
  12. <view class="main">
  13. <view class="box-pack-between ft32 item flex-y-center pd40">
  14. <text>上传原图 <text style="color:red">*</text> <text class="tips"></text></text>
  15. <image v-if="Original_img" @click="ChooseImage" :data-type="1" class="qrupimg" :src="URL+''+Original_img" mode="aspectFit"></image>
  16. <image v-else @click="ChooseImage" :data-type="1" class="qrupimg" src="../../static/images/upimg.png" mode="aspectFit"></image>
  17. </view>
  18. <view class="box-pack-between ft32 flex-y-center header-tab">
  19. <view class="flex-grow-11 flex-center" @click="bindOriginal" :class="make_type==1?'act':''">快速模式</view>
  20. <view class="flex-grow-11 flex-center" @click="bindOrigina2" :class="make_type==2?'act':''">高级模式</view>
  21. <!-- <view class="flex-center ft24">
  22. <switch :checked="make_type==1?true:false" name="is_real" @change="bindOriginal" style="transform:scale(0.7)" />
  23. </view> -->
  24. </view>
  25. <block v-if="make_type==2">
  26. <view class="item-bg pd40">
  27. <view class="box-pack-between ">
  28. <text>配置替换</text>
  29. <picker @change="bindPickerAdvertising" :range="Advertising">
  30. <text class="col">{{Advertising[Adver_index]}} <text class="iconfont icon-prev"></text></text>
  31. </picker>
  32. </view>
  33. <view class="item-pd20 box-pack-between flex-y-center" v-if="Adver_index==0">
  34. <view class="flex-grow-0">二维码(扫码/相册选取)</view>
  35. <image v-if="code_img" @click="bindCode" class="qrupimg_end" src="../../static/images/pay_bz.png" mode=""></image>
  36. <image v-else @click="bindCode" class="qrupimg_end" src="../../static/images/saoma.png" mode=""></image>
  37. </view>
  38. <navigator hover-class="none" url="../enabling/enabling" class="box-pack-between flex-y-center item-pd20" v-if="Adver_index==1">
  39. <text style="min-width: 150rpx;">{{$test.$test}}记录</text>
  40. <view class="col flex-y-center">
  41. <view class="content" v-if="code_url">
  42. {{code_url}}
  43. </view>
  44. <text v-else>请选择{{$test.$test}}记录</text>
  45. <text class="iconfont icon-prev"></text>
  46. </view>
  47. </navigator>
  48. <view class="box-pack-between flex-y-center item-pd20" v-if="Adver_index==2">
  49. <text style="min-width: 150rpx;">链接地址</text>
  50. <input maxlength="5000" @input="address" :value="code_url" adjust-position="false"
  51. placeholder="请输入链接" class="tr"></input>
  52. </view>
  53. </view>
  54. </block>
  55. <view v-else class="pd40">
  56. <view class="">
  57. <view class="box-pack-between ft32 item" style="padding-top:0;">
  58. <text>{{$test.$test}}场景 </text>
  59. <view class="add-home flex-center ft24">
  60. <picker @change="bindPickerChange" :range-key="'name'" :range="allwayList">
  61. 添加
  62. </picker>
  63. </view>
  64. </view>
  65. <view class="item-bg" v-if="arr.length>0">
  66. <view class="box-pack-between mar64 flex-y-center" v-for="(item,index) of arr" :key='item.id'>
  67. <view class="flex-y-center flex-grow-1 pdr-20">
  68. <text style="margin-right: 10rpx;">{{item.name}}</text>
  69. <input class="flex-grow-1" type="text" @input="getScene"
  70. :data-index="index" placeholder="请填写链接或内容" :value="item.way_power" />
  71. </view>
  72. <image class="item-del" @click="delScene" :data-index='index' src="../../static/images/del.png" mode=""></image>
  73. </view>
  74. </view>
  75. </view>
  76. <view class="box-pack-between ft32 item flex-y-center">
  77. <text>开启遮盖指引</text>
  78. <view class="flex-center ft24">
  79. <switch :checked="hj_state==1?true:false" @change="bindHj" style="transform:scale(0.7)" />
  80. </view>
  81. </view>
  82. </view>
  83. <view class="tips pd40" style="margin-top: 20rpx;">
  84. ps:本功能目前处于尝鲜阶段,成功率并不是100%,后续将不断优化二维码替换成功率。
  85. </view>
  86. </view>
  87. <view class="btm-btn-replace">
  88. <view class="btm-btn" @click="Confirm">{{card_num?'修改替换':'确认替换'}}</view>
  89. </view>
  90. </view>
  91. </template>
  92. <script>
  93. // #ifdef H5
  94. import getWXSign from "@/static/js/config.js";
  95. // #endif
  96. export default {
  97. data() {
  98. return {
  99. $test: this.$test.$test,
  100. Advertising: ["二维码", `${this.$test.$test}记录`, "链接"],
  101. Adver_index: 0,
  102. URL: getApp().globalData.URL,
  103. Original_img: "",
  104. code_img: "",
  105. save_url: "",
  106. code_url:"",
  107. make_type: 1,
  108. allwayList: [],
  109. arr: [],
  110. hj_state: 2,
  111. info: {},
  112. type:"",
  113. }
  114. },
  115. onLoad(e) {
  116. this.card_num = e.card_num;
  117. this.allways();
  118. },
  119. onShow(e) {
  120. },
  121. methods: {
  122. bindHj(e) {
  123. this.hj_state = e.target.value ? 1 : 2;
  124. },
  125. bindOriginal(e) {
  126. this.make_type = 1;
  127. },
  128. bindOrigina2(e) {
  129. this.make_type = 2;
  130. },
  131. bindPickerChange: function(e) {
  132. console.log(e, this.allwayList, "bindPickerChange", )
  133. if (this.arr.length > 0) {
  134. for (let i of this.arr) {
  135. if (i.id == this.allwayList[e.target.value].id) {
  136. uni.showToast({
  137. title: "场景重复",
  138. icon: 'none'
  139. })
  140. return
  141. }
  142. }
  143. }
  144. this.arr.push({
  145. id: this.allwayList[e.target.value].id,
  146. name: this.allwayList[e.target.value].name,
  147. super_id: this.allwayList[e.target.value].super_id,
  148. });
  149. },
  150. allways() {
  151. this.request({
  152. url: "funeng/allways",
  153. data: {},
  154. }).then(res => {
  155. console.log(res, "res")
  156. if (res.code === '200') {
  157. this.allwayList = res.data;
  158. this.arr.push({
  159. id: res.data[0].id,
  160. name: res.data[0].name,
  161. super_id: res.data[0].super_id,
  162. });
  163. if (this.card_num) {
  164. this.edit_detail();
  165. }
  166. }
  167. }).catch((res) => {});
  168. },
  169. edit_detail(e) {
  170. this.request({
  171. url: "picture/edit_detail",
  172. data: {
  173. card_num: this.card_num,
  174. },
  175. }).then(res => {
  176. console.log(res, "res")
  177. if (res.code === '200') {
  178. this.info = res.data;
  179. this.Original_img = res.data.bg;
  180. this.make_type = res.data.make_type;
  181. this.type=res.data.is_video==1?6:0;
  182. if (res.data.make_type == 1) {
  183. this.save_url =res.data.url;
  184. this.arr = res.data.funeng;
  185. this.hj_state = res.data.hj_state;
  186. } else {
  187. if(res.data.type==1){
  188. this.code_img=true;
  189. }
  190. this.code_url =res.data.url;
  191. this.Adver_index = Number(res.data.type) - 1;
  192. this.arr = [];
  193. this.hj_state = 2;
  194. }
  195. // this.allmuban();
  196. // make_type
  197. }
  198. }).catch((res) => {
  199. });
  200. },
  201. qr_del(e) {
  202. var index = e.currentTarget.dataset.index;
  203. this.qr_arr.splice(index, 1)
  204. },
  205. getScene(e) {
  206. var index = e.currentTarget.dataset.index;
  207. this.arr[index].way_power = e.detail.value;
  208. },
  209. delScene(e) {
  210. var index = Number(e.currentTarget.dataset.index);
  211. this.arr.splice(index, 1);
  212. },
  213. bindPickerAdvertising(e) {
  214. this.save_url = "";
  215. this.code_url="";
  216. this.Adver_index = e.detail.value;
  217. },
  218. address(e) {
  219. this.code_url = e.detail.value;
  220. },
  221. bindCode(e) {
  222. console.log(e, "bangCode")
  223. // #ifdef MP-WEIXIN
  224. uni.scanCode({
  225. success: (res) => {
  226. console.log('条码类型:' + res.scanType);
  227. console.log('条码内容:' + res.result);
  228. this.code_img = true;
  229. this.code_url = res.result;
  230. }
  231. });
  232. // #endif
  233. // #ifdef H5
  234. getWXSign().then(res => {
  235. console.log('wx_getLocation');
  236. this.$wx.scanQRCode({
  237. needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  238. scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
  239. success: (res) => {
  240. console.log(res, "qrCode")
  241. this.code_url = res.resultStr;
  242. this.code_img = true;
  243. }
  244. })
  245. })
  246. // #endif
  247. },
  248. ChooseImage(e) {
  249. console.log(e, "rrr")
  250. let type = e.currentTarget.dataset.type;
  251. uni.chooseImage({
  252. count: 1, //默认9
  253. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  254. sourceType: ['album'], //从相册选择
  255. success: (res) => {
  256. res.tempFilePaths.forEach((v, i) => {
  257. console.log(v)
  258. this.Upload({
  259. url: "Spread/upload_img",
  260. data: {
  261. url: v,
  262. type: 1,
  263. token: uni.getStorageSync("token"),
  264. }
  265. }).then(res => {
  266. console.log(res, "res")
  267. // if (this.make_type==1) {
  268. this.Original_img = res.file;
  269. this.save_url = res.url;
  270. // } else {
  271. // this.Original_img = res.file;
  272. // this.save_url ="";
  273. // }
  274. }).catch(err => {
  275. console.log(err, "err")
  276. this.Original_img = err.data.file;
  277. uni.showModal({
  278. title: '提示',
  279. content: '上传图片里的二维码无法识别,请重新上传原图',
  280. showCancel: false,
  281. confirmText: '再试一次',
  282. success: res => {
  283. if (res.confirm) {
  284. // #ifdef MP-WEIXIN
  285. uni.scanCode({
  286. success: (res) => {
  287. console.log('条码类型:' + res.scanType);
  288. console.log('条码内容:' + res.result);
  289. this.save_url = res.result;
  290. }
  291. });
  292. // #endif
  293. // #ifdef H5
  294. getWXSign().then(res => {
  295. console.log('wx_getLocation');
  296. this.$wx.scanQRCode({
  297. needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  298. scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
  299. success: (res) => {
  300. console.log(res, "qrCode")
  301. this.save_url = res.resultStr;
  302. }
  303. })
  304. })
  305. // #endif
  306. }
  307. },
  308. fail: () => {},
  309. complete: () => {}
  310. });
  311. });
  312. })
  313. },
  314. });
  315. },
  316. Confirm(e) {
  317. let arr = this.arr,
  318. qr_arr = this.qr_arr,
  319. way_id = [],
  320. way_power = [];
  321. for (let i of arr) {
  322. way_id.push(i.id);
  323. way_power.push(i.way_power)
  324. }
  325. if (this.make_type == 1 && way_power.length <= 0) {
  326. uni.showToast({
  327. title: "场景为空",
  328. icon: 'none'
  329. })
  330. return
  331. }
  332. if (!this.Original_img) {
  333. uni.showToast({
  334. title: "请上传原图",
  335. icon: "none"
  336. })
  337. return false
  338. }
  339. this.request({
  340. url: "picture/save",
  341. data: {
  342. id: this.card_num ? this.info.id : "",
  343. bg: this.Original_img,
  344. type: Number(this.Adver_index) + 1,
  345. url: this.make_type==1?this.save_url:this.code_url,
  346. make_type: this.make_type,
  347. token: uni.getStorageSync("token"),
  348. is_video:this.type==6?1:2,
  349. way_id: way_id.join(","),
  350. way_power: way_power.join(","),
  351. hj_state: this.hj_state,
  352. },
  353. }).then(res => {
  354. console.log(res, "res")
  355. if (res.code === '200') {
  356. let qrcode = res.data.data;
  357. uni.setStorageSync("qrcode", qrcode);
  358. uni.redirectTo({
  359. url: "./results?typpe=1"
  360. })
  361. }
  362. }).catch((res) => {
  363. uni.showToast({
  364. title: res.message,
  365. icon: 'none'
  366. })
  367. });
  368. }
  369. }
  370. }
  371. </script>
  372. <style>
  373. .content {
  374. word-wrap: break-word;
  375. word-break: break-all;
  376. }
  377. .qrupimg_end {
  378. width: 80rpx;
  379. height: 80rpx;
  380. }
  381. .header {
  382. width: 100%;
  383. height: 198rpx;
  384. position: relative;
  385. }
  386. .header .bg-img {
  387. display: block;
  388. position: absolute;
  389. left: 0;
  390. top: 0;
  391. z-index: -1;
  392. width: 100%;
  393. height: 198rpx;
  394. }
  395. .header .info-block {
  396. padding: 0 40rpx 0 48rpx;
  397. height: 198rpx;
  398. }
  399. .header .info-block .title {
  400. font-size: 36rpx;
  401. color: #fff;
  402. font-weight: 500;
  403. line-height: 50rpx;
  404. }
  405. .header .info-block .desc {
  406. font-size: 28rpx;
  407. font-weight: 500;
  408. color: #fff;
  409. line-height: 40rpx;
  410. margin-top: 8rpx;
  411. }
  412. .header .info-block .btn {
  413. width: 120rpx;
  414. height: 56rpx;
  415. border: 2rpx solid #fff;
  416. border-radius: 28rpx;
  417. background-color: rgba(255, 255, 255, 0.2);
  418. text-align: center;
  419. line-height: 52rpx;
  420. font-size: 28rpx;
  421. font-weight: 500;
  422. color: #fff;
  423. }
  424. .col {
  425. color: #999999;
  426. }
  427. .item {
  428. padding: 30rpx 0;
  429. /* border-bottom: 1rpx solid #F1F1F1; */
  430. }
  431. .header-tab {
  432. height: 100rpx;
  433. background: #F1F1F1;
  434. font-size: 28rpx;
  435. margin-top: 50rpx;
  436. padding: 0 20px;
  437. margin-bottom: 60rpx;
  438. }
  439. .header-tab .flex-grow-11 {
  440. width: 40%;
  441. height: 79%;
  442. }
  443. .header-tab .act {
  444. color: #3387ff;
  445. background: #fff;
  446. border-radius: 8rpx;
  447. }
  448. .add-home {
  449. color: #FFFFFF;
  450. width: 126rpx;
  451. height: 54rpx;
  452. background: linear-gradient(315deg, #3387ff 2%, #569bff 99%);
  453. border-radius: 8rpx;
  454. box-shadow: 0px 0px 8rpx 0px rgba(51, 135, 255, 0.2);
  455. }
  456. .item-bg {
  457. width: 670rpx;
  458. background: #f6f8fe;
  459. border-radius: 12rpx;
  460. margin: 0 auto;
  461. font-size: 28rpx;
  462. font-family: PingFang SC, PingFang SC-Regular;
  463. font-weight: 400;
  464. color: #333333;
  465. padding: 36rpx 32rpx;
  466. }
  467. .main {
  468. background-color: #fff;
  469. border-radius: 20rpx 20rpx 0 0;
  470. margin-top: -20rpx;
  471. padding: 20rpx 0rpx 0;
  472. }
  473. .pd40 {
  474. padding: 0rpx 40rpx;
  475. }
  476. .qrupimg {
  477. width: 126rpx;
  478. height: 126rpx;
  479. }
  480. .headerMind {
  481. font-size: 32rpx;
  482. font-family: PingFang SC, PingFang SC-Medium;
  483. font-weight: 500;
  484. color: #333333;
  485. padding: 44rpx 0 32rpx 0;
  486. }
  487. .item-pd20 {
  488. padding: 50rpx 0 20rpx 0;
  489. }
  490. .tr {
  491. text-align: right;
  492. }
  493. .btm-btn-replace {
  494. width: 100%;
  495. margin-top: 100rpx;
  496. }
  497. .btm-btn {
  498. width: 670rpx;
  499. height: 98rpx;
  500. background: linear-gradient(315deg, #3387ff 2%, #569bff 99%);
  501. border-radius: 8rpx;
  502. box-shadow: 0px 0px 8rpx 0px rgba(51, 135, 255, 0.2);
  503. font-size: 32rpx;
  504. font-weight: 500;
  505. text-align: center;
  506. color: #fff;
  507. line-height: 98rpx;
  508. margin: 0 auto;
  509. margin-top: 50rpx;
  510. }
  511. .tips {
  512. font-size: 26rpx;
  513. color: #999;
  514. }
  515. .item-bg {
  516. width: 670rpx;
  517. /* height: 298rpx; */
  518. background: #f6f8fe;
  519. border-radius: 12rpx;
  520. margin: 0 auto;
  521. font-size: 28rpx;
  522. font-family: PingFang SC, PingFang SC-Regular;
  523. font-weight: 400;
  524. color: #333333;
  525. padding: 36rpx 32rpx;
  526. }
  527. .item-del {
  528. width: 40rpx;
  529. height: 40rpx;
  530. }
  531. .mar64 {
  532. margin-bottom: 64rpx;
  533. }
  534. .item-bg .mar64:last-child {
  535. margin-bottom: 0rpx;
  536. }
  537. .hg200rpx {
  538. height: 100rpx;
  539. }
  540. .mgr57 {
  541. margin-bottom: 57rpx;
  542. }
  543. .item-bg-32 {
  544. margin-right: 32rpx;
  545. }
  546. </style>