index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <view :style="{ minHeight: sys.windowHeight + 'px' }"
  3. :class="[$tm.vx.state().tmVuetify.black ? 'black' : ' ']">
  4. <tm-menubars title="衣物录入" :shadow="0" :showback="true"></tm-menubars>
  5. <div class="zhuti">
  6. <tm-sheet class="kuang" style="padding-bottom: 70px !important;">
  7. <image v-if="active==1" class="jindu" src="/static/img/49.png" mode="widthFix"></image>
  8. <image v-if="active==2" class="jindu" src="/static/img/50.png" mode="widthFix"></image>
  9. <image v-if="active==3" class="jindu" src="/static/img/51.png" mode="widthFix"></image>
  10. <view class="wenzi flex-between flex-center" style="margin-top: 10px;">
  11. <view>
  12. <text class="text-white text-size-m">衣物拍照</text>
  13. </view>
  14. <view>
  15. <text class="text-white text-size-m">确认衣物属性</text>
  16. </view>
  17. <view>
  18. <text class="text-white text-size-m">入库成功</text>
  19. </view>
  20. </view>
  21. <view v-if="active==1">
  22. <view class="mt-20 ml-15">
  23. <text class="text-white text-size-m">*衣物拍照实例图</text>
  24. </view>
  25. <image block class="zhanshi" mode="widthFix" src="/static/img/48.png"></image>
  26. <tm-button :round="24" class="mb-40" @click="paizhao()" block>拍照录入</tm-button>
  27. </view>
  28. <view v-if="active==2">
  29. <image v-if="alldata" block class="nicheng" mode="widthFix" :src="alldata.img"></image>
  30. <view class="you black mt-30">
  31. <view v-for="(item,index) in arrbig">
  32. <tm-pickers :default-value="getshow(item)" class="tan" v-if="item.type=='select'" @confirm="xuanze" :indexfu="item.name" :list="item.value">
  33. <tm-input :title="item.name" align="right" :placeholder="'请选择'+item.name" v-model="item.choosevalue" disabled right-icon="icon-angle-right"></tm-input>
  34. </tm-pickers>
  35. <tm-input v-if="item.type=='text' && item.name !='颜色'" :title="item.name" v-model="item.choosevalue" align="right"></tm-input>
  36. <view class="border-b-0 border-grey-darken-4-b-1 py-24 flex-between" v-if="item.name=='颜色'">
  37. <text class="text-size-n ">{{item.name}}</text>
  38. <view>
  39. <view class="seka" :style="{'backgroundColor':item.choosevalue}" @tap="showPickerColorPop"></view>
  40. <picker-color :isShow="showPickerColor" :bottom="bottomPickerColor" @callback='getPickerColor' />
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <tm-button :round="24" class="sao mb-40 mt-40" @click="chuangjianFun()" block>提交</tm-button>
  46. </view>
  47. <view v-if="active==3">
  48. <tm-translate ref="a_1" :auto="true" animation-name="zoomIn">
  49. <image block class="nicheng" mode="widthFix" src="/static/img/52.png"></image>
  50. </tm-translate>
  51. <view class="text-align-center mt-20">
  52. <text class="text-size-m text-white">衣物添加成功!</text>
  53. </view>
  54. <view class="text-align-center mb-40">
  55. <text class="text-size-m">您可以在我的衣柜中添加或删除衣物</text>
  56. </view>
  57. <view class="px-24">
  58. <tm-button @click="jixu()" :round="24" block class="mt-50 logincla">继续添加衣物</tm-button>
  59. <tm-button @click="quindex()" theme="primary" :round="24" block class="mt-30 quindex">进入衣柜</tm-button>
  60. </view>
  61. </view>
  62. </tm-sheet>
  63. </div>
  64. <!-- 弹出层消息 -->
  65. <tm-message ref="toast"></tm-message>
  66. </view>
  67. </template>
  68. <script>
  69. import{myRequest} from '@/api/request.js'
  70. import { pathToBase64, base64ToPath } from '@/js_sdk/mmmm-image-tools/index.js'
  71. import pickerColor from "@/components/helang-pickerColor/helang-pickerColor.vue"
  72. export default {
  73. components: {
  74. "picker-color":pickerColor,
  75. },
  76. data() {
  77. return {
  78. buttonColor:"#0099FF",
  79. showPickerColor:false,
  80. bottomPickerColor:0,
  81. arrbig:[],
  82. koutu:'/static/img/53.png',
  83. active:1,
  84. role_arr:[],
  85. fenlei:[],
  86. alldata:{},
  87. lable_code:''
  88. };
  89. },
  90. onLoad(e) {
  91. console.log(e)
  92. this.lable_code=e.lable_code;
  93. },
  94. created() {
  95. this.sys = uni.getSystemInfoSync();
  96. this.getCY();
  97. },
  98. methods: {
  99. getshow(data){
  100. return [data.choosevalue]
  101. },
  102. /* 显示获取颜色选择弹窗 */
  103. showPickerColorPop(){
  104. this.showPickerColor=true;
  105. },
  106. /* 获取颜色选择回调 */
  107. getPickerColor(color){
  108. /* 隐藏弹窗 */
  109. this.showPickerColor=false;
  110. /* 判断颜色值是否有效 */
  111. if(color){
  112. this.buttonColor=color;
  113. var xunhuan=this.arrbig;
  114. for(let i=0;i<xunhuan.length;i++){
  115. if(xunhuan[i].name=="颜色"){
  116. xunhuan[i].choosevalue=color
  117. }
  118. }
  119. }
  120. },
  121. showPickerColorPop(){
  122. this.showPickerColor=true;
  123. },
  124. xuanze(data){
  125. for(let i=0;i<this.arrbig.length;i++){
  126. if(this.arrbig[i].name==data[0].name){
  127. this.arrbig[i].choosevalue=data[0].data
  128. }
  129. }
  130. },
  131. getCY(){
  132. var that=this;
  133. myRequest({
  134. url: "/api/MemberInfo/getFamilyMember",
  135. method:'post',
  136. data:{family_id:uni.getStorageSync("family_id")}
  137. }).then(res => {
  138. if (res.data.code == 200) {
  139. that.role_arr=res.data.data;
  140. }else{
  141. that.role_arr=[];
  142. }
  143. })
  144. },
  145. obTstr1(o){
  146. if(Array.isArray(o)){
  147. if(o.length.length===0) return "";
  148. return o[0]?.category_name??""
  149. }
  150. return ''
  151. },
  152. obTstr2(o){
  153. if(Array.isArray(o)){
  154. if(o.length.length===0) return "";
  155. return o[0]?.title??""
  156. }
  157. return ''
  158. },
  159. obTstr3(o){
  160. if(Array.isArray(o)){
  161. if(o.length.length===0) return "";
  162. return o[0]?.username??""
  163. }
  164. return ''
  165. },
  166. jixu(){
  167. this.active=1;
  168. },
  169. quindex(){
  170. uni.switchTab({
  171. url: "/pages/wardrobe/index",
  172. success: function (e) {
  173. var page = getCurrentPages()[0]
  174. console.log(getCurrentPages())
  175. if (page == undefined || page == null) return;
  176. page.shuaxin();
  177. }
  178. })
  179. },
  180. paizhao(){
  181. var that=this;
  182. uni.chooseImage({ //uni官方api,用于选取本地图片
  183. count: 1, //默认9
  184. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  185. sourceType: ['album','camera'], //从相册选择
  186. success: function (res) {
  187. that.imgpath = res.tempFilePaths[0] //先获得本地文件的路径列表,存储到数组
  188. console.log(that.imgpath) //注意该api会将路径转换为blob格式
  189. // that.getBase64Image(that.imgpath);
  190. // 调脚本接口
  191. that.jiaobenFun()
  192. }
  193. })
  194. },
  195. obTstrnew(o){
  196. if(Array.isArray(o)){
  197. if(o.length.length===0) return "";
  198. return o[0]?.category_name??""
  199. }
  200. return ''
  201. },
  202. jiaobenFun(){
  203. var that=this;
  204. myRequest({
  205. url: "/api/Goods/selectScript",
  206. method:'post',
  207. data:''
  208. }).then(res => {
  209. if (res.data.code == 200) {
  210. // var arrbig=[
  211. // {name:"名称",value:"羽绒服",choosevalue:'',type:'text'},
  212. // {name:"颜色",value:"#b1b1b1",choosevalue:'',type:'text'},
  213. // {name:"尺码",value:["S","L","M"],choosevalue:'L',type:'select'},
  214. // {name:"材质",value:["牛仔","纯棉","羊毛"],choosevalue:'纯棉',type:'select'}
  215. // ]
  216. that.alldata=res.data.data;
  217. that.arrbig=res.data.data.parm;
  218. // var xunhuan=that.arrbig;
  219. // for(let i=0;i<xunhuan.length;i++){
  220. // if(xunhuan[i].name=="颜色"){
  221. // that.buttonColor="#"+xunhuan[i].choosevalue
  222. // }
  223. // }
  224. myRequest({
  225. url: "/api/Category/list",
  226. method:'post',
  227. data:''
  228. }).then(res => {
  229. if (res.data.code == 200) {
  230. var valuearr=[],rolevaluearr=[];
  231. for(let i=0;i<res.data.data.length;i++){
  232. valuearr.push(res.data.data[i].category_name)
  233. }
  234. for(let i=0;i<that.role_arr.length;i++){
  235. rolevaluearr.push(that.role_arr[i].username)
  236. }
  237. var arrsmall=[
  238. {name:"分类",value:valuearr,choosevalue:'',type:'select',classid:''},
  239. {name:"所属成员",value:rolevaluearr,choosevalue:'',type:'select',memberid:''},
  240. ];
  241. that.arrbig=arrsmall.concat(that.arrbig)
  242. that.fenlei=res.data.data;
  243. that.active=2;
  244. }else{
  245. }
  246. })
  247. }else{
  248. }
  249. })
  250. },
  251. getBase64Image(path){
  252. var that=this;
  253. pathToBase64(path)
  254. .then(base64 => {
  255. that.shibie(base64)
  256. })
  257. .catch(error => {
  258. console.error(error)
  259. })
  260. },
  261. shibie(src){
  262. var that=this;
  263. // 抠图
  264. uni.request({
  265. url: 'https://objseg.market.alicloudapi.com/commonseg/rgba',
  266. method : "post",
  267. header: {
  268. 'Authorization':'APPCODE a4a922a41afa43a0bbca6c831a13bf43',
  269. "Content-Type":"application/json;charset=UTF-8"
  270. },
  271. data:{
  272. photo:src
  273. },
  274. success : function(data) {
  275. that.koutu=data.data.data.result;
  276. that.active=2;
  277. },
  278. error : function(e) {
  279. that.$refs.toast.show({model:'error',label:"网络异常,请重试"})
  280. }
  281. });
  282. },
  283. chuangjianFun(){
  284. var that=this;
  285. for(let i=0;i<that.arrbig.length;i++){
  286. if(that.arrbig[i].choosevalue==""){
  287. that.$refs.toast.show({model:'warn',label:'请将数据填写完整'})
  288. return
  289. }
  290. }
  291. // 分类id
  292. for(let i=0;i<that.fenlei.length;i++){
  293. if(that.fenlei[i].category_name==that.arrbig[0].choosevalue){
  294. that.arrbig[0].classid=that.fenlei[i].id
  295. }
  296. }
  297. // 成员id
  298. console.log(that.role_arr)
  299. for(let i=0;i<that.role_arr.length;i++){
  300. if(that.role_arr[i].username==that.arrbig[1].choosevalue){
  301. that.arrbig[1].memberid=that.role_arr[i].id
  302. }
  303. }
  304. // 去掉图片的头
  305. var img=""
  306. if(that.alldata.img){
  307. var oldimg=that.alldata.img;
  308. img=oldimg.substr(24)
  309. }
  310. myRequest({
  311. url: "/api/Goods/addGodds",
  312. method:'post',
  313. data:{
  314. img:img,
  315. id:that.alldata.id,
  316. parm:that.arrbig,
  317. lable_code:that.lable_code
  318. }
  319. }).then(res => {
  320. console.log({
  321. img:img,
  322. id:that.alldata.id,
  323. parm:that.arrbig,
  324. lable_code:that.lable_code
  325. })
  326. if (res.data.code == 200) {
  327. that.active=3;
  328. }else{
  329. that.$refs.toast.show({model:'error',label:res.data.msg})
  330. }
  331. })
  332. }
  333. },
  334. }
  335. </script>
  336. <style lang="scss">
  337. .zhanshi{
  338. width: 100%;
  339. margin: 0 auto;
  340. margin-top: 10px;
  341. margin-bottom: 40px;
  342. }
  343. /deep/ .tm-menubars .body{
  344. background-color: #1b1b1b !important;
  345. }
  346. /deep/ .kuang{margin:0 !important;padding: 14px !important;margin-bottom: 40px !important;}
  347. // /deep/ .kuang uni-button{background-color: #303440 !important;}
  348. .jindu{width: 90%;margin: 0 auto;display: block;}
  349. .wenzi{width: 94%;margin: 0 auto;}
  350. .nicheng{width: 60%;display: block;margin:0 auto;margin-top: 50px;}
  351. /deep/ .shuru .grey-darken-5{
  352. background-color: #0d0d0d!important;
  353. padding: 0px !important;
  354. }
  355. .shuru{border:1px solid #303030;border-radius: 10px;}
  356. /deep/ .shuru .text-primary.bk{color:#303030 !important;}
  357. /deep/ .shuru .border-grey-darken-4-b-1{border-bottom:none !important;}
  358. .zuo image{width:60px;display: block;}
  359. .you{border:1px solid #303030;border-radius: 10px;padding:10px;}
  360. /deep/ .you .grey-darken-5{
  361. background-color: #0d0d0d!important;
  362. padding: 0px !important;
  363. }
  364. /deep/ .you .text-red{color: white;}
  365. /deep/ .tan .active{background-color: #AAAAAA !important;}
  366. /deep/ .tan .tm-poups .grey-darken-5{background-color: gray !important;}
  367. /deep/ .tan uni-input{text-align: right;}
  368. /deep/ .you .border-grey-darken-4-b-1 {
  369. border-bottom: solid 1px #313131 !important;
  370. }
  371. /deep/ .tm--badges{position: absolute;top: 0px;right:6px}
  372. .logincla{margin-top: 100px;}
  373. /deep/ .logincla .primary{background-color: #303440 !important;}
  374. /deep/ .quindex uni-button{background-color: #0A84FF !important;}
  375. .seka{width: 40px;height: 20px;border:1px solid white;}
  376. </style>